Esempio n. 1
0
        private void TransformServiceFunction(TemplateDomain templateDomain, TemplateRow row)
        {
            var templateFunction = templateDomain.TemplateFunctions.FirstOrDefault(d => d.FunctionName == row.ServiceFunction);

            if (templateFunction == null)
            {
                var dateTimeNow = DateTime.Now;
                var function    = new TemplateFunction
                {
                    FunctionName       = row.ServiceFunction,
                    TemplateComponents = new List <TemplateComponent>(),
                    InsertedDate       = dateTimeNow,
                    InsertedBy         = _userIdentity.Name,
                    UpdatedDate        = dateTimeNow,
                    UpdatedBy          = _userIdentity.Name
                };

                templateDomain.TemplateFunctions.Add(function);
                templateFunction = function;
            }

            if (!string.IsNullOrEmpty(row.ServiceComponentLevel1))
            {
                TransformServiceComponent(templateFunction, row);
            }
        }
Esempio n. 2
0
        protected object EvalExpression(Expression exp)
        {
            currentExpression = exp;

            if (exp is StringLiteral)
            {
                return(((StringLiteral)exp).Content);
            }
            else if (exp is Name)
            {
                object obj = variables[((Name)exp).Id];
                return(obj);
            }
            else if (exp is FieldAccess)
            {
                FieldAccess fa           = (FieldAccess)exp;
                object      obj          = variables[fa.Exp];
                string      propertyName = fa.Field;
                return(EvalProperty(obj, propertyName));
            }
            else if (exp is IntLiteral)
            {
                return(((IntLiteral)exp).Value);
            }
            else if (exp is FCall)
            {
                FCall fcall = (FCall)exp;
                if (!functions.ContainsKey(fcall.Name))
                {
                    string msg = string.Format("Function {0} is not defined", fcall.Name);
                    WriteError(msg, exp.Line, exp.Col);
                    return(null);
                }

                TemplateFunction func   = functions[fcall.Name];
                object[]         values = new object[fcall.Args.Length];
                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = EvalExpression(fcall.Args[i]);
                }

                return(func(values));
            }
            else if (exp is StringExpression)
            {
                StringExpression stringExp = (StringExpression)exp;
                StringBuilder    sb        = new StringBuilder();
                foreach (Expression ex in stringExp.Expressions)
                {
                    sb.Append(EvalExpression(ex));
                }

                return(sb.ToString());
            }

            return(null);
        }
Esempio n. 3
0
        private void TransformServiceComponent(TemplateFunction templateFunction, TemplateRow row)
        {
            var templateComponent = templateFunction.TemplateComponents.FirstOrDefault(c => c.ComponentName == row.ServiceComponentLevel1 && c.ComponentLevel == 1);

            if (templateComponent == null)
            {
                var dateTimeNow       = DateTime.Now;
                var levelOneComponent = new TemplateComponent
                {
                    ComponentName     = row.ServiceComponentLevel1,
                    ComponentLevel    = 1,
                    ServiceActivities =
                        string.IsNullOrEmpty(row.ServiceComponentLevel2) &&
                        !string.IsNullOrEmpty(row.ServiceActivities)
                            ? row.ServiceActivities
                            : string.Empty,
                    ChildTemplateComponents = new List <TemplateComponent>(),
                    TemplateResolvers       = new List <TemplateResolver>(),
                    TemplateFunction        = templateFunction,
                    InsertedDate            = dateTimeNow,
                    InsertedBy  = _userIdentity.Name,
                    UpdatedDate = dateTimeNow,
                    UpdatedBy   = _userIdentity.Name
                };

                templateFunction.TemplateComponents.Add(levelOneComponent);
                templateComponent = levelOneComponent;
            }

            if (!string.IsNullOrEmpty(row.ServiceComponentLevel2))
            {
                if (templateComponent.TemplateResolvers.Any())
                {
                    throw new DataImportException(
                              $"Error reading Service Decomposition Design spreadsheet. Worksheet, Resolvers and Childs Components detected on Component [{row.ServiceComponentLevel1}].");
                }
                TransformServiceComponentLevelTwo(templateComponent, row);
            }
            else if (!string.IsNullOrEmpty(row.ServiceDeliveryOrganisation))
            {
                if (templateComponent.TemplateResolvers.Any())
                {
                    throw new DataImportException(
                              $"Error reading Service Decomposition Template spreadsheet. Worksheet, Multiple Resolvers per Component detected on Component [{row.ServiceComponentLevel1}].");
                }
                TransformResolver(templateComponent, row);
            }
        }
        /// <summary>
        /// 載入Functions 建立Tab
        /// </summary>
        private void LoadFunctions()
        {
            var queryFunctions = from qf in dde.Functions
                                 where qf.Function_IsEnable == true
                                 select qf;

            if (queryFunctions.Count() > 0)
            {
                foreach (var qf in queryFunctions)
                {
                    TabItem fTabItem = new TabItem
                    {
                        Header = qf.Function_Title,
                        Uid    = qf.Function_ID.ToString()
                    };
                    switch (fTabItem.Uid)
                    {
                    case "1":
                        if (lf == null)
                        {
                            lf = new ListFunction(Agencys, ShowImages);
                        }
                        break;

                    case "2":
                        if (tf == null)
                        {
                            tf = new TemplateFunction(Agencys, Patients, ShowImages);
                            tf.ReturnValueCallback += new TemplateFunction.ReturnValueDelegate(RenewUsercontrol);
                        }
                        break;
                    }
                    if (qf.Function_ID == Agencys.Function_ID)
                    {
                        FunctionsTabItem = fTabItem;
                    }

                    if (FunctionsTab == null)
                    {
                        FunctionsTab = new ObservableCollection <TabItem>();
                    }
                    FunctionsTab.Add(fTabItem);
                }
            }
        }
Esempio n. 5
0
        private string ParseFunction(string content)
        {
            if (_methods == null)
            {
                return(content);
            }
            RiseNoEmplementationException(content);
            foreach (var functionName in _methods)
            {
                var pattern = @"({%" + functionName + @"\(\)%})|({%" + functionName + @"\(({%\w+%}|{%=\w+.\w+%}|\\\""\w+\\\""){1}(,({%\w+%}|{%=\w+.\w+%}|\\\""\w+\\\""))*\)%})";
                foreach (var expression in Regex.Matches(content, pattern))
                {
                    var templateFunction = new TemplateFunction(functionName);
                    var function         = expression.ToString();
                    foreach (var variable in Regex.Matches(function, @"({%\w+%}|{%=\w+.\w+%})"))
                    {
                        var varFormatting = variable.ToString()
                                            .Replace("{%=", "")
                                            .Replace("{%", "")
                                            .Replace("%}", "");
                        templateFunction.Add(new Parameter(varFormatting));
                        varFormatting = variable.ToString().StartsWith("{%=")
                            ? string.Format("GetVal(item,\"{0}\")", varFormatting)
                            : string.Format("GetVal(data,\"{0}\")", varFormatting);
                        function = function.Replace(variable.ToString(), varFormatting);
                    }
                    /*replace Handler[funcname](args)*/
                    content = content.Replace(expression.ToString(), function
                                              .Replace(@"\""", "\"")
                                              .Replace("{%", "\",")
                                              .Replace("%}", ",\"")
                                              .Replace(functionName, string.Format("handlers[\"{0}\"]", functionName)));
                    _functionsContainer.Add(templateFunction);
                }
            }

            return(content);
        }
Esempio n. 6
0
        /// <summary>
        /// evaluates expression.
        /// This method is used by TemplateManager extensibility.
        /// </summary>
        public object EvalExpression(Expression exp)
        {
            currentExpression = exp;

            try
            {
                if (exp is StringLiteral)
                {
                    return(((StringLiteral)exp).Content);
                }
                else if (exp is Name)
                {
                    return(GetValue(((Name)exp).Id));
                }
                else if (exp is FieldAccess)
                {
                    FieldAccess fa           = (FieldAccess)exp;
                    object      obj          = EvalExpression(fa.Exp);
                    string      propertyName = fa.Field;
                    return(EvalProperty(obj, propertyName));
                }
                else if (exp is MethodCall)
                {
                    MethodCall ma         = (MethodCall)exp;
                    object     obj        = EvalExpression(ma.CallObject);
                    string     methodName = ma.Name;

                    return(EvalMethodCall(obj, methodName, EvalArguments(ma.Args)));
                }
                else if (exp is IntLiteral)
                {
                    return(((IntLiteral)exp).Value);
                }
                else if (exp is DoubleLiteral)
                {
                    return(((DoubleLiteral)exp).Value);
                }
                else if (exp is FCall)
                {
                    FCall fcall = (FCall)exp;
                    if (!functions.ContainsKey(fcall.Name))
                    {
                        string msg = string.Format("函数 '{0}' 未定义.", fcall.Name);
                        throw new TemplateRuntimeException(msg, exp.Line, exp.Col);
                    }

                    TemplateFunction func   = functions[fcall.Name];
                    object[]         values = EvalArguments(fcall.Args);

                    return(func(values));
                }
                else if (exp is StringExpression)
                {
                    StringExpression stringExp = (StringExpression)exp;
                    StringBuilder    sb        = new StringBuilder();
                    foreach (Expression ex in stringExp.Expressions)
                    {
                        sb.Append(EvalExpression(ex));
                    }

                    return(sb.ToString());
                }
                else if (exp is BinaryExpression)
                {
                    return(EvalBinaryExpression(exp as BinaryExpression));
                }
                else if (exp is ArrayAccess)
                {
                    return(EvalArrayAccess(exp as ArrayAccess));
                }
                else
                {
                    throw new TemplateRuntimeException("无效的表达式类型: " + exp.GetType().Name, exp.Line, exp.Col);
                }
            }
            catch (TemplateRuntimeException ex)
            {
                DisplayError(ex);
                return(null);
            }
            catch (Exception ex)
            {
                DisplayError(new TemplateRuntimeException(ex.Message, currentExpression.Line, currentExpression.Col));
                return(null);
            }
        }