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();
                }
            }
        }
        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));
                }
            }
        }
        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
        }