コード例 #1
0
        public static List <TemplatePhaidraAttribute> GetTemplatePhaidraAttributes()
        {
            var attributes        = new List <TemplatePhaidraAttribute>();
            var attributeFilesDir = new System.IO.DirectoryInfo(System.IO.Path.Combine(new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).Directory.FullName, "PhaidraAttributeFiles", "AttributeTemplates"));

            if (attributeFilesDir.Exists)
            {
                var orderedFiles = attributeFilesDir.GetFiles("*.json").OrderBy(i => i.Name);
                foreach (var attributeFile in orderedFiles)
                {
                    if (!attributeFile.Name.StartsWith("x_"))
                    {
                        var attrs = TemplatePhaidraAttribute.GetTemplatePhaidraAttributes(attributeFile.FullName);
                        foreach (var attr in attrs)
                        {
                            if (attr.IsValid)
                            {
                                attributes.Add(attr);
                            }
                        }
                    }
                }
            }

            return(attributes);
        }
コード例 #2
0
        public static List <TemplatePhaidraAttribute> GetTemplatePhaidraAttributes(string templateDefinitionFilename)
        {
            var attributes = new List <TemplatePhaidraAttribute>();

            try
            {
                List <PredicateItem> predicates = null;
                var templateObj = JObject.Parse(System.IO.File.ReadAllText(templateDefinitionFilename));
                if (templateObj.ContainsKey(CONST_predicatesAttribute))
                {
                    predicates = templateObj[CONST_predicatesAttribute].ToObject <List <PredicateItem> >();
                }

                if (predicates != null)
                {
                    JArray fields = null;

                    if (templateObj.ContainsKey(CONST_fieldsAttribute))
                    {
                        fields = templateObj[CONST_fieldsAttribute] as JArray;
                    }

                    JToken template = null;

                    if (templateObj.ContainsKey(CONST_templateAttribute))
                    {
                        template = templateObj[CONST_templateAttribute];
                    }

                    foreach (var predicate in predicates)
                    {
                        var attribute = new TemplatePhaidraAttribute();
                        attributes.Add(attribute);
                        try
                        {
                            attribute.IsValid      = true;
                            attribute._predicate   = predicate.predicatename;
                            attribute._displayName = predicate.displayname ?? predicate.predicatename;
                            attribute._templateDefinitionFilename = templateDefinitionFilename;

                            if (fields != null)
                            {
                                foreach (JObject field in fields)
                                {
                                    var fieldItem = field.ToObject <FieldItem>();
                                    attribute._fields.Add(fieldItem.displayname, fieldItem);
                                    attribute._fieldNames.Add(fieldItem.displayname, fieldItem.displayname);
                                }
                            }

                            if (template != null)
                            {
                                attribute._templateObj = template.DeepClone();
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.LogE($"Error in GetTemplatePhaidraAttributes in file '{templateDefinitionFilename}': {ex.ToString()}");
                            attribute.IsValid = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogE($"Error in GetTemplatePhaidraAttributes in file '{templateDefinitionFilename}': {ex.ToString()}");
            }

            return(attributes);
        }