private void ListPlaceholders()
        {
            //Adding dynamic placeholders
            if (!string.IsNullOrEmpty(_pSmoSystemName))
            {
                SmartObjectClientServer smoServer = ServiceBroker.K2Connection.GetConnection <SmartObjectClientServer>();
                using (smoServer.Connection)
                {
                    var smo = smoServer.GetSmartObject(_pSmoSystemName);
                    smo.MethodToExecute = _pSmoListName;
                    var dt = smoServer.ExecuteListDataTable(smo);
                    foreach (DataRow row in dt.Rows)
                    {
                        _placeholders.AddItem(row[_pNameProperty].ToString());
                    }
                }
            }
            //Adding static placeholders
            //Adding static placeholders
            foreach (var item in GetStaticPlaceholders())
            {
                _placeholders.AddItem(item);
            }
            ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();
            DataTable results = ServiceBroker.ServicePackage.ResultTable;

            foreach (var item in _placeholders.Items)
            {
                DataRow dr = results.NewRow();
                dr[Constants.Properties.Placeholder]            = item.Name;
                dr[Constants.Properties.PlaceholderWithWrapper] = _placeholders.Wrapper + item.Name + _placeholders.Wrapper;
                results.Rows.Add(dr);
            }
        }
示例#2
0
        public UserAD GetByFQN(string userFQN)
        {
            UserAD result = null;

            if (userFQN.Length > 3)
            {
                K2Services svcK2 = new K2Services();
                svcK2.AppConfig = this.AppConfig;
                SmartObjectClientServer soServer = svcK2.NewSmartObjectClientServer();

                using (soServer.Connection)
                {
                    string soName     = this.AppConfig.SmartObjectName_ADUser;
                    string methodName = "GetUserDetails";
                    //load the SmartObject from the server.
                    SmartObject soAD_User = soServer.GetSmartObject(soName);

                    soAD_User.MethodToExecute = methodName;
                    //this particular method has an input parameter for the UserName
                    // Assign Input properties
                    soAD_User.Methods[methodName].InputProperties["UserName"].Value = userFQN.Right(userFQN.Length - 3);

                    soAD_User = soServer.ExecuteScalar(soAD_User);

                    result             = new UserAD();
                    result.Name        = soAD_User.Properties["Name"].Value;
                    result.DisplayName = soAD_User.Properties["DisplayName"].Value;
                    result.Email       = soAD_User.Properties["Email"].Value;
                }
            }
            return(result);
        }
        /// <summary>
        /// Set Smartobject Name and Method Name.
        /// </summary>
        /// <param name="soServer">The SmartObjectClientServer.</param>
        /// <param name="model">The Information smart object.</param>
        /// <returns></returns>
        private SmartObject WorkflowSmartObject(SmartObjectClientServer soServer, SmartObjectModel model)
        {
            var result = soServer.GetSmartObject(model.SmartObjectName);

            result.MethodToExecute = model.ExecuteMethodName;
            return(result);
        }
示例#4
0
        /// <summary>
        /// Method to check if a specified process instance still exists.
        /// </summary>
        /// <param name="procInstID">The process instance ID that needs to be checked.</param>
        /// <param name="server">An instance of the workflow management server.</param>
        /// <returns></returns>
        private bool ProcessInstanceExists(int procInstID, k2Mgnt.WorkflowManagementServer server)
        {
            // use SmartObjectClientServer for accessing SmartObjects
            SmartObjectClientServer sos = new SmartObjectClientServer();

            // prepare the connection
            sos.CreateConnection();

            // open the connection
            sos.Connection.Open(connectionString);

            // get a "Process Instance" SmartObject (an ootB K2 SmartObject > Workflow Reports > Workflow General)
            SmartObject so = sos.GetSmartObject("Process_Instance");

            // tell the SmartObject to return a list of results
            so.MethodToExecute = "List";

            // set filter for results - return the live instance for the specified procInstID
            so.Properties["ProcessInstanceID"].Value = procInstID.ToString();

            // execute - return the results as a DataTable
            DataTable dt = sos.ExecuteListDataTable(so);

            // if there's one row the instance is still there and not deleted
            if (dt.Rows.Count == 1)
            {
                // close the connection and return true
                sos.Connection.Close();
                return(true);
            }

            // if there is no row than the instance has been deleted
            return(false);
        }
        private void GetEmailTemplate()
        {
            //Getting all the ServiceConfig and Input properties
            var _inputSubject = GetStringProperty(Constants.Properties.InputEmailSubject) ?? string.Empty;
            var _inputBody    = GetStringProperty(Constants.Properties.InputEmailBody) ?? string.Empty;

            foreach (var idName in GetInputIds())
            {
                _inputIds.Add(idName, GetStringParameter(idName));
            }

            if (!string.IsNullOrEmpty(_pSmoSystemName))
            {
                SmartObjectClientServer smoServer = ServiceBroker.K2Connection.GetConnection <SmartObjectClientServer>();
                using (smoServer.Connection)
                {
                    var smo = smoServer.GetSmartObject(_pSmoSystemName);
                    smo.MethodToExecute = _pSmoListName;
                    var dt = smoServer.ExecuteListDataTable(smo);
                    foreach (DataRow row in dt.Rows)
                    {
                        var placeholder = _placeholders.Wrapper + row[_pNameProperty] + _placeholders.Wrapper;
                        //Getting only the placholders, which are used in the EmailSubject/EmailBody
                        if (_inputSubject.Contains(placeholder) || _inputBody.Contains(placeholder))
                        {
                            _placeholders.AddItem(row[_pNameProperty].ToString(), row[_pAdoNetProperty].ToString(), row[_pReturnProperty].ToString());
                        }
                    }
                }
                //Getting the values of the placeholders
                _placeholders.GetAllValues(_inputIds, ServiceBroker);
            }
            //Adding static placeholders
            foreach (var item in GetStaticPlaceholders())
            {
                _placeholders.AddItemWithValue(item, GetStringParameter(item));
            }
            //Replacing all the values
            var outputSubject = _placeholders.ReplacePlaceholders(_inputSubject);
            var outputBody    = _placeholders.ReplacePlaceholders(_inputBody);

            ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();
            DataTable results = ServiceBroker.ServicePackage.ResultTable;

            DataRow dr = results.NewRow();

            dr[Constants.Properties.OutputEmailBody]    = outputBody;
            dr[Constants.Properties.OutputEmailSubject] = outputSubject;
            results.Rows.Add(dr);
        }
示例#6
0
        static void Main(string[] args)
        {
            string smoConnectionString = "Integrated=True;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;Host=development.k2software.cn;Port=5555;SecurityLabelName=K2;UserID=Administrator;Password=K2pass!;WindowsDomain=DENALLIX";
            //Integrated=True; IsPrimaryLogin=True; Authenticate=True; EncryptedPassword=False; CachePassword=True;Host=DLX; Port=5555
            //Create a SO Server Client Object
            SmartObjectClientServer soServer = new SmartObjectClientServer();
            try
            {
                //Open the connection to the K2 Server
                soServer.CreateConnection();
                soServer.Connection.Open(smoConnectionString);

                //Get a handle to the 'Employee' SO
                SmartObject soUMUser = soServer.GetSmartObject("ProjectData");

                //Call the GetList Method
                //soUMUser.MethodToExecute = "Get_Role_Users";
                //soUMUser.MethodToExecute = "Get_Users";
                soUMUser.MethodToExecute = "GetList";
                //Input Properties setting:
                //soUMUser.ListMethods["Get_Role_Users"].InputProperties["Role_Name"].Value = "tester";
                //soUMUser.ListMethods["Get_Group_Users"].InputProperties["Group_Name"].Value = "Domain Admins";
                //soUMUser.ListMethods["Get_Group_Users"].InputProperties["LabelName"].Value = "K2";
                //Execute GetList Method, and put the result to a SmartObjectList

                SmartObjectList smoList = soServer.ExecuteList(soUMUser);

                //Iterate the SmartObject List
                foreach (SmartObject soDetail in smoList.SmartObjectsList)
                {
                    Console.WriteLine("ID:" + soDetail.Properties["ID"].Value.ToString());
                }


                soServer.Connection.Close();

                Console.ReadKey();
            }
            catch (Exception ex)
            {

                throw ex;
            }


        }
示例#7
0
文件: K2Helper.cs 项目: zhangwxyc/BPM
        /// <summary>
        ///
        /// </summary>
        /// <param name="soname">Smart Object Name</param>
        /// <param name="method">Method</param>
        /// <param name="properties">Input Properties</param>
        /// <returns></returns>
        public static DataTable SOExecuteListDataTable(string soname, string method, NameValueCollection properties)
        {
            SmartObjectClientServer soClient = null;
            DataTable SOList = null;

            try
            {
                // get connection to smartobject Server
                soClient = GetSOClientConnection();

                // get smartobject
                SmartObject SO = soClient.GetSmartObject(soname);

                if (properties != null)
                {
                    for (int i = 0; i < properties.Count; i++)
                    {
                        string key = properties.GetKey(i).ToString();
                        if (properties[key] != null && !string.IsNullOrEmpty(properties[key]))
                        {
                            string value = properties[key].ToString();
                            //SO.ListMethods[method].InputProperties[key].Value = value;
                            SO.Properties[key].Value = value;
                        }
                    }
                }

                SO.MethodToExecute = method;

                SOList = soClient.ExecuteListDataTable(SO);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                // close connection
                if (soClient != null)
                {
                    soClient.Connection.Close();
                }
            }
            return(SOList);
        }
        public static string CreateDataFromPDFForm(string smartobjectName, string method, string returnProperty, Data.PDFInfo info, Dictionary<string, Data.PDFField> fields)
        {
            SourceCode.SmartObjects.Client.SmartObject smoReturn = null;
            SmartObjectClientServer smoSvr = new SmartObjectClientServer();

            Dictionary<string, string> Settings = new Dictionary<string, string>();
            string returnId = string.Empty;

            try
            {
                smoSvr.CreateConnection();
                smoSvr.Connection.Open(GetSmOConnection().ToString());

                SourceCode.SmartObjects.Client.SmartObject smoParam = smoSvr.GetSmartObject(smartobjectName);

                foreach (KeyValuePair<string, Data.PDFField> field in fields)
                {
                    smoParam.Properties[field.Key.Replace(" ", "_")].Value = field.Value.FieldValue;
                }

                smoParam.MethodToExecute = method;

                smoReturn = smoSvr.ExecuteScalar(smoParam);

                returnId = smoReturn.Properties[returnProperty].Value;

            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (smoSvr.Connection.IsConnected)
                {
                    smoSvr.Connection.Close();
                }
                smoSvr.Connection.Dispose();
            }
            return returnId;
        }
        public static string CreateDataFromPDFForm(string smartobjectName, string method, string returnProperty, Data.PDFInfo info, Dictionary <string, Data.PDFField> fields)
        {
            SourceCode.SmartObjects.Client.SmartObject smoReturn = null;
            SmartObjectClientServer smoSvr = new SmartObjectClientServer();

            Dictionary <string, string> Settings = new Dictionary <string, string>();
            string returnId = string.Empty;

            try
            {
                smoSvr.CreateConnection();
                smoSvr.Connection.Open(GetSmOConnection().ToString());

                SourceCode.SmartObjects.Client.SmartObject smoParam = smoSvr.GetSmartObject(smartobjectName);

                foreach (KeyValuePair <string, Data.PDFField> field in fields)
                {
                    smoParam.Properties[field.Key.Replace(" ", "_")].Value = field.Value.FieldValue;
                }

                smoParam.MethodToExecute = method;

                smoReturn = smoSvr.ExecuteScalar(smoParam);

                returnId = smoReturn.Properties[returnProperty].Value;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (smoSvr.Connection.IsConnected)
                {
                    smoSvr.Connection.Close();
                }
                smoSvr.Connection.Dispose();
            }
            return(returnId);
        }
        public static Dictionary<string, string> GetAllSettings(string[] SettingKeys)
        {
            SourceCode.SmartObjects.Client.SmartObject smoReturn = null;
            SmartObjectClientServer smoSvr = new SmartObjectClientServer();

            Dictionary<string, string> Settings = new Dictionary<string, string>();

            try
            {
                smoSvr.CreateConnection();
                smoSvr.Connection.Open(GetSmOConnection().ToString());

                foreach (string setting in SettingKeys)
                {
                    SourceCode.SmartObjects.Client.SmartObject smoParam = smoSvr.GetSmartObject("K2_Generic_Settings_Shared_Setting");
                    smoParam.Properties["SectionName"].Value = "Yammer";
                    smoParam.Properties["SettingKey"].Value = setting;
                    smoParam.MethodToExecute = "Load";

                    smoReturn = smoSvr.ExecuteScalar(smoParam);

                    Settings.Add(setting, GetValue(smoReturn));
                    smoReturn = null;
                }

            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (smoSvr.Connection.IsConnected)
                {
                    smoSvr.Connection.Close();
                }
                smoSvr.Connection.Dispose();
            }
            return Settings;
        }
        public static string GetSettingValue(string section, string key)
        {
            SourceCode.SmartObjects.Client.SmartObject smoReturn = null;

            SmartObjectClientServer smoSvr = new SmartObjectClientServer();

            try
            {
                smoSvr.CreateConnection();
                smoSvr.Connection.Open(GetSmOConnection().ToString());

                SourceCode.SmartObjects.Client.SmartObject smoParam = smoSvr.GetSmartObject("K2_Generic_Settings_Shared_Setting");

                smoParam.Properties["SectionName"].Value = section;
                smoParam.Properties["SettingKey"].Value  = key;

                smoParam.MethodToExecute = "Load";

                smoReturn = smoSvr.ExecuteScalar(smoParam);

                if (smoReturn.IsEmpty)
                {
                    return("");
                }
                else
                {
                    return(smoReturn.Properties["SettingValue"] != null ? smoReturn.Properties["SettingValue"].Value : "");
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                smoSvr.Connection.Close();
                smoSvr.Connection.Dispose();
            }
        }
        public static Dictionary <string, string> GetAllSettings(string[] SettingKeys)
        {
            SourceCode.SmartObjects.Client.SmartObject smoReturn = null;
            SmartObjectClientServer smoSvr = new SmartObjectClientServer();

            Dictionary <string, string> Settings = new Dictionary <string, string>();

            try
            {
                smoSvr.CreateConnection();
                smoSvr.Connection.Open(GetSmOConnection().ToString());

                foreach (string setting in SettingKeys)
                {
                    SourceCode.SmartObjects.Client.SmartObject smoParam = smoSvr.GetSmartObject("K2_Generic_Settings_Shared_Setting");
                    smoParam.Properties["SectionName"].Value = "Yammer";
                    smoParam.Properties["SettingKey"].Value  = setting;
                    smoParam.MethodToExecute = "Load";

                    smoReturn = smoSvr.ExecuteScalar(smoParam);

                    Settings.Add(setting, GetValue(smoReturn));
                    smoReturn = null;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (smoSvr.Connection.IsConnected)
                {
                    smoSvr.Connection.Close();
                }
                smoSvr.Connection.Dispose();
            }
            return(Settings);
        }
示例#13
0
        private string getTaxData()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();


            SmartObjectClientServer smoServer = ConnectionClass.GetSmartObjectClient();
            SmartObject             mmdSmo    = smoServer.GetSmartObject(this.SMOInternalName);
            SmartListMethod         getList   = mmdSmo.ListMethods["GetAllChildTermsInTermSet"];

            getList.InputProperties["TermStoreId"].Value = this.TermStoreGuid;
            getList.InputProperties["TermSetId"].Value   = this.TermSetGuid;
            mmdSmo.MethodToExecute = "GetAllChildTermsInTermSet";


            var             TermList = new List <Term>();
            SmartObjectList smoList  = smoServer.ExecuteList(mmdSmo);

            foreach (SmartObject smo in smoList.SmartObjectsList)
            {
                string termId    = smo.Properties["TermId"].Value;
                string termLabel = smo.Properties["Label"].Value;
                string termPath  = smo.Properties["Path"].Value;
                TermList.Add(new Term()
                {
                    TermId = termId, TermLabel = termLabel, TermPath = termPath
                });
            }
            var serializer  = new JavaScriptSerializer();
            var serialized  = serializer.Serialize(TermList);
            var fixedString = serialized.Replace("&quot;", @"""");

            sb.Append(@"{""terms"":");
            sb.Append(fixedString);
            sb.Append(@"}");
            return(HttpUtility.HtmlDecode(sb.ToString()));
        }
        internal static SmartFormatProperties CreateSmartFormatProperties(
            string soGuid, string server, string name, string displayname,
            string methodname, string methoddisplayname,
            bool methodislist,
            System.Collections.Generic.Dictionary <string, K2Field> SOInputs,
            System.Collections.Generic.Dictionary <string, K2Field> SOReturns,
            string connection)
        {
            Guid smoGuid;


            SmartObjectClientServer svr = new SmartObjectClientServer();

            svr.CreateConnection();
            svr.Connection.Open(connection);

            SmartObject so = svr.GetSmartObject(name);

            smoGuid = so.Guid;

            SmartFormatProperties properties = new SmartFormatProperties();

            properties.Locals["Guid"] = new Local("Guid", soGuid);
            //properties.Locals["Server"] = new Local("Server", "Integrated=True;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;Host=Localhost;Port=5555");
            properties.Locals["Server"]            = new Local("Server", connection);
            properties.Locals["Name"]              = new Local("Name", name);
            properties.Locals["DisplayName"]       = new Local("DisplayName", displayname);
            properties.Locals["MethodName"]        = new Local("MethodName", methodname);
            properties.Locals["MethodDisplayName"] = new Local("MethodDisplayName", methoddisplayname);
            properties.Locals["IsList"]            = new Local("IsList", new K2Field(new K2FieldPart[] { new ValueTypePart(methodislist) }));
            properties.Locals["MethodType"]        = new Local("MethodType", "execute");

            foreach (SmartProperty item in so.Properties)
            {
                properties.Properties.Add(item.Name, new Property(item.Name, item.Name, null, item.Type.ToString(), item.IsUnique));
            }

            //Add inputs
            foreach (var item in SOInputs)
            {
                if (so.Methods[methodname].InputProperties.Contains(item.Key))
                {
                    SmartProperty prop = so.Methods[methodname].InputProperties[item.Key];
                    properties.Inputs.Add(prop.Name, new Input(prop.Name, prop.Type.ToString(), item.Value));
                }

                foreach (SmartParameter itemParams in so.Methods[methodname].Parameters)
                {
                    if (itemParams.Name == item.Key)
                    {
                        SmartProperty prop = so.Methods[methodname].Parameters[item.Key];
                        properties.Inputs.Add(prop.Name, new Input(prop.Name, prop.Type.ToString(), item.Value));
                    }
                }
            }


            //Map return properties
            foreach (SmartProperty item in so.Methods[methodname].ReturnProperties)
            {
                bool found = false;

                //Search and see if we have passed a mapped item
                if (SOReturns != null)
                {
                    foreach (var SetReturnItem in SOReturns)
                    {
                        if (SetReturnItem.Key == item.Name)
                        {
                            SmartProperty prop = so.Methods[methodname].ReturnProperties[SetReturnItem.Key];
                            properties.Returns.Add(prop.Name, new Return(prop.Name, SetReturnItem.Value, prop.Type.ToString()));
                            found = true;
                        }
                    }
                }

                //If no mapped item found set a null value.
                if (found == false)
                {
                    properties.Returns.Add(item.Name, new Return(item.Name, item.Name, item.IsUnique, null, item.Type.ToString()));
                }
            }


            return(properties);
        }
        private void btnGenerateCRMProcess_Click(object sender, RoutedEventArgs e)
        {
            SourceCode.SmartObjects.Client.SmartObjectClientServer smoServer = new SmartObjectClientServer();
            smoServer.CreateConnection();
            smoServer.Connection.Open("Integrated=True;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;Host=localhost;Port=5555");

            SmartObject smoCRM = smoServer.GetSmartObject("Demo_K2_CRM_Functions");

            smoCRM.MethodToExecute = "GetAllEntities";

            SmartObjectList smoEntities = smoServer.ExecuteList(smoCRM);


            // get state status details
            CRMPicklist pl = new CRMPicklist();

//            pl.AttributeLogicalName = att.LogicalName;
            pl.EntityLogicalName = "lead";

            CRMPicklist cp = functions.CRMGetStateStatus(pl);

            int seq = 0;

            foreach (CRMPicklistOption plo in cp.Picklist.OrderBy(p => p.PicklistParentValue).OrderBy(p => p.PicklistValue))
            {
                StateStatus ss = new StateStatus();
                ss.State      = plo.PicklistParentValue;
                ss.StateName  = plo.PicklistParentLabel;
                ss.Status     = plo.PicklistValue;
                ss.StatusName = plo.PicklistLabel;
                ss.Sequence   = seq;
                seq++;
                CRMSS.Add(ss);
            }


            bool ActiveOnly = true;


            string nowish = DateTime.Now.ToString("yyyyMMddHHmmss");

            // Create new process
            process = WorkflowFactory.CreateProcess <DefaultProcess>(nowish, WizardNames.DefaultProcess);

            DataField dfEntityId   = new DataField("Entity Id", "");
            DataField dfEntityName = new DataField("Entity Name", "");

            process.DataFields.Add(dfEntityId);
            process.DataFields.Add(dfEntityName);


            var dimensions = WorkflowHelpers.GetActivityDimensions(process.StartActivity);
            int x          = Convert.ToInt32(Math.Round(dimensions.X + dimensions.Width + 40D));
            int y          = Convert.ToInt32(dimensions.Y) + 100;

            DefaultActivity PrevStatAct   = null;
            DefaultActivity PrevReviewAct = null;

            PrevStatAct = CreateStartActivity("", dfEntityId, dfEntityName, x, ref y);

            SourceCode.Workflow.Authoring.Line startLine = WorkflowFactory.CreateLine("StartLine");
            startLine.StartActivity  = process.StartActivity;
            startLine.FinishActivity = PrevStatAct;
            process.Lines.Add(startLine);

            int c = 0;

            foreach (StateStatus ss in CRMSS.OrderBy(p => p.Sequence))
            {
                DefaultActivity act = CreateStatusActivity(ss.StateName + " - " + ss.StatusName, dfEntityId, dfEntityName, x, ref y);
                if (PrevReviewAct != null)
                {
                    PrevReviewAct.FinishLines[0].FinishActivity = act;
                }

                if (c == 0)
                {
                    SourceCode.Workflow.Authoring.Line firstline = WorkflowFactory.CreateLine("Firstline");
                    firstline.StartActivity  = PrevStatAct;
                    firstline.FinishActivity = act;
                    process.Lines.Add(firstline);
                }
                c++;

                DefaultActivity act1 = null;
                if (!ActiveOnly || ActiveOnly && ss.State == 0)
                {
                    act1 = CreateCRMActivity(ss.StateName + " - " + ss.StatusName, dfEntityId, dfEntityName, x, ref y);

                    SourceCode.Workflow.Authoring.Line line = WorkflowFactory.CreateLine("Line " + ss.Sequence);
                    line.StartActivity  = act;
                    line.FinishActivity = act1;
                    process.Lines.Add(line);

                    if (PrevStatAct != null)
                    {
                        act1.FinishLines[1].FinishActivity = PrevStatAct;
                    }
                }

                if (act1 == null && PrevStatAct.FinishLines.Count == 0)
                {
                    PrevReviewAct = null;
                    SourceCode.Workflow.Authoring.Line updateLine = WorkflowFactory.CreateLine("Update Line " + ss.Sequence);
                    updateLine.StartActivity  = PrevStatAct;
                    updateLine.FinishActivity = act;
                    process.Lines.Add(updateLine);
                }


                if (act != null)
                {
                    WorkflowHelpers.AutoPositionLines(act.StartLines);
                    WorkflowHelpers.AutoPositionLines(act.FinishLines);
                }
                if (act1 != null)
                {
                    WorkflowHelpers.AutoPositionLines(act1.StartLines);
                    WorkflowHelpers.AutoPositionLines(act1.FinishLines);
                }

                PrevReviewAct = act1;
                PrevStatAct   = act;
            }



            process.FinishRule = new DesignCRMClient.CRMClientProcessFinishRule();

            process.SaveAs(txtProcessPath.Text + nowish + ".kprx");

            process = null;
        }
示例#16
0
        public string GetRegularExpression(string control)
        {
            SmartObjectSMOConnection smoConnection = new SmartObjectSMOConnection();

            smoConnection.GetSmartObjectDetails();


            string Result = string.Empty;
            SmartObjectClientServer soServer = new SmartObjectClientServer();

            soServer.CreateConnection();
            try
            {
                soServer.Connection.Open(ConnectToK2());
                SourceCode.SmartObjects.Client.SmartObject ControlExpressionLibrary = soServer.GetSmartObject(smoConnection.SmartObjectName);
                ControlExpressionLibrary.Properties[smoConnection.SmartObjectInputParameter].Value = control;
                ControlExpressionLibrary.MethodToExecute = smoConnection.SmartObjectMethod;
                soServer.ExecuteScalar(ControlExpressionLibrary);
                Result = ControlExpressionLibrary.Properties[smoConnection.SmartObjectProperty].Value;
            }
            catch (Exception ex)
            {
                Result = ex.Message;
            }
            finally
            {
                soServer.Connection.Close();
            }

            return(Result);
        }
示例#17
0
        static void Main(string[] args)
        {
            SmartObjectClientServer server = new SmartObjectClientServer();

            try
            {

                SCConnectionStringBuilder cb = new SCConnectionStringBuilder();

                cb.Host = "DLX";

                cb.Port = 5555;

                cb.Integrated = true;

                cb.IsPrimaryLogin = true;

                //Connect to server

                server.CreateConnection();

                server.Connection.Open(cb.ToString());

                //--------------------------

                //Get the Employee

                //Get SmartObject Definition

                SmartObject employee = server.GetSmartObject("Employee");

                //Set properties

                employee.Properties["ID"].Value = "2";

                //Get the record

                employee.MethodToExecute = "FindEmployee";

                server.ExecuteScalar(employee);

                System.Diagnostics.Trace.WriteLine(

                    employee.Properties["FirstName"].Value);

                System.Diagnostics.Trace.WriteLine(

                    employee.Properties["LastName"].Value);

                System.Diagnostics.Trace.WriteLine(

                    employee.Properties["Email"].Value);

            }

            catch (Exception ex)
            {

                throw new Exception("Error Creating Request >> " + ex.Message);

            }
        }
示例#18
0
        static void Main(string[] args)
        {
            SmartObjectClientServer server = new SmartObjectClientServer();



            try
            {
                SCConnectionStringBuilder cb = new SCConnectionStringBuilder();

                cb.Host = "DLX";

                cb.Port = 5555;

                cb.Integrated = true;

                cb.IsPrimaryLogin = true;



                //Connect to server

                server.CreateConnection();

                server.Connection.Open(cb.ToString());



                //--------------------------

                //Get the Employee

                //Get SmartObject Definition

                SmartObject employee = server.GetSmartObject("Employee");



                //Set properties

                employee.Properties["ID"].Value = "2";



                //Get the record

                employee.MethodToExecute = "FindEmployee";

                server.ExecuteScalar(employee);



                System.Diagnostics.Trace.WriteLine(

                    employee.Properties["FirstName"].Value);



                System.Diagnostics.Trace.WriteLine(

                    employee.Properties["LastName"].Value);



                System.Diagnostics.Trace.WriteLine(

                    employee.Properties["Email"].Value);
            }

            catch (Exception ex)
            {
                throw new Exception("Error Creating Request >> " + ex.Message);
            }
        }
        public static string GetSettingValue(string section, string key)
        {
            SourceCode.SmartObjects.Client.SmartObject smoReturn = null;

            SmartObjectClientServer smoSvr = new SmartObjectClientServer();
            try
            {
                smoSvr.CreateConnection();
                smoSvr.Connection.Open(GetSmOConnection().ToString());

                SourceCode.SmartObjects.Client.SmartObject smoParam = smoSvr.GetSmartObject("K2_Generic_Settings_Shared_Setting");

                smoParam.Properties["SectionName"].Value = section;
                smoParam.Properties["SettingKey"].Value = key;

                smoParam.MethodToExecute = "Load";

                smoReturn = smoSvr.ExecuteScalar(smoParam);

                if (smoReturn.IsEmpty)
                {
                    return "";
                }
                else
                {
                    return smoReturn.Properties["SettingValue"] != null ? smoReturn.Properties["SettingValue"].Value : "";
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                smoSvr.Connection.Close();
                smoSvr.Connection.Dispose();
            }
        }
        private void btnGenerateCRMProcess_Click(object sender, RoutedEventArgs e)
        {
            SourceCode.SmartObjects.Client.SmartObjectClientServer smoServer = new SmartObjectClientServer();
            smoServer.CreateConnection();
            smoServer.Connection.Open("Integrated=True;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;Host=localhost;Port=5555");

            SmartObject smoCRM = smoServer.GetSmartObject("Demo_K2_CRM_Functions");
            smoCRM.MethodToExecute = "GetAllEntities";

            SmartObjectList smoEntities = smoServer.ExecuteList(smoCRM);


            // get state status details
            CRMPicklist pl = new CRMPicklist();
//            pl.AttributeLogicalName = att.LogicalName;
            pl.EntityLogicalName = "lead";

            CRMPicklist cp = functions.CRMGetStateStatus(pl);

            int seq = 0;
            foreach (CRMPicklistOption plo in cp.Picklist.OrderBy(p => p.PicklistParentValue).OrderBy(p => p.PicklistValue))
            {
                StateStatus ss = new StateStatus();
                ss.State = plo.PicklistParentValue;
                ss.StateName = plo.PicklistParentLabel;
                ss.Status = plo.PicklistValue;
                ss.StatusName = plo.PicklistLabel;
                ss.Sequence = seq;
                seq++;
                CRMSS.Add(ss);
            }


            bool ActiveOnly = true;


            string nowish = DateTime.Now.ToString("yyyyMMddHHmmss");
            // Create new process
            process = WorkflowFactory.CreateProcess<DefaultProcess>(nowish, WizardNames.DefaultProcess);

            DataField dfEntityId = new DataField("Entity Id", "");
            DataField dfEntityName = new DataField("Entity Name", "");
            process.DataFields.Add(dfEntityId);
            process.DataFields.Add(dfEntityName);


            var dimensions = WorkflowHelpers.GetActivityDimensions(process.StartActivity);
            int x = Convert.ToInt32(Math.Round(dimensions.X + dimensions.Width + 40D));
            int y = Convert.ToInt32(dimensions.Y) + 100;

            DefaultActivity PrevStatAct = null;
            DefaultActivity PrevReviewAct = null;

            PrevStatAct = CreateStartActivity("", dfEntityId, dfEntityName, x, ref y);

            SourceCode.Workflow.Authoring.Line startLine = WorkflowFactory.CreateLine("StartLine"); 
            startLine.StartActivity = process.StartActivity;
            startLine.FinishActivity = PrevStatAct;
            process.Lines.Add(startLine);

            int c = 0;

            foreach (StateStatus ss in CRMSS.OrderBy(p => p.Sequence))
            {
                DefaultActivity act = CreateStatusActivity(ss.StateName + " - " + ss.StatusName, dfEntityId, dfEntityName, x, ref y);
                if (PrevReviewAct != null)
                {
                    PrevReviewAct.FinishLines[0].FinishActivity = act;
                }

                if (c == 0)
                {
                    SourceCode.Workflow.Authoring.Line firstline = WorkflowFactory.CreateLine("Firstline");
                    firstline.StartActivity = PrevStatAct;
                    firstline.FinishActivity = act;
                    process.Lines.Add(firstline);
                }
                c++;

                DefaultActivity act1 = null;
                if (!ActiveOnly || ActiveOnly && ss.State == 0)
                {
                    act1 = CreateCRMActivity(ss.StateName + " - " + ss.StatusName, dfEntityId, dfEntityName, x, ref y);

                    SourceCode.Workflow.Authoring.Line line = WorkflowFactory.CreateLine("Line " + ss.Sequence);
                    line.StartActivity = act;
                    line.FinishActivity = act1;
                    process.Lines.Add(line);

                    if (PrevStatAct != null)
                    {
                        act1.FinishLines[1].FinishActivity = PrevStatAct;
                    }
                }

                if (act1 == null && PrevStatAct.FinishLines.Count == 0)
                {
                    PrevReviewAct = null;
                    SourceCode.Workflow.Authoring.Line updateLine = WorkflowFactory.CreateLine("Update Line " + ss.Sequence);
                    updateLine.StartActivity = PrevStatAct;
                    updateLine.FinishActivity = act;
                    process.Lines.Add(updateLine);
                }


                if (act != null)
                {
                    WorkflowHelpers.AutoPositionLines(act.StartLines);
                    WorkflowHelpers.AutoPositionLines(act.FinishLines);
                }
                if (act1 != null)
                {
                    WorkflowHelpers.AutoPositionLines(act1.StartLines);
                    WorkflowHelpers.AutoPositionLines(act1.FinishLines);
                }

                PrevReviewAct = act1;
                PrevStatAct = act;
            }
            


            process.FinishRule = new DesignCRMClient.CRMClientProcessFinishRule();

            process.SaveAs(txtProcessPath.Text+nowish+".kprx");

            process = null;
        }
示例#21
0
 public virtual SmartObject GetSmartObject(string smartObjectName)
 {
     return(_serviceClientServer.GetSmartObject(smartObjectName));
 }
        internal static SmartFormatProperties CreateSmartFormatProperties(
            string soGuid, string server, string name, string displayname,
            string methodname, string methoddisplayname,
            bool methodislist,
            System.Collections.Generic.Dictionary<string, K2Field> SOInputs,
            System.Collections.Generic.Dictionary<string, K2Field> SOReturns,
            string connection)
        {

            Guid smoGuid;


            SmartObjectClientServer svr = new SmartObjectClientServer();
            svr.CreateConnection();
            svr.Connection.Open(connection);

            SmartObject so = svr.GetSmartObject(name);
            smoGuid = so.Guid;

            SmartFormatProperties properties = new SmartFormatProperties();
            properties.Locals["Guid"] = new Local("Guid", soGuid);
            //properties.Locals["Server"] = new Local("Server", "Integrated=True;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;Host=Localhost;Port=5555");
            properties.Locals["Server"] = new Local("Server", connection);
            properties.Locals["Name"] = new Local("Name", name);
            properties.Locals["DisplayName"] = new Local("DisplayName", displayname);
            properties.Locals["MethodName"] = new Local("MethodName", methodname);
            properties.Locals["MethodDisplayName"] = new Local("MethodDisplayName", methoddisplayname);
            properties.Locals["IsList"] = new Local("IsList", new K2Field(new K2FieldPart[] { new ValueTypePart(methodislist) }));
            properties.Locals["MethodType"] = new Local("MethodType", "execute");

            foreach (SmartProperty item in so.Properties)
            {
                properties.Properties.Add(item.Name, new Property(item.Name, item.Name, null, item.Type.ToString(), item.IsUnique));
            }

            //Add inputs
            foreach (var item in SOInputs)
            {
                if (so.Methods[methodname].InputProperties.Contains(item.Key))
                {
                    SmartProperty prop = so.Methods[methodname].InputProperties[item.Key];
                    properties.Inputs.Add(prop.Name, new Input(prop.Name, prop.Type.ToString(), item.Value));
                }

                foreach (SmartParameter itemParams in so.Methods[methodname].Parameters)
                {
                    if (itemParams.Name == item.Key)
                    {
                        SmartProperty prop = so.Methods[methodname].Parameters[item.Key];
                        properties.Inputs.Add(prop.Name, new Input(prop.Name, prop.Type.ToString(), item.Value));
                    }
                }

            }


            //Map return properties
            foreach (SmartProperty item in so.Methods[methodname].ReturnProperties)
            {
                bool found = false;

                //Search and see if we have passed a mapped item 
                if (SOReturns != null)
                {
                    foreach (var SetReturnItem in SOReturns)
                    {
                        if (SetReturnItem.Key == item.Name)
                        {
                            SmartProperty prop = so.Methods[methodname].ReturnProperties[SetReturnItem.Key];
                            properties.Returns.Add(prop.Name, new Return(prop.Name, SetReturnItem.Value, prop.Type.ToString()));
                            found = true;
                        }
                    }
                }

                //If no mapped item found set a null value.
                if (found == false)
                {
                    properties.Returns.Add(item.Name, new Return(item.Name, item.Name, item.IsUnique, null, item.Type.ToString()));
                }
            }


            return properties;
        }
示例#23
0
        public void RetryWorkflow()
        {
            SmartObjectClientServer soServer = this.NewSmartObjectClientServer();

            try
            {
                using (soServer.Connection)
                {
                    SmartObject soError = soServer.GetSmartObject("com_K2_System_Workflow_SmartObject_ErrorLog");
                    //set method we want to execute.
                    soError.MethodToExecute = "GetErrorLogs";
                    soError.Properties["ErrorProfileName"].Value = "All";

                    //get the list of SmartObjects returned by the method
                    SmartObjectList soListError = soServer.ExecuteList(soError);
                    //iterate over the collection

                    List <K2ErrorLog> listK2ErrorLog = new List <K2ErrorLog>();
                    string[]          workflowNames  = this.AppConfig.WorkflowNames.Split(';');
                    foreach (SmartObject soItem in soListError.SmartObjectsList)
                    {
                        for (int i = 0; i < workflowNames.Length; i++)
                        {
                            if (soItem.Properties["ProcessName"].Value == workflowNames[i])
                            {
                                string soDescription = soItem.Properties["Description"].Value.ToString();
                                if (soDescription.Contains("was deadlocked on lock resources with another process") ||
                                    soDescription.Contains("SQL") ||
                                    soDescription.Contains("IIF"))
                                {
                                    listK2ErrorLog.Add(new K2ErrorLog(soItem));
                                }
                            }
                        }
                        //ambil hanya transaksi deadlocked saja
                    }

                    foreach (K2ErrorLog k2ErrorLog in listK2ErrorLog)
                    {
                        SmartObject errorSO = soServer.GetSmartObject("com_K2_System_Workflow_SmartObject_ErrorLog");
                        //set method we want to execute.
                        errorSO.MethodToExecute = "RetryError";

                        errorSO.Properties["Id"].Value         = k2ErrorLog.Id.ToString();
                        errorSO.Properties["ProcInstId"].Value = k2ErrorLog.ProcInstID.ToString();
                        errorSO.Properties["TypeId"].Value     = k2ErrorLog.TypeID.ToString();
                        errorSO.Properties["ObjectId"].Value   = k2ErrorLog.ObjectID.ToString();
                        errorSO.Properties["UserName"].Value   = "System";

                        this.Logger.Info("K2 Retry ProcInstId = " + k2ErrorLog.ProcInstID.ToString());

                        //get the list of SmartObjects returned by the method
                        Thread.Sleep(1000); //delay 1 detik
                        soServer.ExecuteScalar(errorSO);
                    }
                }
            }
            finally
            {
                soServer.DeleteConnection();
            }
        }
示例#24
0
 private List<TaskUser> GetUsers(SourceCode.KO.Destination dest)
 {
     //System.Diagnostics.EventLog.WriteEntry("K2EventListener", "K2EventListener GetUsers Started!Data:" + JsonConvert.SerializeObject(arr), System.Diagnostics.EventLogEntryType.Warning);
     //System.Diagnostics.EventLog.WriteEntry("K2EventListener", "smoConnectionString Data:" + smoConnectionString + ",K2EventReceiverUrl:" + K2EventReceiverUrl, System.Diagnostics.EventLogEntryType.Error);
     _log.Info("Start GetUsers");
     List<TaskUser> users = new List<TaskUser>();
     try
     {
         //Create a SO Server Client Object
         SmartObjectClientServer soServer = new SmartObjectClientServer();
         //Open the connection to the K2 Server
         soServer.CreateConnection();
         soServer.Connection.Open(smoConnectionString);
         //Get a handle to the 'Employee' SO
         SmartObject soUMUser = soServer.GetSmartObject("UMUser");
         if (dest.Type == DestinationType.User)
         {
             soUMUser.MethodToExecute = "Get_Users";
             string[] arr = dest.Name.Split(':');
             if (arr.Length > 1)
             {
                 soUMUser.ListMethods["Get_Users"].InputProperties["Label_Name"].Value = arr[0];
                 soUMUser.ListMethods["Get_Users"].InputProperties["Name"].Value = arr[1];
                 //Execute GetList Method, and put the result to a SmartObjectList
                 SmartObjectList smoList = soServer.ExecuteList(soUMUser);
                 //Iterate the SmartObject List
                 foreach (SmartObject soDetail in smoList.SmartObjectsList)
                 {
                     TaskUser user = new TaskUser()
                     {
                         Name = soDetail.Properties["Name"].Value.ToString(),
                         Email = soDetail.Properties["Email"].Value.ToString(),
                         Manager = soDetail.Properties["Manager"].Value.ToString()
                     };
                     users.Add(user);
                 }
                 soServer.Connection.Close();
             }
             soServer.Connection.Close();
             if (Enviroment == "Development") _log.Info("GetUsers Return DestinationType.User Data:" + JsonConvert.SerializeObject(users));
             return users;
         }
         else if (dest.Type == DestinationType.Group)
         {
             soUMUser.MethodToExecute = "Get_Group_Users";
             //Input Properties setting:
             string[] arr = dest.Name.Split(':');
             if (arr.Length > 1)
             {
                 soUMUser.ListMethods["Get_Group_Users"].InputProperties["Group_Name"].Value = arr[1];
                 soUMUser.ListMethods["Get_Group_Users"].InputProperties["LabelName"].Value = arr[0];
                 //Execute GetList Method, and put the result to a SmartObjectList
                 SmartObjectList smoList = soServer.ExecuteList(soUMUser);
                 //Iterate the SmartObject List
                 foreach (SmartObject soDetail in smoList.SmartObjectsList)
                 {
                     TaskUser user = new TaskUser()
                     {
                         Name = soDetail.Properties["Name"].Value.ToString(),
                         Email = soDetail.Properties["Email"].Value.ToString(),
                         Manager = soDetail.Properties["Manager"].Value.ToString()
                     };
                     users.Add(user);
                 }
                 soServer.Connection.Close();
             }
             if (Enviroment == "Development") _log.Info("GetUsers Return DestinationType.Group Data:" + JsonConvert.SerializeObject(users));
             return users;
         }
         else if (dest.Type == DestinationType.Queue)
         {
             //Call the GetList Method
             soUMUser.MethodToExecute = "Get_Role_Users";
             //Input Properties setting:
             soUMUser.ListMethods["Get_Role_Users"].InputProperties["Role_Name"].Value = dest.Name;
             //Execute GetList Method, and put the result to a SmartObjectList
             SmartObjectList smoList = soServer.ExecuteList(soUMUser);
             //Iterate the SmartObject List
             foreach (SmartObject soDetail in smoList.SmartObjectsList)
             {
                 TaskUser user = new TaskUser()
                 {
                     Name = soDetail.Properties["Name"].Value.ToString(),
                     Email = soDetail.Properties["Email"].Value.ToString(),
                     Manager = soDetail.Properties["Manager"].Value.ToString()
                 };
                 users.Add(user);
             }
             soServer.Connection.Close();
             if (Enviroment == "Development") _log.Info("GetUsers Return DestinationType.Queue Data:" + JsonConvert.SerializeObject(users));
             //System.Diagnostics.EventLog.WriteEntry("K2EventListener", "K2EventListener Return GetUsers Data:" + JsonConvert.SerializeObject(users), System.Diagnostics.EventLogEntryType.Error);
             return users;
         }
         else
         {
             soServer.Connection.Close();
             if (Enviroment == "Development") _log.InfoFormat("GetUsers Return null Data:" + JsonConvert.SerializeObject(users));
             return users;
         }
     }
     catch (Exception ex)
     {
         //System.Diagnostics.EventLog.WriteEntry("K2EventListener", "K2EventListener Error Data:" + JsonConvert.SerializeObject(ex), System.Diagnostics.EventLogEntryType.Error);
         _log.Error(ex);
     }
     return users;
 }