public static MethodBasedFunction Create(IMethodBasedFunctionInfo info)
        {
            Type type = TypeManager.TryGetType(info.Type);

            if (type == null)
            {
                string errorMessage = "Could not find the type '{0}'".FormatWith(info.Type);

                // Skipping error log while package installation, the type/method may be available after restart
                if (!HostingEnvironment.ApplicationHost.ShutdownInitiated())
                {
                    Log.LogError(LogTitle, GetErrorMessage(info) + errorMessage);
                }

                return(new NotLoadedMethodBasedFunction(info, errorMessage));
            }

            MethodInfo methodInfo = type.GetMethods().FirstOrDefault(mi => mi.Name == info.MethodName);

            if (methodInfo == null)
            {
                string errorMessage = "Could not find the method '{0}' on the the type '{1}'".FormatWith(info.MethodName, info.Type);

                // Skipping error log while package installation, the type/method may be available after restart
                if (!HostingEnvironment.ApplicationHost.ShutdownInitiated())
                {
                    Log.LogError(LogTitle, GetErrorMessage(info) + errorMessage);
                }

                return(new NotLoadedMethodBasedFunction(info, errorMessage));
            }

            return(new MethodBasedFunction(info, type, methodInfo));
        }
        private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            DataEntityToken token = (DataEntityToken)this.EntityToken;

            IMethodBasedFunctionInfo methodBasedFunctionInfo = (IMethodBasedFunctionInfo)token.Data;

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

                DataFacade.Delete(token.Data);

                int count =
                    (from info in DataFacade.GetData <IMethodBasedFunctionInfo>()
                     where info.Namespace == methodBasedFunctionInfo.Namespace
                     select info).Count();

                if (count == 0)
                {
                    RefreshFunctionTree();
                }
                else
                {
                    treeRefresher.PostRefreshMesseges();
                }
            }
            else
            {
                this.ShowMessage(
                    DialogType.Error,
                    StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "CascadeDeleteErrorTitle"),
                    StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "CascadeDeleteErrorMessage")
                    );
            }
        }
示例#3
0
        private void IsValidData(object sender, ConditionalEventArgs e)
        {
            e.Result = false;

            IMethodBasedFunctionInfo function = this.GetBinding <IMethodBasedFunctionInfo>("CurrentMethodFunctionInfo");

            if (function.UserMethodName == String.Empty)
            {
                this.ShowFieldMessage("CurrentMethodFunctionInfo.UserMethodName", "${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditFunction.MethodNameEmpty}");
                return;
            }

            if (!function.Namespace.IsCorrectNamespace('.'))
            {
                this.ShowFieldMessage("CurrentMethodFunctionInfo.UserMethodName", "${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditFunction.InvalidNamespace}");
                return;
            }

            Type type = TypeManager.TryGetType(function.Type);

            if (type == null)
            {
                this.ShowFieldMessage("CurrentMethodFunctionInfo.Type", "${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditFunction.TypeNotFound}");
                return;
            }

            List <string> methodNames =
                (from methodInfo in type.GetMethods()
                 select methodInfo.Name).ToList();


            if (!methodNames.Contains(function.MethodName))
            {
                this.ShowFieldMessage("CurrentMethodFunctionInfo.MethodName", "${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditFunction.MethodNotInType}");
                return;
            }


            if (methodNames.Count == 0)
            {
                this.ShowFieldMessage("CurrentMethodFunctionInfo.Type", "${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditFunction.NoValidMethod}");
                return;
            }

            int destinctCount = methodNames.Distinct().Count();

            if (destinctCount != methodNames.Count)
            {
                this.ShowFieldMessage("CurrentMethodFunctionInfo.Type", "${Composite.Plugins.MethodBasedFunctionProviderElementProvider, EditFunction.MethodOverloadsNotAllowed}");
                return;
            }

            e.Result = true;
        }
示例#4
0
        private void saveCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            UpdateTreeRefresher updateTreeRefresher = this.CreateUpdateTreeRefresher(this.EntityToken);

            IMethodBasedFunctionInfo methodBasedFunctionInfo = this.GetBinding <IMethodBasedFunctionInfo>("CurrentMethodFunctionInfo");

            DataFacade.Update(methodBasedFunctionInfo);

            SetSaveStatus(true);

            updateTreeRefresher.PostRefreshMesseges(methodBasedFunctionInfo.GetDataEntityToken());
        }
        private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            IMethodBasedFunctionInfo methodBasedFunctionInfo = this.GetBinding <IMethodBasedFunctionInfo>("NewMethodBasedFunction");

            methodBasedFunctionInfo.Id = Guid.NewGuid();

            methodBasedFunctionInfo = DataFacade.AddNew <IMethodBasedFunctionInfo>(methodBasedFunctionInfo);

            addNewTreeRefresher.PostRefreshMesseges(methodBasedFunctionInfo.GetDataEntityToken());
        }
        private void step2CodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            IMethodBasedFunctionInfo function = this.GetBinding <IMethodBasedFunctionInfo>("NewMethodBasedFunction");

            Type type = TypeManager.TryGetType(function.Type);

            string methodName = this.GetBinding <string>("SelectedMethodName");


            function.MethodName     = methodName;
            function.UserMethodName = methodName;
            function.Namespace      = type.Namespace + "." + type.Name;
        }
示例#7
0
        public static IEnumerable <IPackItem> CreateCSharp(EntityToken entityToken)
        {
            if (entityToken is DataEntityToken)
            {
                DataEntityToken dataEntityToken = (DataEntityToken)entityToken;
                if (dataEntityToken.Data is IMethodBasedFunctionInfo)
                {
                    IMethodBasedFunctionInfo data = (IMethodBasedFunctionInfo)dataEntityToken.Data;
                    yield return(new PCFunctions(data.Namespace + "." + data.UserMethodName));

                    yield break;
                }
            }
        }
        private void CheckType(object sender, ConditionalEventArgs e)
        {
            IMethodBasedFunctionInfo function = this.GetBinding <IMethodBasedFunctionInfo>("NewMethodBasedFunction");

            Type type = TypeManager.TryGetType(function.Type);

            if (type == null)
            {
                string errorMessage = StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "AddFunction.CouldNotFindType");
                ShowFieldMessage("NewMethodBasedFunction.Type", errorMessage);
                e.Result = false;
                return;
            }


            List <string> methodNames =
                (from methodInfo in type.GetMethods(BindingFlags.Static | BindingFlags.Public)
                 select methodInfo.Name).ToList();

            if (methodNames.Count == 0)
            {
                string errorMessage = StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "AddFunction.TypeHasNoValidMethod");
                ShowFieldMessage("NewMethodBasedFunction.Type", errorMessage);
                e.Result = false;
                return;
            }


            int destinctCount = methodNames.Distinct().Count();

            if (destinctCount != methodNames.Count)
            {
                string errorMessage = StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "AddFunction.TypeMustNotHaveOverloads");
                ShowFieldMessage("NewMethodBasedFunction.Type", errorMessage);
                e.Result = false;
                return;
            }


            this.UpdateBinding("MethodNames", methodNames);
            this.UpdateBinding("SelectedMethodName", "");

            _lastAddedType = type.FullName;

            e.Result = true;
        }
        private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            IMethodBasedFunctionInfo             function = DataFacade.BuildNew <IMethodBasedFunctionInfo>();
            BaseFunctionFolderElementEntityToken token    = (BaseFunctionFolderElementEntityToken)this.EntityToken;

            string namespaceName = "";
            int    index         = token.Id.IndexOf('.');

            if (index > 0)
            {
                namespaceName = token.Id.Substring(index + 1);
            }
            function.Namespace = namespaceName;
            if (_lastAddedType != null)
            {
                function.Type = _lastAddedType;
            }

            this.Bindings.Add("UserMethodName", "");
            this.Bindings.Add("NewMethodBasedFunction", function);
        }
        private void IsValidMethodName(object sender, ConditionalEventArgs e)
        {
            IMethodBasedFunctionInfo function = this.GetBinding <IMethodBasedFunctionInfo>("NewMethodBasedFunction");

            FlowControllerServicesContainer container = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
            var flowRenderingService = container.GetService <IFormFlowRenderingService>();


            if (function.UserMethodName == String.Empty)
            {
                string errorMessage = StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "AddFunction.MethodNameIsEmpty");
                ShowFieldMessage("NewMethodBasedFunction", errorMessage);
                e.Result = false;
                return;
            }
            if (!function.Namespace.IsCorrectNamespace('.'))
            {
                string errorMessage = StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "AddFunction.InvalidNamespace");
                ShowFieldMessage("NewMethodBasedFunction", errorMessage);
                e.Result = false;
                return;
            }

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

            if (exists)
            {
                string errorMessage = StringResourceSystemFacade.GetString("Composite.Plugins.MethodBasedFunctionProviderElementProvider", "AddFunction.NameAlreadyUsed");
                errorMessage = string.Format(errorMessage, StringExtensionMethods.CreateNamespace(function.Namespace, function.UserMethodName));
                ShowFieldMessage("NewMethodBasedFunction.UserMethodName", errorMessage);
                e.Result = false;
                return;
            }

            e.Result = true;
        }
 private static string GetErrorMessage(IMethodBasedFunctionInfo info)
 {
     return("Failed to initialize function '{0}.{1}'. ".FormatWith(info.Namespace, info.UserMethodName));
 }
 protected MethodBasedFunction(IMethodBasedFunctionInfo info, Type type, MethodInfo methodInfo)
 {
     _methodBasedFunctionInfo = info;
     _type       = type;
     _methodInfo = methodInfo;
 }
 protected MethodBasedFunction(IMethodBasedFunctionInfo info, Type type, MethodInfo methodInfo) : this(typeof(MethodBasedFunction).Name)
 {
     _methodBasedFunctionInfo = info;
     _type       = type;
     _methodInfo = methodInfo;
 }
 public NotLoadedMethodBasedFunction(IMethodBasedFunctionInfo functionInfo, string errorMessage)
     : base(functionInfo, null, null)
 {
     _errorMessage = errorMessage;
 }
 public MethodFunctionTreeBuilderLeafInfo(IMethodBasedFunctionInfo function)
 {
     _function = function;
 }
示例#16
0
 public NotLoadedMethodBasedFunction(IMethodBasedFunctionInfo functionInfo, string errorMessage)
     : base(functionInfo, null, null)
 {
     _errorMessage = errorMessage;
 }
示例#17
0
        public static MethodBasedFunction Create(IMethodBasedFunctionInfo info)
        {
            Type type = TypeManager.TryGetType(info.Type);

            if (type == null)
            {
                string errorMessage = "Could not find the type '{0}'".FormatWith(info.Type);

                // Skipping error log while package installation, the type/method may be available after restart
                if (!HostingEnvironment.ApplicationHost.ShutdownInitiated())
                {
                    Log.LogError(LogTitle, GetErrorMessage(info) + errorMessage);
                }

                return new NotLoadedMethodBasedFunction(info, errorMessage);
            }

            MethodInfo methodInfo = type.GetMethods().FirstOrDefault(mi => mi.Name == info.MethodName);

            if (methodInfo == null)
            {
                string errorMessage = "Could not find the method '{0}' on the the type '{1}'".FormatWith(info.MethodName, info.Type);

                // Skipping error log while package installation, the type/method may be available after restart
                if (!HostingEnvironment.ApplicationHost.ShutdownInitiated())
                {
                    Log.LogError(LogTitle, GetErrorMessage(info) + errorMessage);
                }

                return new NotLoadedMethodBasedFunction(info, errorMessage);
            }

            return new MethodBasedFunction(info, type, methodInfo);
        }
示例#18
0
 private static string GetErrorMessage(IMethodBasedFunctionInfo info)
 {
     return "Failed to initialize function '{0}.{1}'. ".FormatWith(info.Namespace, info.UserMethodName);
 }
示例#19
0
 protected MethodBasedFunction(IMethodBasedFunctionInfo info, Type type, MethodInfo methodInfo)
 {
     _methodBasedFunctionInfo = info;
     _type = type;
     _methodInfo = methodInfo;
 }