public virtual void SetPageTitle() { if (this.UseTitleCommand()) { try { if (String.IsNullOrEmpty(this.Screen.Title.CommandName)) { throw new ApplicationException("Title.CommandName is missing"); } List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(this.Screen.Title.CommandName, this); DataTable data = dataCommandDB.GetDataForDataCommand(this.Screen.Title.CommandName, parameters); if (data.Rows.Count > 0) { this.Title = BuildTitle(data.Rows[0], GetTitleFormatString()); } } catch (Exception ex) { this.Title = String.Format("Error while setting page title - {0}", ex.Message); } } else { if (Screen != null) { this.Title = GetGlobalResourceString("Screen.Title.Name", Screen.Title.Name); } } }
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); }
private Hashtable GetContentItems(Template contentTemplate) { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); Hashtable retVal = new Hashtable(); var dataItems = from t in contentTemplate.DataItems join c in Me.DataItems on t.Name.ToLower() equals c.DataItem.ToLower() select new { t.Name, Item = c }; foreach (var dataItem in dataItems) { List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(dataItem.Item.DataCommand, page); DataTable data = dataCommandDB.GetDataForDataCommand(dataItem.Item.DataCommand, parameters); retVal.Add(dataItem.Name, data); } return(retVal); }
private string GetDynamicPageTemplate(ScreenPageTemplate pageTemplate) { string retVal = null; log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); try { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(pageTemplate.DataCommand, this); DataTable dt = dataCommandDB.GetDataForDataCommand(pageTemplate.DataCommand, parameters); if (dt.Rows.Count > 0) { if (dt.Columns.Contains(pageTemplate.DataField)) { retVal = dt.Rows[0][pageTemplate.DataField].ToString(); } } } catch (Exception ex) { DisplayErrorAlert(ex); log.Error(ex); } return(retVal); }
public override void PopulateControl() { base.PopulateControl(); if (!String.IsNullOrEmpty(Me.SelectDataCommand)) { PageDB pageDB = new PageDB(); List <ScreenDataCommandParameter> parameters; BasePage page = ((BasePage)this.Page); DataCommandService dataCommand = DataCommandService.GetInstance(); parameters = pageDB.GetPopulatedCommandParameters(Me.SelectDataCommand, (BasePage)this.Page); DataTable data = dataCommand.GetDataForDataCommand(Me.SelectDataCommand, parameters); if (data.Rows.Count > 0) { this.Content.Text = PopulateContent(Me.Content, data.Rows[0]); } else { this.Content.Text = Me.Content; } } else { this.Content.Text = Me.Content; } }
private DataTable GetData(DataCommandService dataCommandDB, PageDB pageDB, CodeTorch.Core.ReportDataSource dataSource) { List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(dataSource.ReportCommand, page); DataTable data = dataCommandDB.GetDataForDataCommand(dataSource.ReportCommand, parameters); return(data); }
public override void PopulateControl() { base.PopulateControl(); string DataCommandName = null; if (DetailsSection != null) { DataCommandName = DetailsSection.SelectDataCommand; } if (!String.IsNullOrEmpty(DataCommandName)) { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); List <ScreenDataCommandParameter> parameters = null; BasePage page = (BasePage)this.Page; parameters = GetParameters(DataCommandName); DataTable data = dataCommandDB.GetDataForDataCommand(DataCommandName, parameters); page.PopulateFormByDataTable(Section.Widgets, data); } ExecuteAfterPopulateSection(); }
private string GetDatabaseDisplayValue(string value) { string retVal = null; DataCommandService dataCommandDB = DataCommandService.GetInstance(); if (String.IsNullOrEmpty(Me.PickerObject.DataCommand)) { throw new ApplicationException("Picker does not have a datacommand specified in configuration"); } DataCommand command = DataCommand.GetDataCommand(Me.PickerObject.DataCommand); if (command == null) { throw new ApplicationException(String.Format("DataCommand {0} does not exist in configuration", Me.PickerObject.DataCommand)); } List<ScreenDataCommandParameter> parameters = new List<ScreenDataCommandParameter>(); ScreenDataCommandParameter parameter = new ScreenDataCommandParameter(); parameter.Name = command.Parameters[0].Name; parameter.Value = value; parameters.Add(parameter); DataTable dt = dataCommandDB.GetDataForDataCommand(command.Name, parameters); if (dt.Rows.Count > 0) { retVal = dt.Rows[0][Me.PickerObject.DisplayField].ToString(); } return retVal; }
private void DefaultForm() { log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); try { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); if (!String.IsNullOrEmpty(Me.DefaultCommand)) { List <ScreenDataCommandParameter> parameters = null; parameters = pageDB.GetPopulatedCommandParameters(Me.DefaultCommand, Page); DataTable retVal = dataCommandDB.GetDataForDataCommand(Me.DefaultCommand, parameters); foreach (Section section in Page.Screen.Sections) { Page.PopulateFormByDataTable(section.Widgets, retVal); } } } catch (Exception ex) { Page.DisplayErrorAlert(ex); log.Error(ex); } }
void DataCommandValidator_ServerValidate(object source, ServerValidateEventArgs args) { bool IsValid = false; DataCommandService dataCommand = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); try { CustomDataCommandValidator validator = (CustomDataCommandValidator)source; List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(validator.DataCommand, ((CodeTorch.Web.Templates.BasePage) this.Page)); if (validator.UseValueParameter) { ScreenDataCommandParameter valueParameter = parameters.Where(p => ( (p.Name.ToLower() == validator.ValueParameter.ToLower()) ) ) .SingleOrDefault(); if (valueParameter != null) { valueParameter.Value = args.Value; } } DataTable data = dataCommand.GetDataForDataCommand(validator.DataCommand, parameters); if (data.Rows.Count == 1) { if (validator.UseErrorMessageField) { if (String.IsNullOrEmpty(validator.ErrorMessageField)) { throw new ApplicationException(String.Format("ErrorMessageField for validator {0} is not configured", validator.ID)); } else { if (data.Columns.Contains(validator.ErrorMessageField)) { validator.ErrorMessage = data.Rows[0][validator.ErrorMessageField].ToString(); } } } if (data.Columns.Contains(validator.ValidationField)) { IsValid = Convert.ToBoolean(data.Rows[0][validator.ValidationField]); } } } catch (Exception ex) { args.IsValid = false; ((System.Web.UI.WebControls.BaseValidator)source).ErrorMessage = "Validator: " + ex.Message; } args.IsValid = IsValid; }
public static DataTable GetUsers(WorkflowDynamicSecurityGroup group, Workflow workflow, WorkflowStep step, string EntityID, string UserName) { DataTable retVal = null; DataCommandService dataCommandDB = DataCommandService.GetInstance(); DataCommand command = Core.DataCommand.GetDataCommand(group.DataCommand); if (command == null) { throw new ApplicationException(String.Format("DataCommand {0} could not be found in configuration", group.DataCommand)); } List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>(); ScreenDataCommandParameter parameter = null; if (!String.IsNullOrEmpty(group.WorkflowCodeParameter)) { parameter = new ScreenDataCommandParameter(); parameter.Name = group.WorkflowCodeParameter; parameter.Value = workflow.Code; parameters.Add(parameter); } if (!String.IsNullOrEmpty(group.CurrentWorkflowStepCodeParameter)) { parameter = new ScreenDataCommandParameter(); parameter.Name = group.CurrentWorkflowStepCodeParameter; parameter.Value = step.Code; parameters.Add(parameter); } if (!String.IsNullOrEmpty(group.EntityIDParameter)) { parameter = new ScreenDataCommandParameter(); parameter.Name = group.EntityIDParameter; parameter.Value = EntityID; parameters.Add(parameter); } if (!String.IsNullOrEmpty(group.UsernameParameter)) { parameter = new ScreenDataCommandParameter(); parameter.Name = group.UsernameParameter; parameter.Value = UserName; parameters.Add(parameter); } //execute command with transaction //CommandType type = (command.Type == DataCommandCommandType.StoredProcedure) ? CommandType.StoredProcedure : CommandType.Text; retVal = dataCommandDB.GetDataForDataCommand(command.Name, parameters); return(retVal); }
private DataTable GetData() { List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(Me.SelectDataCommand, ((CodeTorch.Web.Templates.BasePage) this.Page)); PopulateScreenParameterWithControlValue(parameters); return(dataCommand.GetDataForDataCommand(Me.SelectDataCommand, parameters)); }
private void FillGrid() { if (String.IsNullOrEmpty(Me.Grid.SelectDataCommand)) { throw new ApplicationException("Invalid SelectDataCommand"); } DataCommandService dataCommand = DataCommandService.GetInstance(); List <ScreenDataCommandParameter> parameters = GetParameters(); Grid.DataSource = dataCommand.GetDataForDataCommand(Me.Grid.SelectDataCommand, parameters); }
private string ExecuteDataCommand(string retVal) { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); DataCommand command = DataCommand.GetDataCommand(Me.DataCommand); List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(Me.DataCommand, Page); DataTable data = null; object commandRetVal = null; if (command == null) { throw new ApplicationException(String.Format("DataCommand {0} could not be found in configuration", Me.DataCommand)); } if (command.ReturnType == DataCommandReturnType.DataTable) { data = dataCommandDB.GetDataForDataCommand(Me.DataCommand, parameters); } else { commandRetVal = dataCommandDB.ExecuteDataCommand(Me.DataCommand, parameters); } if (command.ReturnType == DataCommandReturnType.DataTable) { if (data != null) { if (!String.IsNullOrEmpty(Me.RedirectUrlField)) { if (data.Rows.Count == 1) { retVal = data.Rows[0][Me.RedirectUrlField].ToString(); } else { throw new ApplicationException("Invalid number of rows returned - " + data.Rows.Count); } } } } else { if (commandRetVal != null) { retVal = commandRetVal.ToString(); } } return(retVal); }
public static string GetProfileProperty(string PropertyName, List <string> profileProperties) { string profileSessionKey = "CodeTorch.Profile"; App app = CodeTorch.Core.Configuration.GetInstance().App; string retVal = ""; int propertyIndex = Enumerable.Range(0, profileProperties.Count).First(i => profileProperties[i].ToLower() == PropertyName.ToLower()); if (app.AuthenticationMode is FormsAuthenticationMode) { //get profile property from form authentication cookie FormsIdentity identity = (FormsIdentity)HttpContext.Current.User.Identity; FormsAuthenticationTicket ticket = identity.Ticket; retVal = ticket.UserData.Split('|')[propertyIndex]; } else { throw new NotImplementedException(); //get profile property from session object DataTable dtProfile = null; if (HttpContext.Current != null) { if (HttpContext.Current.Session[profileSessionKey] != null) { dtProfile = (DataTable)HttpContext.Current.Session[profileSessionKey]; } else { //TODO - needs to be moved to app authenticate DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(app.ProfileCommand, null); dtProfile = dataCommandDB.GetDataForDataCommand(app.ProfileCommand, parameters); HttpContext.Current.Session[profileSessionKey] = dtProfile; } if ((dtProfile != null) && (dtProfile.Rows.Count == 1)) { retVal = dtProfile.Rows[0][PropertyName].ToString(); } } } return(retVal); }
private DataTable GetData() { if (String.IsNullOrEmpty(SelectDataCommand)) { throw new ApplicationException("SelectDataCommand is invalid"); } List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(SelectDataCommand, ((CodeTorch.Web.Templates.BasePage) this.Page)); PopulateScreenParameterWithControlValue(parameters); return(dataCommand.GetDataForDataCommand(SelectDataCommand, parameters)); }
private DataTable GetContentTemplateData() { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); if (String.IsNullOrEmpty(Me.ContentTemplateDataCommand)) { throw new ApplicationException("ContentTemplateDataCommand is not configured"); } List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(Me.ContentTemplateDataCommand, page); DataTable data = dataCommandDB.GetDataForDataCommand(Me.ContentTemplateDataCommand, parameters); return(data); }
private CodeTorch.Core.Workflow GetWorkflow() { CodeTorch.Core.Workflow workflow = null; string workflowCode = null; switch (Me.WorkflowSelectionMode) { case WorkflowSelectionMode.Static: if (String.IsNullOrEmpty(Me.WorkflowCode)) { throw new ApplicationException("Invalid Workflow Code"); } workflowCode = Me.WorkflowCode; break; case WorkflowSelectionMode.DataCommand: //call screen datacommand if (String.IsNullOrEmpty(Me.WorkflowSelectionCommandName) || String.IsNullOrEmpty(Me.WorkflowSelectionFieldName)) { throw new ApplicationException("Invalid WorkflowSelectionCommandName OR WorkflowSelectionFieldName"); } List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(Me.WorkflowSelectionCommandName, ((CodeTorch.Web.Templates.BasePage) this.Page)); DataTable data = dataCommand.GetDataForDataCommand(Me.WorkflowSelectionCommandName, parameters); if (data.Rows.Count > 0) { workflowCode = data.Rows[0][Me.WorkflowSelectionFieldName].ToString(); } break; } if (!String.IsNullOrEmpty(workflowCode)) { workflow = CodeTorch.Core.Workflow.GetWorkflowByCode(workflowCode); } return(workflow); }
private DataTable GetDataForDataCommand(string dataCommand, List <ScreenDataCommandParameter> parameters) { DataTable retVal = null; if (Connection == null) { retVal = sql.GetDataForDataCommand(dataCommand, parameters); } else { DataCommand command = DataCommand.GetDataCommand(dataCommand); if (command == null) { throw new Exception(String.Format("DataCommand {0} could not be found in configuration", dataCommand)); } retVal = sql.GetData(null, Connection, command, parameters, command.Text); } return(retVal); }
private static void HandleEditableGridDetailPopulation(BasePage page, CodeTorch.Core.Grid GridConfig, bool UseDefaultCommand, string DefaultCommandName, GridItemEventArgs e) { if (e.Item is GridEditFormItem && e.Item.IsInEditMode) { Control c = page.FindControlRecursive(e.Item, GridEditFormItem.EditFormUserControlID); if (c != null) { GridDetail detail = ((GridDetail)c); if (e.Item.OwnerTableView.IsItemInserted) { if (UseDefaultCommand) { if (!String.IsNullOrEmpty(DefaultCommandName)) { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(DefaultCommandName, page); DataTable data = dataCommandDB.GetDataForDataCommand(GridConfig.SelectDataCommand, parameters); detail.Default(e.Item, data); } } } else { DataRowView data = ((DataRowView)detail.DataItem); detail.Populate(e.Item); } detail.ExecuteAfterPopulateSections(); } } }
public static void FillGrid(BasePage page, RadGrid Grid, CodeTorch.Core.Grid GridConfig) { log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); try { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); if (String.IsNullOrEmpty(GridConfig.SelectDataCommand)) { throw new ApplicationException("SelectDataCommand is not configured"); } List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(GridConfig.SelectDataCommand, page); Grid.DataSource = dataCommandDB.GetDataForDataCommand(GridConfig.SelectDataCommand, parameters); } catch (Exception ex) { page.DisplayErrorAlert(ex); log.Error(ex); } }
private void DownloadResizedDocument() { log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); try { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); if (!String.IsNullOrEmpty(Me.RetrieveCommand)) { List <ScreenDataCommandParameter> parameters = null; parameters = pageDB.GetPopulatedCommandParameters(Me.RetrieveCommand, Page); DataTable dt = dataCommandDB.GetDataForDataCommand(Me.RetrieveCommand, parameters); if (dt.Rows.Count != 0) { byte[] data = null; string DocumentUrl = dt.Rows[0]["DocumentUrl"].ToString(); Page.Response.Clear(); Page.Response.ContentType = dt.Rows[0]["ContentType"].ToString(); Page.Response.AddHeader("Content-Disposition", "attachment;filename=" + dt.Rows[0]["DocumentName"].ToString()); if (String.IsNullOrEmpty(DocumentUrl)) { data = (byte[])dt.Rows[0]["File"]; data = ScaleImageByteArray(data, MaxWidth, MaxHeight, GetImageFormatFromContentType(Page.Response.ContentType)); Page.Response.OutputStream.Write(data, 0, data.Length); // Flush the data Page.Response.Flush(); } else { //redirect to the document url location UriBuilder remoteDocument = new UriBuilder(DocumentUrl); HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(remoteDocument.Uri.AbsoluteUri); HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse(); if (fileReq.ContentLength > 0) { fileResp.ContentLength = fileReq.ContentLength; } Stream stream = fileResp.GetResponseStream(); int length = stream.Read(data, 0, Convert.ToInt32(fileResp.ContentLength)); data = ScaleImageByteArray(data, MaxWidth, MaxHeight, GetImageFormatFromContentType(Page.Response.ContentType)); Page.Response.OutputStream.Write(data, 0, data.Length); // Flush the data Page.Response.Flush(); } HttpContext.Current.ApplicationInstance.CompleteRequest(); } else { throw new Exception("File Not Found"); } } } catch (Exception ex) { Page.DisplayErrorAlert(ex); log.Error(ex); } }
private void DownloadDocument() { log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); try { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); if (!String.IsNullOrEmpty(Me.RetrieveCommand)) { List <ScreenDataCommandParameter> parameters = null; parameters = pageDB.GetPopulatedCommandParameters(Me.RetrieveCommand, Page); DataTable dt = dataCommandDB.GetDataForDataCommand(Me.RetrieveCommand, parameters); if (dt.Rows.Count != 0) { byte[] data = null; string DocumentUrl = dt.Rows[0]["DocumentUrl"].ToString(); Page.Response.Clear(); Page.Response.ContentType = dt.Rows[0]["ContentType"].ToString(); //Force file download with content disposition if (Me.ForceDownloadWithContentDisposition) { Page.Response.AddHeader("Content-Disposition", "attachment;filename=" + dt.Rows[0]["DocumentName"].ToString()); } if (String.IsNullOrEmpty(DocumentUrl)) { data = (byte[])dt.Rows[0]["File"]; Page.Response.OutputStream.Write(data, 0, Convert.ToInt32(dt.Rows[0]["Size"])); // Flush the data Page.Response.Flush(); } else { //redirect to the document url location UriBuilder remoteDocument = new UriBuilder(DocumentUrl); HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(remoteDocument.Uri.AbsoluteUri); HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse(); if (fileReq.ContentLength > 0) { fileResp.ContentLength = fileReq.ContentLength; } Stream stream = fileResp.GetResponseStream(); int bytesToRead = 10000; int length; data = new Byte[bytesToRead]; do { // Verify that the client is connected. if (Page.Response.IsClientConnected) { // Read data into the buffer. length = stream.Read(data, 0, bytesToRead); // and write it out to the response's output stream Page.Response.OutputStream.Write(data, 0, length); // Flush the data Page.Response.Flush(); //Clear the buffer data = new Byte[bytesToRead]; } else { // cancel the download if client has disconnected length = -1; } } while (length > 0); //Repeat until no data is read } HttpContext.Current.ApplicationInstance.CompleteRequest(); } else { throw new Exception("File Not Found"); } } } catch (Exception ex) { Page.DisplayErrorAlert(ex); log.Error(ex); } }
private CodeTorch.Core.Menu PopulateDynamicMenuItems(CodeTorch.Core.Menu menuObject) { CodeTorch.Core.Menu retVal = null; DataCommandService dataCommandDB = DataCommandService.GetInstance(); List <ScreenDataCommandParameter> parameters = new List <ScreenDataCommandParameter>(); var items = from item in menuObject.Items where item.UseCommand == true select item; if (items.Count() > 0) { retVal = new Core.Menu(); retVal.Name = menuObject.Name; retVal.CssClass = menuObject.CssClass; foreach (Core.MenuItem item in menuObject.Items) { if (item.UseCommand == false) { Core.MenuItem copiedItem = ObjectCopier.Clone <Core.MenuItem>(item); retVal.Items.Add(copiedItem); } else { DataCommand cmd = DataCommand.GetDataCommand(item.CommandName); foreach (DataCommandParameter cmdParam in cmd.Parameters) { ScreenDataCommandParameter p = new ScreenDataCommandParameter(); //TODO: need to support context with multiple items - presently assumes one item if (!String.IsNullOrEmpty(item.Context)) { if (cmdParam.Name.ToLower().EndsWith(item.Context.ToLower())) { p.Name = cmdParam.Name; p.InputType = ScreenInputType.QueryString; p.InputKey = item.Context; p.Value = this.Page.Request.QueryString[item.Context]; } } if (cmdParam.Name.ToLower().EndsWith("username")) { p.Name = cmdParam.Name; p.InputType = ScreenInputType.Special; p.InputKey = "UserName"; p.Value = Common.UserName; } if (cmdParam.Name.ToLower().EndsWith("hostheader")) { p.Name = cmdParam.Name; p.InputType = ScreenInputType.Special; p.InputKey = "HostHeader"; p.Value = Common.HostHeader; } parameters.Add(p); } DataTable dt = dataCommandDB.GetDataForDataCommand(item.CommandName, parameters); DataRow[] rows = null; bool containsParentID = dt.Columns.Contains("ParentID"); if (containsParentID) { rows = dt.Select("ParentID IS NULL"); } else { rows = dt.Select(); } AddMenuItems(retVal, dt, item, rows, true); } } } else { retVal = menuObject; } return(retVal); }
public void ProcessRequest(HttpContext context) { App app = CodeTorch.Core.Configuration.GetInstance().App; StringBuilder builder = new StringBuilder(); StringWriter writer = new StringWriter(builder); try { if (Me == null) { if (context.Request.Path.ToLower().EndsWith("xml")) { Format = "xml"; } throw new ApplicationException("No service has been configured for this path"); } DataCommand command = null; RestServiceMethodReturnTypeEnum returnType = RestServiceMethodReturnTypeEnum.None; //collect parameters DataTable dt = null; XmlDocument doc = null; context.Response.TrySkipIisCustomErrors = true; if (Format.ToLower() == "json") { context.Response.ContentType = "application/json"; } else { context.Response.ContentType = "text/xml"; } BaseRestServiceMethod method = Me.Methods.Where(i => (i.Action.ToString() == HttpContext.Current.Request.HttpMethod)).SingleOrDefault(); if (method != null) { //pass parameters - minus dbcommand parameters to datacommand DataCommandService dataCommandDB = DataCommandService.GetInstance(); if (String.IsNullOrEmpty(method.RequestDataCommand)) { throw new ApplicationException(String.Format("Request Data Command has not been configured for this service - {0}", Me.Name)); } command = DataCommand.GetDataCommand(method.RequestDataCommand); if (command == null) { throw new ApplicationException(String.Format("Request Data Command - {0} - could not be found in configuration", method.RequestDataCommand)); } List <ScreenDataCommandParameter> parameters = GetPopulatedCommandParameters(method.RequestDataCommand, method.DataCommands, null); returnType = method.ReturnType; //execute request datacommand and return data if applicable switch (command.ReturnType) { case DataCommandReturnType.Integer: object newID = dataCommandDB.ExecuteDataCommand(method.RequestDataCommand, parameters); if (method is PostRestServiceMethod) { DataCommand postCommand = null; PostRestServiceMethod postMethod = (PostRestServiceMethod)method; returnType = postMethod.ReturnType; if (!String.IsNullOrEmpty(postMethod.ResponseDataCommand)) { postCommand = DataCommand.GetDataCommand(postMethod.ResponseDataCommand); if (postCommand == null) { throw new ApplicationException(String.Format("Response Data Command - {0} - could not be found in configuration", postMethod.ResponseDataCommand)); } parameters = GetPopulatedCommandParameters(postMethod.ResponseDataCommand, method.DataCommands, newID); switch (returnType) { case RestServiceMethodReturnTypeEnum.DataRow: case RestServiceMethodReturnTypeEnum.DataTable: dt = dataCommandDB.GetDataForDataCommand(postMethod.ResponseDataCommand, parameters); break; case RestServiceMethodReturnTypeEnum.Xml: doc = dataCommandDB.GetXmlDataForDataCommand(postMethod.ResponseDataCommand, parameters); break; } } } if (method is PutRestServiceMethod) { PutRestServiceMethod putMethod = (PutRestServiceMethod)method; returnType = putMethod.ReturnType; if (!String.IsNullOrEmpty(putMethod.ResponseDataCommand)) { parameters = GetPopulatedCommandParameters(putMethod.ResponseDataCommand, method.DataCommands, newID); dt = dataCommandDB.GetDataForDataCommand(putMethod.ResponseDataCommand, parameters); } } break; case DataCommandReturnType.Xml: doc = dataCommandDB.GetXmlDataForDataCommand(method.RequestDataCommand, parameters); break; default: dt = dataCommandDB.GetDataForDataCommand(method.RequestDataCommand, parameters); break; } //in certain cases execute response datacommand } else { throw new NotSupportedException(); } //get data if any if ( ((dt != null) && (returnType == RestServiceMethodReturnTypeEnum.DataTable)) || ((dt != null) && (returnType == RestServiceMethodReturnTypeEnum.DataRow)) || ((doc != null) && (returnType == RestServiceMethodReturnTypeEnum.Xml)) ) { if (Format.ToLower() == "json") { using (JsonWriter json = new JsonTextWriter(writer)) { DataColumnCollection columns = null; switch (returnType) { case RestServiceMethodReturnTypeEnum.DataTable: columns = dt.Columns; BuildJsonArrayResponse(app, context, method, command, dt, json, columns); break; case RestServiceMethodReturnTypeEnum.DataRow: columns = dt.Columns; BuildJsonObjectResponse(app, context, method, command, dt, json, columns); break; case RestServiceMethodReturnTypeEnum.Xml: BuildJsonXmlObjectResponse(app, method, builder, doc); break; } } } else { //xml using (XmlWriter xml = new XmlTextWriter(writer)) { DataColumnCollection columns = null; switch (method.ReturnType) { case RestServiceMethodReturnTypeEnum.DataTable: columns = dt.Columns; BuildXmlListResponse(app, context, method, command, dt, xml, columns); break; case RestServiceMethodReturnTypeEnum.DataRow: columns = dt.Columns; BuildXmlItemResponse(app, context, method, command, dt, xml, columns); break; case RestServiceMethodReturnTypeEnum.Xml: BuildXmlObjectResponse(app, method, doc, xml); break; } } } } //perform any special post processing //string url = ((System.Web.Routing.Route)(RouteData.Route)).Url; //context.Response.Write("From the handler at " + DateTime.Now + " - " + Me.Name + " - " + url + " - " + HttpContext.Current.Request.HttpMethod); //context.Response.ContentType = "text/xml"; //context.Response.Write(dt.DataSet.GetXml()); context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.Write(builder.ToString()); } catch (CodeTorchException cex) { builder = new StringBuilder(); RestServiceException exception = new RestServiceException(); exception.Status = (int)HttpStatusCode.InternalServerError; exception.Message = cex.Message; exception.MoreInfo = cex.MoreInfo; exception.ErrorCode = cex.ErrorCode; context.Response.TrySkipIisCustomErrors = true; context.Response.StatusCode = exception.Status; SerializeRestException(app, context, builder, writer, exception); } catch (Exception ex) { builder = new StringBuilder(); RestServiceException exception = new RestServiceException(); exception.Status = (int)HttpStatusCode.InternalServerError; exception.Message = ex.Message; context.Response.TrySkipIisCustomErrors = true; context.Response.StatusCode = exception.Status; SerializeRestException(app, context, builder, writer, exception); } }
public async void ExecuteCommand() { if (Command != null) { Me = (ValidateUserCommand)Command; } try { DataTable dt = null; DataCommandService dataCommandDB = DataCommandService.GetInstance(); bool IsAuthenticated = false; //call data command //if we get datatable and row=1 store List <ScreenDataCommandParameter> parameters = null; parameters = Common.GetPopulatedCommandParameters(Me.LoginCommand, IPage); DataCommand command = DataCommand.GetDataCommand(Me.LoginCommand); switch (command.ReturnType) { case DataCommandReturnType.DataTable: dt = await dataCommandDB.GetDataForDataCommand(Me.LoginCommand, parameters); break; case DataCommandReturnType.Integer: throw new NotImplementedException(); break; case DataCommandReturnType.Xml: throw new NotImplementedException(); break; case DataCommandReturnType.None: throw new NotImplementedException(); break; } if (dt != null) { if (dt.Rows.Count > 0) { DataRow row = dt.Rows[0]; Common.DataRowToSettings(row, Me.AfterLoginSettings); IsAuthenticated = true; if (!String.IsNullOrEmpty(Me.AfterLoginRedirectScreen)) { Page p = MobilePage.GetPage(Me.AfterLoginRedirectScreen).GetPage(); Page.Navigation.PushAsync(p); } } } if (!IsAuthenticated) { IPage.DisplayErrorAlert("You have entered an invalid username/password combination. Please try again."); } } catch (Exception ex) { IPage.DisplayErrorAlert(ex.Message); } }
protected async void SaveEditForm() { DataCommandService dataCommandDB = DataCommandService.GetInstance(); bool SuccessIndicator = false; string retVal = null; if (true)//Page.IsValid) { try { object r = null; List <ScreenDataCommandParameter> parameters = null; switch (PageMode) { case FormViewMode.View: CodeTorch.Core.Common.LogInfo("\r\n\r\nIn Insert Mode"); if (String.IsNullOrEmpty(Me.InsertCommand)) { throw new Exception("InsertCommand is invalid"); } CodeTorch.Core.Common.LogDebug(String.Format("InsertCommand:{0}", Me.InsertCommand)); parameters = Common.GetPopulatedCommandParameters(Me.InsertCommand, IPage); DataCommand command = DataCommand.GetDataCommand(Me.InsertCommand); switch (command.ReturnType) { case DataCommandReturnType.DataTable: r = await dataCommandDB.GetDataForDataCommand(Me.InsertCommand, parameters); break; case DataCommandReturnType.Integer: r = await dataCommandDB.ExecuteDataCommand(Me.InsertCommand, parameters); break; case DataCommandReturnType.Xml: throw new NotImplementedException(); break; case DataCommandReturnType.None: break; } if (r != null) { if (!String.IsNullOrEmpty(Me.AfterInsertSettings)) { if (r is DataTable) { DataTable dt = r as DataTable; if (dt.Rows.Count > 0) { DataRow row = dt.Rows[0]; Common.DataRowToSettings(row, Me.AfterInsertSettings); } } } //if r is datatable - see if any of the values need to be stored in settings //retVal = r.ToString(); //CodeTorch.Core.Common.LogDebug(String.Format("Output Parameter:{0}", retVal)); } CodeTorch.Core.Common.LogDebug(String.Format("RedirectAfterInsert:{0}", Me.RedirectAfterInsert)); if (Me.RedirectAfterInsert) { if (!String.IsNullOrEmpty(Me.AfterInsertRedirectScreen)) { Page p = MobilePage.GetPage(Me.AfterInsertRedirectScreen).GetPage(); Page.Navigation.PushAsync(p); } else { //TODO: do what -tell about config error } //string url = GetRedirectUrl(retVal); //log.DebugFormat("RedirectUrl:{0}", url); //Page.Response.Redirect(url,false); //HttpContext.Current.ApplicationInstance.CompleteRequest(); } else { Page.DisplayAlert("Alert", Me.AfterInsertConfirmationMessage, "OK"); //Page.DisplaySuccessAlert(String.Format(Me.AfterInsertConfirmationMessage, retVal)); //RefreshSections(); } break; //case FormViewMode.Edit: // log.Info("In Edit Mode"); // if (String.IsNullOrEmpty(Me.UpdateCommand)) // { // throw new ApplicationException("UpdateCommand is invalid"); // } // log.DebugFormat("UpdateCommand:{0}", Me.UpdateCommand); // parameters = pageDB.GetPopulatedCommandParameters(Me.UpdateCommand, Page); // dataCommandDB.ExecuteDataCommand(Me.UpdateCommand, parameters); // log.DebugFormat("RedirectAfterUpdate:{0}", Me.RedirectAfterUpdate); // if (Me.RedirectAfterUpdate) // { // string url = GetRedirectUrl(Page.Request.QueryString[Me.EntityID]); // log.DebugFormat("RedirectUrl:{0}", url); // Page.Response.Redirect(url, false); // HttpContext.Current.ApplicationInstance.CompleteRequest(); // } // else // { // Page.DisplaySuccessAlert(String.Format(Me.AfterUpdateConfirmationMessage, retVal)); // RefreshSections(); // } // break; } SuccessIndicator = true; } catch (Exception ex) { SuccessIndicator = false; IPage.DisplayErrorAlert(ex.Message); //log.Error(ex); } } //return SuccessIndicator; }
private bool ValidateUser() { bool IsAuthenticated = false; DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); DataTable data = null; string password = String.Empty; List <ScreenDataCommandParameter> parameters = pageDB.GetPopulatedCommandParameters(Me.ProfileCommand, Page); foreach (ScreenDataCommandParameter p in parameters) { if (p.Name.ToLower() == Me.UserNameParameter.ToLower()) { LoginName = Page.GetEntityIDValue(Page.Screen, p.InputKey, p.InputType); break; } } password = Page.GetEntityIDValue(Page.Screen, Me.PasswordEntityID, Me.PasswordEntityInputType); data = dataCommandDB.GetDataForDataCommand(Me.ProfileCommand, parameters); if (data.Rows.Count == 1) { profile = data.Rows[0]; string dbPassword = profile[Me.PasswordField].ToString(); PasswordMode mode = Me.PasswordMode; if (!String.IsNullOrEmpty(dbPassword)) { switch (mode) { case PasswordMode.Hash: if (Cryptographer.CompareHash(Me.PasswordAlgorithm, password, dbPassword)) { IsAuthenticated = true; } break; case PasswordMode.Encrypted: string decryptedPassword = Cryptographer.DecryptSymmetric(Me.PasswordAlgorithm, dbPassword); if (decryptedPassword == password) { IsAuthenticated = true; } break; case PasswordMode.PlainText: if (dbPassword == password) { IsAuthenticated = true; } break; } } } return(IsAuthenticated); }
public void ExecuteCommand() { DataCommandService dataCommandDB = DataCommandService.GetInstance(); PageDB pageDB = new PageDB(); log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); try { if (Command != null) { Me = (SetScreenObjectsDataCommand)Command; } if (String.IsNullOrEmpty(Me.DataCommand)) { throw new ApplicationException(String.Format("Command {0} - SetScreenObjects - DataCommand is invalid", Me.Name)); } log.DebugFormat("DataCommand:{0}", Me.DataCommand); DataCommand dataCommand = DataCommand.GetDataCommand(Me.DataCommand); if (dataCommand == null) { throw new ApplicationException(String.Format("SetScreenObjects Data Command - {0} - does not exist in configuration", Me.DataCommand)); } if (dataCommand.ReturnType != DataCommandReturnType.DataTable) { throw new ApplicationException(String.Format("SetScreenObjects Data Command - {0} - invalid return type - return type must be Data Table", Me.DataCommand)); } List <ScreenDataCommandParameter> parameters = null; parameters = pageDB.GetPopulatedCommandParameters(Me.DataCommand, Page); DataTable dt = dataCommandDB.GetDataForDataCommand(Me.DataCommand, parameters); foreach (DataRow row in dt.Rows) { switch (row["ObjectType"].ToString().ToLower()) { case "control": SetPageControl( row["Name"].ToString(), row["MemberType"].ToString(), row["Member"].ToString(), row["Value"].ToString() ); break; case "section": SetPageSection( row["Name"].ToString(), row["MemberType"].ToString(), row["Member"].ToString(), row["Value"].ToString() ); break; } } } catch (Exception ex) { Page.DisplayErrorAlert(ex); log.Error(ex); } }