示例#1
0
        private static string GetTemplateAttribute(Type currentType, Attribute[] attrs, out TemplateAttribute templateAttr)
        {
            string tagName = currentType.Name;

            templateAttr = null;

            for (int index = 0; index < attrs.Length; index++)
            {
                Attribute attr = attrs[index];

                if (attr is TemplateTagNameAttribute templateTagNameAttr)
                {
                    tagName = templateTagNameAttr.tagName;
                }

                if (attr is TemplateAttribute templateAttribute)
                {
                    templateAttr = templateAttribute;
                }
            }

            // if no template attribute is defined, assume the default scheme
            if (templateAttr == null)
            {
                templateAttr = new TemplateAttribute(TemplateType.DefaultFile, null);
            }

            return(tagName);
        }
        //[ValidateAntiForgeryToken]
        public JsonResult Create(int templateItemID, string name, string description)
        {
            try
            {
                TemplateItem templateItem = this.serviceTemplateItem.Find(templateItemID);
                int          order        = templateItem.ModelAttributes.Count() + 1;

                TemplateAttribute templateAttribute = new TemplateAttribute()
                {
                    Name        = name,
                    Description = description,
                    Order       = order
                };

                this.serviceTemplateAttribute.Insert(templateAttribute);

                templateItem.ModelAttributes.Add(templateAttribute);

                this.serviceTemplateItem.Update(templateItem);


                base.unitOfWorkAsync.SaveChanges();

                var result = new { Success = "True" };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                var result = new { Success = "False", Message = e.Message };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
示例#3
0
 public void Add(string prefix, TemplateAttribute template)
 {
     if (template.IsLocalizable)
     {
         _templateTranslations.Add(MakeList(prefix, template.Usage.ToString()), template.Patterns);
     }
 }
        public void RenderShouldDelegateCallToHtmlHelperShouldUseAttributesAndProvideTagModel()
        {
            var attribute =
                new TemplateAttribute(new ParsedTemplate(null, new ExpressionPart(new ExpressionLib().Parse("name"))));
            var tag = Html.New <TestHtmlTag>(new List <IParameterValue>
            {
                new TestParameterValue {
                    Name = "isChecked", TestValue = true
                },
                new ParameterValue {
                    Name = "name", Attribute = attribute
                },
            }
                                             );

            Assert.That(tag.Method, Is.Not.Null);
            var model = new TagModel(new Hashtable());

            model.Model["name"] = "a";
            model.Page[Html.PAGE_MODEL_HTMLHELPER_INSTANCE] = GetHelper();
            string result = tag.Evaluate(model);

            Assert.That(result.Contains("name=\"a\""));
            Assert.That(result.Contains("checked=\"checked\""));
        }
        // GET: Templates/BlankTemplateAttribute/108
        public PartialViewResult BlankTemplateAttribute(string attributeType = "")
        {
            TemplateAttribute templateAttribute = new TemplateAttribute();

            if (attributeType != "")
            {
                templateAttribute.TemplateAttributeType = attributeType;
            }

            string pView;

            switch (attributeType)
            {
            case "Text":
                pView = "_TemplateAttributes";
                break;

            case "Select":
                pView = "_TemplateAttributesList";
                break;

            case "Autofill":
                pView = "_TemplateAttributesAutofill";
                break;

            default:
                pView = "_TemplateAttributes";
                break;
            }
            return(PartialView(pView, templateAttribute));
        }
        public static Tag CreateFromTemplate(TemplateAttribute templateAttribute, object data = null)
        {
            HandlebarsDirectory directory = new HandlebarsDirectory(templateAttribute.DirectoryPath ?? "./Handlebars");
            Tag result = Tags.Span();

            result.Content = directory.Render(templateAttribute.Name, data);
            return(result);
        }
示例#7
0
        private bool HasTemplateAnnotation(Type pageType, out string templateName)
        {
            TemplateAttribute annotation = pageType.GetCustomAttribute <TemplateAttribute>();

            templateName = annotation?.ProcName;

            return(!string.IsNullOrWhiteSpace(templateName));
        }
示例#8
0
        public TemplatedControl()
        {
            TemplateAttribute templateAttribute = AttributeSearcher.GetAttribute <TemplateAttribute>(GetType());

            if (templateAttribute != null)
            {
                LoadTemplate(templateAttribute.FileName);
            }
        }
示例#9
0
 public ProcessedType(Type rawType, TemplateAttribute templateAttr, string tagName = null)
 {
     this.id               = -1; // set by TypeProcessor
     this.rawType          = rawType;
     this.templateAttr     = templateAttr;
     this.tagName          = tagName;
     this.requiresUpdateFn = ReflectionUtil.IsOverride(rawType.GetMethod(nameof(UIElement.OnUpdate)));
     this.requiresOnEnable = ReflectionUtil.IsOverride(rawType.GetMethod(nameof(UIElement.OnEnable)));
     this.requiresBeforePropertyUpdates = ReflectionUtil.IsOverride(rawType.GetMethod(nameof(UIElement.OnBeforePropertyBindings)));
     this.requiresAfterPropertyUpdates  = ReflectionUtil.IsOverride(rawType.GetMethod(nameof(UIElement.OnAfterPropertyBindings)));
     this.namespaceName = rawType.Namespace;
 }
示例#10
0
        public void AddAttribute(string attribute, string replaceValue)
        {
            if (Compiled) throw new InvalidOperationException("You cannot edit a compiled template, if you would like to edit the template then Reset() it.");
            TemplateAttribute t = new TemplateAttribute();
            t.Placeholder = attribute;
            t.Replacement = replaceValue;
            t.Index = Builder.ToString().IndexOf(replaceValue);

            Index[t.Placeholder] = t;

            Builder.Replace(t.Placeholder, t.Replacement, t.Index, t.Length);
        }
示例#11
0
        public ILocalizer Load(IResourceReader reader, out IEnumerable <string> missing, out IEnumerable <string> extra)
        {
            var lmissing     = new List <string>();
            var lextra       = new List <string>();
            var newLocalizer = new Localizer();

            foreach (DictionaryEntry entry in reader)
            {
                var fullKey = (string)entry.Key;
                var semi    = fullKey.IndexOf(SEPARATOR[0]);
                var type    = fullKey.Substring(0, semi);
                var key     = fullKey.Substring(semi + 1);
                var val     = (string)entry.Value;
                if (type == "CULTURE")
                {
                    newLocalizer.Culture = new CultureInfo(val);
                }
                else if (type == "VALUE")
                {
                    newLocalizer.Add(key, val);
                }
                else if (type == "LIST")
                {
                    newLocalizer.Add(key, val.SplitList().ToArray());
                }
                else if (type == "TEMPLATE")
                {
                    var elements = key.SplitList();
                    var usage    = elements.First();
                    var fields   = elements.Skip(1);
                    var patterns = val.SplitList();
                    var template = new TemplateAttribute((TemplateUsage)Enum.Parse(typeof(TemplateUsage), usage), patterns.ToArray());
                    foreach (var field in fields)
                    {
                        newLocalizer.Add(field, template);
                    }
                }
            }

            // Find missing and extra keys
            lmissing.AddRange(_translations.Keys.Except(newLocalizer._translations.Keys));
            lmissing.AddRange(_arrayTranslations.Keys.Except(newLocalizer._arrayTranslations.Keys));
            lmissing.AddRange(_templateTranslations.Keys.Except(newLocalizer._templateTranslations.Keys));
            lextra.AddRange(newLocalizer._translations.Keys.Except(_translations.Keys));
            lextra.AddRange(newLocalizer._arrayTranslations.Keys.Except(_arrayTranslations.Keys));
            lextra.AddRange(newLocalizer._templateTranslations.Keys.Except(_templateTranslations.Keys));
            missing = lmissing;
            extra   = lextra;
            return(newLocalizer);
        }
示例#12
0
        public TemplateRootNode GetParsedTemplate(ProcessedType processedType)
        {
            TemplateAttribute templateAttr = processedType.templateAttr;

            templateAttr.filePath = ResolveTemplateFilePath(processedType);
            if (templateAttr.fullPathId == null)
            {
                templateAttr.fullPathId = templateAttr.templateId == null
                    ? templateAttr.filePath
                    : templateAttr.filePath + "#" + templateAttr.templateId;
            }

            Debug.Assert(templateAttr.fullPathId != null, "templateAttr.fullPathId != null");

            if (templateMap.TryGetValue(templateAttr.fullPathId, out LightList <TemplateRootNode> list))
            {
                for (int i = 0; i < list.size; i++)
                {
                    if (list.array[i].processedType.rawType == processedType.rawType)
                    {
                        return(list.array[i]);
                    }
                }

                TemplateRootNode retn = list[0].Clone(processedType);
                list.Add(retn);
                return(retn);
            }

            list = new LightList <TemplateRootNode>(2);

            templateMap[templateAttr.fullPathId] = list;

            TemplateDefinition templateDefinition = GetTemplateDefinition(processedType);

            templateAttr.source = templateDefinition.contents;

            TemplateShell shell = xmlTemplateParser.GetOuterTemplateShell(templateAttr);

            TemplateRootNode templateRootNode = new TemplateRootNode(templateAttr.templateId, shell, processedType, null, default)
            {
                tagName = processedType.tagName
            };

            list.Add(templateRootNode);

            xmlTemplateParser.Parse(templateRootNode, processedType);

            return(templateRootNode);
        }
示例#13
0
        void ConfigureFormBuilder(FormBuilder <WineForm> builder)
        {
            FormConfiguration buildConfig = builder.Configuration;

            buildConfig.Yes = "Yes;y;sure;ok;yep;1;good".SplitList();

            TemplateAttribute tmplAttr = buildConfig.Template(TemplateUsage.EnumSelectOne);

            tmplAttr.Patterns = new[] { "What {&} would you like? {||}" };

            buildConfig.Commands[FormCommand.Quit].Help =
                "Quit: Quit the form without completing it. " +
                "Warning - this will clear your previous choices!";
        }
示例#14
0
        private void HandleExpression(string name, TemplateAttribute value)
        {
            if (value == null)
            {
                return;
            }
            var nodes = value.
                        TemplateParsed.
                        Select(Yield).
                        Where(n => n != null).
                        ToArray();

            With(name, nodes);
        }
示例#15
0
        private TemplateDefinition GetTemplateDefinition(ProcessedType processedType)
        {
            TemplateAttribute templateAttr = processedType.templateAttr;

            string templatePath = ResolveTemplateFilePath(templateAttr.templateType, templateAttr.filePath);

            switch (templateAttr.templateType)
            {
            case TemplateType.Internal: {
                string file = settings.TryReadFile(templatePath);

                if (file == null)
                {
                    throw new TemplateParseException(settings.templateResolutionBasePath, $"Cannot find template in (internal) path {templatePath}.");
                }

                return(new TemplateDefinition()
                    {
                        contents = file,
                        filePath = templateAttr.templateType == TemplateType.File ? processedType.rawType.AssemblyQualifiedName : templateAttr.filePath,
                        language = TemplateLanguage.XML
                    });
            }

            case TemplateType.DefaultFile:
            case TemplateType.File: {
                string file = settings.TryReadFile(templatePath);
                if (file == null)
                {
                    throw new TemplateParseException(settings.templateResolutionBasePath, $"Cannot find template in path {templatePath}.");
                }

                return(new TemplateDefinition()
                    {
                        contents = file,
                        filePath = templateAttr.filePath,
                        language = TemplateLanguage.XML
                    });
            }

            default:
                return(new TemplateDefinition()
                {
                    contents = templateAttr.source,
                    filePath = templatePath,
                    language = TemplateLanguage.XML
                });
            }
        }
示例#16
0
 private static TemplateAttributeGetDTO MapAttributesToDTO(TemplateAttribute oa)
 {
     return(new()
     {
         Id = oa.Id,
         Featured = oa.Featured,
         Name = oa.Attribute !.Name,
         Type = oa.Attribute !.AttributeType !.Name,
         TypeId = oa.Attribute !.AttributeType.Id,
         AttributeId = oa.AttributeId,
         DataType = (AttributeDataType)oa.Attribute !.AttributeType !.DataType,
         UsesDefinedUnits = oa.Attribute !.AttributeType !.UsesDefinedUnits,
         UsesDefinedValues = oa.Attribute !.AttributeType !.UsesDefinedValues
     });
 }
示例#17
0
        public static ProcessedType AddResolvedGenericElementType(Type newType, TemplateAttribute templateAttr, string tagName)
        {
            ProcessedType retn = null;

            if (!typeMap.TryGetValue(newType, out retn))
            {
                retn    = new ProcessedType(newType, templateAttr, tagName);
                retn.id = NextTypeId;
                typeMap.Add(retn.rawType, retn);
            }

            if (retn != null)
            {
                retn.references++;
            }

            return(retn);
        }
示例#18
0
        internal void Parse(TemplateRootNode templateRootNode, ProcessedType processedType)
        {
            TemplateAttribute templateAttr = processedType.templateAttr;

            string filePath = templateAttr.filePath;

            if (parsedFiles.TryGetValue(filePath, out TemplateShell rootNode))
            {
                ParseContentTemplate(templateRootNode, rootNode, processedType);
                return;
            }

            TemplateShell shell = ParseOuterShell(templateAttr.filePath, templateAttr.source);

            parsedFiles.Add(filePath, shell);

            ParseContentTemplate(templateRootNode, shell, processedType);
        }
示例#19
0
        private ITemplate CreateTemplate(TemplateAttribute attribute)
        {
            var path     = "~/Views/" + attribute.TemplateAlias.ToPascalCase() + ".cshtml";
            var template = new Template(path, attribute.TemplateName, attribute.TemplateAlias);

            lock (_lock)
            {
                if (System.IO.File.Exists(HostingEnvironment.MapPath(path)))
                {
                    //get the existing content from the file so it isn't overwritten when we save the template.
                    template.Content = System.IO.File.ReadAllText(HostingEnvironment.MapPath(path));
                }
                else
                {
                    //TODO get this from a file resource containing a default view
                    var content = "@inherits Felinesoft.UmbracoCodeFirst.Views.UmbracoDocumentViewPage<" + attribute.DecoratedTypeFullName + ">" + Environment.NewLine + Environment.NewLine;
                    template.Content = content;
                }

                _fileService.SaveTemplate(template);
            }
            return(template);
        }
示例#20
0
        public async Task UpdateAsync(long id, TemplatePatchDTO templatePatchDTO)
        {
            var template = await ValidateAndReturnTemplateAsync(id, templatePatchDTO.Id);

            template.Name = templatePatchDTO.Name;

            await UnitOfWork.Templates.UpdateAsync(template);

            var templateAttributesCount = await UnitOfWork.TemplateAttributes.CountByTemplateId(id);

            foreach (var attributePatchDTO in templatePatchDTO.Attributes.OrderBy(dto => dto.PatchOption))
            {
                TemplateAttribute attribute;

                switch (attributePatchDTO.PatchOption)
                {
                case PatchOption.Updated:
                    if (!(attributePatchDTO.Id.HasValue &&
                          await UnitOfWork.TemplateAttributes.AnyAsync(attributePatchDTO.Id.Value, id)))
                    {
                        throw new NotFoundException("Атрибут не найден");
                    }

                    await ValidateAndFormatAttribute(attributePatchDTO);

                    attribute =
                        await UnitOfWork.TemplateAttributes.FirstOrDefaultNoTrackAsync(attributePatchDTO.Id.Value) !;

                    attribute.Featured    = attributePatchDTO.Featured;
                    attribute.AttributeId = attributePatchDTO.AttributeId;

                    await UnitOfWork.TemplateAttributes.UpdateAsync(attribute);

                    break;

                case PatchOption.Created:

                    await ValidateAndFormatAttribute(attributePatchDTO);

                    attribute = new TemplateAttribute()
                    {
                        Featured    = attributePatchDTO.Featured,
                        AttributeId = attributePatchDTO.AttributeId,
                        TemplateId  = template.Id
                    };

                    await UnitOfWork.TemplateAttributes.AddAsync(attribute);

                    templateAttributesCount++;

                    break;

                case PatchOption.Deleted:
                    if (!(attributePatchDTO.Id.HasValue &&
                          await UnitOfWork.TemplateAttributes.AnyAsync(attributePatchDTO.Id.Value, id)))
                    {
                        throw new NotFoundException("Атрибут не найден");
                    }

                    await UnitOfWork.TemplateAttributes.RemoveAsync(attributePatchDTO.Id.Value);

                    templateAttributesCount--;

                    break;
                }
            }

            if (templateAttributesCount < 1)
            {
                throw new ValidationException("В шаблоне должен быть как минимум один атрибут");
            }

            await UnitOfWork.SaveChangesAsync();
        }
示例#21
0
 public void Add(string prefix, TemplateAttribute template)
 {
     if (template.IsLocalizable)
     {
         _templateTranslations.Add(MakeList(prefix, template.Usage.ToString()), template.Patterns);
     }
 }
示例#22
0
        private string ResolveTemplateFilePath(ProcessedType processedType)
        {
            TemplateAttribute templateAttr = processedType.templateAttr;

            if (templateAttr.templateType == TemplateType.Internal)
            {
                return(templateAttr.filePath);
            }

            if (settings.filePathResolver != null)
            {
                return(settings.filePathResolver(processedType.rawType, templateAttr.templateId));
            }

            string namespacePath = processedType.rawType.Namespace;

            if (namespacePath != null && namespacePath.Contains("."))
            {
                namespacePath = namespacePath.Replace(".", Path.DirectorySeparatorChar.ToString());
            }

            string xmlPath;

            // Special behavior for template attributes with no file path parameter. We figure out the whole path
            // based on a convention that looks for a given template like:
            //     namespace My.Name.Space { [Template] public class MyElement : UIElement ... }
            // right here:
            // basepath + My/Name/Space/ClassName.xml
            if (templateAttr.templateType == TemplateType.DefaultFile)
            {
                string basePath = namespacePath == null
                    ? processedType.rawType.Name
                    : Path.Combine(namespacePath, processedType.rawType.Name);

                string relativePath = basePath + settings.templateFileExtension;
                xmlPath = Path.GetFullPath(Path.Combine(settings.templateResolutionBasePath, relativePath));
                if (!File.Exists(xmlPath))
                {
                    throw new TemplateNotFoundException(processedType, xmlPath);
                }

                return(relativePath);
            }

            // first we try to find the template based on the resolution base path + a guessed namespace path
            if (namespacePath != null)
            {
                // namespace My.Name.Space.MyElement { [Template("MyElement.xml#id")] }
                // basepath + My/Name/Space/MyElement/MyElement.xml
                // templateRootNamespace = My/Name/Space
                xmlPath = Path.GetFullPath(Path.Combine(settings.templateResolutionBasePath, namespacePath, templateAttr.filePath));
                if (File.Exists(xmlPath))
                {
                    return(Path.Combine(namespacePath, templateAttr.filePath));
                }
            }

            // namespace My.Name.Space.MyElement { [Template("My/Name/Space/MyElement/MyElement.xml#id")] }
            // basepath + My/Name/Space/MyElement/MyElement.xml
            // templateRootNamespace = My/Name/Space
            // ------
            // If the previous method didn't find a template we probably have a full path in the template attribute.
            // This should be the mode that is compatible with non-convention paths and namespaces
            xmlPath = Path.GetFullPath(Path.Combine(settings.templateResolutionBasePath, templateAttr.filePath));
            if (File.Exists(xmlPath))
            {
                return(templateAttr.filePath);
            }

            throw new TemplateNotFoundException(processedType, xmlPath);
        }
示例#23
0
        private ITemplate ConfigureTemplate(Type docType, ref ITemplate defaultTemplate, TemplateAttribute attribute)
        {
            var template = _fileService.GetTemplates().FirstOrDefault(x => string.Equals(x.Alias, attribute.TemplateAlias, StringComparison.InvariantCultureIgnoreCase));

            if (template == null)
            {
                template = CreateTemplate(attribute);
            }
            if (attribute.IsDefault)
            {
                if (defaultTemplate == null)
                {
                    defaultTemplate = template;
                }
                else
                {
                    throw new CodeFirstException("More than one default template specified for " + docType.FullName);
                }
            }
            if (attribute.TemplateName != template.Name)
            {
                var t = new umbraco.cms.businesslogic.template.Template(template.Id);
                t.Text = attribute.TemplateName;
                t.Save();
                template = _fileService.GetTemplates().FirstOrDefault(x => x.Alias == attribute.TemplateAlias); //re-get the template to pick up the changes
            }
            return(template);
        }
示例#24
0
        private static void SeedPipe(UnitOfWorkProcurement unit, IRepositoryItem repItem, IRepositoryItemType repItemType, IRepositoryTemplateItem repTemplateItem, IRepositoryTemplateAttribute repTemplateAttribute
                                     , IRepositoryAttributeValue repAttributeValue)
        {
            //Pipe_catalogue.csv

            #region Pipe
            ItemType itemType = new ItemType()
            {
                Name = "Pipe"
            };
            repItemType.Insert(itemType);


            TemplateAttribute spec = new TemplateAttribute()
            {
                Name = "Specification", Order = 1
            };
            TemplateAttribute grade = new TemplateAttribute()
            {
                Name = "Grade", Order = 2
            };
            TemplateAttribute nps = new TemplateAttribute()
            {
                Name = "NPS", Order = 3
            };
            TemplateAttribute thickness = new TemplateAttribute()
            {
                Name = "Thickness", Order = 54
            };
            TemplateAttribute welded = new TemplateAttribute()
            {
                Name = "Welded/Seamless", Order = 5
            };
            TemplateAttribute kg = new TemplateAttribute()
            {
                Name = "Kg/m", Order = 6
            };

            //UNSPSC Code;Specification;Grade;NPS;Thickness;Welded/Seamless;Kg/m
            List <TemplateAttribute> attributes = new List <TemplateAttribute>()
            {
                spec,
                grade,
                nps,
                thickness,
                welded,
                kg,
                new TemplateAttribute()
                {
                    Name = "Reference standard", Order = 7
                },
                new TemplateAttribute()
                {
                    Name = "Rating class", Order = 8
                },
                new TemplateAttribute()
                {
                    Name = "Material Specification", Order = 9
                },
                new TemplateAttribute()
                {
                    Name = "Endings", Order = 10
                },
            };
            repTemplateAttribute.InsertRange(attributes);
            TemplateItem pipe = new TemplateItem()
            {
                Name = "Pipe", ItemType = itemType, ModelAttributes = attributes
            };
            repTemplateItem.Insert(pipe);

            IEnumerable <string> lines = System.IO.File.ReadLines(@"C:\Proc\Pipe_catalogue.csv");

            int count = 1;

            foreach (var line in lines)
            {
                string[] columnsValues = null;
                if (count == 1)
                {
                    columnsValues = line.Split(';');
                }
                else
                {
                    columnsValues = line.Split(';');

                    Item item = new Item()
                    {
                        Template = pipe,
                        UNSPSC   = columnsValues[0]
                    };
                    repItem.Insert(item);
                    unit.SaveChanges();

                    List <AttributeValue> listAttrValues = new List <AttributeValue>()
                    {
                        new AttributeValue()
                        {
                            Item = item, TemplateAttribute = spec, Value = columnsValues[1]
                        },
                        new AttributeValue()
                        {
                            Item = item, TemplateAttribute = grade, Value = columnsValues[2]
                        },
                        new AttributeValue()
                        {
                            Item = item, TemplateAttribute = nps, Value = columnsValues[3]
                        },
                        new AttributeValue()
                        {
                            Item = item, TemplateAttribute = thickness, Value = columnsValues[4]
                        },
                        new AttributeValue()
                        {
                            Item = item, TemplateAttribute = welded, Value = columnsValues[5]
                        },
                        new AttributeValue()
                        {
                            Item = item, TemplateAttribute = kg, Value = columnsValues[6]
                        }
                    };
                    repAttributeValue.InsertRange(listAttrValues);
                    item.AttributeValues = listAttrValues;
                    repItem.Update(item);
                }
                count++;

                if (count >= 700)
                {
                    break;
                }
            }



            #endregion
        }
示例#25
0
 /// <summary>   Replace a template in the field. </summary>
 /// <param name="template"> The template. </param>
 /// <returns>   A Field&lt;T&gt; </returns>
 public Field <T> ReplaceTemplate(TemplateAttribute template)
 {
     UpdateAnnotations();
     AddTemplate(template);
     return(this);
 }
示例#26
0
 /// <summary>   Replace a template in the field. </summary>
 /// <param name="template"> The template. </param>
 /// <returns>   A <see cref="Field{T}"/>. </returns>
 public Field <T> ReplaceTemplate(TemplateAttribute template)
 {
     AddTemplate(template);
     return(this);
 }
示例#27
0
        public ILocalizer Load(IDictionaryEnumerator reader, out IEnumerable<string> missing, out IEnumerable<string> extra)
        {
            var lmissing = new List<string>();
            var lextra = new List<string>();
            var newLocalizer = new Localizer();
            while (reader.MoveNext())
            {
                var entry = (DictionaryEntry) reader.Current;
                var fullKey = (string)entry.Key;
                var semi = fullKey.LastIndexOf(SEPARATOR[0]);
                var key = fullKey.Substring(0, semi);
                var type = fullKey.Substring(semi + 1);
                var val = (string)entry.Value;
                if (type == "VALUE")
                {
                    newLocalizer.Add(key, val);
                }
                else if (type == "LIST")
                {
                    newLocalizer.Add(key, val.SplitList().ToArray());
                }
                else if (type == "TEMPLATE")
                {
                    var elements = key.SplitList();
                    var usage = elements.First();
                    var fields = elements.Skip(1);
                    var patterns = val.SplitList();
                    var template = new TemplateAttribute((TemplateUsage)Enum.Parse(typeof(TemplateUsage), usage), patterns.ToArray());
                    foreach (var field in fields)
                    {
                        newLocalizer.Add(field, template);
                    }
                }
            }

            // Find missing and extra keys
            lmissing.AddRange(_translations.Keys.Except(newLocalizer._translations.Keys));
            lmissing.AddRange(_arrayTranslations.Keys.Except(newLocalizer._arrayTranslations.Keys));
            lmissing.AddRange(_templateTranslations.Keys.Except(newLocalizer._templateTranslations.Keys));
            lextra.AddRange(newLocalizer._translations.Keys.Except(_translations.Keys));
            lextra.AddRange(newLocalizer._arrayTranslations.Keys.Except(_arrayTranslations.Keys));
            lextra.AddRange(newLocalizer._templateTranslations.Keys.Except(_templateTranslations.Keys));
            missing = lmissing;
            extra = lextra;
            return newLocalizer;
        }
示例#28
0
 protected void AddTemplate(TemplateAttribute template)
 {
     _templates[template.Usage] = template;
 }
示例#29
0
 internal TemplateShell GetOuterTemplateShell(TemplateAttribute templateAttribute)
 {
     return(GetOuterTemplateShell(templateAttribute.filePath, templateAttribute.source));
 }