private IList <Field> DeserialiseFields(IList <string> templatePath)
        {
            var fields     = new Dictionary <long, Field>();
            var fieldsPath = MakePath(templatePath, "Field");

            foreach (var key in EnumerateKeys(fieldsPath))
            {
                var fieldPath = MakePath(fieldsPath, SerialisationMetadata.FormatKey(key));
                var editable  = true;
                if (TryGetValue(fieldPath, "InitialRange", out long initialRange))
                {
                    editable = initialRange != -1;
                }
                TryGetValue(fieldPath, "Expression", out string expression);
                var order = GetValue <long>(fieldPath, "Order");
                var field = new Field
                {
                    Name             = key,
                    Editable         = editable,
                    Expression       = expression,
                    EditableInstance = initialRange
                };
                fields.Add(order, field);
            }

            return(fields.OrderBy(f => f.Key).Select(f => f.Value).ToList());
        }
        private Template DeserialiseTemplate(Guid guid)
        {
            var templateKey  = SerialisationMetadata.FormatKey(SerialisationMetadata.FormatGuid(guid));
            var templatePath = MakePath(RootPath, templateKey);
            var template     = new Template {
                Guid = guid
            };
            var index = GetIndexedValues <bool>(templatePath, "Applicability").First().Key;

            Enum.TryParse(index, out template.Type);
            if (template.Type != TemplateType.File)
            {
                template.Shortcut = GetValue <string>(templatePath, "Shortcut");
            }
            if (!TryGetValue(templatePath, "Description", out string description))
            {
                Console.WriteLine("Warning: Template {0} does not have a description.", template.Shortcut);
            }
            template.Description = description;
            template.Text        = GetValue <string>(templatePath, "Text");
            template.Image       = TryGetValue(templatePath, "Image", (string)null);
            template.Reformat    = TryGetValue(templatePath, "Reformat", true);
            template.ShortenQualifiedReferences = TryGetValue(templatePath, "ShortenQualifiedReferences", true);
            template.Scopes           = DeserialiseScopes(templatePath);
            template.CustomProperties = DeserialiseCustomProperties(templatePath);
            template.Categories       = DeserialiseCategories(templatePath);
            template.Fields           = DeserialiseFields(templatePath);
            return(template);
        }
        public SettingsStore AddIndexedSettings(string name, string index)
        {
            var newPath  = Combine(path, name, SerialisationMetadata.FormatKey(index));
            var settings = new SettingsStore(dictionary, newPath);

            settings.Add(SerialisationMetadata.KeyIndexDefined, true);
            return(settings);
        }
        private Scope DeserialiseScope(IEnumerable <string> templatePath, Guid guid)
        {
            var scopePath = MakePath(templatePath, "Scope",
                                     SerialisationMetadata.FormatKey(SerialisationMetadata.FormatGuid(guid)));
            var scope = new Scope
            {
                Guid       = guid,
                Type       = GetValue <string>(scopePath, "Type"),
                Parameters = DeserialiseScopeParameters(scopePath)
            };

            return(scope);
        }
 public void AddIndexedValue(string name, string key, object value)
 {
     Add(Combine(name, SerialisationMetadata.FormatKey(key), SerialisationMetadata.EntryIndexedValue), value);
 }