Exemplo n.º 1
0
        public static ITemplatesConfig ResolveTemplates(ProfileOptions options)
        {
            var templatesPath = options.Project.Templates;

            if (string.IsNullOrEmpty(templatesPath))
            {
                templatesPath = "asm://Conjure.EFX.DotNetTool/res.templates.yaml";
            }

            return(TemplatesConfig.Load(options, templatesPath,
                                        options.Options.ProfilePath));
        }
        public static void WriteAllTemplatesToXml(TemplatesConfig templateConfig, string xmlPath)
        {
            try
            {
                System.Xml.Serialization.XmlSerializer writer =
                    new System.Xml.Serialization.XmlSerializer(typeof(TemplatesConfig));

                System.IO.StreamWriter file = new System.IO.StreamWriter(
                    xmlPath);
                writer.Serialize(file, templateConfig);
                file.Close();
            }
            catch (Exception ex)
            {
                _log.Error("Error during writing xml: {0}", ex.Message);
            }
        }
        public static TemplatesConfig GetAllTemplatesFromXml(string xmlPath)
        {
            var templates = new TemplatesConfig();

            try
            {
                var reader     = new StreamReader(xmlPath);
                var serializer = new XmlSerializer(typeof(TemplatesConfig));
                templates = (TemplatesConfig)serializer.Deserialize(reader);
                reader.Close();
            }
            catch (Exception ex)
            {
                _log.Error("Deserialization to TemplatesConfig was failed. Error: {0}", ex.Message);
            }

            return(templates);
        }
        public void CreateTemplatesXml()
        {
            try
            {
                var templateIndex = 0;

                var updatedTemplates = new TemplatesConfig
                {
                    Templates = new Template[templatesValue.Values.ToArray <string>().Length]
                };

                // выбираем уже существующие данные из Templates.xml
                var templates = CustomXmlSerializer.GetAllTemplatesFromXml(_tempateXmlPath);

                // проходим по всем шаблонам, которые нужно обновлять
                foreach (var template in templatesValue)
                {
                    var updatesPath = Path.Combine(_updatesNodePath, template.Value, "info.xml");

                    // выгребаем новые обновления данного шаблона из info.xml
                    var templateUpdates = CustomXmlSerializer.GetTemplateUpdatesFromXml(updatesPath).Updates;

                    // выбираем данный шаблон из уже существующих данных из Templates.xml
                    var templateDetail = templates.Templates.FirstOrDefault(x => x.Name == template.Value);

                    if (templateUpdates == null)
                    {
                        _log.Error("Error by getting updates from xml: template - {0}", template);
                        throw new ArgumentNullException();
                    }

                    if (templateDetail == null)
                    {
                        _log.Error("Template {0} not found in xml", template.Value);
                        throw new ArgumentNullException();
                    }

                    // перезаполняем (обновляем)  детальную информацию по данному шаблону
                    var info = new Detail
                    {
                        IbName         = template.Key.ToString(),
                        ActualVersion  = templateUpdates.OrderByDescending(x => DateTime.Parse(x.Date)).FirstOrDefault().Version,
                        CurrentVersion = templateDetail.Detail.CurrentVersion,
                        LastUpdateDate = templateDetail.Detail.LastUpdateDate,
                        TemplatePath   = _templatesPath,
                        UpdatesPath    = Path.Combine(_updatesNodePath, template.Value),
                        UpdatesCount   = templateDetail.Detail.UpdatesCount,//templateUpdates.Length.ToString(),
                        Updates        = new TemplateUpdater.Models.TemplatesXmlModel.Update[templateUpdates.Length]
                    };

                    // заполняем список обновлений в Templates.xml обновлениями из info.xml
                    for (int i = 0; i < templateUpdates.Length; i++)
                    {
                        var update = templateUpdates[i];

                        info.Updates[i] = new Models.TemplatesXmlModel.Update()
                        {
                            ApplyVersions = update.ApplyVersions.OrderBy(x => x).ToArray <string>(),
                            UpdateDate    = update.Date,
                            UpdateVersion = update.Version,
                            Title         = update.Version
                        };
                    }


                    // добавляем сформированную информацию по шаблону к обновлённому списку шаблонов
                    updatedTemplates.Templates[templateIndex] = new Template
                    {
                        Detail = info,
                        Name   = template.Value
                    };

                    templateIndex++;
                }

                // сериализуем обновлённый список шаблонов снова в Templates.xml
                CustomXmlSerializer.WriteAllTemplatesToXml(updatedTemplates, _tempateXmlPath);
            }
            catch (Exception ex)
            {
                _log.Error("Creating Templates.xml ERROR: {0}", ex.Message);
            }
        }