Example #1
0
        public object GetEvaluated(Domain domain, string parameterValue)
        {
            var namedGroupMatch = Regex.Match(parameterValue, NamedGroupPatern);

            if (namedGroupMatch.Success)
            {
                return namedGroupMatch;
            }
            else
            {
                var dynamicMatch = Regex.Match(parameterValue, DynamicPatern);

                if (!parameterValue.StartsWith(FormulaKey) && dynamicMatch.Groups["fieldId"].Success)
                {
                    return domain.Parent.GetChildDomain(dynamicMatch.Groups["fieldId"].Value).Value;
                }
                else if (parameterValue.StartsWith(FormulaKey))
                {
                    return Formulas.FormulaParser.Parse(parameterValue, domain.Parent);
                }
                else
                {
                    return parameterValue;
                }
            }

            return null;
        }
Example #2
0
 public FieldDomain(string label, Type type, Domain parent)
     : this(label, type)
 {
     if (parent == null)
         throw new ArgumentNullException("parent");
     Parent = parent;
 }
        public override IProcessResponse Execute(Domain domain, Action<object> before, Action<object> after)
        {
            try
            {
                IdentifiedArgument argument = URI.Argument as IdentifiedArgument;
                if (argument != null)
                {
                    Context ctx = ContextFactory.GetContext(EntityType);
                    object edit = ctx.Get(argument.Id, EntityType);

                    EntityDomain entity = domain as EntityDomain;
                    if (entity != null)
                    {
                        before(edit);
                        foreach (Domain d in entity.Domains)
                        {
                            if (!d.Visible) continue;
                            ComplexDomain.ConvertValue(d);
                            PropertyInfo p = EntityType.GetProperty(d.ID);
                            p.SetValue(edit, d.ObjectValue, null);
                        }
                        ctx.Save(edit);
                        after(edit);
                        return RedirectResponse;
                    }
                    return new InputProcessResponse(new EntityDomain(EntityType, URI, argument.Id, edit)) { URI = URI };
                }
                throw new Exception("Invalid URI!");
            }
            catch (Exception ex)
            {
                return CreateFailureResponse(ex, (EntityDomain)domain ?? new EntityDomain(EntityType, URI));
            }
        }
        public TemplateDomain Find(Domain domain)
        {
            if (domain != null)
            {
                string domainID = domain.ID;
                foreach (TemplateDomain template in this)
                {
                    if (template.Attributes.Contains(domainID))
                        return template;
                }

                Type domainType = domain.Type;
                while (domainType != null)
                {
                    foreach (TemplateDomain template in this)
                        if (IsValid(domain, domainType, template))
                            return template;
                    domainType = domainType.BaseType;
                }

                const string message = "The domain for type {0} or id {1} was not found! Please check the rendering configuration.";
                throw new Exception(string.Format(message, domain.ID, domain.Type));
            }
            return null;
        }
Example #5
0
 /// <summary>
 /// Executes the supplied <see cref="uri"/>.
 /// </summary>
 /// <param name="uri">Specifies the <see cref="ProcessURI"/> to be executed.</param>
 /// <param name="domain">Specifies the <see cref="Domain"/> with the information necessary to execute.</param>
 /// <returns>The <see cref="IProcessResponse"/> of the executed process.</returns>
 public static IProcessResponse Execute(ProcessURI uri, Domain domain)
 {
     List<IInterceptor> interceptors = CoreSection.Current.GetInteceptors();
     return GetProcess(uri).Execute(domain,
         o => interceptors.ForEach(i => i.OnProcessExecuting(uri, o)),
         o => interceptors.ForEach(i => i.OnProcessExecuted(uri, o)));
 }
Example #6
0
 public override IProcessResponse Execute(Domain domain, Action<object> before, Action<object> after)
 {
     try
     {
         var argument = URI.Argument as QueryArgument;
         if (argument != null)
         {
             before(null);
             Query query = ContextFactory.GetContext(EntityType).CreateQuery(EntityType);
             query.Skip = argument.Skip;
             query.Take = argument.Take;
             query.Where = argument.Where;
             query.OrderBy = argument.OrderBy;
             var items = query.Execute();
             after(items);
             return CreateResponse(EntityType, items, URI);
         }
         throw new Exception("Invalid URI!");
     }
     catch (Exception ex)
     {
         while (ex.InnerException != null) ex = ex.InnerException;
         return CreateMessageResponse(ex.Message, MessageProcessResponseType.Failure);
     }
 }
Example #7
0
        internal override string Parse(string expression, Domain domain)
        {
            var matchs = Regex.Matches(expression, @"=IsNull\((?<comparator>(\{|)(?<inComparator>(.*?))(\}|)),(?<true>(\{|)(?<inTrue>(.*?))(\}|))\)");

            foreach (Match match in matchs)
            {
                var comparator = match.Groups["comparator"];
                var inComparator = match.Groups["inComparator"];
                var @true = match.Groups["true"];
                var inTrue = match.Groups["inTrue"];

                if (!match.Success || !comparator.Success || [email protected])
                    continue;

                var trueValue = string.Empty;
                var comparatorValue = (comparator.Value.Equals(inComparator.Value)) ? inComparator.Value : GetValue(comparator.Value, domain);

                if (string.IsNullOrEmpty(comparatorValue))
                    trueValue = (@true.Value.Equals(inTrue.Value)) ? inTrue.Value : GetValue(@true.Value, domain);

                expression = expression.Replace(match.Value, string.IsNullOrEmpty(comparatorValue) ? trueValue : comparatorValue);
            }

            return expression;
        }
Example #8
0
 public override IProcessResponse Execute(Domain domain, Action<object> before, Action<object> after)
 {
     EntityDomain entity = domain as EntityDomain;
     if (entity != null && CurrentState == ProcessState.ToExecute)
     {
         try
         {
             IndexedArgument argument = URI.Argument as IndexedArgument;
             if (argument != null)
             {
                 object instance = ComplexDomain.CreateEntityInstance(entity, argument.Index);
                 if (instance != null && EntityType.IsInstanceOfType(instance))
                 {
                     before(instance);
                     ContextFactory.GetContext(EntityType).Insert(instance);
                     after(instance);
                     return RedirectResponse;
                 }
             }
             else
                 throw new Exception("Invalid URI!");
         }
         catch (Exception ex)
         {
             return CreateFailureResponse(ex, entity);
         }
     }
     return new InputProcessResponse(entity ?? new EntityDomain(EntityType, URI)) { URI = URI };
 }
Example #9
0
        protected Control LoadControl(string templateName, Page page, IProcessResponse response, Domain domain)
        {
            string templatePath = string.Format("~/{0}/{1}", RenderingSection.Current.Path, templateName);
            WebFormsControl control = null;

            try
            {
                control = page.LoadControl(templatePath) as WebFormsControl;
            }
            catch (Exception ex)
            {
            #if DEBUG
                throw ex;
            #endif
            }

            if (control != null)
            {
                control.URI = URI;
                control.Response = response;
                control.Domain = domain;
                control.Renderer = this;
            }
            return control;
        }
Example #10
0
        public override IProcessResponse Execute(Domain domain, Action<object> before, Action<object> after)
        {
            try
            {
                var argument = URI.Argument as ExecutionArgument;
                if (argument != null)
                {
                    object instance = null;
                    var entity = domain as EntityDomain;
                    if (CurrentState == ProcessState.ToExecute)
                    {
                        var methods = new List<MethodBase>(EntityType.GetMethods());
                        var method = ComplexDomain.GetMethodByName(methods, argument.Name, argument.Index);
                        var context = ContextFactory.GetContext(EntityType);
                        try
                        {
                            instance = (method.IsStatic) ? null : context.Get(argument.Id, EntityType);
                            if (CanProcess(method, entity, argument.Id))
                            {
                                LogManager.Logger.Write(LogType.Info, "Executiong {0}", URI);
                                before(instance);
                                var arguments = ComplexDomain.GetMethodParameters(method, entity);
                                var response = method.Invoke(instance, arguments);
                                if (instance != null) context.Save(instance);
                                context.SaveAll();
                                after(instance);
                                LogManager.Logger.Write(LogType.Info, "Executiong {0}", URI);

                                if (response != null)
                                {
                                    var returnResponse = CreateReturnResponse(method, response);
                                    if (returnResponse != null) return returnResponse;
                                }

                                return URI.PreviousURI != null
                                    ? new RedirectProcessResponse(URI.PreviousURI)
                                    : RedirectResponse;
                            }
                        }
                        catch (Exception ex)
                        {
                            context.Rollback();
                            LogManager.Logger.Write(LogType.Error, "Exception occurred executing {0}", URI, ex);
                            return CreateFailureResponse(ex, entity);
                        }
                        finally
                        {
                            context.CloseTransaction();
                        }
                    }
                    return new InputProcessResponse(entity ?? new EntityDomain(EntityType, URI, argument.Id, instance)) { URI = URI };
                }
                throw new Exception("Invalid URI!");
            }
            catch (Exception ex)
            {
                return CreateFailureResponse(ex, (EntityDomain)domain ?? new EntityDomain(EntityType, URI));
            }
        }
Example #11
0
 public static string Parse(string expression, Domain domain)
 {
     foreach (var formula in formulas)
     {
         expression = formula.Parse(expression, domain);
     }
     return expression;
 }
Example #12
0
 public static string Register(Domain domain, string name)
 {
     var key = Guid.NewGuid().ToString("N");
     var session = SessionManager.Session;
     var serialize = ViewStateManager.Serialize(domain);
     session.Add(key, serialize);
     return string.Format("<input type='hidden' id='{0}' name='{0}' value='{1}' />", ViewStateManager.FieldName, key);
 }
 public EntityCollectionDomain(Type type, Type collectionType, ProcessURI uri, object instance, Domain parent)
     : base(type, uri, null)
 {
     if (collectionType == null) throw new ArgumentNullException("collectionType");
     CollectionType = collectionType;
     Instance = instance;
     Parent = parent;
 }
Example #14
0
 public override void ProcessTemplate(TextWriter writer, string templateName, IProcessResponse response,
                                      Domain domain)
 {
     if (!string.IsNullOrEmpty(templateName))
     {
         Template template = Engine.GetTemplate(templateName);
         template.Merge(CreateTemplateContext(URI, response, domain), writer);
     }
 }
Example #15
0
 public void LoadTemplate(IProcessResponse response, Domain domain, Control container)
 {
     Configuration.Template template = GetTemplate(response);
     if (template != null)
     {
         var control = LoadControl(template.FileName, container.Page, response, domain);
         if (control != null)
             container.Controls.Add(control);
     }
 }
Example #16
0
 public override void ProcessTemplate(TextWriter writer, string templateName, IProcessResponse response,
                                      Domain domain)
 {
     if (!string.IsNullOrEmpty(templateName))
     {
         Page page = new Page();
         page.Controls.Add(LoadControl(templateName, page, response, domain));
         page.RenderControl(new HtmlTextWriter(writer));
     }
 }
Example #17
0
 public void LoadDomainTemplate(IProcessResponse response, Domain domain, Control container)
 {
     string templateName = GetTemplateName(response, domain);
     if (!string.IsNullOrEmpty(templateName))
     {
         var control = LoadControl(templateName, container.Page, response, domain);
         if (control != null)
             container.Controls.Add(control);
     }
 }
Example #18
0
 public override IProcessResponse Execute(Domain domain, Action<object> before, Action<object> after)
 {
     if (Steps.ContainsKey(URI.Entity))
     {
         before(null);
         var response = Steps[URI.Entity].Execute(domain, before, after);
         after(response);
         return response;
     }
     throw new ArgumentException();
 }
Example #19
0
 public static string Serialize(Domain domain)
 {
     if (domain != null)
     {
         MemoryStream domainStream = new MemoryStream();
         BinaryFormatter fmt = new BinaryFormatter();
         fmt.Serialize(domainStream, domain);
         return Convert.ToBase64String(domainStream.GetBuffer());
     }
     return string.Empty;
 }
Example #20
0
        private VelocityContext CreateTemplateContext(ProcessURI uri, IProcessResponse response, Domain domain)
        {
            VelocityContext context = new VelocityContext();
            context.Put("uri", uri);
            context.Put("renderer", this);

            if (response != null) context.Put("response", response);
            if (domain != null) context.Put("domain", domain);

            foreach (RendererHelper helper in Helpers)
                context.Put(helper.Name, helper);

            return context;
        }
Example #21
0
        protected string GetValue(string expression, Domain domain)
        {
            var matchs = Regex.Matches(expression, @"\{(?<field>(.*?))\}");

            foreach (Match match in matchs)
            {
                var field = match.Groups["field"];

                if (!string.IsNullOrEmpty(field.Value))
                    expression = expression.Replace(match.Value, GetChildDomainValue(field.Value, domain));
            }

            return expression;
        }
Example #22
0
 /// <summary>
 /// Execute the command for the current URI REST query.
 /// and the specified Domain's instance.
 /// </summary>
 /// <param name="domain">The specified Domain's instance</param>
 /// <param name="before"> </param>
 /// <param name="after"> </param>
 /// <returns>An IProcessResponse's instance.</returns>
 public override IProcessResponse Execute(Domain domain, Action<object> before, Action<object> after)
 {
     before(null);
     var response = new SchemaProcessResponse { URI = URI };
     if (domain == null || !CoreSection.Current.IsEntity(domain.Type))
     {
         foreach (EntityAssembly asm in CoreSection.Current.EntityAssemblies){
             response.Namespaces.Add(new NamespaceSchema(asm.RootNamespace, asm.GetTypes()) { IsRoot = true });                }
     }
     else
     {
         response.Namespaces.Add(new NamespaceSchema(domain.Type.Namespace, new[] { (EntityDomain)domain }));
     }
     after(response);
     return response;
 }
Example #23
0
        private string GetValue(List<Capture> captures, Capture capture, Domain domain)
        {
            var lastCapture = captures.Where(x => x.Index < capture.Index).OrderByDescending(x => x.Index).FirstOrDefault();

            if ((lastCapture != null) && (lastCapture.Value.Equals("{")))
            {
                var childDomain = domain.GetChildDomain(capture.Value);

                if ((childDomain.GetType().Name.Contains("EntityDomain")) && (childDomain.ObjectValue != null))
                {
                    return childDomain.ObjectValue.ToString();
                }

                return (childDomain.Value ?? string.Empty).ToString();
            }

            return capture.Value;
        }
 private static bool IsValid(Domain domain, Type type, TemplateDomain element)
 {
     string typeName = element.TypeName;
     return typeName.Equals(type.FullName) ||
            (
                type.IsGenericType &&
                type.Name.Equals("Nullable`1") &&
                typeName.Equals(type.GetGenericArguments()[0].FullName)
            ) ||
            (
                CoreSection.Current.IsEntity(type) &&
                (
                    (domain is EntityCollectionDomain &&
                     typeName.Equals(((EntityCollectionDomain) domain).CollectionType.FullName)) ||
                    (domain is EntityCollectionDomain && typeName.Equals(TemplateDomain.CollectionKey)) ||
                    (domain is EntityDomain && typeName.Equals(TemplateDomain.SingleKey))
                )
            );
 }
 public override object Deserialize(IDictionary<string, object> dictionary, Type type,
                                    JavaScriptSerializer serializer)
 {
     if (type.Equals(typeof (Domain)))
     {
         Domain domain = new Domain
                             {
                                 ID = dictionary["ID"].ToString(),
                                 Type = Type.GetType(dictionary["Type"].ToString()),
                                 Label = dictionary["Label"].ToString(),
                                 Value = dictionary["Value"].ToString(),
                                 IsQueryable = bool.Parse(dictionary["IsQueryable"].ToString()),
                                 CanRead = bool.Parse(dictionary["CanRead"].ToString()),
                                 CanWrite = bool.Parse(dictionary["CanWrite"].ToString())
                             };
         return domain;
     }
     return null;
 }
Example #26
0
        internal override string Parse(string expression, Domain domain)
        {
            var matchs = Regex.Matches(expression, @"=IIF\((?<leftSide>(\{|)(?<inLeftSide>(.*?))(\}|)),(?<operator>(.*?)),(?<rightSide>(\{|)(?<inRightSide>(.*?))(\}|)),(?<true>(\{|)(?<inTrue>(.*?))(\}|))(,(?<false>(\{|)(?<inFalse>(.*?))(\}|)|)|)\)");

            foreach (Match match in matchs)
            {
                var @operator = match.Groups["operator"];
                var leftSide = match.Groups["leftSide"];
                var inLeftSide = match.Groups["inLeftSide"];
                var rightSide = match.Groups["rightSide"];
                var inRightSide = match.Groups["inRightSide"];
                var @true = match.Groups["true"];
                var inTrue = match.Groups["inTrue"];
                var @false = match.Groups["false"];
                var inFfalse = match.Groups["inFalse"];

                if (!match.Success || [email protected] || !leftSide.Success || !rightSide.Success || [email protected])
                    continue;

                var leftSideValue = (leftSide.Value.Equals(inLeftSide.Value)) ? inLeftSide.Value : GetValue(leftSide.Value, domain);
                var rightSideValue = (rightSide.Value.Equals(inRightSide.Value)) ? inRightSide.Value : GetValue(rightSide.Value, domain);
                var trueValue = (@true.Value.Equals(inTrue.Value)) ? inTrue.Value : GetValue(@true.Value, domain);
                var falseValue = (@false.Value.Equals(inFfalse.Value)) ? inFfalse.Value : GetValue(@false.Value, domain);

                switch (@operator.Value)
                {
                    case "Equals":

                        expression = expression.Replace(match.Value, ((leftSideValue == null && rightSideValue == null) || (leftSideValue.Equals(rightSideValue))) ? trueValue : falseValue);

                        break;
                    case "NotEquals":

                        expression = expression.Replace(match.Value, (!(leftSideValue == null && rightSideValue == null) && !(leftSideValue.Equals(rightSideValue))) ? trueValue : falseValue);

                        break;
                }

            }

            return expression;
        }
Example #27
0
 public override IProcessResponse Execute(Domain domain, Action<object> before, Action<object> after)
 {
     try
     {
         IdentifiedArgument argument = URI.Argument as IdentifiedArgument;
         if (argument != null)
         {
             before(null);
             object view = ContextFactory.GetContext(EntityType).Get(argument.Id, EntityType);
             after(view);
             return new ViewProcessResponse(new EntityDomain(EntityType, URI, argument.Id, view));
         }
         throw new Exception("Invalid URI argument!");
     }
     catch (Exception ex)
     {
         return new ViewProcessResponse(domain ?? new EntityDomain(EntityType, URI, -1),
                                        (MessageProcessResponse) CreateFailureResponse(ex, null));
     }
 }
Example #28
0
        protected string GetChildDomainValue(string id, Domain domain)
        {
            var childDomain = domain.GetChildDomain(id);

            if (childDomain != null)
            {

                if (childDomain.GetType().Name.Contains("EntityDomain"))
                {
                    if (childDomain.ObjectValue != null)
                        return childDomain.ObjectValue.ToString();
                    else
                        return null;
                }

                return (childDomain.Value != null) ? childDomain.Value.ToString() : null;
            }

            return null;
        }
 public override IProcessResponse Execute(Domain domain, Action<object> before, Action<object> after)
 {
     try
     {
         IdentifiedArgument argument = URI.Argument as IdentifiedArgument;
         if (argument != null)
         {
             object obj = ContextFactory.GetContext(EntityType).Get(argument.Id, EntityType);
             if (obj == null)
                 throw new Exception(string.Format("Object of type {0} not found!", EntityType.Name));
             before(obj);
             ContextFactory.GetContext(EntityType).Delete(obj);
             after(obj);
             return RedirectResponse;
         }
         throw new Exception("Invalid URI argument!");
     }
     catch (Exception ex)
     {
         return CreateFailureResponse(ex, null);
     }
 }
Example #30
0
 public override void ProcessTemplate(TextWriter writer, string templateName, IProcessResponse response, Domain domain)
 {
     if ((UrlHelper.CurrentExtension.Equals(UrlHelper.ExcelInteropExtension) || UrlHelper.CurrentExtension.Equals(UrlHelper.PdfExtension)) && response is QueryProcessResponse)
     {
         if (templateName.EndsWith(ExcelExtension))
         {
             SetFileName(response);
             var filePath = CreateExcelFile(templateName);
             if (UrlHelper.CurrentExtension.Equals(UrlHelper.ExcelInteropExtension))
             {
                 LoadExcelData(filePath, (QueryProcessResponse)response);
                 HttpContext.Current.Response.WriteFile(filePath);
             }
             else
             {
                 LoadPdfData(filePath, (QueryProcessResponse)response);
                 HttpContext.Current.Response.WriteFile(filePath.Replace(ExcelExtension, PdfExtension));
             }
         }
     }
     else
         base.ProcessTemplate(writer, templateName, response, domain);
 }