/DICK.B1/B1Engine.cs
C# | 907 lines | 778 code | 63 blank | 66 comment | 64 complexity | 6d058743098a8215a3fcb742cea683f3 MD5 | raw file
- /* This file is part of DI Construction Kit.
- *
- * DI Construction Kit is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * DI Construction Kit is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with DI Construction Kit. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- using System;
- using System.Collections;
- using System.Reflection;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using System.Data;
- using DICK;
- using DICK.Core;
- using DICK.Core.JobManagement;
- using SAPbobsCOM;
- using System.Xml;
- using IronPython.Hosting;
- using IronPython.Runtime;
- using Microsoft.Scripting;
- using Microsoft.Scripting.Hosting;
- using Fireball.Syntax;
-
-
- namespace DICK.B1
- {
- /// <summary>
- /// B1Engine is an extension of the DICK.Core.Engine class
- /// that adds the B1-dependent functionality to the core class.
- /// </summary>
- public class B1Engine : Engine
- {
- public const int MAGIC_NULLERRORCODE = -666;
-
- private DataTable dataservertypes;
-
- /// <summary>
- /// DataTable containing the database server types supported by DICK.
- /// </summary>
- public DataTable DataServerTypes
- {
- get
- {
- return dataservertypes;
- }
- }
- public string systemdescription;
- public CompanyClass session;
- private static B1Engine B1instance;
- public static bool AutoRelease { get; set; }
- public bool pythoninitialized = false;
- public ScriptEngine pythonengine;
- public ScriptScope scope;
- public Dictionary<string, object> B1EnumClassList = new Dictionary<string, object>();
- public Dictionary<string, object> B1EnumList = new Dictionary<string, object>();
- public Dictionary<string, object> B1EnumValues = new Dictionary<string, object>();
- public Dictionary<string, object> B1ObjectList = new Dictionary<string, object>();
- public Dictionary<string, object> B1ServiceList = new Dictionary<string, object>();
- public enum LISTCASE {
- /// <summary>
- /// Uppercase
- /// </summary>
- CASE_UPPER,
- /// <summary>
- /// Lowercase
- /// </summary>
- CASE_LOWER,
- /// <summary>
- /// Any case
- /// </summary>
- CASE_ALL,
- /// <summary>
- /// Upper and lower case mixed
- /// </summary>
- CASE_MIXED};
-
- private B1Engine()
- {
- PopulateDataServerTypeList();
- PopulateB1BusinessObjectList();
- PopulateB1ServiceList();
- PopulateB1EnumList();
- }
-
- private void PopulateB1ServiceList()
- {
- foreach (object st in Enum.GetValues(typeof(SAPbobsCOM.ServiceTypes)))
- {
- string sname = st.ToString();
- AddIfKeyNotExists(B1ServiceList, sname, st);
- AddIfKeyNotExists(B1ServiceList, sname.ToLower(), st);
- AddIfKeyNotExists(B1ServiceList, sname.ToUpper(), st);
- AddIfKeyNotExists(B1ServiceList, sname.Substring(0,sname.Length-7), st);
- AddIfKeyNotExists(B1ServiceList, sname.Substring(0, sname.Length - 7).ToLower(), st);
- AddIfKeyNotExists(B1ServiceList, sname.Substring(0, sname.Length - 7).ToUpper(), st);
- }
- }
-
- private void PopulateDataServerTypeList()
- {
- dataservertypes = new DataTable("ServerTypes");
- dataservertypes.Columns.Add("ServerTypeName", typeof(String));
- dataservertypes.Columns.Add("ServerType", typeof(BoDataServerTypes));
- string[] dbtypenames = Enum.GetNames(typeof(BoDataServerTypes));
- System.Array dbtypevalues = Enum.GetValues(typeof(BoDataServerTypes));
- for (int i = 0; i < dbtypenames.Length; i++)
- {
- string dbtypename = dbtypenames[i].Substring(4, dbtypenames[i].Length - 4).Replace("_", "");
- dataservertypes.Rows.Add(dbtypename, dbtypevalues.GetValue(i));
- }
- }
-
- private string currentIP;
- public string CurrentImportProgram
- {
- get { return currentIP; }
- set { currentIP = value; }
- }
-
- private string currentPythonJob;
-
- public string CurrentPythonJob
- {
- get { return currentPythonJob; }
- set { currentPythonJob = value; }
- }
-
- /// <summary>
- /// Used to retrieve a correct type of job
- /// </summary>
- /// <param name="jobid"></param>
- /// <param name="row"></param>
- /// <returns></returns>
- /// <exclude/>
- protected override ExportJob GetRealJob(string jobid, XmlElement row)
- {
- XmlNode b1 = row.SelectSingleNode("B1Required");
- if (b1 != null)
- {
- string b1RequiredString = b1.InnerText.ToLower().Trim();
- if (b1RequiredString.Equals("true"))
- {
- return new B1ExportJob(jobid, row);
- }
- else
- {
- return new ExportJob(jobid, row);
- }
- }
- else
- {
- LogError("ENGINE.GETREALJOB: B1REQUIRED PARAMETER NOT FOUND FOR JOB " + jobid);
- return null;
- }
- }
-
- public B1ImportJob SetCurrentImportJob(string ID)
- {
- currentIP = ID;
- return GetImportJob(currentIP);
- }
-
- public B1ImportJob GetCurrentImportJob()
- {
- return GetImportJob(currentIP);
- }
-
- public B1PythonJob SetCurrentPythonJob(string ID)
- {
- CurrentPythonJob = ID;
- return GetPythonJob(ID);
- }
-
- public B1PythonJob GetPythonJob(string name)
- {
- FileInfo fi = new FileInfo(pythonjobdirectory + name + ".xml");
- if (fi.Exists)
- {
- XmlDocument doc = new XmlDocument();
- try
- {
- doc.Load(fi.FullName);
- //Calling the virtual method here - it's overridden in B1Engine
- return new B1PythonJob(name, doc.DocumentElement);
- }
- catch (XmlException xex)
- {
- LogError("Failed parsing the xml document for ExportJob " + name + ":" + xex.Message);
- return null;
- }
- }
- else
- {
- LogError("ExportJob " + fi.FullName + " not found!");
- return null;
- }
- }
-
- public B1ImportJob GetImportJob(string name)
- {
- FileInfo fi = new FileInfo(importjobdirectory + name + ".xml");
- if (fi.Exists)
- {
- XmlDocument doc = new XmlDocument();
- try
- {
- doc.Load(fi.FullName);
- return new B1ImportJob(name, doc.DocumentElement);
- }
- catch (XmlException xex)
- {
- LogError("Failed parsing the xml document for ExportJob " + name + ":" + xex.Message);
- return null;
- }
- }
- else
- {
- LogError("ExportJob " + fi.FullName + " not found!");
- return null;
- }
- }
-
- public System.Collections.Generic.List<B1ImportJob> ListImports()
- {
- System.Collections.Generic.List<B1ImportJob> imports = new System.Collections.Generic.List<B1ImportJob>();
-
- DirectoryInfo di = new DirectoryInfo(importjobdirectory);
- if (di.Exists)
- {
- FileInfo[] files = di.GetFiles("*.xml");
- foreach (FileInfo file in files)
- {
- XmlDocument doc = new XmlDocument();
- doc.Load(file.FullName);
- try
- {
- imports.Add(new B1ImportJob(file.Name.Substring(0, file.Name.Length - 4), doc.DocumentElement));
- }
- catch (Exception ex)
- {
- Engine.GetInstance().LogDebug("Failed to initialize ImportJob " + file.Name + ". Errormessage:" + ex.Message);
- }
- }
- }
- else
- {
- LogError("The importjob directory " + di.FullName + " does not exist! ");
- }
- return imports;
- }
-
- /// <summary>
- /// Returns the singleton instance of B1Engine
- /// </summary>
- /// <returns></returns>
- public static new B1Engine GetInstance()
- {
- if (B1instance == null)
- {
- B1Init();
- }
- if (B1instance == null)
- {
- throw new DICKException();
- }
- return B1instance;
- }
-
- public ScriptEngine PythonInit(Stream outstream, Stream tracestream)
- {
- LogDebug("Initializing PythonEngine...");
- if (pythoninitialized)
- {
- LogDebug("Python already initialized.");
- return pythonengine;
- }
- else
- {
- pythonengine = Python.CreateEngine();
- scope = pythonengine.CreateScope();
- AddSessionHandleToPythonScope();
- MapStreams(outstream, tracestream);
- AddCurrentPathToPythonSearchPath();
- //pythonengine.SetStandardOutput(outstream);
- /* HUOMIOI NÄMÄ !!!
- pythonengine.SetStandardError(new MyStream(Shell));
- */
- AddDefaultReferencesToPythonScope();
- AddB1BusinessObjectReferencesToPythonScope();
- AddServiceReferencesToPythonScope();
- AddToolReferencesToPythonScope();
- AddB1EnumReferencesToPythonScope();
- pythoninitialized = true;
- }
- return pythonengine;
- }
-
- private void MapStreams(Stream outstream, Stream tracestream)
- {
- if (outstream != null)
- {
- pythonengine.Runtime.IO.SetOutput(outstream, Encoding.Default);
- }
- if (tracestream != null)
- {
- pythonengine.Runtime.IO.SetErrorOutput(tracestream, Encoding.Default);
- }
- }
-
- private void AddCurrentPathToPythonSearchPath()
- {
- List<string> paths = new List<string>();
- paths.Add(Environment.CurrentDirectory);
- pythonengine.SetSearchPaths(paths);
- }
-
- private void AddSessionHandleToPythonScope()
- {
- if (Connected)
- {
- scope.SetVariable("session", session);
- scope.SetVariable("Session", session);
- scope.SetVariable("SESSION", session);
- }
- else
- {
- LogError("Session is not connected!");
- throw new DICKException("B1Engine.PythonInit: Session is not connected!");
- }
- }
-
- private void AddB1BusinessObjectReferencesToPythonScope()
- {
- foreach (string key in B1ObjectList.Keys)
- {
- scope.SetVariable(key, B1ObjectList[key]);
- }
- }
-
- private void PopulateB1BusinessObjectList()
- {
- Array boobjecttypes = Enum.GetValues(typeof(SAPbobsCOM.BoObjectTypes));
- //IronPython.Runtime.List boobjecttypes = pythonengine.Execute<IronPython.Runtime.List>("dir(SAPbobsCOM.BoObjectTypes)", scope);
- foreach (object otype in boobjecttypes)
- {
- string otypename = otype.ToString();
- //if (otypename.StartsWith("o"))
- //{
- string handle;
- handle = ProcessObjectNames(otypename);
- //BoObjectTypes oref = pythonengine.Execute<BoObjectTypes>("SAPbobsCOM.BoObjectTypes." + otype, scope);
- //BoObjectTypes oref = Enum.GetValuesSAPbobsCOM.BoObjectTypes.//)Type.GetType("SAPbobsCOM.BoObjectTypes." + otype);
- AddIfKeyNotExists(B1ObjectList, handle, otype);
- AddIfKeyNotExists(B1ObjectList, handle.ToLower(), otype);
- AddIfKeyNotExists(B1ObjectList, handle.ToUpper(), otype);
- AddIfKeyNotExists(B1ObjectList, otypename, otype);
- AddIfKeyNotExists(B1ObjectList, otypename.ToLower(), otype);
- AddIfKeyNotExists(B1ObjectList, otypename.ToUpper(), otype);
- //}
- }
- }
-
- private static string ProcessObjectNames(string otypename)
- {
- string handle;
- int endcut = 2;
- if (otypename.ToUpper().EndsWith("US"))
- {
- endcut = 1;
- }
- else if (otypename.ToUpper().EndsWith("HES"))
- {
- endcut = 3;
- }
- else if (otypename.ToUpper().EndsWith("S"))
- {
- endcut = 2;
- }
- else
- {
- endcut = 1;
- }
- handle = otypename.Substring(1, otypename.Length - endcut).ToUpper();
- if (handle.EndsWith("IE"))
- {
- handle = handle.Substring(0, handle.Length - 2) + "Y";
- }
- return handle;
- }
-
- private void AddIfKeyNotExists(Dictionary<string, object> dictionary, string key, object value)
- {
- if (!dictionary.ContainsKey(key))
- {
- dictionary.Add(key, value);
- }
- }
-
- private void AddB1EnumReferencesToPythonScope()
- {
- foreach (string key in B1EnumList.Keys)
- {
- scope.SetVariable(key, B1EnumList[key]);
- }
- }
-
- private void PopulateB1EnumList()
- {
- System.Collections.Generic.List<string> enums = new System.Collections.Generic.List<string>();
- Assembly[] domainAssemblies = AppDomain.CurrentDomain.GetAssemblies();
- //TODO: In .NET 4.0 version, use LINQ for selecting the assemblies to process.
- foreach (Assembly ass in domainAssemblies)
- {
- if (ass.FullName.Contains("SAPbobsCOM"))
- {
- Type[] types = ass.GetTypes();
- foreach (Type type in types)
- {
- if (type.IsEnum)
- {
- string[] enumnames = System.Enum.GetNames(type);
- Array enumvalues = System.Enum.GetValues(type);
- for (int enumindex = 0; enumindex < enumnames.Length; enumindex++)
- {
- if (!enumnames[enumindex].StartsWith("o"))
- {
- B1EnumList.Add(enumnames[enumindex], enumvalues.GetValue(enumindex));
- B1EnumValues.Add(enumnames[enumindex], enumvalues.GetValue(enumindex).GetType().Name);
- Type enumclass = enumvalues.GetValue(enumindex).GetType();
- if (!B1EnumClassList.ContainsKey(enumclass.Name))
- {
- B1EnumClassList.Add(enumclass.Name, null);
- }
- }
- //enums.Add(type.Name + ":" + enumvalues.GetValue(enumindex));
- }
- }
- }
- }
- }
- }
-
- private void AddDefaultReferencesToPythonScope()
- {
- pythonengine.Execute("import clr;clr.AddReferenceToFile(\"Interop.SAPbobsCOM.dll\")", scope);
- pythonengine.Execute("import SAPbobsCOM;import System;import System.IO;import System.Text;import System.Collections", scope);
- }
-
- private void AddToolReferencesToPythonScope()
- {
- scope.SetVariable("Engine", this);
- scope.SetVariable("engine", this);
- scope.SetVariable("ENGINE", this);
- scope.SetVariable("TextTools", typeof(TextTools));
- scope.SetVariable("texttools", typeof(TextTools));
- scope.SetVariable("TEXTTOOLS", typeof(TextTools));
- scope.SetVariable("XmlTools", typeof(XmlTools));
- scope.SetVariable("xmltools", typeof(XmlTools));
- scope.SetVariable("XMLTOOLS", typeof(XmlTools));
- scope.SetVariable("QueryToolsADO", typeof(QueryToolsADO));
- scope.SetVariable("querytoolsado", typeof(QueryToolsADO));
- scope.SetVariable("QUERYTOOLSADO", typeof(QueryToolsADO));
- scope.SetVariable("B1QueryTools", typeof(B1QueryTools));
- scope.SetVariable("b1querytools", typeof(B1QueryTools));
- scope.SetVariable("B1QUERYTOOLS", typeof(B1QueryTools));
- }
-
- private void AddServiceReferencesToPythonScope()
- {
- foreach (string stype in B1ServiceList.Keys)
- {
- object svc = B1ServiceList[stype];
- scope.SetVariable(stype, svc);
- }
- }
-
- public object ExecutePython(string statement)
- {
- if (pythoninitialized)
- {
- LogDebug("PYTHON EXECUTING: " + statement);
- object result = pythonengine.Execute(statement, scope);
- if (result != null)
- {
- LogDebug("PYTHON RETURNED: " + result.ToString());
- }
- else
- {
- LogDebug("PYTHON RETURNED NULL");
- }
- return result;
- }
- else
- {
- string message = "PYTHON ENGINE NOT INIIALIZED WHEN CALLING ExecutePython with statement " + statement;
- B1Engine.GetInstance().LogDebug(message);
- return message;
- }
- }
-
- public void ReleaseComObject(object o)
- {
- if (AutoRelease)
- {
- System.Runtime.InteropServices.Marshal.FinalReleaseComObject(o);
- }
- }
-
- public static string FormatValue(object initial, string format)
- {
- B1Engine app = B1Engine.GetInstance();
- if (initial == null || format == null)
- {
- app.LogWarn("ERROR: EITHER the initial value or the format string is null!");
- return "FORMAT OBJECT IS NULL";
- }
- try
- {
- switch (format.ToLower())
- {
- case "date":
- System.DateTime intermediateDate = (System.DateTime)initial;
- string res = intermediateDate.ToString("yyyyMMdd");
- app.LogDebug("Converted " + initial.ToString() + " into " + res);
- return res;
- case "currency":
- SBObob bob = (SBObob)app.session.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge);
- Recordset rs = bob.Format_MoneyToString((double)initial, BoMoneyPrecisionTypes.mpt_Sum);
- return rs.Fields.Item(0).Value.ToString().Replace(".", "");
- case "html":
- return TextTools.HtmlEncode(initial);
- case "url":
- return TextTools.UrlEncode(initial);
- case "xml":
- return TextTools.XmlEncode(initial);
- default:
- return "UNIDENTIFIED FORMAT";
- }
- }
- catch (Exception ex)
- {
- app.LogWarn("Failed to format value +" + initial + " to " + format + ". Message:" + ex.Message);
- return "Failed to format value " + initial == null ? "null" : initial.ToString() + " to " + format;
- }
- }
-
- #region Initialization and Login
-
- public static MessageToken B1Init()
- {
- return B1Init(null);
- }
-
- public static MessageToken B1Init(string workdirectory)
- {
- MessageToken res = new MessageToken();
- res.OK = false;
- if (B1instance == null)
- {
- //We need to initialize the base class first
- Engine coreengine = Engine.GetInstance();
- B1Engine.AutoRelease = true;
- B1instance = new B1Engine();
- //Set the instance Singleton field in the base class to point to the B1Engine instance.
- Engine.SetInstance(B1instance);
- //InitializeEngineclass is called from the base class
- res = InitializeEngine(workdirectory);
-
- if (res.OK)
- {
- B1instance.LogDebug("Creating an instance of SAPbobsCOM.CompanyClass...");
- try
- {
- B1instance.session = new SAPbobsCOM.CompanyClass();
- B1instance.LogDebug("OK");
- }
- catch (Exception ex)
- {
- B1instance.LogDebug("Instantiation failed:" + ex.Message);
- res.OK = false;
- res.AddTextToDetails("Instantiation failed:" + ex.Message);
- }
- return res;
- }
- else
- {
- Engine.GetInstance().LogError("Engine.B1Init failed:" + res.GetMessageBody());
- B1instance = null;
- Engine.SetInstance(null);
- res.AddTextToDetails("Returning from B1Init with failed CoreInit");
- return res;
- }
- }
- else
- {
- res.OK = true;
- return res;
- }
- }
-
-
- public CompanyClass Connect(string systemID, out string log)
- {
- MessageToken res = LoadSystemParameters(systemID);
- log = res.GetMessageBody();
- string log2;
- return Login(out log2);
- }
-
- /// <summary>
- /// Added to accommodate decoupling of DI API and the DICKcmd / DICK Visual Library assemblies.
- /// </summary>
- /// <param name="log"></param>
- public static void SilentLogin(out string log)
- {
- Login(out log);
- }
-
- public static CompanyClass Login(out string log)
- {
- log = "";
- B1Engine engine = B1Engine.GetInstance();
- if (engine.session == null)
- {
- engine.session = new CompanyClass();
- }
- engine.session.CompanyDB = engine.Db;
- engine.session.UserName = engine.User;
- engine.session.Password = engine.Password;
- engine.session.Server = engine.Host;
- engine.session.UseTrusted = engine.UseTrusted;
- BoDataServerTypes dst = BoDataServerTypes.dst_MSSQL2005;
- DataRow[] rows = engine.DataServerTypes.Select("ServerTypeName='" + engine.dataservertype + "'");
- if (rows.Length > 0)
- {
- dst = (BoDataServerTypes)rows[0]["ServerType"];
- }
- engine.session.DbServerType = dst;
- engine.session.language = BoSuppLangs.ln_English;
- if (!engine.session.UseTrusted)
- {
- engine.session.DbUserName = engine.dbusername;
- engine.session.DbPassword = engine.dbpwd;
- engine.session.LicenseServer = engine.LicenseServer;
- }
- int connectionFlag = -1;
- StringBuilder messages = new StringBuilder();
- try
- {
- messages.Append("Connecting... ");
- engine.LogInfo("Calling company.Connect()");
- connectionFlag = engine.session.Connect();
- engine.LogInfo("Connection flag:" + connectionFlag);
- }
- catch (NullReferenceException ex)
- {
- messages.Append(ex.Message);
- engine.LogError("Connection failed. There is a problem with the DI API.");
- engine.LogError(ex.Message);
- engine.LogError(ex.StackTrace);
- }
- if (connectionFlag == 0)
- {
- messages.Append("Connection ok");
- engine.LogInfo("Connected successfully to " + engine.session.CompanyName + ".");
- log += messages.ToString();
- string connectionstring = "Server = " + engine.Host + "; Database = " + engine.Db + "; User ID = " + engine.dbusername + "; Password = " + engine.dbpwd + "; Trusted_Connection = " + (engine.UseTrusted ? "True" : "False") + ";";
- engine.ConnectionString = connectionstring;
- return engine.session;
- }
- else
- {
- messages.Append(connectionFlag.ToString());
- int a;
- String b;
- engine.session.GetLastError(out a, out b);
- messages.Append(b);
- log += messages.ToString();
- engine.LogDebug("Login failed. Errorcode:" + a);
- engine.LogDebug("Error message:" + b);
- return null;
- }
- }
-
- #endregion
-
- public void SendSBOMessage(string[] recipients, string subject, string message)
- {
- try
- {
- Messages m = (Messages)session.GetBusinessObject(BoObjectTypes.oMessages);
- m.MessageText = message;
- m.Subject = subject;
- bool isfirstrecipient = true;
- foreach (string recipient in recipients)
- {
- if (!isfirstrecipient)
- {
- m.Recipients.Add();
- }
- m.Recipients.UserCode = recipient;
- m.Recipients.UserType = BoMsgRcpTypes.rt_InternalUser;
- m.Recipients.SendInternal = BoYesNoEnum.tYES;
- isfirstrecipient = false;
- }
- m.Add();
- }
- catch (Exception ex)
- {
- B1Engine.GetInstance().LogError("SendSBOMessage failed:" + ex.Message);
- }
- }
-
- #region Accessors and methods duplicated from SAPbobsCOM to enable decoupling of calling classes from DI API
- public String CompanyDB
- {
- get
- {
- return session.CompanyDB;
- }
- set
- {
- session.CompanyDB = value;
- }
- }
-
- public String DbPassword
- {
- get
- {
- return session.DbPassword;
- }
- set
- {
- session.DbPassword = value;
- }
- }
-
- public string DbServerType
- {
- get
- {
- return session.DbServerType.ToString();
- }
- set
- {
- const int FIRSTROW = 0;
- DataRow[] rows = DataServerTypes.Select("ServerTypeName='" + value + "'");
- if (rows != null && rows.Length > 0)
- {
- session.DbServerType = (BoDataServerTypes)rows[FIRSTROW]["ServerType"];
- }
-
- }
- }
-
- public string DbUserName
- {
- get
- {
- return session.DbUserName;
- }
- set
- {
- session.DbUserName = value;
- }
- }
-
- public string Server
- {
- get
- {
- return session.Server;
- }
- set
- {
- session.Server = value;
- }
- }
-
-
-
- public string CompanyName
- {
- get
- {
- return session.CompanyName;
- }
- }
-
- public bool Connected
- {
- get
- {
- return session != null && session.Connected;
- }
- }
-
- public void Disconnect()
- {
- if (session != null && session.Connected)
- {
- session.Disconnect();
- }
- }
-
- public int GetLastErrorCode()
- {
- if (session != null && session.Connected)
- {
- return session.GetLastErrorCode();
- }
- else
- {
- return MAGIC_NULLERRORCODE;
- }
- }
-
- public string GetLastErrorDescription()
- {
- if (session != null && session.Connected)
- {
- return session.GetLastErrorDescription();
- }
- else
- {
- return "SESSION INVALID OR NOT CONNECTED!";
- }
- }
- #endregion
-
- public ObjectTypeContainer[] GetObjectTypes()
- {
- string[] objectnames = Enum.GetNames(typeof(BoObjectTypes));
- ObjectTypeContainer[] otc = new ObjectTypeContainer[objectnames.Length];
- int ocounter = 0;
- foreach (string oname in objectnames)
- {
- BoObjectTypes t = (BoObjectTypes)Enum.Parse(typeof(BoObjectTypes), oname, true);
- ObjectTypeContainer li = new ObjectTypeContainer();
- li.Name = oname;
- li.Value = t;
- otc[ocounter] = li;
- ocounter++;
- }
- return otc;
- }
-
- public DataView GetCompanyDataView(B1Engine app)
- {
- Recordset rs;
- try
- {
- rs = app.session.GetCompanyList();
- }
- catch (System.Exception ex)
- {
- LogError(ex.Message);
- throw;
- }
- DataTable companytable = new DataTable("companies");
- DataColumn dbItem = new DataColumn("dbName", Type.GetType("System.String"));
- DataColumn cmpItem = new DataColumn("cmpName", Type.GetType("System.String"));
- DataColumn versItem = new DataColumn("versStr", Type.GetType("System.String"));
- companytable.Columns.Add(dbItem);
- companytable.Columns.Add(cmpItem);
- companytable.Columns.Add(versItem);
- DataView companyview = new DataView(companytable);
-
- int companyCount = rs.RecordCount;
- rs.MoveFirst();
- DataRow NewRow;
- for (int c = 0; c < companyCount; c++)
- {
- NewRow = companytable.NewRow();
- NewRow["dbName"] = rs.Fields.Item("dbName").Value;
- NewRow["cmpName"] = rs.Fields.Item("cmpName").Value;
- NewRow["versStr"] = rs.Fields.Item("versStr").Value;
- companytable.Rows.Add(NewRow);
- rs.MoveNext();
- }
- return companyview;
- }
-
- public object GetBOBHandle()
- {
- return session.GetBusinessObject(BoObjectTypes.BoBridge);
- }
- }
-
- public class ObjectTypeContainer
- {
- public string Name { get; set; }
- public BoObjectTypes Value { get; set; }
- }
- }