private void HandlexSocketRequest() { this.Context.Response.Header.AddOrUpdate("Content-Type", this._DomainControl.ServiceMimeType); this.Context.Response.Header.AddOrUpdate("Content-Encoding", "identity"); // Decode Encoded Call Function to Readable Basics.Execution.Bind bind = this._DomainControl.GetxSocketBind(); bind.Parameters.Prepare( (parameter) => { Property property = new Property(0, parameter.Query, null); property.InstanceRequested += (ref Basics.Domain.IDomain instance) => instance = this._DomainControl.Domain; property.Setup(); property.Render(null); return(property.ObjectResult); } ); List <KeyValuePair <string, object> > keyValueList = new List <KeyValuePair <string, object> >(); foreach (Basics.Execution.ProcedureParameter item in bind.Parameters) { keyValueList.Add(new KeyValuePair <string, object>(item.Key, item.Value)); } IHttpContext context = this.Context; SocketObject xSocketObject = new SocketObject(ref context, keyValueList.ToArray()); bind.Parameters.Override(new string[] { "xso" }); bind.Parameters.Prepare( (parameter) => xSocketObject ); Basics.Execution.InvokeResult <object> invokeResult = Manager.AssemblyCore.InvokeBind <object>(Helpers.Context.Request.Header.Method, bind, Manager.ExecuterTypes.Undefined); if (invokeResult.Exception != null) { throw new Exception.ServiceSocketException(invokeResult.Exception.ToString()); } if (invokeResult.Result is Message) { Message MessageResult = (Message)invokeResult.Result; if (MessageResult.Type == Message.Types.Error) { throw new Exception.ServiceSocketException(MessageResult.Content); } } }
private void RenderObjectFeed(string requesterUniqueID, Basics.Execution.InvokeResult <Basics.ControlResult.IDataSource> invokeResult, Global.ContentDescription contentDescription) { object[] objectList = (object[])invokeResult.Result.GetResult(); Global.ArgumentInfoCollection dataListArgs = new Global.ArgumentInfoCollection(); if (invokeResult.Result.Message != null) { Basics.Helpers.VariablePool.Set(this.ControlID, new Global.DataListOutputInfo(this.UniqueID, 0, 0)); if (!contentDescription.HasMessageTemplate) { this.RenderedValue = invokeResult.Result.Message.Content; } else { dataListArgs.AppendKeyWithValue("MessageType", invokeResult.Result.Message.Type); dataListArgs.AppendKeyWithValue("Message", invokeResult.Result.Message.Content); this.RenderedValue = ControllerHelper.RenderSingleContent( contentDescription.MessageTemplate, this, dataListArgs, requesterUniqueID); } return; } Basics.Helpers.VariablePool.Set(this.ControlID, new Global.DataListOutputInfo(this.UniqueID, invokeResult.Result.Count, invokeResult.Result.Total)); StringBuilder renderedContent = new StringBuilder(); int contentIndex = 0, rC = 0; foreach (object current in objectList) { dataListArgs.Reset(); dataListArgs.AppendKeyWithValue("_sys_ItemIndex", rC); dataListArgs.AppendKeyWithValue("ItemIndex", rC); dataListArgs.AppendKeyWithValue("CurrentObject", current); contentIndex = rC % contentDescription.Parts.Count; string renderedRow = ControllerHelper.RenderSingleContent( contentDescription.Parts[contentIndex], this, dataListArgs, requesterUniqueID); renderedContent.Append(renderedRow); rC += 1; } this.RenderedValue = renderedContent.ToString(); }
private bool ExecuteBind() { int level = this.Leveling.Level; IDirective leveledDirective = this; while (level > 0) { leveledDirective = leveledDirective.Parent; level--; if (leveledDirective != null) { continue; } leveledDirective = this; break; } // Execution preparation should be done at the same level with it's parent. Because of that, send parent as parameters this.Bind.Parameters.Prepare( parameter => { Tuple <bool, object> result = Directives.Property.Render(leveledDirective, parameter.Query); return(result.Item2); }); Basics.Execution.InvokeResult <object> invokeResult = Manager.Executer.InvokeBind <object>(Helpers.Context.Request.Header.Method, this.Bind, Manager.ExecuterTypes.Other); if (invokeResult.Exception != null) { throw new Exceptions.ExecutionException(invokeResult.Exception); } if (invokeResult.Result is Basics.ControlResult.RedirectOrder redirectOrder) { Helpers.Context.AddOrUpdate("RedirectLocation", redirectOrder.Location); // this.Children.Add( // new Static(string.Empty)); return(true); } string result = Manager.Executer.GetPrimitiveValue(invokeResult.Result); if (!string.IsNullOrEmpty(result)) { this.Children.Add(new Static(result)); } return(true); }
public static Basics.Execution.InvokeResult <T> InvokeBind <T>(Basics.Context.Request.HttpMethod httpMethod, Basics.Execution.Bind bind, ExecuterTypes executerType) { if (bind == null) { throw new NoNullAllowedException("Requires bind!"); } // Check if BindInfo Parameters has been parsed! if (!bind.Ready) { throw new Exception("Bind Parameters should be parsed first!"); } DateTime executionBegins = DateTime.Now; Basics.Execution.InvokeResult <T> rInvokeResult = new Basics.Execution.InvokeResult <T>(bind); object invokedObject = ApplicationFactory.Prepare(bind.Executable).Invoke( httpMethod, bind.Classes, bind.Procedure, bind.Parameters.Values, bind.InstanceExecution, executerType ); if (invokedObject is Exception exception) { rInvokeResult.Exception = exception; } else { rInvokeResult.Result = (T)invokedObject; } if (!Basics.Configurations.Xeora.Application.Main.PrintAnalysis) { return(rInvokeResult); } double totalMs = DateTime.Now.Subtract(executionBegins).TotalMilliseconds; Basics.Console.Push( "analysed - execution duration", $"{totalMs}ms - {bind}", string.Empty, false, groupId: Basics.Helpers.Context.UniqueId, type: totalMs > Basics.Configurations.Xeora.Application.Main.AnalysisThreshold ? Basics.Console.Type.Warn: Basics.Console.Type.Info); return(rInvokeResult); }
private void HandlexSocketRequest() { this.Context.Response.Header.AddOrUpdate("Content-Type", this._DomainControl.ServiceMimeType); this.Context.Response.Header.AddOrUpdate("Content-Encoding", "identity"); // Decode Encoded Call Function to Readable Basics.Execution.Bind bind = this._DomainControl.GetxSocketBind(); bind.Parameters.Prepare( parameter => Property.Render(null, parameter.Query).Item2 ); List <KeyValuePair <string, object> > keyValueList = new List <KeyValuePair <string, object> >(); foreach (Basics.Execution.ProcedureParameter item in bind.Parameters) { keyValueList.Add(new KeyValuePair <string, object>(item.Key, item.Value)); } IHttpContext context = this.Context; SocketObject xSocketObject = new SocketObject(ref context, keyValueList.ToArray()); bind.Parameters.Override(new [] { "xso" }); bind.Parameters.Prepare( parameter => xSocketObject ); Basics.Execution.InvokeResult <object> invokeResult = Web.Manager.Executer.InvokeBind <object>(Helpers.Context.Request.Header.Method, bind, Web.Manager.ExecuterTypes.Undefined); if (invokeResult.Exception != null) { throw new Exceptions.ServiceSocketException(invokeResult.Exception.ToString()); } if (!(invokeResult.Result is Message messageResult)) { return; } if (messageResult.Type == Message.Types.Error) { throw new Exceptions.ServiceSocketException(messageResult.Content); } }
public static Basics.Execution.InvokeResult <T> InvokeBind <T>(Basics.Context.HttpMethod httpMethod, Basics.Execution.Bind bind, ExecuterTypes executerType) { if (bind == null) { throw new NoNullAllowedException("Requires bind!"); } // Check if BindInfo Parameters has been parsed! if (!bind.Ready) { throw new System.Exception("Bind Parameters shoud be parsed first!"); } Basics.Execution.InvokeResult <T> rInvokeResult = new Basics.Execution.InvokeResult <T>(bind); try { object invokedObject = Application.Prepare(bind.Executable).Invoke( httpMethod, bind.Classes, bind.Procedure, bind.Parameters.Values, bind.InstanceExecution, executerType ); if (invokedObject is System.Exception) { throw (System.Exception)invokedObject; } rInvokeResult.Result = (T)invokedObject; } catch (System.Exception ex) { Helper.EventLogger.Log(ex); rInvokeResult.Exception = ex; } return(rInvokeResult); }
private void RenderObjectFeed(ref Basics.Execution.InvokeResult <Basics.ControlResult.IDataSource> invokeResult) { object[] objectList = (object[])invokeResult.Result.GetResult(); ArgumentCollection dataListArgs = new ArgumentCollection(); for (int index = 0; index < objectList.Length; index++) { dataListArgs.Reset(); dataListArgs.AppendKeyWithValue("CurrentObject", objectList[index]); dataListArgs.AppendKeyWithValue("_sys_ItemIndex", index); dataListArgs.AppendKeyWithValue("ItemIndex", index); this.RenderRow(index, dataListArgs); } this._Parent.Parent.Arguments.AppendKeyWithValue( this._Parent.DirectiveId, new DataListOutputInfo(this._Parent.UniqueId, invokeResult.Result.Count, invokeResult.Result.Total, false) ); }
private PermissionResult EnsurePermission() { this.Mother.RequestInstance(out IDomain instance); if (string.IsNullOrEmpty(instance.Settings.Configurations.SecurityExecutable)) { return(new PermissionResult(PermissionResult.Results.Forbidden)); } Basics.Execution.Bind permissionBind = Basics.Execution.Bind.Make($"{instance.Settings.Configurations.SecurityExecutable}?EnsurePermission,p1"); permissionBind.Parameters.Prepare(parameter => this.DirectiveId); permissionBind.InstanceExecution = true; Basics.Execution.InvokeResult <PermissionResult> permissionInvokeResult = Manager.Executer.InvokeBind <PermissionResult>(Helpers.Context.Request.Header.Method, permissionBind, Manager.ExecuterTypes.Undefined); if (permissionInvokeResult.Result == null || permissionInvokeResult.Exception != null) { return(new PermissionResult(PermissionResult.Results.Forbidden)); } return(permissionInvokeResult.Result); }
private void RenderPartialDataTable(ref Basics.Execution.InvokeResult <Basics.ControlResult.IDataSource> invokeResult) { ArgumentCollection dataListArgs = new ArgumentCollection(); bool isItemIndexColumnExists = false; DataTable repeaterList = (DataTable)invokeResult.Result.GetResult(); foreach (DataColumn dC in repeaterList.Columns) { isItemIndexColumnExists = string.Compare(dC.ColumnName, "ItemIndex", StringComparison.InvariantCultureIgnoreCase) == 0; dataListArgs.AppendKey(dC.ColumnName); } for (int index = 0; index < repeaterList.Rows.Count; index++) { dataListArgs.Reset( repeaterList.Rows[index].ItemArray); dataListArgs.AppendKeyWithValue("_sys_ItemIndex", index); // this is for user interaction if (!isItemIndexColumnExists) { dataListArgs.AppendKeyWithValue("ItemIndex", index); } this.RenderRow(index, dataListArgs); } this._Parent.Parent.Arguments.AppendKeyWithValue( this._Parent.DirectiveId, new DataListOutputInfo(this._Parent.UniqueId, invokeResult.Result.Count, invokeResult.Result.Total, false) ); }
public Basics.RenderResult Render(string executeIn, string serviceId) { // call = Calling Function Providing in Query String Basics.Execution.Bind bind = Basics.Execution.Bind.Make( string.Format( "{0}?{1}.{2},~xParams", executeIn, serviceId, Basics.Helpers.Context.Request.QueryString["call"] ) ); bind.Parameters.Prepare( parameter => { Basics.X.ServiceParameterCollection serviceParameterCol = new Basics.X.ServiceParameterCollection(); try { serviceParameterCol.ParseXml( Basics.Helpers.Context.Request.Body.Form[parameter.Key]); } catch { /* Just handle Exceptions */ } return(serviceParameterCol); } ); Basics.Execution.InvokeResult <object> invokeResult = Manager.Executer.InvokeBind <object>(Basics.Helpers.Context.Request.Header.Method, bind, Manager.ExecuterTypes.Undefined); return(this.GenerateXml(invokeResult.Result)); }
private void HandleTemplateRequest() { Message messageResult = null; string methodResult = string.Empty; string encryptedBindInformation = this.Context.Request.Body.Form[$"_sys_bind_{this.Context.HashCode}"]; if (this.Context.Request.Header.Method == HttpMethod.POST && !string.IsNullOrEmpty(encryptedBindInformation)) { // Decode Encoded Call Function to Readable string bindInformation = this._DomainControl.Cryptography.Decrypt(encryptedBindInformation); if (string.IsNullOrEmpty(bindInformation)) { this.Context.AddOrUpdate( "RedirectLocation", Helpers.CreateUrl( false, this._DomainControl.Domain.Settings.Configurations.DefaultTemplate ) ); return; } Basics.Execution.Bind bind = Basics.Execution.Bind.Make(bindInformation); bind.Parameters.Prepare( parameter => Property.Render(null, parameter.Query).Item2 ); Basics.Execution.InvokeResult <object> invokeResult = Web.Manager.Executer.InvokeBind <object>(Helpers.Context.Request.Header.Method, bind, Web.Manager.ExecuterTypes.Undefined); if (invokeResult.Exception != null) { messageResult = new Message(invokeResult.Exception.ToString()); } else if (invokeResult.Result is Message message) { messageResult = message; } else if (invokeResult.Result is RedirectOrder redirectOrder) { this.Context.AddOrUpdate("RedirectLocation", redirectOrder.Location); } else { methodResult = Web.Manager.Executer.GetPrimitiveValue(invokeResult.Result); } } if (!string.IsNullOrEmpty((string)this.Context["RedirectLocation"])) { return; } // Create HashCode for request and apply to Url if (this.Context.Request.Header.Method == HttpMethod.GET) { string applicationRootPath = Configurations.Xeora.Application.Main.ApplicationRoot.BrowserImplementation; string currentUrl = this.Context.Request.Header.Url.RelativePath; currentUrl = currentUrl.Remove(0, currentUrl.IndexOf(applicationRootPath, StringComparison.InvariantCulture)); Match mR = Regex.Match(currentUrl, $"{applicationRootPath}\\d+/"); // Not assigned, so assign! if (!mR.Success) { string tailUrl = this.Context.Request.Header.Url.RelativePath; tailUrl = tailUrl.Remove(0, tailUrl.IndexOf(applicationRootPath, StringComparison.InvariantCulture) + applicationRootPath.Length); string rewrittenPath = $"{applicationRootPath}{this.Context.HashCode}/{tailUrl}"; if (!string.IsNullOrEmpty(this.Context.Request.Header.Url.QueryString)) { rewrittenPath = $"{rewrittenPath}?{this.Context.Request.Header.Url.QueryString}"; } this.Context.Request.RewritePath(rewrittenPath); } } this.CreateTemplateResult(messageResult, methodResult); }
protected override void RenderControl(string requesterUniqueID) { Global.ContentDescription contentDescription = new Global.ContentDescription(this.Value); string blockContent = contentDescription.Parts[0]; // Call Related Function and Exam It IController leveledController = this; int level = this.Leveling.Level; do { if (level == 0) { break; } leveledController = leveledController.Parent; if (leveledController is Renderless) { leveledController = leveledController.Parent; } level -= 1; } while (leveledController != null); // Execution preparation should be done at the same level with it's parent. Because of that, send parent as parameters this.Bind.Parameters.Prepare( (parameter) => { Property property = new Property(0, parameter.Query, (leveledController.Parent == null ? null : leveledController.Parent.ContentArguments)); property.Mother = leveledController.Mother; property.Parent = leveledController.Parent; property.InstanceRequested += (ref IDomain instance) => InstanceRequested?.Invoke(ref instance); property.Setup(); property.Render(requesterUniqueID); return(property.ObjectResult); } ); Basics.Execution.InvokeResult <Basics.ControlResult.VariableBlock> invokeResult = Manager.AssemblyCore.InvokeBind <Basics.ControlResult.VariableBlock>(Basics.Helpers.Context.Request.Header.Method, this.Bind, Manager.ExecuterTypes.Control); if (invokeResult.Exception != null) { throw new Exception.ExecutionException(invokeResult.Exception.Message, invokeResult.Exception.InnerException); } // ---- if (!this.Leveling.ExecutionOnly) { this.ContentArguments.Replace(leveledController.ContentArguments); } if (invokeResult.Result != null) { foreach (string key in invokeResult.Result.Keys) { this.ContentArguments.AppendKeyWithValue(key, invokeResult.Result[key]); } } // Just parse the children to be accessable in search this.Parse(blockContent); if (!this.Leveling.ExecutionOnly) { this.RenderedValue = ControllerHelper.RenderSingleContent(blockContent, leveledController, this.ContentArguments, requesterUniqueID); } else { this.RenderedValue = ControllerHelper.RenderSingleContent(blockContent, this, this.ContentArguments, requesterUniqueID); } this.Mother.Scheduler.Fire(this.ControlID); }
public void Parse() { if (this._Settings.Bind == null) { throw new ArgumentNullException(nameof(this._Settings.Bind)); } // Execution preparation should be done at the same level with it's parent. Because of that, send parent as parameters this._Settings.Bind.Parameters.Prepare( parameter => { string query = parameter.Query; int paramIndex = DirectiveHelper.CaptureParameterPointer(query); if (paramIndex < 0) { return(Property.Render(this._Parent, query).Item2); } if (paramIndex >= this._Parameters.Length) { throw new Exceptions.FormatIndexOutOfRangeException("DataList"); } return(Property.Render(this._Parent, this._Parameters[paramIndex]).Item2); } ); Basics.Execution.InvokeResult <Basics.ControlResult.IDataSource> invokeResult = Manager.Executer.InvokeBind <Basics.ControlResult.IDataSource>(Helpers.Context.Request.Header.Method, this._Settings.Bind, Manager.ExecuterTypes.Control); if (invokeResult.Exception != null) { throw new Exceptions.ExecutionException(invokeResult.Exception); } this._Parent.Parent.Arguments.AppendKeyWithValue( this._Parent.DirectiveId, new DataListOutputInfo(this._Parent.UniqueId, 0, 0, true) ); if (invokeResult.Result.Message != null) { this.RenderError(invokeResult.Result.Message.Type, invokeResult.Result.Message.Content); return; } if (this._CacheHandler(invokeResult.Result.ResultId)) { return; } this.ResultId = invokeResult.Result.ResultId; switch (invokeResult.Result.Type) { case Basics.ControlResult.DataSourceTypes.DirectDataAccess: this.RenderDirectDataAccess(ref invokeResult); break; case Basics.ControlResult.DataSourceTypes.ObjectFeed: this.RenderObjectFeed(ref invokeResult); break; case Basics.ControlResult.DataSourceTypes.PartialDataTable: this.RenderPartialDataTable(ref invokeResult); break; } }
public void Parse() { if (this._Settings.Bind == null) { throw new System.ArgumentNullException(nameof(this._Settings.Bind)); } // Execution preparation should be done at the same level with it's parent. Because of that, send parent as parameters this._Settings.Bind.Parameters.Prepare( parameter => { string query = parameter.Query; int paramIndex = DirectiveHelper.CaptureParameterPointer(query); if (paramIndex < 0) { return(Property.Render(this._Parent, query).Item2); } if (paramIndex >= this._Parameters.Length) { throw new Exceptions.FormatIndexOutOfRangeException("VariableBlock"); } return(Property.Render(this._Parent, this._Parameters[paramIndex]).Item2); } ); Basics.Execution.InvokeResult <Basics.ControlResult.VariableBlock> invokeResult = Manager.Executer.InvokeBind <Basics.ControlResult.VariableBlock>(Basics.Helpers.Context.Request.Header.Method, this._Settings.Bind, Manager.ExecuterTypes.Control); if (invokeResult.Exception != null) { throw new Exceptions.ExecutionException(invokeResult.Exception); } // ---- if (invokeResult.Result == null) { return; } if (invokeResult.Result.Message != null) { if (!this._Contents.HasMessageTemplate) { this._Parent.Children.Clear(); if (!string.IsNullOrEmpty(invokeResult.Result.Message.Content)) { this._Parent.Children.Add(new Static(invokeResult.Result.Message.Content)); } } else { this._Parent.Arguments.AppendKeyWithValue("MessageType", invokeResult.Result.Message.Type); this._Parent.Arguments.AppendKeyWithValue("Message", invokeResult.Result.Message.Content); this._Parent.Mother.RequestParsing(this._Contents.MessageTemplate, this._Parent.Children, this._Parent.Arguments); } return; } if (invokeResult.Result != null) { foreach (string key in invokeResult.Result.Keys) { this._Parent.Arguments.AppendKeyWithValue(key, invokeResult.Result[key]); } } this._Parent.Mother.RequestParsing(this._Contents.Parts[0], this._Parent.Children, this._Parent.Arguments); }
private void HandleTemplateRequest() { Message messageResult = null; string methodResult = string.Empty; string bindInformation = this.Context.Request.Body.Form[string.Format("_sys_bind_{0}", this.Context.HashCode)]; if (this.Context.Request.Header.Method == HttpMethod.POST && !string.IsNullOrEmpty(bindInformation)) { // Decode Encoded Call Function to Readable Basics.Execution.Bind bind = Basics.Execution.Bind.Make( Manager.AssemblyCore.DecodeFunction(bindInformation)); bind.Parameters.Prepare( (parameter) => { Property property = new Property(0, parameter.Query, null); property.InstanceRequested += (ref Basics.Domain.IDomain instance) => instance = this._DomainControl.Domain; property.Setup(); property.Render(null); return(property.ObjectResult); } ); Basics.Execution.InvokeResult <object> invokeResult = Manager.AssemblyCore.InvokeBind <object>(Helpers.Context.Request.Header.Method, bind, Manager.ExecuterTypes.Undefined); if (invokeResult.Exception != null) { messageResult = new Message(invokeResult.Exception.ToString()); } else if (invokeResult.Result != null && invokeResult.Result is Message) { messageResult = (Message)invokeResult.Result; } else if (invokeResult.Result != null && invokeResult.Result is RedirectOrder) { this.Context.AddOrUpdate("RedirectLocation", ((RedirectOrder)invokeResult.Result).Location); } else { methodResult = Manager.AssemblyCore.GetPrimitiveValue(invokeResult.Result); } } if (string.IsNullOrEmpty((string)this.Context["RedirectLocation"])) { // Create HashCode for request and apply to URL if (this.Context.Request.Header.Method == HttpMethod.GET) { string applicationRootPath = Configurations.Xeora.Application.Main.ApplicationRoot.BrowserImplementation; string currentURL = this.Context.Request.Header.URL.RelativePath; currentURL = currentURL.Remove(0, currentURL.IndexOf(applicationRootPath)); System.Text.RegularExpressions.Match mR = System.Text.RegularExpressions.Regex.Match(currentURL, string.Format("{0}\\d+/", applicationRootPath)); // Not assigned, so assign! if (!mR.Success) { string tailURL = this.Context.Request.Header.URL.RelativePath; tailURL = tailURL.Remove(0, tailURL.IndexOf(applicationRootPath) + applicationRootPath.Length); string rewrittenPath = string.Format("{0}{1}/{2}", applicationRootPath, this.Context.HashCode, tailURL); if (!string.IsNullOrEmpty(this.Context.Request.Header.URL.QueryString)) { rewrittenPath = string.Format("{0}?{1}", rewrittenPath, this.Context.Request.Header.URL.QueryString); } this.Context.Request.RewritePath(rewrittenPath); } } this.CreateTemplateResult(messageResult, methodResult); } }
protected override void RenderControl(string requesterUniqueID) { Global.ContentDescription contentDescription = new Global.ContentDescription(this.Value); // ConditionalStatment does not have any ContentArguments, That's why it copies it's parent Arguments if (this.Parent != null) { this.ContentArguments.Replace(this.Parent.ContentArguments); } string contentTrue = contentDescription.Parts[0]; string contentFalse = string.Empty; if (contentDescription.Parts.Count > 1) { contentFalse = contentDescription.Parts[1]; } // Call Related Function and Exam It IController leveledController = this; int level = this.Leveling.Level; do { if (level == 0) { break; } leveledController = leveledController.Parent; if (leveledController is Renderless) { leveledController = leveledController.Parent; } level -= 1; } while (leveledController != null); // Execution preparation should be done at the same level with it's parent. Because of that, send parent as parameters this.Bind.Parameters.Prepare( (parameter) => { Property property = new Property(0, parameter.Query, (leveledController.Parent == null ? null : leveledController.Parent.ContentArguments)); property.Mother = leveledController.Mother; property.Parent = leveledController.Parent; property.InstanceRequested += (ref IDomain instance) => InstanceRequested?.Invoke(ref instance); property.Setup(); property.Render(requesterUniqueID); return(property.ObjectResult); } ); Basics.Execution.InvokeResult <Basics.ControlResult.Conditional> invokeResult = Manager.AssemblyCore.InvokeBind <Basics.ControlResult.Conditional>(Basics.Helpers.Context.Request.Header.Method, this.Bind, Manager.ExecuterTypes.Control); if (invokeResult.Exception != null) { throw new Exception.ExecutionException(invokeResult.Exception.Message, invokeResult.Exception.InnerException); } // ---- if (invokeResult.Result != null) { switch (invokeResult.Result.Result) { case Basics.ControlResult.Conditional.Conditions.True: if (!string.IsNullOrEmpty(contentTrue)) { if (!this.Leveling.ExecutionOnly) { this.ContentArguments.Replace(leveledController.ContentArguments); // Just parse the children to be accessable in search this.Parse(contentTrue); this.RenderedValue = ControllerHelper.RenderSingleContent(contentTrue, leveledController, this.ContentArguments, requesterUniqueID); } else { // Just parse the children to be accessable in search this.Parse(contentTrue); this.RenderedValue = ControllerHelper.RenderSingleContent(contentTrue, this, this.ContentArguments, requesterUniqueID); } } break; case Basics.ControlResult.Conditional.Conditions.False: if (!string.IsNullOrEmpty(contentFalse)) { if (!this.Leveling.ExecutionOnly) { this.ContentArguments.Replace(leveledController.ContentArguments); // Just parse the children to be accessable in search this.Parse(contentFalse); this.RenderedValue = ControllerHelper.RenderSingleContent(contentFalse, leveledController, this.ContentArguments, requesterUniqueID); } else { // Just parse the children to be accessable in search this.Parse(contentFalse); this.RenderedValue = ControllerHelper.RenderSingleContent(contentFalse, this, this.ContentArguments, requesterUniqueID); } } break; case Basics.ControlResult.Conditional.Conditions.Unknown: // Reserved For Future Uses break; } } this.Mother.Scheduler.Fire(this.ControlID); }
private void RenderPartialDataTable(string requesterUniqueID, Basics.Execution.InvokeResult <Basics.ControlResult.IDataSource> invokeResult, Global.ContentDescription contentDescription) { DataTable repeaterList = (DataTable)invokeResult.Result.GetResult(); Global.ArgumentInfoCollection dataListArgs = new Global.ArgumentInfoCollection(); if (invokeResult.Result.Message != null) { if (!contentDescription.HasMessageTemplate) { this.RenderedValue = invokeResult.Result.Message.Content; } else { dataListArgs.AppendKeyWithValue("MessageType", invokeResult.Result.Message.Type); dataListArgs.AppendKeyWithValue("Message", invokeResult.Result.Message.Content); this.RenderedValue = ControllerHelper.RenderSingleContent( contentDescription.MessageTemplate, this, dataListArgs, requesterUniqueID); } return; } Basics.Helpers.VariablePool.Set(this.ControlID, new Global.DataListOutputInfo(this.UniqueID, invokeResult.Result.Count, invokeResult.Result.Total)); CultureInfo compareCulture = new CultureInfo("en-US"); StringBuilder renderedContent = new StringBuilder(); int contentIndex = 0, rC = 0; bool isItemIndexColumnExists = false; foreach (DataColumn dC in repeaterList.Columns) { if (compareCulture.CompareInfo.Compare(dC.ColumnName, "ItemIndex", CompareOptions.IgnoreCase) == 0) { isItemIndexColumnExists = true; } dataListArgs.AppendKey(dC.ColumnName); } dataListArgs.AppendKey("_sys_ItemIndex"); repeaterList.Columns.Add("_sys_ItemIndex", typeof(int)); // this is for user interaction if (!isItemIndexColumnExists) { dataListArgs.AppendKey("ItemIndex"); repeaterList.Columns.Add("ItemIndex", typeof(int)); } foreach (DataRow dR in repeaterList.Rows) { object[] dRValues = dR.ItemArray; if (!isItemIndexColumnExists) { dRValues[dRValues.Length - 2] = rC; dRValues[dRValues.Length - 1] = rC; } else { dRValues[dRValues.Length - 1] = rC; } dataListArgs.Reset(dRValues); contentIndex = rC % contentDescription.Parts.Count; string renderedRow = ControllerHelper.RenderSingleContent( contentDescription.Parts[contentIndex], this, dataListArgs, requesterUniqueID); renderedContent.Append(renderedRow); rC += 1; } this.RenderedValue = renderedContent.ToString(); }
public void Parse() { if (this._Settings.Bind == null) { throw new System.ArgumentNullException(nameof(this._Settings.Bind)); } this._Settings.Bind.Parameters.Prepare( parameter => { string query = parameter.Query; int paramIndex = DirectiveHelper.CaptureParameterPointer(query); if (paramIndex < 0) { return(Property.Render(this._Parent, query).Item2); } if (paramIndex >= this._Parameters.Length) { throw new Exceptions.FormatIndexOutOfRangeException("ConditionalStatement"); } return(Property.Render(this._Parent, this._Parameters[paramIndex]).Item2); } ); Basics.Execution.InvokeResult <Basics.ControlResult.Conditional> invokeResult = Manager.Executer.InvokeBind <Basics.ControlResult.Conditional>(Basics.Helpers.Context.Request.Header.Method, this._Settings.Bind, Manager.ExecuterTypes.Control); if (invokeResult.Exception != null) { throw new Exceptions.ExecutionException(invokeResult.Exception); } // ---- if (invokeResult.Result == null) { return; } switch (invokeResult.Result.Result) { case Basics.ControlResult.Conditional.Conditions.True: if (string.IsNullOrEmpty(this._Contents.Parts[0])) { break; } this._Parent.Mother.RequestParsing( this._Contents.Parts[0], this._Parent.Children, this._Parent.Arguments); break; case Basics.ControlResult.Conditional.Conditions.False: if (this._Contents.Parts.Count < 2) { break; } if (string.IsNullOrEmpty(this._Contents.Parts[1])) { break; } this._Parent.Mother.RequestParsing( this._Contents.Parts[1], this._Parent.Children, this._Parent.Arguments); break; case Basics.ControlResult.Conditional.Conditions.Unknown: // Reserved For Future Uses return; } }
private void RenderDirectDataAccess(ref Basics.Execution.InvokeResult <Basics.ControlResult.IDataSource> invokeResult) { IDbCommand dbCommand = (IDbCommand)invokeResult.Result.GetResult(); if (dbCommand == null) { throw new NullReferenceException( $"DirectDataAccess [{this._Parent.DirectiveId}] failed! DatabaseCommand must not be null!"); } IDataReader dbReader = null; try { dbCommand.Connection.Open(); dbReader = dbCommand.ExecuteReader(); ArgumentCollection dataListArgs = new ArgumentCollection(); bool isItemIndexColumnExists = false; int count = 0; long total = -1; while (dbReader.Read()) { dataListArgs.Reset(); for (int cC = 0; cC < dbReader.FieldCount; cC++) { if (string.Compare(dbReader.GetName(cC), "_sys_Total", StringComparison.InvariantCultureIgnoreCase) == 0) { total = dbReader.GetInt64(cC); } isItemIndexColumnExists = string.Compare(dbReader.GetName(cC), "ItemIndex", StringComparison.InvariantCultureIgnoreCase) == 0; dataListArgs.AppendKeyWithValue(dbReader.GetName(cC), dbReader.GetValue(cC)); } dataListArgs.AppendKeyWithValue("_sys_ItemIndex", count); // this is for user interaction if (!isItemIndexColumnExists) { dataListArgs.AppendKeyWithValue("ItemIndex", count); } this.RenderRow(count, dataListArgs); count++; } this._Parent.Parent.Arguments.AppendKeyWithValue( this._Parent.DirectiveId, new DataListOutputInfo(this._Parent.UniqueId, count, total == -1 ? count : total, false) ); } catch (Exception ex) { this.RenderError(Basics.ControlResult.Message.Types.Error, ex.Message); Basics.Console.Push("Execution Exception...", ex.Message, ex.ToString(), false, true, type: Basics.Console.Type.Error); } finally { if (dbReader != null) { dbReader.Close(); dbReader.Dispose(); } if (dbCommand.Connection.State == ConnectionState.Open) { dbCommand.Connection.Close(); } dbCommand.Dispose(); } }
private void RenderInternal(string requesterUniqueID) { string[] controlValueSplitted = this.Value.Split(':'); // Call Related Function and Exam It IController leveledController = this; int level = this.Leveling.Level; do { if (level == 0) { break; } leveledController = leveledController.Parent; if (leveledController is Renderless) { leveledController = leveledController.Parent; } level -= 1; } while (leveledController != null); Basics.Execution.Bind bind = Basics.Execution.Bind.Make(string.Join(":", controlValueSplitted, 1, controlValueSplitted.Length - 1)); // Execution preparation should be done at the same level with it's parent. Because of that, send parent as parameters bind.Parameters.Prepare( (parameter) => { Property property = new Property(0, parameter.Query, (leveledController.Parent == null ? null : leveledController.Parent.ContentArguments)); property.Mother = leveledController.Mother; property.Parent = leveledController.Parent; property.InstanceRequested += (ref Basics.Domain.IDomain instance) => InstanceRequested?.Invoke(ref instance); property.Setup(); property.Render(requesterUniqueID); return(property.ObjectResult); } ); Basics.Execution.InvokeResult <object> invokeResult = Manager.AssemblyCore.InvokeBind <object>(Basics.Helpers.Context.Request.Header.Method, bind, Manager.ExecuterTypes.Other); if (invokeResult.Exception != null) { throw new Exception.ExecutionException(invokeResult.Exception.Message, invokeResult.Exception.InnerException); } if (invokeResult.Result != null && invokeResult.Result is Basics.ControlResult.RedirectOrder) { Helpers.Context.AddOrUpdate("RedirectLocation", ((Basics.ControlResult.RedirectOrder)invokeResult.Result).Location); this.RenderedValue = string.Empty; return; } this.RenderedValue = Manager.AssemblyCore.GetPrimitiveValue(invokeResult.Result); }
private void RenderDirectDataAccess(string requesterUniqueID, Basics.Execution.InvokeResult <Basics.ControlResult.IDataSource> invokeResult, Global.ContentDescription contentDescription) { IDbCommand dbCommand = (IDbCommand)invokeResult.Result.GetResult(); Global.ArgumentInfoCollection dataListArgs = new Global.ArgumentInfoCollection(); if (dbCommand == null) { if (invokeResult.Result.Message != null) { if (!contentDescription.HasMessageTemplate) { this.RenderedValue = invokeResult.Result.Message.Content; } else { dataListArgs.AppendKeyWithValue("MessageType", invokeResult.Result.Message.Type); dataListArgs.AppendKeyWithValue("Message", invokeResult.Result.Message.Content); this.RenderedValue = ControllerHelper.RenderSingleContent( contentDescription.MessageTemplate, this, dataListArgs, requesterUniqueID); } Helper.EventLogger.Log(string.Format("DirectDataAccess [{0}] failed! DatabaseCommand must not be null!", this.ControlID)); } else { throw new NullReferenceException(string.Format("DirectDataAccess [{0}] failed! DatabaseCommand must not be null!", this.ControlID)); } return; } IDataReader dbReader = null; try { dbCommand.Connection.Open(); dbReader = dbCommand.ExecuteReader(); CultureInfo compareCulture = new CultureInfo("en-US"); StringBuilder renderedContent = new StringBuilder(); int contentIndex = 0, rC = 0; bool isItemIndexColumnExists = false; if (!dbReader.Read()) { if (invokeResult.Result.Message != null) { if (!contentDescription.HasMessageTemplate) { this.RenderedValue = invokeResult.Result.Message.Content; } else { dataListArgs.AppendKeyWithValue("MessageType", invokeResult.Result.Message.Type); dataListArgs.AppendKeyWithValue("Message", invokeResult.Result.Message.Content); this.RenderedValue = ControllerHelper.RenderSingleContent( contentDescription.MessageTemplate, this, dataListArgs, requesterUniqueID); } } return; } do { dataListArgs.Reset(); for (int cC = 0; cC < dbReader.FieldCount; cC++) { if (compareCulture.CompareInfo.Compare(dbReader.GetName(cC), "ItemIndex", CompareOptions.IgnoreCase) == 0) { isItemIndexColumnExists = true; } dataListArgs.AppendKeyWithValue(dbReader.GetName(cC), dbReader.GetValue(cC)); } dataListArgs.AppendKeyWithValue("_sys_ItemIndex", rC); // this is for user interaction if (!isItemIndexColumnExists) { dataListArgs.AppendKeyWithValue("ItemIndex", rC); } contentIndex = rC % contentDescription.Parts.Count; string renderedRow = ControllerHelper.RenderSingleContent( contentDescription.Parts[contentIndex], this, dataListArgs, requesterUniqueID); renderedContent.Append(renderedRow); rC += 1; } while (dbReader.Read()); Basics.Helpers.VariablePool.Set(this.ControlID, new Global.DataListOutputInfo(this.UniqueID, rC, rC)); this.RenderedValue = renderedContent.ToString(); } catch (System.Exception ex) { Basics.Helpers.VariablePool.Set(this.ControlID, new Global.DataListOutputInfo(this.UniqueID, 0, 0)); if (invokeResult.Result.Message == null) { throw new Exception.DirectDataAccessException(ex); } if (!contentDescription.HasMessageTemplate) { this.RenderedValue = invokeResult.Result.Message.Content; } else { dataListArgs.AppendKeyWithValue("MessageType", invokeResult.Result.Message.Type); dataListArgs.AppendKeyWithValue("Message", invokeResult.Result.Message.Content); this.RenderedValue = ControllerHelper.RenderSingleContent( contentDescription.MessageTemplate, this, dataListArgs, requesterUniqueID); } Helper.EventLogger.Log(ex); } finally { if (dbReader != null) { dbReader.Close(); dbReader.Dispose(); GC.SuppressFinalize(dbReader); } if (dbCommand != null) { if (dbCommand.Connection.State == ConnectionState.Open) { dbCommand.Connection.Close(); } dbCommand.Dispose(); GC.SuppressFinalize(dbCommand); } } }
protected override void RenderControl(string requesterUniqueID) { Global.ContentDescription contentDescription = new Global.ContentDescription(this.Value); // Reset Variables Basics.Helpers.VariablePool.Set(this.ControlID, null); // Call Related Function and Exam It IController leveledController = this; int level = this.Leveling.Level; do { if (level == 0) { break; } leveledController = leveledController.Parent; if (leveledController is Renderless) { leveledController = leveledController.Parent; } level -= 1; } while (leveledController != null); // Execution preparation should be done at the same level with it's parent. Because of that, send parent as parameters this.Bind.Parameters.Prepare( (parameter) => { Property property = new Property(0, parameter.Query, (leveledController.Parent == null ? null : leveledController.Parent.ContentArguments)); property.Mother = leveledController.Mother; property.Parent = leveledController.Parent; property.InstanceRequested += (ref IDomain instance) => InstanceRequested?.Invoke(ref instance); property.Setup(); property.Render(requesterUniqueID); return(property.ObjectResult); } ); Basics.Execution.InvokeResult <Basics.ControlResult.IDataSource> invokeResult = Manager.AssemblyCore.InvokeBind <Basics.ControlResult.IDataSource>(Basics.Helpers.Context.Request.Header.Method, this.Bind, Manager.ExecuterTypes.Control); if (invokeResult.Exception != null) { throw new Exception.ExecutionException(invokeResult.Exception.Message, invokeResult.Exception.InnerException); } Basics.Helpers.VariablePool.Set(this.ControlID, new Global.DataListOutputInfo(this.UniqueID, 0, 0)); switch (invokeResult.Result.Type) { case Basics.ControlResult.DataSourceTypes.DirectDataAccess: this.RenderDirectDataAccess(requesterUniqueID, invokeResult, contentDescription); break; case Basics.ControlResult.DataSourceTypes.ObjectFeed: this.RenderObjectFeed(requesterUniqueID, invokeResult, contentDescription); break; case Basics.ControlResult.DataSourceTypes.PartialDataTable: this.RenderPartialDataTable(requesterUniqueID, invokeResult, contentDescription); break; } // ---- this.Mother.Scheduler.Fire(this.ControlID); }