Example #1
0
        public TypeProvider(ILog logger)
        {
            this._name        = "TypeService";
            this._description = "Provides service to create instances of various project item types model.";
            this._collection  = new TypeModelCollection();
            this._logger      = logger;

            Logger.Info(this._name + "instance has been created successfully");
        }
        private TemplateModelCollection LoadAllTemplates()
        {
            try{
                XmlNodeList v_templateNodes = _document.SelectNodes("//Templates/Template");
                Logger.Info(String.Format("{0} templates found in the Xml document", v_templateNodes.Count));

                foreach (XmlNode v_xmlTemplate in v_templateNodes)
                {
                    ITemplate v_template = new TemplateModel();
                    int       id         = Convert.ToInt32(v_xmlTemplate.Attributes["Id"].Value);
                    v_template.TemplateId = id;
                    v_template.Name       = v_xmlTemplate.Attributes["Name"].Value;

                    Logger.Debug(String.Format("Template instance created for template with Id: [{0}] and Name: [{1}]",
                                               v_template.TemplateId, v_template.Name));

                    v_template.LanguageType             = v_xmlTemplate.Attributes["LanguageType"].Value;
                    v_template.Author                   = v_xmlTemplate.Attributes["Author"].Value;
                    v_template.Category                 = v_xmlTemplate.Attributes["Category"].Value;
                    v_template.Description              = v_xmlTemplate.Attributes["Description"].Value;
                    v_template.Revision                 = v_xmlTemplate.Attributes["Revision"].Value;
                    v_template.ReleaseDate              = GetReleaseDateFromString(v_xmlTemplate.Attributes["ReleaseDate"].Value);
                    v_template.WorkspaceAssembly        = v_xmlTemplate.Attributes["WorkspaceAssembly"].Value;
                    v_template.WorkspaceAssemblyPath    = v_xmlTemplate.Attributes["WorkspaceAssemblyPath"].Value;
                    v_template.WorkspaceRootNamespace   = v_xmlTemplate.Attributes["WorkspaceRootNamespace"].Value;
                    v_template.TypeObjectsAssembly      = v_xmlTemplate.Attributes["TypeObjectsAssembly"].Value;
                    v_template.TypeObjectsAssemblyPath  = v_xmlTemplate.Attributes["TypeObjectsAssemblyPath"].Value;
                    v_template.TypeObjectsRootNamespace = v_xmlTemplate.Attributes["TypeObjectsRootNamespace"].Value;

                    XmlNode projectsNode      = v_xmlTemplate.ChildNodes[0];
                    var     projectCollection = new TypeModelCollection();
                    PopulateProjects(projectsNode, projectCollection, v_template);
                    v_template.Projects = projectCollection;

                    this._templates.Add(v_template);
                    Logger.Debug(String.Format("{0} template has been added to the collection", v_template.Name));
                }
            }catch (Exception ex) {
                Logger.Error("Template load process has been failed due to following error =>", ex);
                throw ex;
            }

            return(this._templates);
        }
        private void PopulateProjects(XmlNode projectsNode, TypeModelCollection projectCollection, ITemplate p_template)
        {
            Logger.Info(String.Format("{0} projects found in template '{1}'", projectsNode.ChildNodes.Count, p_template.Name));

            foreach (XmlNode v_child in projectsNode.ChildNodes)
            {
                Logger.Debug(String.Format("Creating instance for object type => '{0}'", v_child.Name));

                IType v_type = GetTypeForName(v_child.Name, v_child.ChildNodes, p_template.TemplateId, p_template);
                v_type.Interface = _typeProvider.GetInterfaceTypeFromString(v_child.Attributes["interface"].Value,
                                                                            p_template.WorkspaceAssembly,
                                                                            p_template.WorkspaceAssemblyPath,
                                                                            p_template.WorkspaceRootNamespace);
                v_type.DisplayName = v_child.Attributes["name"].Value;
                v_type.TypeId      = Convert.ToInt32(v_child.Attributes["id"].Value);
                v_type.IconPath    = v_child.Attributes["icon"].Value;

                projectCollection.Add(v_type);
            }
            Logger.Info(String.Format("All projects have been loaded successfully from template '{0}'", p_template));
        }