public bool HasPermission(string permissionName) { bool retVal = false; UserIdentityService userIdentity = UserIdentityService.GetInstance(); string userName = userIdentity.IdentityProvider.GetUserName(); List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>(); ScreenDataCommandParameter p = null; p = new ScreenDataCommandParameter(ParameterUserName, userName); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterPermissionName, permissionName); parameters.Add(p); //get data from data command DataTable dt = sql.GetDataForDataCommand(DataCommandUserGetPermissions, parameters); if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { if (Convert.ToBoolean(row[ColumnHasPermission])) { retVal = true; break; } } } return(retVal); }
public bool IsInRole(string roleName) { bool retVal = false; UserIdentityService userIdentity = UserIdentityService.GetInstance(); string userName = userIdentity.IdentityProvider.GetUserName(); List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>(); ScreenDataCommandParameter p = null; p = new ScreenDataCommandParameter(ParameterUserName, userName); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterRoleName, roleName); parameters.Add(p); //get data from data command DataTable dt = sql.GetDataForDataCommand(DataCommandRoleGetByUserAndRoleName, parameters); if (dt.Rows.Count > 0) { retVal = true; } return(retVal); }
public void SetStep(CodeTorch.Core.Workflow workflow, WorkflowStep step, string entityIDValue, string comment) { List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>(); ScreenDataCommandParameter p = null; p = new ScreenDataCommandParameter(ParameterWorkflowStatusID, null); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterWorkflowCode, workflow.Code); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterWorkflowStepCode, step.Code); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterEntityID, entityIDValue); parameters.Add(p); string userName; userName = UserIdentityService.GetInstance().IdentityProvider.GetUserName(); p = new ScreenDataCommandParameter(ParameterCreatedBy, userName); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterComment, comment); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterUpdateCurrent, step.UpdateEntityWithStatusCode); parameters.Add(p); //get data from data command ExecuteDataCommand(DataCommandWorkflowSetStep, parameters); }
public bool ChangeWorkflowStep(CodeTorch.Core.Workflow workflow, WorkflowNextStep nextStep, string entityIDValue, string comment) { bool success = false; //get current workflow step WorkflowStep currentStep = GetCurrentWorkflowStep(workflow, entityIDValue); //see if next workflowstep is in possible WorkflowNextStep validNextStep = currentStep.PossibleNextSteps. Where(s => s.Code.ToLower() == nextStep.Code.ToLower()).SingleOrDefault(); if (validNextStep != null) { //check comments if ((validNextStep.RequireComment) && (String.IsNullOrEmpty(comment))) { throw new ApplicationException("Comments are required to change to this step"); } else { WorkflowStep step = workflow.GetStepByCode(validNextStep.Code); string userName; userName = UserIdentityService.GetInstance().IdentityProvider.GetUserName(); using (TransactionScope rootScope = TransactionUtils.CreateTransactionScope()) { foreach (BaseWorkflowAction action in step.Actions) { action.Execute(null, workflow.Code, currentStep.Code, validNextStep.Code, entityIDValue, comment, userName); } //update workflow step SetStep(workflow, step, entityIDValue, comment); if (step.UpdateEntityWithStatusCode) { //update existing table status SetEntityStatus(workflow, step, entityIDValue); } success = true; rootScope.Complete(); } } } else { //invalid - someone may have changed status throw new ApplicationException("Status cannot be changed at this time"); } return(success); }
public static IMobilePage GetPage(string pageName) { IMobilePage retVal = null; MobileScreen screen = MobileScreen.GetByName(pageName); switch (screen.Type.ToLower()) { case "mobilecontent": retVal = new MobileContentPage(screen); break; case "mobiletabbed": retVal = new MobileTabbedPage(screen); break; case "mobilenavigation": Page root = GetPage(((MobileNavigationScreen)screen).GetRootScreen()).GetPage(); retVal = new MobileNavigationPage(screen, root); break; } if (retVal != null) { string loginScreen = Configuration.GetInstance().App.LoginScreen; if (!String.IsNullOrEmpty(loginScreen)) { if (retVal.Screen != null) { if (retVal.Screen.RequireAuthentication) { UserIdentityService identity = UserIdentityService.GetInstance(); string userName = identity.IdentityProvider.GetUserName(); if (String.IsNullOrEmpty(userName)) { retVal = GetPage(loginScreen); } } } } } return(retVal); }
private void UploadDocument( Document doc ) { doc.ID = Guid.NewGuid().ToString(); string modifiedBy = null; string fileExtension = Path.GetExtension(doc.FileName); string storageProviderFolder = null; byte[] fileContents = null; modifiedBy = UserIdentityService.GetInstance().IdentityProvider.GetUserName(); foreach (Setting setting in doc.Settings) { switch (setting.Name.ToLower()) { case "modifiedby": if (!string.IsNullOrEmpty(setting.Value)) { modifiedBy = setting.Value; } break; } } fileContents = new byte[doc.Size]; using (Stream str = doc.Stream) { str.Read(fileContents, 0, doc.Size); // more code } DocumentFunctions utility = new DocumentFunctions(); utility.InsertDocument( doc.ID, "DB", doc.EntityID, doc.EntityType, doc.FileName, doc.DocumentType, doc.ContentType, doc.Size, 1, doc.Url, fileContents, false, modifiedBy); }
public void InsertMailMessage(EmailMessage message) { List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>(); ScreenDataCommandParameter p = null; p = new ScreenDataCommandParameter(ParameterMailMessageID, message.ID); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterMailSubject, message.Subject); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterMailBody, message.Body); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterPriority, message.Priority); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterIsBodyHtml, message.IsBodyHtml); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterTemplate, message.Template); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterEntityType, message.EntityType); parameters.Add(p); p = new ScreenDataCommandParameter(ParameterEntityID, message.EntityID); parameters.Add(p); string userName; userName = UserIdentityService.GetInstance().IdentityProvider.GetUserName(); p = new ScreenDataCommandParameter(ParameterCreatedBy, userName); parameters.Add(p); //get data from data command sql.ExecuteDataCommand(DataCommandWMailInsertMailMessage, parameters); }
private void UploadDocument( Document doc ) { string modifiedBy = null; string fileExtension = Path.GetExtension(doc.FileName); string storageProviderFolder = null; byte[] fileContents = null; modifiedBy = UserIdentityService.GetInstance().IdentityProvider.GetUserName(); foreach (Setting setting in doc.Settings) { switch (setting.Name.ToLower()) { case "folder": storageProviderFolder = setting.Value; break; case "modifiedby": if (!string.IsNullOrEmpty(setting.Value)) { modifiedBy = setting.Value; } break; } } string accessKeyID = GetUserName(storageProviderUserNameSource, storageProviderUserNameKey); string secretAccessKey = GetPassword(storageProviderPasswordSource, storageProviderPasswordKey); string region = GetRegion(storageProviderRegionSource, storageProviderRegionKey); TransferUtility fileTransferUtility = new TransferUtility(accessKeyID, secretAccessKey, RegionEndpoint.GetBySystemName(region)); TransferUtilityUploadRequest request = new TransferUtilityUploadRequest(); request.BucketName = GetBucket(storageProviderContainerSource, storageProviderContainerKey); //TODO - need to secure and provide options for ACL and storage class request.CannedACL = S3CannedACL.PublicRead; request.StorageClass = S3StorageClass.ReducedRedundancy; doc.ID = Guid.NewGuid().ToString(); if (String.IsNullOrEmpty(storageProviderFolder)) { request.Key = String.Format("{0}{1}", doc.ID, fileExtension); } else { request.Key = String.Format("{0}/{1}{2}", storageProviderFolder, doc.ID, fileExtension); } request.AutoCloseStream = false; request.ContentType = doc.ContentType; request.InputStream = doc.Stream; request.InputStream.Position = 0; fileTransferUtility.Upload(request); doc.Url = String.Format("{0}.s3.amazonaws.com/{1}", request.BucketName, request.Key); DocumentFunctions utility = new DocumentFunctions(); utility.InsertDocument( doc.ID, "AmazonS3", doc.EntityID, doc.EntityType, doc.FileName, doc.DocumentType, doc.ContentType, doc.Size, 1, doc.Url, fileContents, false, modifiedBy); }
private object GetParameterInputValue(IScreenParameter parameter, object newID) { object retVal = null; App app = CodeTorch.Core.Configuration.GetInstance().App; CodeTorch.Web.FieldTemplates.BaseFieldTemplate f = null; switch (parameter.InputType) { case ScreenInputType.AppSetting: retVal = ConfigurationManager.AppSettings[parameter.InputKey]; break; case ScreenInputType.Control: throw new NotSupportedException(); //if (container == null) //{ // f = page.FindFieldRecursive(parameter.InputKey); //} //else //{ // f = page.FindFieldRecursive(container, parameter.InputKey); //} //if (f != null) //{ // retVal = f.Value; //} break; case ScreenInputType.ControlText: //if (container == null) //{ // f = page.FindFieldRecursive(parameter.InputKey); //} //else //{ // f = page.FindFieldRecursive(container, parameter.InputKey); //} //if (f != null) //{ // retVal = f.DisplayText; //} throw new NotSupportedException(); break; case ScreenInputType.Cookie: retVal = HttpContext.Current.Request.Cookies[parameter.InputKey].Value; break; case ScreenInputType.File: //currently onlu supports storage to database if (HttpContext.Current.Request.ContentType.ToLower().Contains("multipart")) { HttpPostedFile file = null; if (HttpContext.Current.Request.Files.Count == 1) { //for refit support file = HttpContext.Current.Request.Files[0] as HttpPostedFile; } else { file = HttpContext.Current.Request.Files[parameter.InputKey] as HttpPostedFile; } file = HttpContext.Current.Request.Files[parameter.InputKey] as HttpPostedFile; if (file != null) { if (file.ContentLength > 0) { DocumentService documentService = DocumentService.GetInstance(); if (String.IsNullOrEmpty(parameter.Default)) { retVal = ReadFully(file.InputStream); } else { DocumentRepository repo = DocumentRepository.GetByName(parameter.Default); if (repo == null) { throw new Exception(String.Format("Parameter {0} is assigned to a missing document repository - {1}. Please check configuration.", parameter.Name, parameter.Default)); } IDocumentProvider documentProvider = documentService.GetProvider(repo); if (documentProvider == null) { throw new Exception(String.Format("Parameter {0} is assigned to document repository - {1}. The provider for this repository could not be found. Please check configuration", parameter.Name, parameter.Default)); } // AppendDocumentID(DocumentID); Document document = new Document(); //need to clone from config document.FileName = file.FileName; document.ContentType = file.ContentType; if (String.IsNullOrEmpty(document.ContentType)) { document.ContentType = "application / octet - stream"; } document.Size = Convert.ToInt32(file.ContentLength); document.Stream = file.InputStream; document.EntityID = "TEMP"; document.EntityType = "TEMP"; document.Settings.Add(new Setting("ModifiedBy", "SYSTEM")); //perform actual upload document.ID = documentProvider.Upload(document); retVal = document.ID; } } } } break; case ScreenInputType.Form: retVal = HttpContext.Current.Request.Form[parameter.InputKey]; break; case ScreenInputType.Header: retVal = HttpContext.Current.Request.Headers[parameter.InputKey]; break; case ScreenInputType.QueryString: retVal = HttpContext.Current.Request.QueryString[parameter.InputKey]; break; case ScreenInputType.Session: retVal = HttpContext.Current.Session[parameter.InputKey]; break; case ScreenInputType.Special: switch (parameter.InputKey.ToLower()) { case "null": retVal = null; break; case "newid": retVal = newID; break; case "dbnull": retVal = DBNull.Value; break; case "username": retVal = UserIdentityService.GetInstance().IdentityProvider.GetUserName(); break; case "hostheader": retVal = HttpContext.Current.Request.ServerVariables["HTTP_HOST"]; break; case "applicationpath": retVal = HttpContext.Current.Request.ApplicationPath; break; case "urlsegment": try { retVal = this.RouteData.Values[parameter.Default]; } catch { } break; case "absoluteapplicationpath": retVal = String.Format("{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.ServerVariables["HTTP_HOST"], ((HttpContext.Current.Request.ApplicationPath == "/") ? String.Empty : HttpContext.Current.Request.ApplicationPath)); break; } break; case ScreenInputType.User: try { List <string> profileProperties = CodeTorch.Core.Configuration.GetInstance().App.ProfileProperties; int propertyIndex = Enumerable.Range(0, profileProperties.Count).First(i => profileProperties[i].ToLower() == parameter.InputKey.ToLower()); FormsIdentity identity = (FormsIdentity)HttpContext.Current.User.Identity; FormsAuthenticationTicket ticket = identity.Ticket; retVal = ticket.UserData.Split('|')[propertyIndex]; } catch { } break; case ScreenInputType.Constant: retVal = parameter.InputKey; break; case ScreenInputType.ServerVariables: retVal = HttpContext.Current.Request.ServerVariables[parameter.InputKey]; break; } if ( (parameter.InputType != ScreenInputType.Special) && (parameter.InputType != ScreenInputType.File) ) { if (retVal == null) { retVal = parameter.Default; } } return(retVal); }
public static object GetParameterInputValue(BasePage page, IScreenParameter parameter, Control container) { object retVal = null; App app = CodeTorch.Core.Configuration.GetInstance().App; CodeTorch.Web.FieldTemplates.BaseFieldTemplate f = null; switch (parameter.InputType) { case ScreenInputType.AppSetting: retVal = ConfigurationManager.AppSettings[parameter.InputKey]; break; case ScreenInputType.Control: if (container == null) { f = page.FindFieldRecursive(parameter.InputKey); } else { f = page.FindFieldRecursive(container, parameter.InputKey); } if (f != null) { retVal = f.Value; } break; case ScreenInputType.ControlText: if (container == null) { f = page.FindFieldRecursive(parameter.InputKey); } else { f = page.FindFieldRecursive(container, parameter.InputKey); } if (f != null) { retVal = f.DisplayText; } break; case ScreenInputType.Cookie: retVal = page.Request.Cookies[parameter.InputKey].Value; break; case ScreenInputType.Form: retVal = page.Request.Form[parameter.InputKey]; break; case ScreenInputType.Header: retVal = page.Request.Headers[parameter.InputKey]; break; case ScreenInputType.QueryString: retVal = page.Request.QueryString[parameter.InputKey]; break; case ScreenInputType.Session: retVal = page.Session[parameter.InputKey]; break; case ScreenInputType.Special: switch (parameter.InputKey.ToLower()) { case "null": retVal = null; break; case "dbnull": retVal = DBNull.Value; break; case "username": retVal = UserIdentityService.GetInstance().IdentityProvider.GetUserName(); break; case "hostheader": retVal = HttpContext.Current.Request.ServerVariables["HTTP_HOST"]; break; case "applicationpath": retVal = HttpContext.Current.Request.ApplicationPath; break; case "absoluteapplicationpath": retVal = String.Format("{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.ServerVariables["HTTP_HOST"], ((HttpContext.Current.Request.ApplicationPath == "/") ? String.Empty : HttpContext.Current.Request.ApplicationPath)); break; } break; case ScreenInputType.User: try { retVal = GetProfileProperty(parameter.InputKey); } catch { } break; case ScreenInputType.Constant: retVal = parameter.InputKey; break; case ScreenInputType.ServerVariables: retVal = HttpContext.Current.Request.ServerVariables[parameter.InputKey]; break; } if (parameter.InputType != ScreenInputType.Special) { if (retVal == null) { retVal = parameter.Default; } } return(retVal); }