/// <summary>
        ///     Добавляет параметр.
        /// </summary>
        public void AddParameter(ParameterElement parameter)
        {
            var name = parameter.GetName();

            _parameters[name] = parameter;
            _context[name]    = parameter;
        }
示例#2
0
        /// <summary>
        /// Builds an Odbc Parameter object from the arguments.
        /// </summary>
        /// <param name="parameterElement">Parameter definition from the config.</param>
        /// <param name="data">The event notification to pull the parameter's value from.</param>
        /// <returns></returns>
        private static OdbcParameter ParseParameter(ParameterElement parameterElement, EventNotificationData data)
        {
            try
            {
                // Need to convert the string representation of the type to the actual
                // enum OdbcType.
                string[] odbcTypes     = Enum.GetNames(typeof(OdbcType));
                string   odbcTypeMatch = odbcTypes.First(t => t.Equals(parameterElement.DataType, StringComparison.InvariantCultureIgnoreCase));
                OdbcType odbcType      = (OdbcType)Enum.Parse(typeof(OdbcType), odbcTypeMatch);

                // Get property from the data using the property DisplayName (source)
                object value = HttpUtility.HtmlDecode(data.GetValueByDisplayName(parameterElement.Source));

                // Build return object.
                var parameter = new OdbcParameter
                {
                    ParameterName = parameterElement.Name,
                    OdbcType      = odbcType,
                    Size          = parameterElement.LengthAsInt,
                    Value         = value == null ? DBNull.Value : (string)value == string.Empty && odbcType == OdbcType.Int ? 0 : value
                };

                return(parameter);
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to parse parameter.", ex);
            }
        }
示例#3
0
        private string GetParameterValueById(Element element, ElementId paramId)
        {
            if (element == null)
            {
                return(string.Empty);
            }

            Parameter parameter = null;

            if (ParameterUtils.IsBuiltInParameter(paramId))
            {
                parameter = element.get_Parameter((BuiltInParameter)paramId.IntegerValue);
            }
            else
            {
                ParameterElement parameterElem = element.Document.GetElement(paramId) as ParameterElement;
                if (parameterElem == null)
                {
                    return(string.Empty);
                }
                parameter = element.get_Parameter(parameterElem.GetDefinition());
            }

            return(parameter?.AsValueString() ?? string.Empty);
        }
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static ParameterElement ToRevitParameterElement(this ParameterDefinition parameterDefinition, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (parameterDefinition == null)
            {
                return(null);
            }

            ParameterElement parameterElement = refObjects.GetValue <ParameterElement>(document, parameterDefinition.BHoM_Guid);

            if (parameterElement != null)
            {
                return(parameterElement);
            }

            settings = settings.DefaultIfNull();

            Definition definition = Create.Parameter(document, parameterDefinition.Name, parameterDefinition.ParameterType, parameterDefinition.ParameterGroup, parameterDefinition.Instance, parameterDefinition.Categories, parameterDefinition.Shared, parameterDefinition.Discipline);

            if (definition is ExternalDefinition)
            {
                parameterElement = SharedParameterElement.Lookup(document, ((ExternalDefinition)definition).GUID);
            }
            else if (definition is InternalDefinition)
            {
                parameterElement = document.GetElement(((InternalDefinition)definition).Id) as ParameterElement;
            }

            refObjects.AddOrReplace(parameterDefinition, parameterElement);
            return(parameterElement);
        }
        public System.Configuration.ConfigurationElement CreateFullClone()
        {
            ParameterElement target = new ParameterElement();
            ParameterElement clonedProperty = (ParameterElement)ConfigurationSectionCloner.CloneElement(paramToClone, target);
            clonedProperty.Value = paramToClone.Value;

            return clonedProperty;
        }
示例#6
0
        public System.Configuration.ConfigurationElement CreateFullClone()
        {
            ParameterElement target         = new ParameterElement();
            ParameterElement clonedProperty = (ParameterElement)ConfigurationSectionCloner.CloneElement(paramToClone, target);

            clonedProperty.Value = paramToClone.Value;

            return(clonedProperty);
        }
        protected override void Act()
        {
            var parameterValueProperty = base.ParameterElement.Property("Value");

            parameterValueProperty.Value = typeof(DependencyElement);

            var valueElementProperty = (ValueElementProperty)ParameterElement.Property("Value");

            dependencyParameterViewModel = valueElementProperty.ValueElementViewModel;
        }
        protected override void Act()
        {
            var parameterValueProperty = base.ParameterElement.Property("Value");

            parameterValueProperty.Value = typeof(OptionalElement);

            var valueElementProperty = (ValueElementProperty)ParameterElement.Property("Value");

            optionalParameterViewModel = valueElementProperty.ValueElementViewModel;
        }
示例#9
0
        internal static object[] BuildArgs(XElement element)
        {
            List <ParameterElement> parameters = new List <ParameterElement>();

            foreach (var e in element.Elements(ParametersName).Elements())
            {
                parameters.Add(ParameterElement.Read(e));
            }

            return(BuildArgs(parameters));
        }
        public void Then_DeserializingWithParametersAndValueChildrenThrows()
        {
            var elementXml = @"
                <param name=""connectionString"" value=""northwind2"">
                    <value value=""northwind"" />
                </param>";

            var reader  = new XmlTextReader(new StringReader(elementXml));
            var result  = reader.MoveToContent();
            var element = new ParameterElement();

            element.Deserialize(reader);
        }
        public object Build(ObjectBuilderContext context, View parent, dynamic metadata)
        {
            var dataBinding = new ParameterBinding(parent, metadata.Parameter, metadata.Property);

            ParameterElement dataSource = parent.GetParameter(metadata.Parameter);

            if (dataSource != null)
            {
                dataSource.AddDataBinding(dataBinding);
            }

            return(dataBinding);
        }
        public void Then_DeserializingWithParametersAndValueChildrenThrows()
        {
            var elementXml = @"
                <param name=""connectionString"" value=""northwind2"">
                    <value value=""northwind"" />
                </param>";

            var reader = new XmlTextReader(new StringReader(elementXml));
            var result = reader.MoveToContent();
            var element = new ParameterElement();

            element.Deserialize(reader);
        }
示例#13
0
        public void ParameterOptionTest()
        {
            ParameterElement target = new ParameterElement();

            ParameterOptions val = ParameterOptions.In; // TODO: Assign to an appropriate value for the property

            target.ParameterOption = val;


            Assert.AreEqual(val, target.ParameterOption, "Composestar.StarLight.Entities.LanguageModel.ParameterElement.ParameterOption was" +
                            " not set correctly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
示例#14
0
        public void OrdinalTest()
        {
            ParameterElement target = new ParameterElement();

            short val = 0; // TODO: Assign to an appropriate value for the property

            target.Ordinal = val;


            Assert.AreEqual(val, target.Ordinal, "Composestar.StarLight.Entities.LanguageModel.ParameterElement.Ordinal was not set" +
                            " correctly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
示例#15
0
        public void NameTest()
        {
            ParameterElement target = new ParameterElement();

            string val = null; // TODO: Assign to an appropriate value for the property

            target.Name = val;


            Assert.AreEqual(val, target.Name, "Composestar.StarLight.Entities.LanguageModel.ParameterElement.Name was not set co" +
                            "rrectly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
        public ApiGraph Build(IEnumerable <Type> controllerTypes)
        {
            var controllers = new List <ControllerElement>();

            foreach (var controllerType in controllerTypes)
            {
                var methods     = new List <MethodElement>();
                var methodInfos = controllerType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                foreach (var methodInfo in methodInfos)
                {
                    ParameterElement bodyParameter = null;
                    var urlParameters = new List <ParameterElement>();
                    var fullRoute     = GetFullRoute(controllerType, methodInfo);
                    var methodName    = methodInfo.Name.EndsWith("Async")
                        ? methodInfo.Name.Substring(0, methodInfo.Name.Length - 5)
                        : methodInfo.Name;

                    foreach (var parameter in methodInfo.GetParameters())
                    {
                        if (parameter.GetCustomAttribute <FromUriAttribute>() != null || RouteUtility.GetPlaceholders(parameter.Name).Any(fullRoute.Contains))
                        {
                            urlParameters.Add(new ParameterElement(parameter.Name, parameter.ParameterType, !parameter.HasDefaultValue));
                        }
                        else if (bodyParameter == null)
                        {
                            bodyParameter = new ParameterElement(parameter.Name, parameter.ParameterType, true);
                        }
                        else
                        {
                            throw new Exception("Multiple body parameters detected for " + methodInfo.Name);
                        }
                    }

                    methods.Add(new MethodElement(
                                    GetHttpMethod(methodInfo),
                                    methodName,
                                    fullRoute,
                                    urlParameters,
                                    bodyParameter,
                                    TryGetReturnType(controllerType, methodInfo)));
                }

                var controllerName = controllerType.Name.Substring(0, controllerType.Name.Length - ControllerSuffix.Length);
                controllers.Add(new ControllerElement(controllerName, methods));
            }

            return(new ApiGraph(controllers));
        }
示例#17
0
        public static RevitElem ModifyParameter(ParameterJSON paramJSON, RevitElem Elem)
        {
            RevitParam param = null;

            if (paramJSON.IsShared)
            {
                param = Elem.get_Parameter(new Guid(paramJSON.GUID));
            }
            else if (paramJSON.Id < 0)
            {
                param = Elem.get_Parameter((BuiltInParameter)paramJSON.Id);
            }
            else if (paramJSON.Id > 0)
            {
                revitDoc         doc       = Elem.Document;
                ParameterElement paramElem = (ParameterElement)doc.GetElement(new ElementId(paramJSON.Id));
                if (paramElem != null)
                {
                    Definition def = paramElem.GetDefinition();
                    param = Elem.get_Parameter(def);
                }
            }

            if (param != null && !param.IsReadOnly)
            {
                switch (paramJSON.StorageType)
                {
                case "Double":
                    param.Set(Convert.ToDouble(paramJSON.Value));
                    break;

                case "ElementId":
                    param.Set(new ElementId(Convert.ToInt32(paramJSON.Value)));
                    break;

                case "Integer":
                    param.Set(Convert.ToInt32(paramJSON.Value));
                    break;

                case "String":
                default:
                    param.Set(paramJSON.Value);
                    break;
                }
            }

            return(Elem);
        }
示例#18
0
        private List <MethodElement> GenerateMethods(int methodCount, int parameterCount)
        {
            List <MethodElement> result = new List <MethodElement>();

            for (int i = 0; i < methodCount; i++)
            {
                MethodElement me = new MethodElement();
                me.Name       = String.Format("Method_{0}", i);
                me.ReturnType = String.Format("ReturnTypeOfMethod_{0}", i);

                if (randomizer.Next(0, 2) == 0)
                {
                    me.IsPrivate = true;
                    me.IsPublic  = false;
                }
                else
                {
                    me.IsPrivate = false;
                    me.IsPublic  = true;
                }

                // Add parameters
                for (short k = 0; k < parameterCount; k++)
                {
                    ParameterElement pe = new ParameterElement();
                    pe.Ordinal = k;
                    pe.Name    = String.Format("Method_{0}-Parameter_{1}", i, k);
                    if (k % 3 == 0)
                    {
                        pe.Type = "System.String";
                    }
                    else if (k % 3 == 1)
                    {
                        pe.Type = "System.Boolean";
                    }
                    else
                    {
                        pe.Type = "System.Int32";
                    }

                    me.Parameters.Add(pe);
                }

                result.Add(me);
            }

            return(result);
        }
示例#19
0
        public static RevitElem ModifyParameter(SerialParameter serialParameter, RevitElem Elem)
        {
            RevitParam param = null;
            RevitDoc   doc   = Elem.Document;

            if (serialParameter.IsShared)
            {
                param = Elem.get_Parameter(new Guid(serialParameter.GUID));
            }
            else if (serialParameter.Id < 0)
            {
                param = Elem.get_Parameter((BuiltInParameter)serialParameter.Id);
            }
            else if (serialParameter.Id > 0)
            {
                ParameterElement paramElem = (ParameterElement)doc.GetElement(new ElementId(serialParameter.Id));
                if (paramElem != null)
                {
                    Definition def = paramElem.GetDefinition();
                    param = Elem.get_Parameter(def);
                }
            }

            if (param != null && !param.IsReadOnly)
            {
                switch (serialParameter.StorageType)
                {
                case "Double":
                    param.Set(Convert.ToDouble(serialParameter.Value));
                    break;

                case "ElementId":
                    SerialParameter._ModifyElementIdParameter(param, serialParameter.ValueElemId, doc);
                    break;

                case "Integer":
                    param.Set(Convert.ToInt32(serialParameter.Value));
                    break;

                case "String":
                default:
                    param.Set(serialParameter.Value);
                    break;
                }
            }

            return(Elem);
        }
        public void Then_CanDeserializeSingleInjectionValueChild()
        {
            var elementXml = @"
                <param name=""connectionString"">
                    <value value=""northwind"" />
                </param>";

            var reader  = new XmlTextReader(new StringReader(elementXml));
            var result  = reader.MoveToContent();
            var element = new ParameterElement();

            element.Deserialize(reader);

            Assert.AreSame(typeof(ValueElement), element.Value.GetType());
            Assert.AreEqual("northwind", ((ValueElement)element.Value).Value);
        }
        public void Then_CanDeserializeSingleInjectionValueChild()
        {
            var elementXml = @"
                <param name=""connectionString"">
                    <value value=""northwind"" />
                </param>";

            var reader = new XmlTextReader(new StringReader(elementXml));
            var result = reader.MoveToContent();
            var element = new ParameterElement();

            element.Deserialize(reader);

            Assert.AreSame(typeof(ValueElement), element.Value.GetType());
            Assert.AreEqual("northwind", ((ValueElement)element.Value).Value);
        }
示例#22
0
        public void GenerateLink(AttributeElement att, AttributesElement gridAtts)
        {
            // Process attributes that use links but don't have one already.
            if (att.Autolink && att.Link == null)
            {
                LevelElement levelToLink = FindLevelToLink(att,gridAtts);
                if (levelToLink != null)
                {
                    LinkElement link = new LinkElement();
                    att.Links.Add(link);
                    //link = new LinkElement();
                    link.Webpanel = levelToLink.View.ObjectName;
                    bool isTemCallBack = false;
                    if (gridAtts.Instance.Settings.Template.TabFunction == SettingsTemplateElement.TabFunctionValue.TreeViewAnchor)
                    {
                        link.Parameters.Add(new ParameterElement("TrnMode.Update"));
                    }
                    foreach (ParameterElement parameter in levelToLink.View.Parameters)
                    {
                        if (parameter.Name == "&" + HPatternInstance.PARMCALLBACK)
                        {
                            isTemCallBack = true;
                        }
                        link.Parameters.Add(parameter.Clone());
                    }
                    if (isTemCallBack == false && gridAtts.Instance.Settings.Template.GenerateCallBackLink)
                    {
                        ParameterElement parm = new ParameterElement("&" + HPatternInstance.PARMCALLBACK);
                        parm.Domain = Domain.Get(gridAtts.Instance.Model,HPatternInstance.PARMCALLBACK);
                        link.Parameters.Add(parm);
                    }
                    /*
                    bool isSuperTypeLink = (General.NodeName(attriNode) != levelToLink.Level.DescriptionAttribute);

                    // Avoid self-links.
                    if (IsAcceptableLink(filename, attriNode, levelToLink, isSuperTypeLink))
                    {
                        attriNode.Attributes["link"].Value = ExtractLinkName(levelToLink.Filename);
                        attriNode.Attributes["level"].Value = levelToLink.Level.Name;

                        if (isSuperTypeLink)
                            AddSupertypeLinkParams(attriNode, levelToLink);
                    }
                    */
                }
            }
        }
示例#23
0
        public static bool TryGetElementBinding(this Document document, string name, out InternalDefinition internalDefinition, out ElementBinding elementBinding)
        {
            internalDefinition = null;
            elementBinding     = null;

            if (document == null || document.ParameterBindings == null || string.IsNullOrEmpty(name))
            {
                return(false);
            }

            DefinitionBindingMapIterator definitionBindingMapIterator = document.ParameterBindings.ForwardIterator();

            if (definitionBindingMapIterator == null)
            {
                return(false);
            }

            while (definitionBindingMapIterator.MoveNext())
            {
                InternalDefinition aInternalDefinition_Temp = definitionBindingMapIterator.Key as InternalDefinition;
                if (aInternalDefinition_Temp == null)
                {
                    continue;
                }

                ElementId elementId = aInternalDefinition_Temp.Id;
                if (elementId == null || elementId == Autodesk.Revit.DB.ElementId.InvalidElementId)
                {
                    continue;
                }

                ParameterElement parameterElement = document.GetElement(elementId) as ParameterElement;
                if (parameterElement == null)
                {
                    continue;
                }

                if (name == parameterElement.Name)
                {
                    elementBinding     = (ElementBinding)definitionBindingMapIterator.Current;
                    internalDefinition = aInternalDefinition_Temp;
                    return(true);
                }
            }
            return(false);
        }
示例#24
0
        public void Then_DeserializingMultipleInjectionValueChildrenThrows()
        {
            var elementXml = @"
                <param name=""connectionString"">
                    <value value=""northwind"" />
                    <value value=""northwind"" />
                </param>";

            var reader  = new XmlTextReader(new StringReader(elementXml));
            var result  = reader.MoveToContent();
            var element = new ParameterElement();

            AssertExtensions.AssertException <ConfigurationErrorsException>(() =>
            {
                element.Deserialize(reader);
            });
        }
        public void Then_DeserializingMultipleInjectionValueChildrenThrows()
        {
            var elementXml = @"
                <param name=""connectionString"">
                    <value value=""northwind"" />
                    <value value=""northwind"" />
                </param>";

            var reader = new XmlTextReader(new StringReader(elementXml));
            var result = reader.MoveToContent();
            var element = new ParameterElement();

            AssertExtensions.AssertException<ConfigurationErrorsException>(() =>
                {
                    element.Deserialize(reader);
                });
        }
示例#26
0
        private static void BindParameters(ObjectBuilderContext context, View parentView, View childView,
                                           dynamic parameters)
        {
            if (parameters != null)
            {
                foreach (var parameterLink in parameters)
                {
                    ParameterElement parameter = childView.GetParameter(parameterLink.Name);

                    if (parameter != null)
                    {
                        IElementDataBinding parameterValueBinding = context.Build(parentView, parameterLink.Value);

                        if (parameterValueBinding != null)
                        {
                            parameterValueBinding.OnPropertyValueChanged += (c, a) => parameter.SetValue(a.Value);
                            parameter.OnValueChanged += (c, a) => parameterValueBinding.SetPropertyValue(a.Value);
                        }
                    }
                }
            }
        }
示例#27
0
 internal static Type GetType(this ParameterElement parameterElement, string rootType, Type[] typeArgs)
 {
     return(TypeElementExtensionMethods.GetType(rootType, typeArgs, parameterElement.Type, parameterElement.Index, parameterElement.Parameters));
 }
 protected override void Because()
 {
     _parameterElement = sut.MapFrom(_booleanParameter);
 }
示例#29
0
        /// <summary>
        /// Generate HTML documentation for all the tasks
        /// </summary>
        /// <param name="NameToTask">Map of task name to implementation</param>
        /// <param name="OutputFile">Output file</param>
        static void GenerateDocumentation(Dictionary <string, ScriptTask> NameToTask, FileReference OutputFile)
        {
            // Find all the assemblies containing tasks
            Assembly[] TaskAssemblies = NameToTask.Values.Select(x => x.ParametersClass.Assembly).Distinct().ToArray();

            // Read documentation for each of them
            Dictionary <string, XmlElement> MemberNameToElement = new Dictionary <string, XmlElement>();

            foreach (Assembly TaskAssembly in TaskAssemblies)
            {
                string XmlFileName = Path.ChangeExtension(TaskAssembly.Location, ".xml");
                if (File.Exists(XmlFileName))
                {
                    // Read the document
                    XmlDocument Document = new XmlDocument();
                    Document.Load(XmlFileName);

                    // Parse all the members, and add them to the map
                    foreach (XmlElement Element in Document.SelectNodes("/doc/members/member"))
                    {
                        string Name = Element.GetAttribute("name");
                        MemberNameToElement.Add(Name, Element);
                    }
                }
            }

            // Create the output directory
            DirectoryReference.CreateDirectory(OutputFile.Directory);
            FileReference.MakeWriteable(OutputFile);
            Log("Writing {0}...", OutputFile);

            // Parse the engine version
            BuildVersion Version;

            if (!BuildVersion.TryRead(BuildVersion.GetDefaultFileName(), out Version))
            {
                throw new AutomationException("Couldn't read Build.version");
            }

            // Write the output file
            using (StreamWriter Writer = new StreamWriter(OutputFile.FullName))
            {
                Writer.WriteLine("Availability: NoPublish");
                Writer.WriteLine("Title: BuildGraph Predefined Tasks");
                Writer.WriteLine("Crumbs: %ROOT%, Programming, Programming/Development, Programming/Development/BuildGraph, Programming/Development/BuildGraph/BuildGraphScriptTasks");
                Writer.WriteLine("Description: This is a procedurally generated markdown page.");
                Writer.WriteLine("version: {0}.{1}", Version.MajorVersion, Version.MinorVersion);
                Writer.WriteLine("parent:Programming/Development/BuildGraph/BuildGraphScriptTasks");
                Writer.WriteLine();
                foreach (string TaskName in NameToTask.Keys.OrderBy(x => x))
                {
                    // Get the task object
                    ScriptTask Task = NameToTask[TaskName];

                    // Get the documentation for this task
                    XmlElement TaskElement;
                    if (MemberNameToElement.TryGetValue("T:" + Task.TaskClass.FullName, out TaskElement))
                    {
                        // Write the task heading
                        Writer.WriteLine("### {0}", TaskName);
                        Writer.WriteLine();
                        Writer.WriteLine(ConvertToMarkdown(TaskElement.SelectSingleNode("summary")));
                        Writer.WriteLine();

                        // Document the parameters
                        List <string[]> Rows = new List <string[]>();
                        foreach (string ParameterName in Task.NameToParameter.Keys)
                        {
                            // Get the parameter data
                            ScriptTaskParameter Parameter = Task.NameToParameter[ParameterName];

                            // Get the documentation for this parameter
                            XmlElement ParameterElement;
                            if (MemberNameToElement.TryGetValue("F:" + Parameter.FieldInfo.DeclaringType.FullName + "." + Parameter.Name, out ParameterElement))
                            {
                                string TypeName = Parameter.FieldInfo.FieldType.Name;
                                if (Parameter.ValidationType != TaskParameterValidationType.Default)
                                {
                                    StringBuilder NewTypeName = new StringBuilder(Parameter.ValidationType.ToString());
                                    for (int Idx = 1; Idx < NewTypeName.Length; Idx++)
                                    {
                                        if (Char.IsLower(NewTypeName[Idx - 1]) && Char.IsUpper(NewTypeName[Idx]))
                                        {
                                            NewTypeName.Insert(Idx, ' ');
                                        }
                                    }
                                    TypeName = NewTypeName.ToString();
                                }

                                string[] Columns = new string[4];
                                Columns[0] = ParameterName;
                                Columns[1] = TypeName;
                                Columns[2] = Parameter.bOptional? "Optional" : "Required";
                                Columns[3] = ConvertToMarkdown(ParameterElement.SelectSingleNode("summary"));
                                Rows.Add(Columns);
                            }
                        }

                        // Always include the "If" attribute
                        string[] IfColumns = new string[4];
                        IfColumns[0] = "If";
                        IfColumns[1] = "Condition";
                        IfColumns[2] = "Optional";
                        IfColumns[3] = "Whether to execute this task. It is ignored if this condition evaluates to false.";
                        Rows.Add(IfColumns);

                        // Get the width of each column
                        int[] Widths = new int[4];
                        for (int Idx = 0; Idx < 4; Idx++)
                        {
                            Widths[Idx] = Rows.Max(x => x[Idx].Length);
                        }

                        // Format the markdown table
                        string Format = String.Format("| {{0,-{0}}} | {{1,-{1}}} | {{2,-{2}}} | {{3,-{3}}} |", Widths[0], Widths[1], Widths[2], Widths[3]);
                        Writer.WriteLine(Format, "", "", "", "");
                        Writer.WriteLine(Format, new string('-', Widths[0]), new string('-', Widths[1]), new string('-', Widths[2]), new string('-', Widths[3]));
                        for (int Idx = 0; Idx < Rows.Count; Idx++)
                        {
                            Writer.WriteLine(Format, Rows[Idx][0], Rows[Idx][1], Rows[Idx][2], Rows[Idx][3]);
                        }

                        // Blank line before next task
                        Writer.WriteLine();
                    }
                }
            }
        }
示例#30
0
        /// <summary>
        /// Generate HTML documentation for all the tasks
        /// </summary>
        /// <param name="NameToTask">Map of task name to implementation</param>
        /// <param name="OutputFile">Output file</param>
        static void GenerateDocumentation(Dictionary <string, ScriptTask> NameToTask, FileReference OutputFile)
        {
            // Find all the assemblies containing tasks
            Assembly[] TaskAssemblies = NameToTask.Values.Select(x => x.ParametersClass.Assembly).Distinct().ToArray();

            // Read documentation for each of them
            Dictionary <string, XmlElement> MemberNameToElement = new Dictionary <string, XmlElement>();

            foreach (Assembly TaskAssembly in TaskAssemblies)
            {
                string XmlFileName = Path.ChangeExtension(TaskAssembly.Location, ".xml");
                if (File.Exists(XmlFileName))
                {
                    // Read the document
                    XmlDocument Document = new XmlDocument();
                    Document.Load(XmlFileName);

                    // Parse all the members, and add them to the map
                    foreach (XmlElement Element in Document.SelectNodes("/doc/members/member"))
                    {
                        string Name = Element.GetAttribute("name");
                        MemberNameToElement.Add(Name, Element);
                    }
                }
            }

            // Create the output directory
            if (FileReference.Exists(OutputFile))
            {
                FileReference.MakeWriteable(OutputFile);
            }
            else
            {
                DirectoryReference.CreateDirectory(OutputFile.Directory);
            }

            // Write the output file
            LogInformation("Writing {0}...", OutputFile);
            using (StreamWriter Writer = new StreamWriter(OutputFile.FullName))
            {
                Writer.WriteLine("<html>");
                Writer.WriteLine("  <head>");
                Writer.WriteLine("    <style>");
                Writer.WriteLine("      table { border-collapse: collapse }");
                Writer.WriteLine("      table, th, td { border: 1px solid black; }");
                Writer.WriteLine("    </style>");
                Writer.WriteLine("  </head>");
                Writer.WriteLine("  <body>");
                Writer.WriteLine("    <h1>BuildGraph Tasks</h1>");
                foreach (string TaskName in NameToTask.Keys.OrderBy(x => x))
                {
                    // Get the task object
                    ScriptTask Task = NameToTask[TaskName];

                    // Get the documentation for this task
                    XmlElement TaskElement;
                    if (MemberNameToElement.TryGetValue("T:" + Task.TaskClass.FullName, out TaskElement))
                    {
                        // Write the task heading
                        Writer.WriteLine("    <h2>{0}</h2>", TaskName);
                        Writer.WriteLine("    <p>{0}</p>", TaskElement.SelectSingleNode("summary").InnerXml.Trim());

                        // Start the parameter table
                        Writer.WriteLine("    <table>");
                        Writer.WriteLine("      <tr>");
                        Writer.WriteLine("        <th>Attribute</th>");
                        Writer.WriteLine("        <th>Type</th>");
                        Writer.WriteLine("        <th>Usage</th>");
                        Writer.WriteLine("        <th>Description</th>");
                        Writer.WriteLine("      </tr>");

                        // Document the parameters
                        foreach (string ParameterName in Task.NameToParameter.Keys)
                        {
                            // Get the parameter data
                            ScriptTaskParameter Parameter = Task.NameToParameter[ParameterName];

                            // Get the documentation for this parameter
                            XmlElement ParameterElement;
                            if (MemberNameToElement.TryGetValue("F:" + Parameter.FieldInfo.DeclaringType.FullName + "." + Parameter.Name, out ParameterElement))
                            {
                                string TypeName = Parameter.FieldInfo.FieldType.Name;
                                if (Parameter.ValidationType != TaskParameterValidationType.Default)
                                {
                                    StringBuilder NewTypeName = new StringBuilder(Parameter.ValidationType.ToString());
                                    for (int Idx = 1; Idx < NewTypeName.Length; Idx++)
                                    {
                                        if (Char.IsLower(NewTypeName[Idx - 1]) && Char.IsUpper(NewTypeName[Idx]))
                                        {
                                            NewTypeName.Insert(Idx, ' ');
                                        }
                                    }
                                    TypeName = NewTypeName.ToString();
                                }

                                Writer.WriteLine("      <tr>");
                                Writer.WriteLine("         <td>{0}</td>", ParameterName);
                                Writer.WriteLine("         <td>{0}</td>", TypeName);
                                Writer.WriteLine("         <td>{0}</td>", Parameter.bOptional? "Optional" : "Required");
                                Writer.WriteLine("         <td>{0}</td>", ParameterElement.SelectSingleNode("summary").InnerXml.Trim());
                                Writer.WriteLine("      </tr>");
                            }
                        }

                        // Always include the "If" attribute
                        Writer.WriteLine("     <tr>");
                        Writer.WriteLine("       <td>If</td>");
                        Writer.WriteLine("       <td>Condition</td>");
                        Writer.WriteLine("       <td>Optional</td>");
                        Writer.WriteLine("       <td>Whether to execute this task. It is ignored if this condition evaluates to false.</td>");
                        Writer.WriteLine("     </tr>");

                        // Close the table
                        Writer.WriteLine("    <table>");
                    }
                }
                Writer.WriteLine("  </body>");
                Writer.WriteLine("</html>");
            }
        }
示例#31
0
        public override void VisitMethodDefinition(MethodDefinition method)
        {
            // If we only extract the unresolvedtypes then we most likely are only interested
            // in methods which can be overriden. So skip the rest.
            if (ExtractUnresolvedOnly && !method.IsVirtual)
            {
                return;
            }

            // Create a new method element
            MethodElement me = new MethodElement();

            me.Name          = method.Name;
            me.ReturnType    = method.ReturnType.ReturnType.FullName;
            me.IsAbstract    = method.IsAbstract;
            me.IsConstructor = method.IsConstructor;
            me.IsStatic      = method.IsStatic;
            me.IsVirtual     = method.IsVirtual;

            MethodAttributes memberAccess = method.Attributes & MethodAttributes.MemberAccessMask;

            me.IsPrivate = memberAccess == MethodAttributes.Private;
            me.IsPublic  = memberAccess == MethodAttributes.Public;

            // Add the parameters
            foreach (ParameterDefinition param in method.Parameters)
            {
                ParameterElement pe = new ParameterElement();

                pe.Name    = param.Name;
                pe.Ordinal = (short)(param.Sequence);
                pe.Type    = param.ParameterType.FullName;

                if ((param.Attributes & Mono.Cecil.ParameterAttributes.Out) != Mono.Cecil.ParameterAttributes.Out)
                {
                    pe.ParameterOption |= ParameterOptions.In;
                }
                else
                {
                    pe.ParameterOption &= ~ParameterOptions.In;
                }

                if ((param.Attributes & Mono.Cecil.ParameterAttributes.Out) == Mono.Cecil.ParameterAttributes.Out)
                {
                    pe.ParameterOption |= ParameterOptions.Out;
                }

                if ((param.Attributes & Mono.Cecil.ParameterAttributes.Optional) == Mono.Cecil.ParameterAttributes.Optional)
                {
                    pe.ParameterOption |= ParameterOptions.Optional;
                }

                // Remark; we do not harvest custom attributes here.

                me.Parameters.Add(pe);
            }

            // Add the method body
            if (ProcessMethodBody && method.HasBody)
            {
                me.Body = new Entities.LanguageModel.MethodBody();

                List <string> callList = new List <string>();

                foreach (Instruction instr in method.Body.Instructions)
                {
                    if (instr.OpCode.Value == OpCodes.Call.Value ||
                        instr.OpCode.Value == OpCodes.Calli.Value ||
                        instr.OpCode.Value == OpCodes.Callvirt.Value
                        )
                    {
                        CallElement ce = new CallElement();

                        // instr.Operand can be a MethodReference or a CallSite
                        ce.MethodReference = instr.Operand.ToString();

                        if (!callList.Contains(ce.MethodReference))
                        {
                            me.Body.Calls.Add(ce);
                            callList.Add(ce.MethodReference);
                        }
                    }
                }
            }

            // Custom attributes
            me.Attributes.AddRange(ExtractCustomAttributes(method.CustomAttributes));

            // Set the signature
            string declaringTypeName = method.DeclaringType.FullName;

            me.Signature = MethodElement.GenerateSignature(declaringTypeName, me);

            // Add to the type
            _currentType.Methods.Add(me);
        }
        public void then_underlying_element_is_value_element()
        {
            ParameterElement paramElement = base.ParameterElement.ConfigurationElement as ParameterElement;

            Assert.IsInstanceOfType(paramElement.Value, typeof(ValueElement));
        }
示例#33
0
        public void then_parameter_configuration_element_has_dependency_value_element()
        {
            ParameterElement parameter = (ParameterElement)base.ParameterElement.ConfigurationElement;

            Assert.IsInstanceOfType(parameter.Value, typeof(DependencyElement));
        }
示例#34
0
        private void Stream( ArrayList data, ParameterElement paramElem )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( ParameterElement ) ) );

              data.Add( new Snoop.Data.Object( "Definition", paramElem.GetDefinition() ) );

              SharedParameterElement sharedParamElem = paramElem as SharedParameterElement;
              if( sharedParamElem != null )
              {
            Stream( data, sharedParamElem );
            return;
              }
        }
示例#35
0
 public ParameterElementCloneable(ParameterElement paramToClone)
 {
     this.paramToClone = paramToClone;
 }
示例#36
0
        /* ----------------------------------------------------------------- */
        ///
        /// LoadValues
        ///
        /// <summary>
        /// レジストリからデータをロードする.レジストリは,階層構造を
        /// 持つ場合,Subkeys と Values に分かれるため,Values の部分
        /// のみを処理する.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void LoadValues(RegistryKey root, ParameterCollection dest)
        {
            foreach (string name in root.GetValueNames()) {
                if (dest.Contains(name)) continue;

                var item = new ParameterElement();
                item.Key = name;

                var kind = root.GetValueKind(name);
                if (kind == Microsoft.Win32.RegistryValueKind.String) {
                    item.Type = ParameterType.String;
                    item.Value = root.GetValue(name, "");
                }
                else if (kind == Microsoft.Win32.RegistryValueKind.DWord) {
                    item.Type = ParameterType.Integer;
                    item.Value = root.GetValue(name, 0);
                }
                else {
                    throw new NotSupportedException(kind.ToString());
                }

                dest.Add(item);
            }
        }
示例#37
0
        /* ----------------------------------------------------------------- */
        /// LoadValue
        /* ----------------------------------------------------------------- */
        private void LoadValue(XmlElement root, ParameterCollection dest)
        {
            var item = new ParameterElement();
            item.Key = root.Name;

            var attr = root.GetAttribute("type");
            if (attr == ParameterType.String.ToString()) item.Type = ParameterType.String;
            else if (attr == ParameterType.Integer.ToString()) item.Type = ParameterType.Integer;
            else return;

            if (item.Type == ParameterType.Unknown) return;
            if (item.Type == ParameterType.String) item.Value = root.InnerText;
            else if (item.Type == ParameterType.Integer) item.Value = Int32.Parse(root.InnerText);

            dest.Add(item);
        }
        public void then_underlying_configuration_property_has_array_element()
        {
            ParameterElement parameter = arrayParameterViewModel.ParentElement.ConfigurationElement as ParameterElement;

            Assert.IsInstanceOfType(parameter.Value, typeof(ArrayElement));
        }
 public ParameterElementCloneable(ParameterElement paramToClone)
 {
     this.paramToClone = paramToClone;
 }