/DICK.B1/IronPython.DICK/Other.cs
C# | 313 lines | 264 code | 35 blank | 14 comment | 16 complexity | e7832370ac0d0599466a824027ee30e9 MD5 | raw file
- /* ****************************************************************************
- *
- * Copyright (c) Microsoft Corporation.
- *
- * This source code is subject to terms and conditions of the Microsoft Public License. A
- * copy of the license can be found in the License.html file at the root of this distribution. If
- * you cannot locate the Microsoft Public License, please send an email to
- * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
- * by the terms of the Microsoft Public License.
- *
- * You must not remove this notice, or any other, from this software.
- *
- *
- * ***************************************************************************/
-
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Reflection;
- using System.Text;
- using System.Threading;
- using DICK.Core;
- using DICK.Core.JobManagement;
- using DICK.B1;
- using SAPbobsCOM;
-
- using Microsoft.Scripting;
- using Microsoft.Scripting.Actions;
- using Microsoft.Scripting.Runtime;
- using Microsoft.Scripting.Utils;
-
- using IronPython.Compiler;
- using IronPython.Runtime;
- using IronPython.Runtime.Binding;
- using IronPython.Runtime.Exceptions;
- using IronPython.Runtime.Operations;
- using IronPython.Runtime.Types;
-
- #if CLR2
- using Microsoft.Scripting.Math;
- using Complex = Microsoft.Scripting.Math.Complex64;
- #else
- using System.Numerics;
- #endif
-
- [assembly: PythonModule("__builtin__", typeof(IronPython.Modules.Builtin))]
- namespace IronPython.Modules {
- public static partial class Builtin {
-
- private static CompanyClass getsession()
- {
- B1Engine engine = B1Engine.GetInstance();
- return engine.session;
- }
-
- public static IronPython.Runtime.List getservices()
- {
- return getservices(B1Engine.LISTCASE.CASE_UPPER);
- }
-
- public static IronPython.Runtime.List getservices(B1Engine.LISTCASE listcase)
- {
- IronPython.Runtime.List list = new IronPython.Runtime.List();
- foreach (string servicename in B1Engine.GetInstance().B1ServiceList.Keys)
- {
- ProcessName(listcase, list, servicename);
- }
- return list;
- }
-
- public static IronPython.Runtime.List getbusinessobjects()
- {
- return getbusinessobjects(B1Engine.LISTCASE.CASE_UPPER);
- }
-
- public static IronPython.Runtime.List getbusinessobjects(B1Engine.LISTCASE listcase)
- {
- IronPython.Runtime.List list = new IronPython.Runtime.List();
- foreach (string objectname in B1Engine.GetInstance().B1ObjectList.Keys)
- {
- ProcessName(listcase, list, objectname);
- }
- return list;
- }
-
- private static void ProcessName(B1Engine.LISTCASE listcase, IronPython.Runtime.List list, string objectname)
- {
- switch (listcase)
- {
- case B1Engine.LISTCASE.CASE_LOWER:
- list.AddNoLockNoDups(objectname.ToLower());
- break;
- case B1Engine.LISTCASE.CASE_UPPER:
- list.AddNoLockNoDups(objectname.ToUpper());
- break;
- case B1Engine.LISTCASE.CASE_MIXED:
- if (!objectname.isupper() && !objectname.islower())
- list.AddNoLockNoDups(objectname);
- break;
- case B1Engine.LISTCASE.CASE_ALL:
- list.AddNoLockNoDups(objectname);
- break;
- default:
- list.AddNoLockNoDups(objectname);
- break;
- }
- }
-
- public static object getservice(SAPbobsCOM.ServiceTypes servicetype, object datainterface)
- {
- CompanyClass session = getsession();
- try
- {
- SAPbobsCOM.CompanyService companyservice;
- companyservice = session.GetCompanyService();
- object svc = companyservice.GetBusinessService(servicetype);
- string expr = servicetype.ToString() + ".GetDataInterface(" + datainterface.ToString() + ")";
- return B1Engine.GetInstance().ExecutePython(expr);
- }
- catch (Exception ex)
- {
- return ex.Message;
- }
- }
-
- public static object getservice(SAPbobsCOM.ServiceTypes servicetype)
- {
- CompanyClass session = getsession();
- try
- {
- SAPbobsCOM.CompanyService companyservice;
- companyservice = session.GetCompanyService();
- return companyservice.GetBusinessService(servicetype);
- }
- catch (Exception ex)
- {
- return ex.Message;
- }
- }
-
- public static int getlasterrorcode()
- {
- CompanyClass session = getsession();
- return session.GetLastErrorCode();
- }
-
- public static int getlasterrorcode(CompanyClass session)
- {
- return session.GetLastErrorCode();
- }
-
- public static string getlasterrordescription()
- {
- CompanyClass session = getsession();
- return session.GetLastErrorDescription();
- }
-
- public static string getlasterrordescription(CompanyClass session)
- {
- return session.GetLastErrorDescription();
- }
-
- public static string getlasterror()
- {
- CompanyClass session = getsession();
- return getlasterror(session);
- }
-
- public static string getlasterror(CompanyClass session)
- {
- string errcode = session.GetLastErrorCode().ToString();
- string errtext = session.GetLastErrorDescription();
- string err = errcode;
- if (errtext != null && !errtext.Trim().Equals(""))
- {
- err += " " + errtext;
- }
- return err;
- }
-
- public static void release(object o)
- {
- if (o != null)
- {
- System.Runtime.InteropServices.Marshal.FinalReleaseComObject(o);
- }
- }
-
- public static Recordset query(string query)
- {
- CompanyClass session = getsession();
- Recordset rs = session.GetBusinessObject(BoObjectTypes.BoRecordset) as Recordset;
- rs.DoQuery(query);
- return rs;
- }
-
- public static Recordset query(string query, CompanyClass session)
- {
- Recordset rs = session.GetBusinessObject(BoObjectTypes.BoRecordset) as Recordset;
- rs.DoQuery(query);
- return rs;
- }
-
- public static IEnumerable<object> inspect(object o)
- {
- Type t = o.GetType();
- MemberInfo[] mis=t.GetMembers();
- foreach(MemberInfo mi in mis)
- {
- yield return mi.Name;
- }
- }
-
-
-
- public static IEnumerable<object> browse(object o)
- {
- if (o is Recordset)
- {
- Recordset rs = (Recordset)o;
- if (rs.Fields.Count == 1)
- {
- return new ColumnBrowser(null, rs);
- }
- else
- {
- return new RowBrowser(rs);
- }
- }
- if(o is IronPython.Runtime.List)
- {
- return new PythonListBrowser((IronPython.Runtime.List)o);
- }
- else
- {
- return new Browser(o);
- }
- }
-
- public static IEnumerable<object> browse(BoObjectTypes objtype, SAPbobsCOM.Recordset rs)
- {
- object o = get(objtype);
- return new BOBSObjectRecordSetBrowser(o, rs);
- }
-
- public static IEnumerable<object> browse(BoObjectTypes objtype, SAPbobsCOM.Recordset rs, CompanyClass session)
- {
- object o = session.GetBusinessObject(objtype);
- return new BOBSObjectRecordSetBrowser(o, rs);
- }
-
- public static IEnumerable<object> browse(SAPbobsCOM.Recordset rs, string columnname)
- {
- return new ColumnBrowser(columnname, rs);
- }
-
- public static ExportJob getexportjob(string jobname)
- {
- return Engine.GetInstance().GetExportJob(jobname);
- }
-
- public static B1ImportJob getimportjob(string jobname)
- {
- return B1Engine.GetInstance().GetImportJob(jobname);
- }
-
- public static GenericJob getgenericjob(string jobname)
- {
- return Engine.GetInstance().GetGenericJob(jobname);
- }
-
- public static object get(string objectname)
- {
- B1Engine engine=B1Engine.GetInstance();
- if(engine.pythoninitialized)
- {
- object handle = B1Engine.GetInstance().scope.GetVariable(objectname.ToUpper());
- if (handle != null && handle.GetType().Equals(typeof(BoObjectTypes)))
- {
- return get((BoObjectTypes)handle);
- }
- else
- {
- engine.LogError("Could not retrieve handle for " + objectname);
- return null;
- }
- }
- else
- {
- engine.LogError("Python Engine not initialized !!!");
- return null;
- }
-
- }
-
- public static DICKContext export(string jobname, DICKContext context, params String[] args)
- {
- B1Engine b1engine = B1Engine.GetInstance();
- ExportJob job=b1engine.GetExportJob(jobname);
- List<String> keys=new List<String>();
- foreach(String arg in args)
- {
- keys.Add(arg);
- }
- job.DoExportByKeys(keys);
- return context;
- }
- }
- }