Ejemplo n.º 1
0
        public async Task <DesignPatternFile> Parse(StorageFile file)
        {
            var readFile = await _fileManager.ReadFile(file.Name, await _fileManager.GetDesignPatternsTemplatesPath());

            var doc           = XDocument.Parse(readFile);
            var designPattern = doc.Descendants("DesignPattern").FirstOrDefault();

            if (designPattern == null)
            {
                throw new Exception("Design Pattern node not found in file " + file.Name);
            }

            var fileName     = designPattern.Attribute("name").Value;
            var type         = designPattern.Attribute("type").Value;
            var description  = designPattern.Descendants("Description").FirstOrDefault().Value;
            var modifiedDate = (await file.GetBasicPropertiesAsync()).DateModified;

            var dpFile = new DesignPatternFile
            {
                Description       = description,
                DesignPatternName = fileName,
                DesignPatternType = type,
                Path         = file.Name,
                ModifiedDate = modifiedDate
            };

            return(dpFile);
        }
Ejemplo n.º 2
0
        private async Task <IEnumerable <DesignPatternFile> > UpdateDesignPatternsFile()
        {
            var designPatternFiles = new List <DesignPatternFile>();

            try
            {
                var designPatternsXml = new XDocument(
                    new XDeclaration("1.0", "utf-8", "yes"),
                    new XElement("DesignPatterns")
                    );
                var files = await GetDesignPatternsFiles();

                var i = 0;
                foreach (var f in files)
                {
                    var readFile = await _fileManager.ReadFile(f.Name, await _fileManager.GetDesignPatternsTemplatesPath());

                    var doc           = XDocument.Parse(readFile);
                    var designPattern = doc.Descendants("DesignPattern").FirstOrDefault();
                    var fileName      = designPattern.Attribute("name").Value;
                    var type          = designPattern.Attribute("type").Value;
                    var description   = designPattern.Descendants("Description").FirstOrDefault();
                    var modifiedDate  = (await f.GetBasicPropertiesAsync()).DateModified;

                    var xmlFile = new XElement("DesignPattern",
                                               new XElement("Name", fileName,
                                                            new XAttribute("modifiedDate", modifiedDate)),
                                               new XElement("Description", description.Value.Trim()),
                                               new XElement("type", type));
                    designPatternsXml.Element("DesignPatterns").Add(xmlFile);

                    var designPatternFile = new DesignPatternFile
                    {
                        Id                = i,
                        Description       = description.Value.Trim(),
                        DesignPatternName = fileName,
                        DesignPatternType = type,
                        Path              = f.Name
                    };
                    designPatternFiles.Add(designPatternFile);
                    i++;
                }
                await _fileManager.CreateFile("DesignPatternsList.dsxml", await _fileManager.GetDesignPatternsTemplatesPath(),
                                              designPatternsXml.ToString());
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }


            return(designPatternFiles);
        }