Пример #1
0
 private static void LogMessageIfNotShuttingDown(IInlineFunction function, string message)
 {
     if (!HostingEnvironment.ApplicationHost.ShutdownInitiated())
     {
         Log.LogWarning(LogTitle, $"{function.Namespace}.{function.Name} : {message}");
     }
 }
        private void finalizeCodeActivity_DeleteFunction_ExecuteCode(object sender, EventArgs e)
        {
            IInlineFunction function = GetDataItemFromEntityToken <IInlineFunction>();

            if (DataFacade.WillDeleteSucceed(function))
            {
                DeleteTreeRefresher treeRefresher = this.CreateDeleteTreeRefresher(this.EntityToken);

                using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
                {
                    DataFacade.Delete <IInlineFunctionAssemblyReference>(f => f.Function == function.Id);
                    DataFacade.Delete <IParameter>(f => f.OwnerId == function.Id);

                    function.DeleteFunctionCode();

                    DataFacade.Delete(function);

                    transactionScope.Complete();
                }

                treeRefresher.PostRefreshMesseges();
            }
            else
            {
                this.ShowMessage(
                    DialogType.Error,
                    StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "CascadeDeleteErrorTitle"),
                    StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "CascadeDeleteErrorMessage")
                    );
            }
        }
Пример #3
0
        public NotLoadedInlineFunction(IInlineFunction functionInfo, StringInlineFunctionCreateMethodErrorHandler errors)
        {
            Verify.ArgumentCondition(errors.HasErrors, "errors", "No errors information provided");

            _function = functionInfo;
            _errors   = errors;
        }
Пример #4
0
        protected InlineFunction(IInlineFunction info, MethodInfo methodInfo)
        {
            Verify.ArgumentNotNull(info, "info");

            _function = info;
            MethodInfo = methodInfo;
        }
        protected InlineFunction(IInlineFunction info, MethodInfo methodInfo)
        {
            Verify.ArgumentNotNull(info, "info");

            _function  = info;
            MethodInfo = methodInfo;
        }
Пример #6
0
        private void AddReturnTypeToCache(IInlineFunction info, Type type)
        {
            string functionName = info.Namespace + "." + info.Name;
            string filePath     = info.GetSourceFilePath();

            _inlineFunctionReturnTypeCache.Add(functionName, filePath, type);
        }
Пример #7
0
        private void ValidateFunctionName(object sender, ConditionalEventArgs e)
        {
            IInlineFunction function = this.GetBinding <IInlineFunction>("NewFunction");

            bool exists = FunctionFacade.FunctionExists(function.Namespace, function.Name);

            if (exists)
            {
                string errorMessage = StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "AddFunction.NameAlreadyUsed");
                errorMessage = string.Format(errorMessage, FunctionFacade.GetFunctionCompositionName(function.Namespace, function.Name));
                ShowFieldMessage("NewFunction.Name", errorMessage);
                e.Result = false;
                return;
            }

            ValidationResults validationResults = ValidationFacade.Validate <IInlineFunction>(function);

            if (!validationResults.IsValid)
            {
                foreach (ValidationResult result in validationResults)
                {
                    this.ShowFieldMessage(string.Format("{0}.{1}", "NewFunction", result.Key), result.Message);
                }

                e.Result = false;
                return;
            }

            e.Result = true;
        }
Пример #8
0
        public NotLoadedInlineFunction(IInlineFunction functionInfo, StringInlineFunctionCreateMethodErrorHandler errors)
        {
            Verify.ArgumentCondition(errors.HasErrors, "errors", "No errors information provided");

            _function = functionInfo;
            _errors = errors;
        }
Пример #9
0
        public void Setup()
        {
            var tokenizer           = new Tokenizer(new StringReader(input));
            var blockFunctions      = new IBlockFunction[] { new ForEach() };
            var inlineFunctions     = new IInlineFunction[] { new LDelim() };
            var expressionFunctions = new IExpressionFunction[] { new If() };

            var functions = new Functions(blockFunctions, inlineFunctions, expressionFunctions, new List <IVariableModifier>());

            parser = new Parser(0, tokenizer, functions);
        }
Пример #10
0
        public static IFunction Create(IInlineFunction info)
        {
            var errors = new StringInlineFunctionCreateMethodErrorHandler();

            MethodInfo methodInfo = InlineFunctionHelper.Create(info, null, errors);

            if (methodInfo == null)
            {
                return(new NotLoadedInlineFunction(info, errors));
            }

            return(new InlineFunction(info, methodInfo));
        }
Пример #11
0
        public static IEnumerable <IPackItem> CreateInline(EntityToken entityToken)
        {
            if (entityToken is DataEntityToken)
            {
                DataEntityToken dataEntityToken = (DataEntityToken)entityToken;
                if (dataEntityToken.Data is IInlineFunction)
                {
                    IInlineFunction data = (IInlineFunction)dataEntityToken.Data;
                    yield return(new PCFunctions(data.Namespace + "." + data.Name));

                    yield break;
                }
            }
        }
Пример #12
0
        private Type GetCachedReturnType(IInlineFunction info)
        {
            string functionName = info.Namespace + "." + info.Name;
            string filePath     = info.GetSourceFilePath();

            Type type;

            if (!_inlineFunctionReturnTypeCache.Get(functionName, filePath, out type))
            {
                return(null);
            }

            return(type);
        }
Пример #13
0
        public void Setup()
        {
            var blockFunctions      = new IBlockFunction[] { new ForEach(), new Literal(), new Strip(), new Capture() };
            var inlineFunctions     = new IInlineFunction[] { new LDelim(), new RDelim(), new Assign(), new Cycle() };
            var expressionFunctions = new IExpressionFunction[] { new If() };
            var variableModifiers   = new IVariableModifier[] { new Capitalize(), new Cat(), new CountCharacters(), new CountParagraphs(), new CountSentences(), new CountWords(), new DateFormat(), new Default(), new Lower(), new NewLineToBreak(), new RegexReplace(), new Replace(), new Spacify(), new StringFormat(), new ASmarty.VariableModifiers.Strip(), new StripTags(), new Truncate(), new Upper(), new WordWrap(), new Indent() };
            var functions           = new Functions(blockFunctions, inlineFunctions, expressionFunctions, variableModifiers);

            viewData     = new Dictionary <string, object>();
            functionData = new Dictionary <string, object>();

            var internalEvaluator = new InternalEvaluator(null, null, functions);

            evaluator         = new ViewEngine.Evaluator(internalEvaluator, 0);
            functionEvaluator = new FunctionEvaluator(internalEvaluator, 0, functionData);
        }
Пример #14
0
        private void initializeCodeActivity_InitBindings_ExecuteCode(object sender, EventArgs e)
        {
            IInlineFunction function = DataFacade.BuildNew <IInlineFunction>();

            function.Id        = Guid.NewGuid();
            function.Namespace = UserSettings.LastSpecifiedNamespace;

            this.Bindings.Add("NewFunction", function);

            Dictionary <string, string> templates = new Dictionary <string, string>();

            templates.Add("clean", StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "InlineFunctionMethodTemplate.Clean"));
            templates.Add("parameter", StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "InlineFunctionMethodTemplate.WithParameters"));
            templates.Add("dataconnection", StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "InlineFunctionMethodTemplate.DataConnection"));

            this.Bindings.Add("TemplateOptions", templates);
            this.Bindings.Add("SelectedTemplate", "clean");
        }
        private void AddReturnTypeToCache(IInlineFunction info, Type type)
        {
            string functionName = info.Namespace + "." + info.Name;
            string filePath = info.GetSourceFilePath();

            _inlineFunctionReturnTypeCache.Add(functionName, filePath, type);
        }
Пример #16
0
        /// <exclude />
        public static MethodInfo Create(IInlineFunction function, string code = null, InlineFunctionCreateMethodErrorHandler createMethodErrorHandler = null, List<string> selectedAssemblies = null)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                try
                {
                    code = GetFunctionCode(function);
                }
                catch (ThreadAbortException)
                {
                }
                catch (Exception ex)
                {
                    if (createMethodErrorHandler != null)
                    {
                        createMethodErrorHandler.OnLoadSourceError(ex);
                    }
                    else
                    {
                        LogMessageIfNotShuttingDown(function, ex.Message);
                    }
                    return null;
                }
            }

            CompilerParameters compilerParameters = new CompilerParameters();
            compilerParameters.GenerateExecutable = false;
            compilerParameters.GenerateInMemory = true;

            if (selectedAssemblies == null)
            {
                IEnumerable<IInlineFunctionAssemblyReference> assemblyReferences =
                    DataFacade.GetData<IInlineFunctionAssemblyReference>(f => f.Function == function.Id).Evaluate();

                foreach (IInlineFunctionAssemblyReference assemblyReference in assemblyReferences)
                {
                    string assemblyPath = GetAssemblyFullPath(assemblyReference.Name, assemblyReference.Location);
                    compilerParameters.ReferencedAssemblies.Add(assemblyPath);
                }
            }
            else
            {
                foreach (string reference in selectedAssemblies)
                {
                    compilerParameters.ReferencedAssemblies.Add(reference);
                }
            }

            Assembly appCodeAssembly = AssemblyFacade.GetAppCodeAssembly();
            if (appCodeAssembly != null)
            {
                compilerParameters.ReferencedAssemblies.Add(appCodeAssembly.Location);
            }

            CSharpCodeProvider compiler = new CSharpCodeProvider();
            CompilerResults results = compiler.CompileAssemblyFromSource(compilerParameters, code);

            if (results.Errors.HasErrors)
            {
                foreach (CompilerError error in results.Errors)
                {
                    if (createMethodErrorHandler != null)
                    {
                        createMethodErrorHandler.OnCompileError(error.Line, error.ErrorNumber, error.ErrorText);
                    }
                    else
                    {
                        LogMessageIfNotShuttingDown(function, error.ErrorText);
                    }
                }

                return null;
            }

            Type type = results.CompiledAssembly.GetTypes().SingleOrDefault(f => f.Name == MethodClassContainerName);
            if (type == null)
            {
                string message = Texts.CSharpInlineFunction_OnMissingContainerType(MethodClassContainerName);

                if (createMethodErrorHandler != null)
                {
                    createMethodErrorHandler.OnMissingContainerType(message);
                }
                else
                {
                    LogMessageIfNotShuttingDown(function, message);
                }

                return null;
            }

            if (type.Namespace != function.Namespace)
            {
                string message = Texts.CSharpInlineFunction_OnNamespaceMismatch(type.Namespace, function.Namespace);

                if (createMethodErrorHandler != null)
                {
                    createMethodErrorHandler.OnNamespaceMismatch(message);
                }
                else
                {
                    LogMessageIfNotShuttingDown(function, message);
                }

                return null;
            }

            MethodInfo methodInfo = type.GetMethods(BindingFlags.Public | BindingFlags.Static).SingleOrDefault(f => f.Name == function.Name);
            if (methodInfo == null)
            {
                string message = Texts.CSharpInlineFunction_OnMissionMethod(function.Name, MethodClassContainerName);

                if (createMethodErrorHandler != null)
                {
                    createMethodErrorHandler.OnMissionMethod(message);
                }
                else
                {
                    LogMessageIfNotShuttingDown(function, message);
                }

                return null;
            }

            return methodInfo;
        }
 public EditableMethodFunctionTreeBuilderLeafInfo(IInlineFunction function)
 {
     _function = function;
 }
Пример #18
0
        /// <exclude />
        public static void FunctionRenamed(IInlineFunction newFunction, IInlineFunction oldFunction)
        {
            newFunction.UpdateCodePath();

            string directoryPath = PathUtil.Resolve(GlobalSettingsFacade.InlineCSharpFunctionDirectory);

            string oldFilepath = Path.Combine(directoryPath, oldFunction.CodePath);
            string newFilepath = Path.Combine(directoryPath, newFunction.CodePath);

            C1File.Move(oldFilepath, newFilepath);
        }
Пример #19
0
 private static void LogMessageIfNotShuttingDown(IInlineFunction function, string message)
 {
     if (!HostingEnvironment.ApplicationHost.ShutdownInitiated())
     {
         Log.LogWarning(LogTitle, string.Format("{0}.{1} : {2}", function.Namespace, function.Name, message));
     }
 }
Пример #20
0
 public LazyInitializedInlineFunction(IInlineFunction inlineFunction)
     : base(inlineFunction, null)
 {
 }
Пример #21
0
        public static IFunction Create(IInlineFunction info)
        {
            var errors = new StringInlineFunctionCreateMethodErrorHandler();

            MethodInfo methodInfo = InlineFunctionHelper.Create(info, null, errors);

            if (methodInfo == null) return new NotLoadedInlineFunction(info, errors);

            return new InlineFunction(info, methodInfo);
        }
Пример #22
0
 public LazyInitializedInlineFunction(IInlineFunction inlineFunction, Type cachedReturnType)
     : base(inlineFunction, null)
 {
     this._cachedReturnType = cachedReturnType;
 }
Пример #23
0
 public LazyInitializedInlineFunction(IInlineFunction inlineFunction, Type cachedReturnType)
     : base(inlineFunction, null)
 {
     this._cachedReturnType = cachedReturnType;
 }
Пример #24
0
 public InlineFunctionNode(int id, IInlineFunction inlineFunction, IDictionary <string, ExpressionNode> attributes)
 {
     Id             = id;
     InlineFunction = inlineFunction;
     Attributes     = attributes;
 }
Пример #25
0
 public LazyInitializedInlineFunction(IInlineFunction inlineFunction)
     : base(inlineFunction, null)
 {
 }
        private Type GetCachedReturnType(IInlineFunction info)
        {
            string functionName = info.Namespace + "." + info.Name;
            string filePath = info.GetSourceFilePath();

            Type type;
            if(!_inlineFunctionReturnTypeCache.Get(functionName, filePath, out type))
            {
                return null;
            }

            return type;
        }