Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
 public K2SmartObjectDAL(string servername,int port)
 {
     Console.WriteLine("K2SmartObjectDAL({0},{1})", servername, port);
     SMOServer = new SmartObjectClientServer();
     string connStr = string.Format("Integrated=True;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;Host={0};Port={1}", servername, port);
     SMOServer.CreateConnection();
     SMOServer.Connection.Open(connStr);
 }
        /// <summary>
        /// Create Connection to K2 Server.
        /// </summary>
        /// <returns></returns>
        private SmartObjectClientServer GetServer()
        {
            var soServer = new SmartObjectClientServer();

            soServer.CreateConnection();
            soServer.Connection.Open(this.GetConnectionString());
            return(soServer);
        }
        private static SmartObjectClientServer SmartObjectClientServer()
        {
            SmartObjectClientServer smoSvr = new SmartObjectClientServer();

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

            return(smoSvr);
        }
 private void ClientServerConnect()
 {
     if (_smoClientServer == null)
     {
         _smoClientServer = new SmartObjectClientServer();
     }
     if (_smoClientServer.Connection == null)
     {
         _smoClientServer.CreateConnection();
     }
     if (!_smoClientServer.Connection.IsConnected)
     {
         _smoClientServer.Connection.Open(_connectionString.ConnectionString);
     }
 }
Exemplo n.º 7
0
        public SmartObjectClientServer NewSmartObjectClientServer()
        {
            SCConnectionStringBuilder hostServerConnectionString = new SCConnectionStringBuilder();

            hostServerConnectionString.Host           = this.AppConfig.K2Server;
            hostServerConnectionString.Port           = 5555;
            hostServerConnectionString.IsPrimaryLogin = true;
            hostServerConnectionString.Integrated     = true;
            SmartObjectClientServer result = new SmartObjectClientServer();

            result.CreateConnection();
            //open the connection to the K2 server
            result.Connection.Open(hostServerConnectionString.ToString());
            //return the SOClientServer object
            return(result);
        }
Exemplo n.º 8
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;
            }


        }
        /// <summary>
        /// Connect to and open the SmartObject Client service of the K2 server.
        /// </summary>
        /// <returns>The SmartObjectClientServer connection</returns>
        private SmartObjectClientServer GetSmartObjectConnection()
        {
            var client = new SmartObjectClientServer();

            client.CreateConnection();

            // Connect to the K2 server
            var scConnectionString = new SCConnectionStringBuilder
            {
                Host           = _settings.K2Server,
                Port           = _settings.Port,
                IsPrimaryLogin = true,
                Integrated     = true
            };

            client.Connection.Open(scConnectionString.ConnectionString);

            return(client);
        }
        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 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();
            }
        }
Exemplo n.º 15
0
        private static SmartObjectClientServer GetSOClientConnection()
        {
            SmartObjectClientServer soClient = new SmartObjectClientServer();

            soClient.Connection = soClient.CreateConnection();

            if (!soClient.Connection.IsConnected)
            {
                //use connection string builder to create connection string.
                SCConnectionStringBuilder connectionStr = new SCConnectionStringBuilder();

                //set server info
                connectionStr.Host = _K2ServerName;

                connectionStr.Integrated        = true;
                connectionStr.IsPrimaryLogin    = true;
                connectionStr.Password          = _Password;
                connectionStr.Port              = 5555;
                connectionStr.UserID            = _K2User;
                connectionStr.WindowsDomain     = _K2Domain;
                connectionStr.SecurityLabelName = _SecurityLabelName;


                //open connection
                try
                {
                    soClient.Connection.Open(connectionStr.ConnectionString);
                }
                catch
                {
                    return(null);
                }
            }

            return(soClient);
        }
        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;
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);

            }
        }
        private static SmartObjectClientServer SmartObjectClientServer()
        {
            SmartObjectClientServer smoSvr = new SmartObjectClientServer();
            smoSvr.CreateConnection();
            smoSvr.Connection.Open(GetSmOConnection().ToString());

            return smoSvr;
        }
        static void Main(string[] args)
        {

            //Get Form View Relation
            DataTable dtFormView = new DataTable();
            dtFormView.Columns.Add("FormGUID", typeof(Guid));            
            dtFormView.Columns.Add("ViewGUID", typeof(Guid));            

            SCConnectionStringBuilder sb = new SCConnectionStringBuilder();
            sb.Authenticate = true;
            sb.IsPrimaryLogin = true;
            sb.Integrated = true;
            sb.Host = "localhost";
            sb.Port = 5555;

            SmartObjectClientServer socs = new SmartObjectClientServer();
            socs.CreateConnection();
            socs.Connection.Open(sb.ToString());
            FormsManager fm = new FormsManager(sb.ToString());
            FormExplorer fe = fm.GetForms();
            foreach (FormInfo fi in fe.Forms)
            {
                Guid formGUID = fi.Guid;
                //Console.WriteLine("Form: " + fi.DisplayName);
                ViewExplorer ve = fm.GetViewsForForm(fi.Guid);                                            

                foreach (ViewInfo vi in ve.Views)
                {
                    DataRow dr = dtFormView.NewRow();
                    dr["FormGUID"] = formGUID;
                    dr["ViewGUID"] = vi.Guid;

                    dtFormView.Rows.Add(dr);
                }
            }

            //Get Form Process Relation
            DataTable dtFormProcess = new DataTable();
            dtFormProcess.Columns.Add("ProcessName", typeof(string));
            dtFormProcess.Columns.Add("FormGUID", typeof(Guid));            

            fe = fm.GetForms();
            foreach (FormInfo fi in fe.Forms)
            {
                Guid formGUID = fi.Guid;

                IEnumerable<string> processes = fm.GetProcessesForForm(fi.Guid);
                
                foreach (var process in processes)
                {
                    DataRow dr = dtFormProcess.NewRow();
                    dr["FormGUID"] = formGUID;
                    dr["ProcessName"] = process;

                    dtFormProcess.Rows.Add(dr);
                }
            }

            //Get View SMO Relation
            DataTable dtViewSMO = new DataTable();
            dtViewSMO.Columns.Add("ViewGUID", typeof(Guid));
            dtViewSMO.Columns.Add("SmartObjectGUID", typeof(Guid));   

            fe = fm.GetForms();
            foreach (FormInfo fi in fe.Forms)
            {                
                ViewExplorer ve = fm.GetViewsForForm(fi.Guid);
                
                foreach (ViewInfo vi in ve.Views)
                {
                    Guid viewGUID = vi.Guid;

                    foreach (Guid soGuid in fm.GetObjectsForView(vi.Guid))
                    {
                        DataRow dr = dtViewSMO.NewRow();
                        dr["ViewGUID"] = viewGUID;
                        dr["SmartObjectGUID"] = soGuid;

                        dtViewSMO.Rows.Add(dr);
                    }                    
                }
            }
            fm.Connection.Close();
            socs.Connection.Close();

            //Delete data from table
            string stmt = "Delete From FormViewDependency";
            ExecuteNoneQuery(stmt, CommandType.Text);

            //Insert Form View Relation to table
            for(int i = 0; i < dtFormView.Rows.Count; i++)
            {
                DataRow dr = dtFormView.Rows[i];
                stmt = @"INSERT INTO [dbo].[FormViewDependency]
                     ([FormGUID]
                    ,[ViewGUID])
                    VALUES
                    ('" + dr["FormGUID"].ToString() + @"'
                    ,'" + dr["ViewGUID"].ToString() + "')";

                ExecuteNoneQuery(stmt, CommandType.Text);
            }

            //Delete data from table
            stmt = "Delete From FormProcessDependency";
            ExecuteNoneQuery(stmt, CommandType.Text);

            //Insert Form Process Relation to table
            for (int i = 0; i < dtFormProcess.Rows.Count; i++)
            {
                DataRow dr = dtFormProcess.Rows[i];
                stmt = @"INSERT INTO [dbo].[FormProcessDependency]
                     ([FormGUID]
                    ,[ProcessName])
                    VALUES
                    ('" + dr["FormGUID"].ToString() + @"'
                    ,'" + dr["ProcessName"].ToString() + "')";

                ExecuteNoneQuery(stmt, CommandType.Text);
            }

            //Delete data from table
            stmt = "Delete From ViewSMODependency";
            ExecuteNoneQuery(stmt, CommandType.Text);

            //Insert View SMO Relation to table
            for (int i = 0; i < dtViewSMO.Rows.Count; i++)
            {
                DataRow dr = dtViewSMO.Rows[i];
                stmt = @"INSERT INTO [dbo].[ViewSMODependency]
                     ([ViewGUID]
                    ,[SmartObjectGUID])
                    VALUES
                    ('" + dr["ViewGUID"].ToString() + @"'
                    ,'" + dr["SmartObjectGUID"].ToString() + "')";

                ExecuteNoneQuery(stmt, CommandType.Text);
            }

            //SmartObjectClientServer socs = new SmartObjectClientServer();
            //socs.CreateConnection();
            //socs.Connection.Open(sb.ToString());
            //FormsManager fm = new FormsManager(sb.ToString());
            //FormExplorer fe = fm.GetForms();
            //foreach (FormInfo fi in fe.Forms)
            //{                
            //    Console.WriteLine("Form: " + fi.DisplayName);
            //    ViewExplorer ve = fm.GetViewsForForm(fi.Guid);
            //    IEnumerable<string> x = fm.GetProcessesForForm(fi.Guid);

            //    foreach (var y in x)
            //    {
            //        Console.WriteLine("Process: " + y);
            //    }

            //    foreach (ViewInfo vi in ve.Views)
            //    {
            //        Console.WriteLine("View: " + vi.DisplayName);
            //        foreach(Guid soGuid in fm.GetObjectsForView(vi.Guid))
            //        {
            //            try
            //            {
            //                SmartObject so = socs.GetSmartObject(soGuid);
            //                Console.WriteLine("SmartObject: " + so.Name);
            //            }
            //            catch (Exception ex)
            //            {
            //                Console.WriteLine(ex.Message);
            //            }
            //        }
            //        Console.WriteLine();
            //    }
            //}
            //fm.Connection.Close();
            //socs.Connection.Close();
            //Console.ReadLine();

        }
        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();
            }
        }
Exemplo n.º 22
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;
 }
        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;
        }
        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;
        }