Exemple #1
0
        private static void IndexNodes(IEnumerable <DesignerNode> nodes, ModelMeta model)
        {
            foreach (var designerNode in nodes)
            {
                switch (designerNode.NodeType)
                {
                case NodeType.TypeName:
                    // got the model
                    string modelText = designerNode.SnapshotSpan.GetText();
                    model.ModelClass = modelText;
                    break;

                case NodeType.Reference:
                    // got the member
                    string memberText = designerNode.SnapshotSpan.GetText();
                    if (model.Members == null)
                    {
                        model.Members = new List <string>();
                    }
                    model.Members.Add(memberText);
                    break;
                }


                if (designerNode.Children.Count > 0)
                {
                    IndexNodes(designerNode.Children, model);
                }
            }
        }
Exemple #2
0
 private void MapModelProperties <TModel>(TModel model, Item item, ModelMeta modelMeta)
 {
     foreach (var propertyMetaInterface in modelMeta.PropertyMap)
     {
         propertyMetaInterface.Mapper.HandleMapping(model, item, propertyMetaInterface, cache, this);
     }
 }
Exemple #3
0
        /// <summary>
        /// Builds a list of syntax nodes for a snapshot. This method is called on a separate thread
        /// </summary>
        private void rebuildNodes(object snapshotObject)
        {
            var nodes = Project.ParseTemplate(Filename, type_resolver);
            // get the snapshot used to parse the template. In theory it is possible to get a different one
            // if the parsing was requested again and there were changes since, by I do not think this is
            // something to really happen
            var snapshot = Project.GetSnapshot(Filename);

            if (snapshot != null)                                                                              // this is an overkill, I know
            {
                snapshot.TextBuffer.Changed -= new EventHandler <TextContentChangedEventArgs>(buffer_Changed); // just to prevent double-firing
                snapshot.TextBuffer.Changed += new EventHandler <TextContentChangedEventArgs>(buffer_Changed);
                List <DesignerNode> designer_nodes = nodes
                                                     .Aggregate(
                    new List <DesignerNode>(),
                    (list, node) => { list.Add(new DesignerNode(this, null, snapshot, (INode)node)); return(list); }
                    );
                List <DesignerNode> oldNodes;
                lock (node_lock)
                {
                    oldNodes   = this.nodes;
                    this.nodes = designer_nodes;
                }

                ModelMeta model = new ModelMeta();
                IndexNodes(this.nodes, model);

                oldNodes.ForEach(node => node.Dispose());
                designer_nodes.ForEach(node => node.ShowDiagnostics());
                RaiseNodesChanged(snapshot);
            }
        }
Exemple #4
0
        private ModelMeta EnsureModelDictionaryEntryExists <TModel>(IDictionary <string, ModelMeta> metadataDictionary)
        {
            var modelType    = typeof(TModel);
            var modelMetaKey = modelType.AssemblyQualifiedName;
            var modelMeta    = default(ModelMeta);

            if (metadataDictionary.ContainsKey(modelMetaKey))
            {
                modelMeta = metadataDictionary[modelMetaKey];
            }
            else
            {
                lock (MetaSyncRoot)
                {
                    if (!metadataDictionary.ContainsKey(modelMetaKey))
                    {
                        modelMeta = new ModelMeta();
                        var propertyMetaBuilder = new PropertyMetaBuilder();
                        modelMeta.PropertyMap = propertyMetaBuilder.BuildPropertyMetaMap <TModel>();
                        metadataDictionary.Add(modelMetaKey, modelMeta);
                    }
                }
            }
            return(modelMeta);
        }
Exemple #5
0
        private ModelMeta EnsureModelDictionaryEntryExists <TModel>(IDictionary <string, ModelMeta> metadataDictionary)
        {
            var       modelType    = typeof(TModel);
            var       modelMetaKey = modelType.AssemblyQualifiedName;
            ModelMeta tmp          = null;

            if (metadataDictionary.TryGetValue(modelMetaKey, out tmp))
            {
                return(tmp);
            }

            lock (MetaSyncRoot)
            {
                if (metadataDictionary.TryGetValue(modelMetaKey, out tmp))
                {
                    return(tmp);
                }

                var modelMeta           = new ModelMeta();
                var propertyMetaBuilder = new PropertyMetaBuilder();

                modelMeta.PropertyMap = propertyMetaBuilder.BuildPropertyMetaMap <TModel>();
                metadataDictionary.Add(modelMetaKey, modelMeta);

                return(modelMeta);
            }
        }
Exemple #6
0
 public ModelListVm(ModelMeta meta, ModelVm[] models)
 {
     Meta   = meta;
     Models = models;
     Keys   = !Models.Any()
         ? Array.Empty <string>()
         : Models.FirstOrDefault().Entries.Select(x => x.key).ToArray();
 }
Exemple #7
0
        private void ResolveServiceModels()
        {
            var types = GetModels();

            foreach (var type in types)
            {
                if (type.IsPublic)
                {
                    ModelMeta model = new ModelMeta(type);
                    ServiceMeta.Models.Add(model);
                }
            }
        }
Exemple #8
0
 public ModelEditVm(ModelMeta meta, Model model)
 {
     Meta  = meta;
     Model = model;
 }
Exemple #9
0
        /// <summary>
        /// Builds a list of syntax nodes for a snapshot. This method is called on a separate thread
        /// </summary>
        private void rebuildNodes(object snapshotObject)
        {
            var nodes = Project.ParseTemplate(Filename, type_resolver);
            // get the snapshot used to parse the template. In theory it is possible to get a different one
            // if the parsing was requested again and there were changes since, by I do not think this is
            // something to really happen
            var snapshot = Project.GetSnapshot(Filename);
            if (snapshot != null) // this is an overkill, I know
            {
                snapshot.TextBuffer.Changed -= new EventHandler<TextContentChangedEventArgs>(buffer_Changed); // just to prevent double-firing
                snapshot.TextBuffer.Changed += new EventHandler<TextContentChangedEventArgs>(buffer_Changed);
                List<DesignerNode> designer_nodes = nodes
                    .Aggregate(
                        new List<DesignerNode>(),
                        (list, node) => { list.Add( new DesignerNode(this, null, snapshot, (INode)node)); return list; }
                            );
                List<DesignerNode> oldNodes;
                lock (node_lock)
                {
                    oldNodes = this.nodes;
                    this.nodes = designer_nodes;
                }

                ModelMeta model = new ModelMeta();
                IndexNodes(this.nodes, model);

                oldNodes.ForEach(node => node.Dispose());
                designer_nodes.ForEach(node => node.ShowDiagnostics());
                RaiseNodesChanged(snapshot);
            }
        }
Exemple #10
0
        private static void IndexNodes(IEnumerable<DesignerNode> nodes, ModelMeta model)
        {
            foreach (var designerNode in nodes)
            {

                switch (designerNode.NodeType)
                {
                    case NodeType.TypeName:
                        // got the model
                        string modelText = designerNode.SnapshotSpan.GetText();
                        model.ModelClass = modelText;
                        break;
                    case NodeType.Reference:
                        // got the member
                        string memberText = designerNode.SnapshotSpan.GetText();
                        if(model.Members == null) model.Members = new List<string>();
                        model.Members.Add(memberText);
                        break;
                }

                if (designerNode.Children.Count > 0)
                {
                    IndexNodes(designerNode.Children, model);
                }
            }
        }