Beispiel #1
0
 private static void ValidateParameter(ManagedParameterDefinition parameterDefinition)
 {
     if (string.IsNullOrEmpty(parameterDefinition.Name))
     {
         throw new InvalidOperationException("Name property can not be null or an empty string");
     }
     if (parameterDefinition.Type == null)
     {
         throw new InvalidOperationException("Type property can not be null");
     }
     if (string.IsNullOrEmpty(parameterDefinition.Label))
     {
         throw new InvalidOperationException("Parameter '{0}' has an empty 'Label' field".FormatWith(parameterDefinition.Name));
     }
 }
Beispiel #2
0
        private static ManagedParameterDefinition BuildParameterDefinition(IParameter parameterData)
        {
            ManagedParameterDefinition paramDef = new ManagedParameterDefinition();

            paramDef.Id                         = parameterData.ParameterId;
            paramDef.Name                       = parameterData.Name;
            paramDef.Type                       = TypeManager.GetType(parameterData.TypeManagerName);
            paramDef.Label                      = parameterData.Label;
            paramDef.HelpText                   = parameterData.HelpText;
            paramDef.Position                   = parameterData.Position;
            paramDef.WidgetFunctionMarkup       = parameterData.WidgetFunctionMarkup;
            paramDef.DefaultValueFunctionMarkup = parameterData.DefaultValueFunctionMarkup;
            paramDef.TestValueFunctionMarkup    = parameterData.TestValueFunctionMarkup;

            return(paramDef);
        }
Beispiel #3
0
        private static IParameter BuildIParameter(Guid ownerId, ManagedParameterDefinition parameterDefinition)
        {
            IParameter newParam = DataFacade.BuildNew <IParameter>();

            newParam.OwnerId                    = ownerId;
            newParam.ParameterId                = parameterDefinition.Id;
            newParam.Name                       = parameterDefinition.Name;
            newParam.TypeManagerName            = TypeManager.SerializeType(parameterDefinition.Type);
            newParam.Label                      = parameterDefinition.Label;
            newParam.HelpText                   = parameterDefinition.HelpText;
            newParam.Position                   = parameterDefinition.Position;
            newParam.WidgetFunctionMarkup       = parameterDefinition.WidgetFunctionMarkup;
            newParam.DefaultValueFunctionMarkup = parameterDefinition.DefaultValueFunctionMarkup;
            newParam.TestValueFunctionMarkup    = parameterDefinition.TestValueFunctionMarkup;

            return(newParam);
        }
        private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e)
        {
            IInlineFunction function = this.GetBinding<IInlineFunction>("NewFunction");
            function.UpdateCodePath();

            string selectedTemplate = this.GetBinding<string>("SelectedTemplate");

            string codeTemplate;
            switch (selectedTemplate)
            {
                case "clean":
                    codeTemplate = _cleanTemplate;
                    break;

                case "parameter":
                    codeTemplate = _parameterTemplate;

                    List<ManagedParameterDefinition> parameters = new List<ManagedParameterDefinition>();

                    ManagedParameterDefinition parameter1 = new ManagedParameterDefinition();
                    parameter1.Id = Guid.NewGuid();
                    parameter1.Name = "myIntValue";
                    parameter1.Label = "myIntValue";
                    parameter1.HelpText = "myIntValue";
                    parameter1.Position = 0;
                    parameter1.Type = typeof(int);
                    parameter1.TestValueFunctionMarkup = "<f:function xmlns:f=\"http://www.composite.net/ns/function/1.0\" name=\"Composite.Constant.Integer\"><f:param name=\"Constant\" value=\"0\" /></f:function>";
                    parameter1.WidgetFunctionMarkup = "<f:widgetfunction xmlns:f=\"http://www.composite.net/ns/function/1.0\" name=\"Composite.Widgets.Integer.TextBox\" label=\"myIntValue\" bindingsourcename=\"\"><f:helpdefinition xmlns:f=\"http://www.composite.net/ns/function/1.0\" helptext=\"myIntValue\" /></f:widgetfunction>";
                    parameters.Add(parameter1);


                    ManagedParameterDefinition parameter2 = new ManagedParameterDefinition();
                    parameter2.Id = Guid.NewGuid();
                    parameter2.Name = "myStringValue";
                    parameter2.Label = "myStringValue";
                    parameter2.HelpText = "myStringValue";
                    parameter2.Position = 1;
                    parameter2.Type = typeof(string);
                    parameter2.TestValueFunctionMarkup = "<f:function xmlns:f=\"http://www.composite.net/ns/function/1.0\" name=\"Composite.Constant.String\"><f:param name=\"Constant\" value=\"Hello world!\" /></f:function>";
                    parameter2.WidgetFunctionMarkup = "<f:widgetfunction xmlns:f=\"http://www.composite.net/ns/function/1.0\" name=\"Composite.Widgets.String.TextBox\" label=\"myStringValue\" bindingsourcename=\"\"><f:helpdefinition xmlns:f=\"http://www.composite.net/ns/function/1.0\" helptext=\"myStringValue\" /></f:widgetfunction>";
                    parameters.Add(parameter2);

                    ManagedParameterManager.Save(function.Id, parameters);
                    break;

                case "dataconnection":
                    codeTemplate = _dataConnectionTemplate;
                    break;

                default:
                    throw new NotImplementedException();
            }

            string code = string.Format(codeTemplate, function.Namespace, InlineFunctionHelper.MethodClassContainerName, function.Name);
            code = code.Replace('и', '\t');

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                foreach (string assemblyPath in InlineFunctionHelper.DefaultAssemblies)
                {
                    IInlineFunctionAssemblyReference reference = DataFacade.BuildNew<IInlineFunctionAssemblyReference>();
                    reference.Id = Guid.NewGuid();
                    reference.Function = function.Id;
                    reference.Name = System.IO.Path.GetFileName(assemblyPath);
                    reference.Location = InlineFunctionHelper.GetAssemblyLocation(assemblyPath);

                    DataFacade.AddNew(reference);
                }

                function.SetFunctinoCode(code);

                function = DataFacade.AddNew(function);

                UserSettings.LastSpecifiedNamespace = function.Namespace;

                transactionScope.Complete();
            }

            this.CloseCurrentView();
            this.CreateAddNewTreeRefresher(this.EntityToken).PostRefreshMesseges(function.GetDataEntityToken());
            this.ExecuteWorklow(function.GetDataEntityToken(), WorkflowFacade.GetWorkflowType("Composite.Workflows.Plugins.Elements.ElementProviders.MethodBasedFunctionProviderElementProvider.EditInlineFunctionWorkflow"));
        }
        private void Field_Save()
        {
            if (CurrentlySelectedFieldId == Guid.Empty)
            {
                return;
            }

            if (this.CurrentFields.Count(f => f.Id == this.CurrentlySelectedFieldId) == 0)
            {
                ManagedParameterDefinition newField = new ManagedParameterDefinition {
                   Id = this.CurrentlySelectedFieldId,
                   Name = this.NameField.Text,
                   Type = this.CurrentlySelectedType
                };
                newField.Position = this.CurrentFields.Count;
                this.CurrentFields.Add(newField);
            }

            if (FieldNameSyntaxValid(this.NameField.Text) == false)
            {
                ShowMessage(this.NameField.ClientID, GetString("FieldNameSyntaxInvalid"));
                return;
            }

            if (this.CurrentFields.Count<ManagedParameterDefinition>(f => f.Name.ToLower() == this.NameField.Text.ToLower() && f.Id != this.CurrentlySelectedFieldId) > 0)
            {
                ShowMessage(this.NameField.ClientID, GetString("CannotSave"));
                return;
            }

            var field = this.CurrentFields.Single(f => f.Id == this.CurrentlySelectedFieldId);

            if (field.Name != this.NameField.Text)
            {
                nameChanged = true;
            }

            field.Name = this.NameField.Text;
            field.Type = this.CurrentlySelectedType;

            bool generateLabel = (this.LabelField.Text == "" && this.NameField.Text.StartsWith(_defaultFieldNamePrefix) == false);
            string label = (generateLabel ? this.NameField.Text : this.LabelField.Text);

            field.Label = label;
            field.HelpText = this.HelpField.Text;

            if (!btnWidgetFunctionMarkup.Value.IsNullOrEmpty())
            {
                XElement functionElement = XElement.Parse(btnWidgetFunctionMarkup.Value);
                if (functionElement.Name.Namespace != Namespaces.Function10)
                    functionElement = functionElement.Elements().First();

                field.WidgetFunctionMarkup = functionElement.ToString(SaveOptions.DisableFormatting);
            }
            else
            {
                field.WidgetFunctionMarkup = "";
            }

            if (!btnDefaultValueFunctionMarkup.Value.IsNullOrEmpty())
            {
                XElement functionElement = XElement.Parse(btnDefaultValueFunctionMarkup.Value);
                if (functionElement.Name.Namespace != Namespaces.Function10)
                    functionElement = functionElement.Elements().First();

                field.DefaultValueFunctionMarkup = functionElement.ToString(SaveOptions.DisableFormatting);
            }
            else
            {
                field.DefaultValueFunctionMarkup = null;
            }

            if (!btnTestValueFunctionMarkup.Value.IsNullOrEmpty())
            {
                XElement functionElement = XElement.Parse(btnTestValueFunctionMarkup.Value);
                if (functionElement.Name.Namespace != Namespaces.Function10)
                    functionElement = functionElement.Elements().First();

                field.TestValueFunctionMarkup = functionElement.ToString(SaveOptions.DisableFormatting);
            }
            else
            {
                field.TestValueFunctionMarkup = null;
            }

            int newPosition = int.Parse(this.PositionField.SelectedValue);
            if (newPosition == -1) newPosition = this.CurrentFields.Count - 1;

            if (field.Position != newPosition)
            {
                this.CurrentFields.Remove(field);

                foreach (ManagedParameterDefinition laterField in this.CurrentFields.Where(f => f.Position > field.Position))
                {
                    laterField.Position--;
                }

                foreach (ManagedParameterDefinition laterField in this.CurrentFields.Where(f => f.Position >= newPosition))
                {
                    laterField.Position++;
                }

                field.Position = newPosition;
                this.CurrentFields.Insert(newPosition, field);
            }
        }