Ejemplo n.º 1
0
 public Element(String number, String name, String symbol, String electronDistrib, String atomicWeight, ElementCategory category, String group, String period, String history)
 {
     this._number          = number;
     this._name            = name;
     this._symbol          = symbol;
     this._electronDistrib = electronDistrib;
     this._atomicWeight    = atomicWeight;
     this._category        = category;
     this._group           = group;
     this._period          = period;
     this._history         = history;
 }
Ejemplo n.º 2
0
        public async Task <bool> LoadElements()
        {
            try
            {
                String ITEM_CONTENT = String.Format("{0}\n\n{0}\n\n{0}\n\n{0}\n\n{0}",
                                                    "Curabitur class aliquam vestibulum nam curae maecenas sed integer cras phasellus suspendisse quisque donec dis praesent accumsan bibendum pellentesque condimentum adipiscing etiam consequat vivamus dictumst aliquam duis convallis scelerisque est parturient ullamcorper aliquet fusce suspendisse nunc hac eleifend amet blandit facilisi condimentum commodo scelerisque faucibus aenean ullamcorper ante mauris dignissim consectetuer nullam lorem vestibulum habitant conubia elementum pellentesque morbi facilisis arcu sollicitudin diam cubilia aptent vestibulum auctor eget dapibus pellentesque inceptos leo egestas interdum nulla consectetuer suspendisse adipiscing pellentesque proin lobortis sollicitudin augue elit mus congue fermentum parturient fringilla euismod feugiat");

                string DataFolder = Path.Combine("Assets", "Data");

                string InitMainChartFileName   = Path.Combine(DataFolder, (string)Application.Current.Resources["properties-initMainChart"]);
                string InitSeriesChartFileName = Path.Combine(DataFolder, (string)Application.Current.Resources["properties-initSeriesChart"]);

                string AtomicFileName  = Path.Combine(DataFolder, (string)Application.Current.Resources["properties-atomic"]);
                string GeneralFileName = Path.Combine(DataFolder, (string)Application.Current.Resources["properties-general"]);

                string MiscFileName = Path.Combine(DataFolder, (string)Application.Current.Resources["properties-misc"]);

                StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;

                ElementCategory category;

                // Main Elements
                StorageFile file = await folder.GetFileAsync(InitMainChartFileName);

                XDocument doc = await GetXDocument(file);

                Element element;

                var groups = doc.Element("data").Elements("element").GroupBy(t => t.Element("category").Value);
                foreach (var categoryNode in groups)
                {
                    category = new ElementCategory(categoryNode.Key);

                    foreach (var node in categoryNode)
                    {
                        element = new Element(
                            node.Element("number").Value,
                            node.Element("name").Value,
                            node.Element("symbol").Value,
                            node.Element("electron_distrib").Value,
                            node.Element("atomic_weight").Value,
                            category,
                            node.Element("group").Value,
                            node.Element("period").Value,
                            ITEM_CONTENT);

                        _elements.Add(element);

                        category.Elements.Add(element);
                    }

                    _categories.Add(category);
                }

                _elements = _elements.OrderBy(t => int.Parse(t.Number)).ToList();

                // Series Elementss
                file = await folder.GetFileAsync(InitSeriesChartFileName);

                doc = await GetXDocument(file);

                foreach (var categoryNode in doc.Element("data").Elements("element").GroupBy(t => t.Element("category").Value))
                {
                    category = new ElementCategory(categoryNode.Key);

                    foreach (var node in categoryNode)
                    {
                        element = new Element(
                            node.Element("number").Value,
                            node.Element("name").Value,
                            node.Element("symbol").Value,
                            node.Element("electron_distrib").Value,
                            node.Element("atomic_weight").Value,
                            category,
                            node.Element("group").Value,
                            node.Element("period").Value,
                            ITEM_CONTENT);

                        _elements.Add(element);

                        category.Elements.Add(element);
                    }

                    _categories.Add(category);
                }

                // General Properties
                file = await folder.GetFileAsync(GeneralFileName);

                doc = await GetXDocument(file);

                foreach (var node in doc.Element("data").Elements("element"))
                {
                    element = _elements.FirstOrDefault(t => t.Number == node.Element("number").Value);
                    if (element != null)
                    {
                        foreach (var propertyNode in node.Elements("property"))
                        {
                            element.Properties.Add(new ElementProperty(
                                                       propertyNode.Element("label").Value,
                                                       propertyNode.Element("value").Value));
                        }
                    }
                }

                // Atomic Properties
                file = await folder.GetFileAsync(AtomicFileName);

                doc = await GetXDocument(file);

                foreach (var node in doc.Element("data").Elements("element"))
                {
                    element = _elements.FirstOrDefault(t => t.Number == node.Element("number").Value);
                    if (element != null)
                    {
                        foreach (var propertyNode in node.Elements("property"))
                        {
                            element.Properties.Add(new ElementProperty(
                                                       propertyNode.Element("label").Value,
                                                       propertyNode.Element("value").Value));
                        }
                    }
                }

                // Miscelaneous Properties
                file = await folder.GetFileAsync(MiscFileName);

                doc = await GetXDocument(file);

                foreach (var node in doc.Element("data").Elements("element"))
                {
                    element = _elements.FirstOrDefault(t => t.Number == node.Element("number").Value);
                    if (element != null)
                    {
                        foreach (var propertyNode in node.Elements("property"))
                        {
                            element.Properties.Add(new ElementProperty(
                                                       propertyNode.Element("label").Value,
                                                       propertyNode.Element("value").Value));
                        }
                    }
                }

                // Ajuste de posições no grid
                int maxPeriod = _elements.Max(t => t.Period);
                int maxGroup  = _elements.Max(t => t.Group);
                int level     = 0;
                for (int i = 1; i <= maxPeriod; i++)
                {
                    for (int j = 1; j <= maxGroup; j++)
                    {
                        if (!_elements.Any(t => t.Period == i && t.Group == j))
                        {
                            _elements.Insert(level, new Element("", "", "", "", "", new ElementCategory("empty"), "", "", ""));
                        }

                        level++;
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }