private void UpdateCRMTask_ExecuteCode(object sender, EventArgs e) { XmlDocument tasks = new XmlDocument(); tasks.LoadXml(K2.ProcessInstance.XmlFields["CRM Tasks"].Value); XmlNode taskidNode = tasks.SelectSingleNode("/CRMTasks/Task[SerialNumber= '" + K2.ProcessInstance.ID + "_" + K2.EventInstance.ActivityInstanceDestination.ID + "']/TaskId"); if (taskidNode != null) { try { using (SourceCode.Workflow.Common.HostedServers.SmartObjects smartObjects = new SmartObjects(K2.Configuration.SmartObjectServer)) { SourceCode.SmartObjects.Client.SmartObject smartObject = smartObjects.GetSmartObject(K2.Configuration.CRMFunctionsSmartObject); SourceCode.SmartObjects.Client.SmartMethod smartMethod = smartObjects.GetSingleMethod(smartObject, "SetStateStatus"); smartObject.Properties["Entity"].Value = "task"; smartObject.Properties["EntityId"].Value = taskidNode.InnerText; smartObject.Properties["State"].Value = "1"; smartObject.Properties["Status"].Value = "5"; SourceCode.SmartObjects.Client.SmartObject smo = smartObjects.ExecuteSingleMethod(smartMethod); } } catch (Exception ex) { K2.ProcessInstance.Logger.LogErrorMessage("CRM Client Event - Completing task", ex.Message); } } }
public void ProcessRequest(HttpContext context) { string imgID = context.Request.QueryString["id"]; SCSMOC.SmartObjectClientServer smoSvr = new SCSMOC.SmartObjectClientServer(); try { smoSvr.CreateConnection(); smoSvr.Connection.Open(GetSMOConnStr()); SCSMOC.SmartObject smoObj = smoSvr.GetSmartObject("DigitalSignature"); smoObj.Properties["ID"].Value = imgID; smoObj.MethodToExecute = "Load"; smoObj = smoSvr.ExecuteScalar(smoObj); context.Response.Write(smoObj.Properties["Signature"].Value); } finally { if (smoSvr.Connection != null && smoSvr.Connection.IsConnected) { smoSvr.Connection.Dispose(); } } }
public void Main($contexttype$ K2) { try { using (SourceCode.Workflow.Common.HostedServers.SmartObjects smartObjects = new SmartObjects(K2.Configuration.SmartObjectServer)) { SourceCode.SmartObjects.Client.SmartObject smartObject = smartObjects.GetSmartObject(K2.Configuration.CRMFunctionsSmartObject); SourceCode.SmartObjects.Client.SmartMethod smartMethod = smartObjects.GetSingleMethod(smartObject, "BulkActionTasksSetCriteria"); smartObject.Properties["FromState"].Value = "0"; smartObject.Properties["FromStatus"].Value = "3"; smartObject.Properties["ToState"].Value = "2"; smartObject.Properties["ToStatus"].Value = "6"; //smartObject.Properties["Regarding"].Value = K2.Configuration.CRMEntityType; //smartObject.Properties["RegardingId"].Value = K2.Configuration.CRMEntityId; ; smartObject.Properties["K2ProcessName"].Value = K2.ProcessInstance.Process.Name; smartObject.Properties["K2ProcessInstanceId"].Value = K2.ProcessInstance.ID.ToString(); SourceCode.SmartObjects.Client.SmartObject smo = smartObjects.ExecuteSingleMethod(smartMethod); } } catch (Exception ex) { K2.ProcessInstance.Logger.LogErrorMessage("CRM Client Finish Rule", ex.Message); } }
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 static string GetValue(SourceCode.SmartObjects.Client.SmartObject smo) { if (smo == null || smo.IsEmpty) { return(""); } else { return(smo.Properties["SettingValue"] != null ? smo.Properties["SettingValue"].Value : ""); } }
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 void Main($contexttype$ K2) { if (SucceedingRuleHelper.AnyOutcomesEvaluatedSuccessfully(K2)) { try { using (SourceCode.Workflow.Common.HostedServers.SmartObjects smartObjects = new SmartObjects(K2.Configuration.SmartObjectServer)) { SourceCode.SmartObjects.Client.SmartObject smartObject = smartObjects.GetSmartObject(K2.Configuration.CRMFunctionsSmartObject); SourceCode.SmartObjects.Client.SmartMethod smartMethod = smartObjects.GetSingleMethod(smartObject, "BulkActionTasksSetCriteria"); smartObject.Properties["FromState"].Value = "0"; smartObject.Properties["FromStatus"].Value = "3"; smartObject.Properties["ToState"].Value = "2"; smartObject.Properties["ToStatus"].Value = "6"; smartObject.Properties["Regarding"].Value = K2.Configuration.CRMEntityType; smartObject.Properties["RegardingId"].Value = K2.Configuration.CRMEntityId;; smartObject.Properties["K2ActivityName"].Value = K2.ActivityInstance.Activity.Name; smartObject.Properties["K2ProcessName"].Value = K2.ProcessInstance.Process.Name; smartObject.Properties["K2ProcessInstanceId"].Value = K2.ProcessInstance.ID.ToString(); SourceCode.SmartObjects.Client.SmartObject smo = smartObjects.ExecuteSingleMethod(smartMethod); K2.SucceedingRule = true; } } catch (Exception ex) { K2.ProcessInstance.Logger.LogErrorMessage("CRM Client Event - Completing task", ex.Message); } } else { K2.SucceedingRule = false; } }
public void Main($contexttype$ K2) { string strURL = string.Empty; string smartObjectName = K2.Configuration.CRMFunctionsSmartObject; try { using (SourceCode.Workflow.Common.HostedServers.SmartObjects smartObjects = new SmartObjects(K2.Configuration.SmartObjectServer)) { SourceCode.SmartObjects.Client.SmartObject smartObject = smartObjects.GetSmartObject(smartObjectName); SourceCode.SmartObjects.Client.SmartMethod smartMethod = smartObjects.GetSingleMethod(smartObject, "GetEntityMetadata"); SourceCode.SmartObjects.Client.SmartProperty logicalEntitName = smartMethod.InputProperties["EntityLogicalName"]; logicalEntitName.Value = K2.Configuration.CRMEntityType.ToLower(); SourceCode.SmartObjects.Client.SmartObject smo = smartObjects.ExecuteSingleMethod(smartMethod); if (string.IsNullOrEmpty(K2.Configuration.CRMFormURL.Trim())) { string extraqs = string.Empty; if (!string.IsNullOrEmpty(K2.Configuration.CRMEntityForm.Trim())) { extraqs = "&extraqs=formid%3d" + K2.Configuration.CRMEntityForm; } if (!string.IsNullOrEmpty(K2.Configuration.CRMCustomSNParameter.Trim())) { if (string.IsNullOrEmpty(extraqs)) { extraqs = "&extraqs=" + K2.Configuration.CRMCustomSNParameter + "%3d" + K2.SerialNumber; } else { extraqs = extraqs + "%26" + K2.Configuration.CRMCustomSNParameter + "%3d" + K2.SerialNumber; } } strURL = CheckCRMURL(K2.Configuration.CRMServerURL) + K2.Configuration.CRMOrganisation + "/main.aspx?etc=" + smo.Properties["EntityObjectTypeCode"].Value + extraqs + "&id=" + K2.Configuration.CRMEntityId + "&pagetype=entityrecord"; } else { strURL = K2.Configuration.CRMFormURL; } smartObject.Dispose(); smartObject = null; smartMethod.Dispose(); smartMethod = null; smartObject = smartObjects.GetSmartObject(smartObjectName); smartMethod = smartObjects.GetSingleMethod(smartObject, "CreateTask"); DateTime due = new DateTime(); smartObject.Properties["Category"].Value = K2.Configuration.TaskCategory; smartObject.Properties["Description"].Value = K2.Configuration.TaskDescription; smartObject.Properties["DueDate"].Value = DateTime.TryParse(K2.Configuration.TaskDueDate, out due) ? DateTime.Parse(K2.Configuration.TaskDueDate).ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.Add(new TimeSpan(3, 0, 0, 0)).ToString("yyyy-MM-dd HH:mm:ss"); smartObject.Properties["Duration"].Value = string.IsNullOrEmpty(K2.Configuration.TaskDuration) ? "0" : K2.Configuration.TaskDuration; smartObject.Properties["OwnerFQN"].Value = K2.ActivityInstanceDestination.User.Name.Replace("K2:", "").Replace("k2:", ""); //K2.Configuration.TaskOwnerFQN.Replace("K2:", "").Replace("k2:", ""); smartObject.Properties["OwnerId"].Value = K2.Configuration.TaskOwnerId; smartObject.Properties["Owner"].Value = K2.Configuration.TaskOwner.Replace("K2:", "").Replace("k2:", ""); smartObject.Properties["Priority"].Value = string.IsNullOrEmpty(K2.Configuration.TaskPriority) ? "1" : K2.Configuration.TaskPriority; smartObject.Properties["Regarding"].Value = K2.Configuration.TaskRegarding; smartObject.Properties["RegardingId"].Value = K2.Configuration.TaskRegardingId; smartObject.Properties["State"].Value = string.IsNullOrEmpty(K2.Configuration.TaskState) ? "0" : K2.Configuration.TaskState; smartObject.Properties["Status"].Value = string.IsNullOrEmpty(K2.Configuration.TaskStatus) ? "3" : K2.Configuration.TaskStatus; smartObject.Properties["Subcategory"].Value = K2.Configuration.TaskSubcategory; smartObject.Properties["Subject"].Value = K2.Configuration.TaskSubject; smartObject.Properties["K2SerialNumber"].Value = K2.SerialNumber; smartObject.Properties["K2ActivityName"].Value = K2.ActivityInstanceDestination.Activity.Name; smartObject.Properties["K2ProcessName"].Value = K2.ProcessInstance.Process.Name; smartObject.Properties["K2ProcessInstanceId"].Value = K2.ProcessInstance.ID.ToString(); smo = smartObjects.ExecuteSingleMethod(smartMethod); XmlDocument tasks = new XmlDocument(); tasks.LoadXml(K2.ProcessInstance.XmlFields["CRM Tasks"].Value); string newtask = "<Task><TaskId>" + smo.Properties["TaskId"].Value + "</TaskId><SerialNumber>" + K2.SerialNumber + "</SerialNumber><DestinationUser>" + K2.Configuration.TaskOwnerFQN + "</DestinationUser><Process>" + K2.Configuration.ProcessName + "</Process><Activity>" + K2.Configuration.ActivityName + "</Activity></Task>"; //string newtask = "<Task><Guid>" + taskresponse.Data.Id + "</Guid><SerialNumber>" + K2.SerialNumber + "</SerialNumber><DestinationUser>" + K2.Configuration.TaskOwnerFQN + "</DestinationUser><Process></Process><Activity></Activity></Task>"; tasks.FirstChild.InnerXml += newtask; K2.ProcessInstance.XmlFields["CRM Tasks"].Value = tasks.OuterXml; K2.AddWorklist(K2.Configuration.InternetPlatform, System.Web.HttpUtility.UrlPathEncode(strURL)); } } catch (Exception ex) { K2.ProcessInstance.Logger.LogErrorMessage(K2.Event.Name, ex.Message); } }
public void ProcessRequest(HttpContext context) { #region Get image in PNG format //take JSON string and convert to png string jsonStr = context.Request.Form["json"]; SignatureToImage sit = new SignatureToImage(); #region set the width and height (IMPORTANT!!) try { sit.CanvasWidth = Convert.ToInt32(context.Request.Form["width"]); } catch { sit.CanvasWidth = 200; } try { sit.CanvasHeight = Convert.ToInt32(context.Request.Form["height"]); } catch { sit.CanvasHeight = 60; } #endregion Bitmap bitmapImg = sit.SigJsonToImage(jsonStr); string pngStr = string.Empty; using (MemoryStream ms = new MemoryStream()) { bitmapImg.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] pngBin = new byte[ms.Length]; pngBin = ms.ToArray(); pngStr = "data:image/png;base64," + Convert.ToBase64String(pngBin); } #endregion #region save to smartobject and return the new obj ID SCSMOC.SmartObjectClientServer smoSvr = new SCSMOC.SmartObjectClientServer(); try { smoSvr.CreateConnection(); smoSvr.Connection.Open(GetSMOConnStr()); SCSMOC.SmartObject smoObj = smoSvr.GetSmartObject("DigitalSignature"); smoObj.Properties["Signature"].Value = pngStr; smoObj.Properties["FormURL"].Value = context.Request.Form["url"]; smoObj.Properties["UserFQN"].Value = context.Request.Form["fqn"]; smoObj.Properties["Date"].Value = DateTime.Now.ToString(); smoObj.MethodToExecute = "Create"; smoObj = smoSvr.ExecuteScalar(smoObj); context.Response.Write(smoObj.Properties["ID"].Value.ToString()); } finally { if (smoSvr.Connection != null && smoSvr.Connection.IsConnected) { smoSvr.Connection.Dispose(); } } #endregion }
/// <summary> /// Import data from Excel file into SmartObject /// </summary> private void Import(FileProperty excelFile, string sheetName, string smartObject, string createMethodName, string headerRowSpaces, string transactionIDName, string transactionIDValue) { // arrays to store the imported column names and also the SmartObject column names // this will be used later to get a list of matching columns. string[] dsColumnNames = null, soColumnNames = null; // To store returned values from Excel file DataTable dt; // Read Data in excel file try { dt = ReadExcelFile(excelFile, sheetName); if (dt.Rows.Count == 0) { throw new ApplicationException(Resources.ExcelImportNoRowsImported); } if (dt.Columns.Count == 0) { throw new ApplicationException(Resources.ExcelImportNoColumnsFound); } // populate an array of column names dsColumnNames = new string[dt.Columns.Count]; foreach (DataColumn col in dt.Columns) { if (!string.IsNullOrWhiteSpace(headerRowSpaces) && string.Compare(headerRowSpaces.Trim(), "remove", true) == 0) { col.ColumnName = col.ColumnName.Replace(" ", ""); } else // by default replace spaces with underscores as SmartObject system names do that { col.ColumnName = col.ColumnName.Replace(" ", "_"); } // just get rid of other (non-underscore or hyphen) punctuation which is also invalid col.ColumnName = Regex.Replace(col.ColumnName, @"[\p{P}\p{S}-[-_]]", ""); dsColumnNames[col.Ordinal] = col.ColumnName.ToLower(); } } catch (Exception ex) { throw new Exception(Resources.ExcelImportUnabledToReadExcelFile, ex); } // If able to read data from Excel File, continue to bulk insert into SmartObject. try { SOC.SmartObjectClientServer smoClientServer = this.ServiceBroker.K2Connection.GetConnection <SOC.SmartObjectClientServer>(); // get the list of columns from the SmartObject, call the Create method by default using (smoClientServer.Connection) { SOC.SmartObject soImport = smoClientServer.GetSmartObject(smartObject); // populate an array of column names soColumnNames = new string[soImport.Properties.Count]; for (int i = 0; i < soImport.Properties.Count; i++) { soColumnNames[i] = soImport.Properties[i].Name.ToLower(); } var arrMatchingCols = dsColumnNames.Join(soColumnNames, dscol => dscol, socol => socol, (dscol, socol) => socol).ToList(); if (arrMatchingCols.Count == 0) { throw new ApplicationException(Resources.ExcelImportNoMatchingColumnsInSmO); } // Bulk Insert into SmartObject try { using (SOC.SmartObjectList inputList = new SOC.SmartObjectList()) { // If the CreateMethodName is not specified, use the default value of "Create" if (string.IsNullOrEmpty(createMethodName)) { soImport.MethodToExecute = "Create"; } else { soImport.MethodToExecute = createMethodName; } string sTransactionIDName = string.Empty; if (!string.IsNullOrEmpty(transactionIDName)) { sTransactionIDName = transactionIDName.ToLower(); } string sTransactionIDValue = string.Empty; if (!string.IsNullOrEmpty(transactionIDValue)) { sTransactionIDValue = transactionIDValue; } if (arrMatchingCols.Contains(sTransactionIDName)) { throw new ApplicationException(Resources.ExcelImportTransactionIDNameExist); } foreach (DataRow dr in dt.Rows) { SOC.SmartObject newSmartObject = soImport.Clone(); // loop through collection of matching fields and insert the values foreach (string sColName in arrMatchingCols) { // for handling date and datetime types DateTime tmpDate; int nonblankCharCount = dr[sColName].ToString().Length; //It is plausible that there will valid cases of null/empty cells // handle Date amd DateTime columns correctly. Convert Excel datetime format (double) to .NET DateTime type if (nonblankCharCount > 0 && newSmartObject.Properties[sColName].Type == SOC.PropertyType.DateTime) // DateTime column { tmpDate = DateTime.FromOADate(Convert.ToDouble(dr[sColName].ToString())); newSmartObject.Properties[sColName].Value = String.Concat(tmpDate.ToShortDateString(), " ", tmpDate.ToShortTimeString()); } else if (nonblankCharCount > 0 && newSmartObject.Properties[sColName].Type == SOC.PropertyType.Date) // Date column { tmpDate = DateTime.FromOADate(Convert.ToDouble(dr[sColName].ToString())); newSmartObject.Properties[sColName].Value = tmpDate.ToShortDateString(); } else if (nonblankCharCount > 0 && newSmartObject.Properties[sColName].Type == SOC.PropertyType.Time) // Time column { tmpDate = DateTime.FromOADate(Convert.ToDouble(dr[sColName].ToString())); newSmartObject.Properties[sColName].Value = tmpDate.ToShortTimeString(); } else // not a Date or DateTime column { newSmartObject.Properties[sColName].Value = dr[sColName].ToString(); } } // Add the transaction ID value for identification purposes. if (!string.IsNullOrEmpty(sTransactionIDName) && !string.IsNullOrEmpty(sTransactionIDValue)) { // replace spaces with underscores as SmartObject system names do that newSmartObject.Properties[sTransactionIDName.Replace(" ", "_")].Value = sTransactionIDValue; } inputList.SmartObjectsList.Add(newSmartObject); } smoClientServer.ExecuteBulkScalar(soImport, inputList); } // free objects arrMatchingCols = null; soImport = null; } catch (Exception ex) { throw new Exception(Resources.ExcelImportUnabledToInsertIntoSmO, ex); } } } catch (Exception ex) { throw new Exception(Resources.ExcelImportUnabledToConnectToK2Server, ex); } }