/// <summary>
        ///   Parses the specified notification element.
        /// </summary>
        /// <param name = "notificationElement">The notification element.</param>
        /// <returns></returns>
        public ConstantEntity Parse(TypedEntity typedEntity, XElement notificationElement)
        {
            ConstantEntity notificationEntity = new ConstantEntity();
            notificationEntity.Type = "NSString";

            // Get the name
            notificationEntity.Name = notificationElement.TrimAll();

            this.Logger.WriteLine("  Notification '" + notificationEntity.Name + "'");

            // Get the content and the discussion
            XElement summaryElement = (from el in notificationElement.ElementsAfterSelf("section")
                                       where (String) el.Attribute("class") == "spaceabove"
                                       select el).FirstOrDefault();
            if (summaryElement != null)
            {
                foreach (XElement element in summaryElement.Elements())
                {
                    notificationEntity.Summary.Add(element.Value.TrimAll());
                }
            }

            // Get the availability
            String minAvailability = (from el in notificationElement.ElementsAfterSelf("div").Elements("ul").Elements("li")
                                      where (String) el.Parent.Parent.Attribute("class") == "api availability"
                                      select el.Value).FirstOrDefault();
            notificationEntity.MinAvailability = CommentHelper.ExtractAvailability(minAvailability.TrimAll());

            return notificationEntity;
        }
Example #2
0
        protected void btnAddConstant_Click(object sender, EventArgs e)
        {
            int index = KPI_ConstantDal.ConstantIDCounts();

            string sID = PageControl.GetGuid();

            ConstantEntity ote = new ConstantEntity();

            ote.ConstantID    = sID;
            ote.ConstantCode  = "InputCode";
            ote.ConstantName  = "Input Name";
            ote.ConstantDesc  = "";
            ote.ConstantValue = "Input Value";
            ote.ConstantNote  = "";

            ote.ConstantCreateTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
            ote.ConstantModifyTime = ote.ConstantCreateTime;

            if (KPI_ConstantDal.Insert(ote))
            {
                //MessageBox.popupClientMessage(this.Page, "添加成功!", "call();");

                gvConstant.EditIndex = index;

                BindConstant();
            }
            else
            {
                MessageBox.popupClientMessage(this.Page, "添加错误!", "call();");
            }
        }
        /// <summary>
        ///   Generates the specified entity.
        /// </summary>
        /// <param name = "framework">The framework.</param>
        /// <param name = "entity">The entity.</param>
        public void Generate(TypedEntity typedEntity, ConstantEntity entity)
        {
            // Don't generate if required
            if (!entity.Generate) {
                return;
            }

            // Append static condition if needed
            this.AppendStartCondition(entity);

            // Append property comments
            this.Writer.WriteLineFormat (2, "/// <summary>");
            foreach (String line in entity.Summary) {
                this.Writer.WriteLineFormat (2, "/// <para>{0}</para>", line.EscapeAll ());
            }
            this.AppendAvailability (2, entity);
            this.Writer.WriteLineFormat (2, "/// </summary>");

            if (entity.Static) {
                // Print the static constant
                this.Writer.WriteLineFormat (2, "public static readonly {0} {1} = {2};", entity.Type, entity.Name, entity.Value);
            } else {
                // Print the extern constant
                this.Writer.WriteLineFormat (2, "public static readonly {0} {2} = ObjectiveCRuntime.GetExtern<{0}>(\"{1}\", \"{2}\");", entity.Type, typedEntity.Namespace, entity.Name);
            }

            // Append static condition if needed
            this.AppendEndCondition(entity);

            // Update statistics
            this.Statistics.Constants++;
        }
Example #4
0
        /// <summary>
        ///   Parses the specified notification element.
        /// </summary>
        /// <param name = "notificationElement">The notification element.</param>
        /// <returns></returns>
        public ConstantEntity Parse(TypedEntity typedEntity, XElement notificationElement)
        {
            ConstantEntity notificationEntity = new ConstantEntity();

            notificationEntity.Type = "NSString";

            // Get the name
            notificationEntity.Name = notificationElement.TrimAll();

            this.Logger.WriteLine("  Notification '" + notificationEntity.Name + "'");

            // Get the content and the discussion
            XElement summaryElement = (from el in notificationElement.ElementsAfterSelf("section")
                                       where (String)el.Attribute("class") == "spaceabove"
                                       select el).FirstOrDefault();

            if (summaryElement != null)
            {
                foreach (XElement element in summaryElement.Elements())
                {
                    notificationEntity.Summary.Add(element.Value.TrimAll());
                }
            }

            // Get the availability
            String minAvailability = (from el in notificationElement.ElementsAfterSelf("div").Elements("ul").Elements("li")
                                      where (String)el.Parent.Parent.Attribute("class") == "api availability"
                                      select el.Value).FirstOrDefault();

            notificationEntity.MinAvailability = CommentHelper.ExtractAvailability(minAvailability.TrimAll());

            return(notificationEntity);
        }
Example #5
0
        private void DeleteInputTagCategory(HttpContext context)
        {
            KPI_ConstantDal DataAccess = new KPI_ConstantDal();
            HttpRequest     Request    = context.Request;
            HttpResponse    Response   = context.Response;
            Msg             msg;

            try {
                ConstantEntity Constant = new ConstantEntity {
                    ConstantID    = Request.Params["ConstantID"],
                    ConstantCode  = "M",
                    ConstantName  = Request.Params["ConstantName"],
                    ConstantValue = Request.Params["ConstantValue"]
                };
                DataAccess.DeleteConstant(Constant);
                msg = new Msg {
                    Status  = "ok",
                    Message = "数据删除成功!"
                };
            }
            catch (Exception ex) {
                msg = new Msg {
                    Status     = "error",
                    Message    = "数据删除失败!错误信息:" + ex.Message,
                    StackTrace = ex.StackTrace
                };
            }
            Response.Write(JsonConvert.SerializeObject(msg));
        }
        static bool HandleVariable(GraphBuilder builder, out INode node,
                                   out Dictionary <string, uint> portToOffsetMapping, out uint?preAllocatedDataIndex, IVariableModel variableModel)
        {
            if (variableModel.DeclarationModel.IsInputOrOutputTrigger())
            {
                preAllocatedDataIndex = null;
                portToOffsetMapping   = new Dictionary <string, uint>();
                if (variableModel.DeclarationModel.Modifiers == ModifierFlags.ReadOnly) // Input
                {
                    var trigger = builder.DeclareInputTrigger(variableModel.DeclarationModel.VariableName);
                    node = MapPort(portToOffsetMapping, variableModel.OutputPort.UniqueId, ref trigger.Output.Port, trigger);
                }
                else
                {
                    var trigger = builder.DeclareOutputTrigger(variableModel.DeclarationModel.VariableName);
                    node = MapPort(portToOffsetMapping, variableModel.OutputPort.UniqueId, ref trigger.Input.Port, trigger);
                }
                return(true);
            }

            var valueType = variableModel.DeclarationModel.DataType.TypeHandleToValueType();

            Assert.AreEqual(VariableType.GraphVariable, variableModel.DeclarationModel.VariableType);
            var type = GraphBuilder.GetVariableType(variableModel.DeclarationModel);

            switch (type)
            {
            case GraphBuilder.VariableType.ObjectReference:
                switch (valueType)
                {
                case ValueType.Entity:
                    preAllocatedDataIndex = builder.GetVariableDataIndex(variableModel.DeclarationModel).DataIndex;
                    portToOffsetMapping   = new Dictionary <string, uint>();
                    var cf = new ConstantEntity();
                    node = MapPort(portToOffsetMapping, variableModel.OutputPort.UniqueId, ref cf.ValuePort.Port, cf);
                    return(true);
                }
                break;

            case GraphBuilder.VariableType.Variable:     // Data
                // Just create an edge later
                node = default;
                portToOffsetMapping   = null;
                preAllocatedDataIndex = null;
                return(false);

            case GraphBuilder.VariableType.InputOutput:
                Assert.IsFalse(variableModel.DeclarationModel.IsDataOutput());     // TODO check legit
                portToOffsetMapping   = new Dictionary <string, uint>();
                preAllocatedDataIndex = null;
                var inputData = builder.DeclareInputData(variableModel.DeclarationModel.VariableName, variableModel.DeclarationModel.DataType.TypeHandleToValueType());
                node = MapPort(portToOffsetMapping, variableModel.OutputPort.UniqueId, ref inputData.Output.Port, inputData);
                return(true);

            default:
                throw new ArgumentOutOfRangeException("Variable type not supported: " + type);
            }

            throw new ArgumentOutOfRangeException(valueType.ToString());
        }
Example #7
0
        public ConstantEntity Parse(TypedEntity typedEntity, XElement constantElement)
        {
            ConstantEntity constantEntity = new ConstantEntity();

            String kind = constantElement.Attribute("kind").Value;

            constantEntity.Name = constantElement.Element("name").TrimAll();

            // Elements for brief description
            IEnumerable <XElement> abstractElements = constantElement.Element("briefdescription").Elements("para");

            // Extract for detailed description
            IEnumerable <XElement> detailsElements = (from el in constantElement.Element("detaileddescription").Elements("para")
                                                      where !el.Elements("simplesect").Any() &&
                                                      el.Elements("parameterlist").Any() &&
                                                      el.Elements("xrefsect").Any()
                                                      select el);

            // Add brief description
            foreach (XElement paragraph in abstractElements)
            {
                constantEntity.Summary.Add(paragraph.TrimAll());
            }
            foreach (XElement paragraph in detailsElements)
            {
                constantEntity.Summary.Add(paragraph.TrimAll());
            }

            switch (kind)
            {
            case "define":
            {
                constantEntity.Type   = "MISSING";
                constantEntity.Static = true;
                constantEntity.Value  = constantElement.Element("initializer").TrimAll();
            }
            break;

            case "variable":
            {
                String type = constantElement.Element("type").TrimAll();
                type = type.Replace("const", String.Empty).Trim();

                bool isOut, isByRef, isBlock;
                constantEntity.Type = this.TypeManager.ConvertType(type, out isOut, out isByRef, out isBlock, this.Logger);
            }
            break;
            }

            /*
             * // Get the availability
             * if (availabilityElement != null)
             * {
             * constantEntity.MinAvailability = CommentHelper.ExtractAvailability(availabilityElement.TrimAll());
             * }
             */

            return(constantEntity);
        }
        public ConstantEntity Parse(TypedEntity typedEntity, XElement constantElement)
        {
            ConstantEntity constantEntity = new ConstantEntity ();

            String kind = constantElement.Attribute ("kind").Value;
            constantEntity.Name = constantElement.Element ("name").TrimAll ();

            // Elements for brief description
            IEnumerable<XElement> abstractElements = constantElement.Element ("briefdescription").Elements ("para");

            // Extract for detailed description
            IEnumerable<XElement> detailsElements = (from el in constantElement.Element ("detaileddescription").Elements ("para")
                                                     where !el.Elements ("simplesect").Any ()
                && el.Elements ("parameterlist").Any ()
                && el.Elements ("xrefsect").Any ()
                                                     select el);

            // Add brief description
            foreach (XElement paragraph in abstractElements) {
                constantEntity.Summary.Add (paragraph.TrimAll ());
            }
            foreach (XElement paragraph in detailsElements) {
                constantEntity.Summary.Add (paragraph.TrimAll ());
            }

            switch (kind) {
            case "define":
                {
                    constantEntity.Type = "MISSING";
                    constantEntity.Static = true;
                    constantEntity.Value = constantElement.Element ("initializer").TrimAll ();
                }
                break;
            case "variable":
                {
                    String type = constantElement.Element ("type").TrimAll ();
                    type = type.Replace ("const", String.Empty).Trim ();

                    bool isOut, isByRef, isBlock;
                    constantEntity.Type = this.TypeManager.ConvertType (type, out isOut, out isByRef, out isBlock, this.Logger);
                }
                break;
            }

            /*
            // Get the availability
            if (availabilityElement != null)
            {
                constantEntity.MinAvailability = CommentHelper.ExtractAvailability(availabilityElement.TrimAll());
            }
             */

            return constantEntity;
        }
Example #9
0
        protected void ExtractNotifications(TypedEntity typedEntity, XElement root)
        {
            IEnumerable <XElement> notificationElements = from el in root.Descendants("h3")
                                                          where (String)el.Attribute("class") == "tight jump notification"
                                                          select el;

            foreach (XElement notificationElement in notificationElements)
            {
                ConstantEntity notificationEntity = this.NotificationParser.Parse(typedEntity, notificationElement);
                typedEntity.Constants.Add(notificationEntity);
            }
        }
        static bool HandleVariable(GraphBuilder builder, out INode node,
                                   out PortMapper portToOffsetMapping, out uint?preAllocatedDataIndex, IVariableModel variableModel)
        {
            if (variableModel.DeclarationModel.IsInputOrOutputTrigger())
            {
                preAllocatedDataIndex = null;
                portToOffsetMapping   = new PortMapper();
                if (variableModel.DeclarationModel.Modifiers == ModifierFlags.ReadOnly) // Input
                {
                    var trigger = builder.DeclareInputTrigger(variableModel.DeclarationModel.VariableName);
                    node = MapPort(portToOffsetMapping, variableModel.OutputPort, ref trigger.Output.Port, trigger);
                }
                else
                {
                    var trigger = builder.DeclareOutputTrigger(variableModel.DeclarationModel.VariableName);
                    node = MapPort(portToOffsetMapping, variableModel.OutputPort, ref trigger.Input.Port, trigger);
                }
                return(true);
            }

            var valueType = variableModel.DeclarationModel.DataType.ToValueType();
            var type      = GraphBuilder.GetVariableType(variableModel.DeclarationModel);

            switch (type)
            {
            case GraphBuilder.VariableType.ObjectReference:
                switch (valueType)
                {
                case ValueType.Entity:
                    preAllocatedDataIndex = builder.GetVariableDataIndex(variableModel.DeclarationModel).DataIndex;
                    portToOffsetMapping   = new PortMapper();
                    var cf = new ConstantEntity();
                    node = MapPort(portToOffsetMapping, variableModel.OutputPort, ref cf.ValuePort.Port, cf);
                    return(true);
                }
                break;

            case GraphBuilder.VariableType.Variable:     // Data
                throw new NotImplementedException();

            case GraphBuilder.VariableType.InputOutput:
                // Just create an edge later
                node = default;
                portToOffsetMapping   = null;
                preAllocatedDataIndex = null;
                return(false);

            default:
                throw new ArgumentOutOfRangeException("Variable type not supported: " + type);
            }

            throw new ArgumentOutOfRangeException(valueType.ToString());
        }
Example #11
0
        /// <summary>
        ///   Extracts the constants.
        /// </summary>
        /// <param name = "typedEntity">The typed entity.</param>
        /// <param name = "root">The root element.</param>
        protected void ExtractConstants(TypedEntity typedEntity, XElement root)
        {
            IEnumerable <XElement> memberDefs = (from el in root.Descendants("memberdef")
                                                 where el.Attribute("kind").Value == "variable" ||
                                                 el.Attribute("kind").Value == "define"
                                                 select el);

            foreach (XElement memberDef in memberDefs)
            {
                ConstantEntity constantEntity = this.ConstantParser.Parse(typedEntity, memberDef);
                typedEntity.Constants.Add(constantEntity);
            }
        }
Example #12
0
        private ConstantEntity ExtractConstant(FieldDeclaration fieldDeclaration)
        {
            ConstantEntity constantEntity = new ConstantEntity();

            constantEntity.Name  = fieldDeclaration.Fields [0].Name;
            constantEntity.Type  = fieldDeclaration.TypeReference.Type;
            constantEntity.Value = "MISSING";

            // Get the method's comment
            IEnumerable <Comment> comments = this.GetDocumentationCommentsBefore(fieldDeclaration);

            AppendComment(constantEntity, comments);

            return(constantEntity);
        }
Example #13
0
        /// <summary>
        ///   Extracts the constants.
        /// </summary>
        /// <param name = "typedEntity">The typed entity.</param>
        /// <param name = "root">The root element.</param>
        protected void ExtractConstants(TypedEntity typedEntity, XElement root)
        {
            XElement listMarker = (from el in root.Descendants("h2")
                                   where el.Value == "Constants"
                                   select el).FirstOrDefault();
            XElement list = listMarker != null?listMarker.ElementsAfterSelf("dl").FirstOrDefault() : null;

            if (list != null)
            {
                // Collect names
                List <String> names = new List <string>();
                foreach (XElement term in list.Descendants("dt"))
                {
                    String name = term.Value.TrimAll();
                    names.Add(name);
                }

                // Search for a table with preceding by an anchor containing the name
                foreach (String name in names)
                {
                    XElement marker = (from el in list.ElementsAfterSelf("a")
                                       where el.Attribute("name") != null &&
                                       el.Attribute("name").Value.EndsWith("/" + name)
                                       select el).FirstOrDefault();
                    if (marker != null)
                    {
                        //XElement startElement = marker.ElementsAfterSelf("table").FirstOrDefault();
                        IEnumerable <XElement> elements = marker.ElementsAfterSelf().TakeWhile(el => el.Name != "a");

                        ConstantEntity entity = this.ConstantParser.Parse(typedEntity, name, elements);
                        if (entity != null)
                        {
                            typedEntity.Constants.Add(entity);
                        }
                    }
                    else
                    {
                        this.Logger.WriteLine("MISSING marker for constant " + name);
                    }
                }
            }
        }
        /// <summary>
        ///   Generates the specified entity.
        /// </summary>
        /// <param name = "framework">The framework.</param>
        /// <param name = "entity">The entity.</param>
        public void Generate(String framework, ConstantEntity entity)
        {
            // Don't generate if required
            if (!entity.Generate)
            {
                return;
            }

            // Append static condition if needed
            this.AppendStartCondition(entity);

            // Append property comments
            this.Writer.WriteLineFormat(2, "/// <summary>");
            foreach (String line in entity.Summary)
            {
                this.Writer.WriteLineFormat(2, "/// <para>{0}</para>", line.EscapeAll());
            }
            this.AppendAvailability(2, entity);
            this.Writer.WriteLineFormat(2, "/// </summary>");

            if (entity.Static)
            {
                // Print the static constant
                this.Writer.WriteLineFormat(2, "public static readonly {0} {1} = {2};", entity.Type, entity.Name, entity.Value);
            }
            else
            {
                // Print the extern constant
                this.Writer.WriteLineFormat(2, "public static readonly {0} {2} = ObjectiveCRuntime.GetExtern<{0}>(\"{1}\", \"{2}\");", entity.Type, framework, entity.Name);
            }

            // Append static condition if needed
            this.AppendEndCondition(entity);

            // Update statistics
            this.Statistics.Constants++;
        }
Example #15
0
        /// <summary>
        ///   Parses the specified entity.
        /// </summary>
        /// <param name = "entity">The entity.</param>
        /// <param name = "reader">The reader.</param>
        public override void Parse(BaseEntity entity, TextReader reader)
        {
            ClassEntity classEntity = entity as ClassEntity;

            if (classEntity == null)
            {
                throw new ArgumentException("ClassEntity expected", "entity");
            }

            IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, reader);

            parser.Parse();

            // Extract the special nodes (comment, etc)
            List <ISpecial> specials = parser.Lexer.SpecialTracker.RetrieveSpecials();

            this.CodeDomSpecialParser = new CodeDomSpecialParser(specials);

            // Parse the compilation unit
            CompilationUnit cu = parser.CompilationUnit;

            foreach (INode child1 in cu.Children)
            {
                NamespaceDeclaration namespaceDeclaration = child1 as NamespaceDeclaration;
                if (namespaceDeclaration == null)
                {
                    continue;
                }
                foreach (INode child2 in child1.Children)
                {
                    TypeDeclaration declaration = child2 as TypeDeclaration;
                    if (declaration == null)
                    {
                        continue;
                    }
                    if (declaration.Type != this.ClassType)
                    {
                        continue;
                    }

                    // Extract super-class
                    if (declaration.BaseTypes.Count > 0)
                    {
                        classEntity.BaseType = declaration.BaseTypes [0].Type;
                    }

                    // Extract comments
                    IEnumerable <Comment> comments = this.GetDocumentationCommentsBefore(declaration);
                    AppendComment(entity, comments);

                    // Append each values
                    foreach (INode child3 in declaration.Children)
                    {
                        MethodDeclaration methodDeclaration = child3 as MethodDeclaration;
                        if (methodDeclaration != null)
                        {
                            MethodEntity methodEntity = this.ExtractMethod(methodDeclaration);
                            classEntity.Methods.Add(methodEntity);
                        }

                        PropertyDeclaration propertyDeclaration = child3 as PropertyDeclaration;
                        if (propertyDeclaration != null)
                        {
                            PropertyEntity propertyEntity = this.ExtractProperty(propertyDeclaration);
                            classEntity.Properties.Add(propertyEntity);
                        }

                        FieldDeclaration fieldDeclaration = child3 as FieldDeclaration;
                        if (fieldDeclaration != null)
                        {
                            if ((fieldDeclaration.Modifier & Modifiers.Static) != Modifiers.Static)
                            {
                                continue;
                            }
                            if (fieldDeclaration.TypeReference.Type == "Class")
                            {
                                continue;
                            }
                            ConstantEntity constantEntity = this.ExtractConstant(fieldDeclaration);
                            classEntity.Constants.Add(constantEntity);
                        }
                    }
                }
            }

            // Ensure that availability is set on entity.
            entity.AdjustAvailability();
        }
        public ConstantEntity Parse(TypedEntity typedEntity, string constantElement, IEnumerable <XElement> elements)
        {
            ConstantEntity constantEntity = new ConstantEntity();

            XElement declarationElement = (from el in elements
                                           where el.Name == "div" &&
                                           el.Attribute("class") != null &&
                                           el.Attribute("class").Value == "declaration_indent"
                                           select el).FirstOrDefault();

            //XElement discussionElement = (from el in elements
            //                              where el.Name == "h5" && el.Value.Trim() == "Discussion"
            //                              select el).FirstOrDefault();

            XElement availabilityElement = (from el in elements
                                            let term = el.Descendants("dt").FirstOrDefault()
                                                       let definition = el.Descendants("dd").FirstOrDefault()
                                                                        where el.Name == "dl" &&
                                                                        term != null &&
                                                                        term.Value.Trim() == "Availability"
                                                                        select definition).FirstOrDefault();

            String stripped = declarationElement.TrimAll();

            stripped = stripped.Trim(';');
            while (stripped.Contains("  "))
            {
                stripped = stripped.Replace("  ", " ");
            }
            stripped = stripped.Replace("extern", String.Empty);
            stripped = stripped.Replace("const", String.Empty);
            stripped = stripped.TrimAll();

            Match r = CONSTANT_REGEX.Match(stripped);

            if (r.Success)
            {
                String type = r.Groups[1].Value.Trim(' ', '*', ' ');

                bool isOut;
                bool isByRef;
                bool isBlock;
                type = this.TypeManager.ConvertType(type, out isOut, out isByRef, out isBlock, this.Logger);

                constantEntity.Type = type;
                constantEntity.Name = r.Groups[2].Value.Trim();
            }
            else
            {
                this.Logger.WriteLine("FAILED to parse constant '{0}'", stripped);
                return(constantEntity);
            }

            // Extract abstract
            IEnumerable <XElement> abstractElements = elements.SkipWhile(el => el.Name != "p").TakeWhile(el => el.Name == "p");

            foreach (XElement element in abstractElements)
            {
                String line = element.TrimAll();
                if (!String.IsNullOrEmpty(line))
                {
                    constantEntity.Summary.Add(line);
                }
            }

            //// Extract discussion
            //if (discussionElement != null)
            //{
            //    IEnumerable<XElement> discussionElements = discussionElement.ElementsAfterSelf().TakeWhile(el => el.Name == "p");
            //    foreach (XElement element in discussionElements)
            //    {
            //        String line = element.TrimAll();
            //        if (!String.IsNullOrEmpty(line))
            //        {
            //            constantEntity.Summary.Add(line);
            //        }
            //    }
            //}

            // Get the availability
            if (availabilityElement != null)
            {
                constantEntity.MinAvailability = CommentHelper.ExtractAvailability(availabilityElement.TrimAll());
            }

            return(constantEntity);
        }
        private ConstantEntity ExtractConstant(FieldDeclaration fieldDeclaration)
        {
            ConstantEntity constantEntity = new ConstantEntity ();

            constantEntity.Name = fieldDeclaration.Fields [0].Name;
            constantEntity.Type = fieldDeclaration.TypeReference.Type;
            constantEntity.Value = "MISSING";

            // Get the method's comment
            IEnumerable<Comment> comments = this.GetDocumentationCommentsBefore (fieldDeclaration);
            AppendComment (constantEntity, comments);

            return constantEntity;
        }
        private List <BaseEntity> ExtractConstants(XElement constantElement, String name, String summary, String declaration)
        {
            List <BaseEntity> constants = new List <BaseEntity> ();

            // Extract types and names
            string[] declarations = declaration.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string part in declarations)
            {
                //this.Logger.WriteLine("Parsing constant '{0}'...", part.Trim());

                String stripped = part.Trim();
                stripped = stripped.Replace("extern", String.Empty);
                stripped = stripped.Replace("const", String.Empty);
                stripped = stripped.TrimAll();

                Match r = CONSTANT_REGEX.Match(stripped);
                if (r.Success)
                {
                    String type = r.Groups [1].Value.Trim(' ', '*', ' ');

                    bool isOut;
                    bool isByRef;
                    bool isBlock;
                    type = this.TypeManager.ConvertType(type, out isOut, out isByRef, out isBlock, this.Logger);

                    ConstantEntity constantEntity = new ConstantEntity();
                    constantEntity.Type = type;
                    constantEntity.Name = r.Groups [2].Value.Trim();
                    constants.Add(constantEntity);

                    //this.Logger.WriteLine("Constant found '{0}' of type '{1}'", constantEntity.Name, constantEntity.Type);
                }
                else
                {
                    this.Logger.WriteLine("FAILED to parse constant '{0}'", stripped);
                    return(null);
                }
            }

            // Get the definitions
            XElement termDefinitions = (from el in constantElement.ElementsAfterSelf("dl")
                                        where (String)el.Attribute("class") == "termdef"
                                        select el).FirstOrDefault();

            if (termDefinitions == null)
            {
                this.Logger.WriteLine("MISSING terms");
                return(null);
            }

            IEnumerable <XElement> termName       = termDefinitions.Elements("dt");
            IEnumerable <XElement> termDefinition = termDefinitions.Elements("dd");

            if (termName.Count() == termDefinition.Count())
            {
                // Iterate over definitions
                for (int i = 0; i < termName.Count(); i++)
                {
                    String term = termName.ElementAt(i).Value.TrimAll();
                    IEnumerable <String> summaries = termDefinition.ElementAt(i).Elements("p").Select(p => p.Value.TrimAll());

                    // Find the enumeration value
                    BaseEntity baseEntity = constants.Find(c => c.Name == term);
                    if (baseEntity != null)
                    {
                        foreach (string sum in summaries)
                        {
                            if (CommentHelper.IsAvailability(sum))
                            {
                                baseEntity.MinAvailability = CommentHelper.ExtractAvailability(sum);
                                break;
                            }
                            baseEntity.Summary.Add(sum);
                        }
                    }
                    else
                    {
                        this.Logger.WriteLine("Term with no match '" + term + "'");
                    }
                }
            }
            else
            {
                this.Logger.WriteLine("MISMATCH in terms");
                return(null);
            }

            return(constants);
        }
Example #19
0
        protected void gvConstant_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            HtmlInputHidden key = (HtmlInputHidden)gvConstant.Rows[e.RowIndex].Cells[0].FindControl("constantid");

            string sID    = key.Value;
            string sCode  = ((TextBox)(gvConstant.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
            string sName  = ((TextBox)(gvConstant.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
            string sDesc  = ((TextBox)(gvConstant.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
            string sValue = ((TextBox)(gvConstant.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
            string sNote  = ((TextBox)(gvConstant.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();

            string msg = "";

            if (sCode == "")
            {
                msg += "类型不能为空!\r\n";
            }

            if (sName == "")
            {
                msg += "名称不能为空!\r\n";
            }

            if (!Regex.IsMatch(sCode, "^[A-Za-z]+$"))
            {
                msg += "类型只能为字母!\r\n";
            }

            if (msg != "")
            {
                MessageBox.popupClientMessage(this.Page, msg);
                return;
            }

            //代码是否重复
            if (KPI_ConstantDal.ConstantNameExists(sName, sCode))
            {
                MessageBox.popupClientMessage(this.Page, "相同的类型下已存在该名称!");
                return;
            }

            //更新
            ConstantEntity ote = new ConstantEntity();

            ote.ConstantID         = sID;
            ote.ConstantCode       = sCode;
            ote.ConstantName       = sName;
            ote.ConstantDesc       = sDesc;
            ote.ConstantValue      = sValue;
            ote.ConstantNote       = sNote;
            ote.ConstantModifyTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");

            if (KPI_ConstantDal.Update(ote))
            {
                MessageBox.popupClientMessage(this.Page, "编辑成功!", "call();");
            }
            else
            {
                MessageBox.popupClientMessage(this.Page, "编辑错误!", "call();");
            }

            gvConstant.EditIndex = -1;

            BindConstant();
        }
        private List<BaseEntity> ExtractConstants(XElement constantElement, String name, String summary, String declaration)
        {
            List<BaseEntity> constants = new List<BaseEntity> ();

            // Extract types and names
            string[] declarations = declaration.Split (new []{';'}, StringSplitOptions.RemoveEmptyEntries);
            foreach (string part in declarations) {
                //this.Logger.WriteLine("Parsing constant '{0}'...", part.Trim());

                String stripped = part.Trim ();
                stripped = stripped.Replace ("extern", String.Empty);
                stripped = stripped.Replace ("const", String.Empty);
                stripped = stripped.TrimAll ();

                Match r = CONSTANT_REGEX.Match (stripped);
                if (r.Success) {
                    String type = r.Groups [1].Value.Trim (' ', '*', ' ');

                    bool isOut;
                    bool isByRef;
                    bool isBlock;
                    type = this.TypeManager.ConvertType (type, out isOut, out isByRef, out isBlock, this.Logger);

                    ConstantEntity constantEntity = new ConstantEntity ();
                    constantEntity.Type = type;
                    constantEntity.Name = r.Groups [2].Value.Trim ();
                    constants.Add (constantEntity);

                    //this.Logger.WriteLine("Constant found '{0}' of type '{1}'", constantEntity.Name, constantEntity.Type);
                } else {
                    this.Logger.WriteLine ("FAILED to parse constant '{0}'", stripped);
                    return null;
                }
            }

            // Get the definitions
            XElement termDefinitions = (from el in constantElement.ElementsAfterSelf ("dl")
                                        where (String)el.Attribute ("class") == "termdef"
                                        select el).FirstOrDefault ();
            if (termDefinitions == null) {
                this.Logger.WriteLine ("MISSING terms");
                return null;
            }

            IEnumerable<XElement> termName = termDefinitions.Elements ("dt");
            IEnumerable<XElement> termDefinition = termDefinitions.Elements ("dd");

            if (termName.Count () == termDefinition.Count ()) {
                // Iterate over definitions
                for (int i = 0; i < termName.Count(); i++) {
                    String term = termName.ElementAt (i).Value.TrimAll ();
                    IEnumerable<String> summaries = termDefinition.ElementAt (i).Elements ("p").Select (p => p.Value.TrimAll ());

                    // Find the enumeration value
                    BaseEntity baseEntity = constants.Find (c => c.Name == term);
                    if (baseEntity != null) {
                        foreach (string sum in summaries) {
                            if (CommentHelper.IsAvailability (sum)) {
                                baseEntity.MinAvailability = CommentHelper.ExtractAvailability (sum);
                                break;
                            }
                            baseEntity.Summary.Add (sum);
                        }
                    } else {
                        this.Logger.WriteLine ("Term with no match '" + term + "'");
                    }
                }
            } else {
                this.Logger.WriteLine ("MISMATCH in terms");
                return null;
            }

            return constants;
        }