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 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 }
private void FindUserInRole() { ServiceObject serviceObject = this.Service.ServiceObjects[0]; serviceObject.Properties.InitResultTable(); DataTable results = this.ServicePackage.ResultTable; DataRow row; bool isRoleMember = false; UserRoleManager urmServer = new UserRoleManager(); using (urmServer.CreateConnection()) { urmServer.Connection.Open(WFMServerConnectionString); Role role = urmServer.GetRole(serviceObject.Properties[Constants.Properties.RoleName].Value as string); if (role == null) { throw new ApplicationException(Constants.ErrorText.RoleNotExist); } foreach (RoleItem roleItem in role.Include) { string roleItemName = roleItem.Name; if (roleItem is UserItem) { // check if the specified username matches the current roleItem name if (serviceObject.Properties[Constants.Properties.RoleItem].Value.ToString() == roleItem.Name) { // user exist in role row = results.NewRow(); results.Rows.Add(FillResultRow(row, true)); isRoleMember = true; break; } } else { // It is a group item, use the smartobject method UMUser.Get_Group_Users to resolve all group users // Open a K2 Server connection smartobjectClient.SmartObjectClientServer smoServer = new smartobjectClient.SmartObjectClientServer(); smoServer.CreateConnection(); smoServer.Connection.Open(WFMServerConnectionString); // Get a handle to the ' UMUser' SmartObject smartobjectClient.SmartObject umUser = smoServer.GetSmartObject("UMUser"); // Specify which method will be called smartobjectClient.SmartListMethod getGroupUsers = umUser.ListMethods["Get_Group_Users"]; umUser.MethodToExecute = getGroupUsers.Name; // Split FQN in SecurityLabel and groupname string[] fqn = roleItem.Name.Split(':'); // Set the input properties getGroupUsers.InputProperties["Labelname"].Value = fqn[0]; getGroupUsers.InputProperties["Group_name"].Value = fqn[1]; // Call the method smartobjectClient.SmartObjectList smartObjectGroupUsers = smoServer.ExecuteList(umUser); List<string> groupUsers = new List<string>(); foreach (smartobjectClient.SmartObject smo in smartObjectGroupUsers.SmartObjectsList) { groupUsers.Add(smo.Properties["FQN"].Value); } foreach (string user in groupUsers) { // check if the specified username matches the current roleItem name if (serviceObject.Properties[Constants.Properties.RoleItem].Value.ToString() == user) { // user exist in role row = results.NewRow(); results.Rows.Add(FillResultRow(row, true)); isRoleMember = true; break; } } } } // the specified user is not found in the specified role if (!isRoleMember) { row = results.NewRow(); results.Rows.Add(FillResultRow(row, false)); } } }
/// <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); } }