Exemplo n.º 1
0
        double SumOfRange(GI.GraphColunm _Input, int _From, int _To, int _CurrentMode)
        {
            if (_To > _Input.GraphElements.Count)
            {
                _To = _Input.GraphElements.Count;
            }
            double ReturnVal = 0;

            for (int i = _From; i < _To; i++)
            {
                ReturnVal += _Input.GraphElements[i].Value[_CurrentMode];
            }
            return(ReturnVal);
        }
Exemplo n.º 2
0
        double SumOfList(GI.GraphColunm Values, int _CurrentMode)
        {
            if (Values.GraphElements == null)
            {
                return(0);
            }

            double Moment = 0;

            for (int i = 0; i < Values.GraphElements.Count; i++)
            {
                Moment += Values.GraphElements[i].Value[_CurrentMode];
            }
            return(Moment);
        }
Exemplo n.º 3
0
        async Task RunMainLoop(List <GI.GraphColunm> GraphData)
        {
            while (true)
            {
                if (ExitSave)
                {
                    if (!SaveComplete)
                    {
                        SaveAndLoadClass.SaveSettings(GraphData, this, DataCacheSize, CurrentGraphMode, CurrentThemeIndex);
                    }
                    SaveComplete = true;
                    while (true)
                    {
                        await Task.Delay(100);
                    }
                }

                if (ClearGraphData)
                {
                    GraphData.Clear();
                    ClearGraphData = false;
                    for (int i = 0; i < DataCacheSize; i++)
                    {
                        GraphData.Add(new GI.GraphColunm(DateTime.Now, new List <GI.GraphElement>()));
                    }
                }

                if (FlatlineGraphData)
                {
                    FlatlineGraphData = false;
                    for (int i = 1; i < DataCacheSize; i++)
                    {
                        GraphData[i] = new GI.GraphColunm(GraphData[0].TimeTable, GraphData[0].GraphElements);
                    }
                }

                GraphLoadingControl NewLoading = new GraphLoadingControl(GraphCanvas, GraphCanvas.ActualWidth, GraphCanvas.ActualHeight);
                GraphCanvas.Children.Add(NewLoading);

                GraphLoadingControl NewLoading2 = null;
                if (GMCValues.IsPieChartEnabled)
                {
                    NewLoading2 = new GraphLoadingControl(PieGraphCanvas, PieGraphCanvas.ActualWidth, PieGraphCanvas.ActualHeight);
                    PieGraphCanvas.Children.Add(NewLoading2);
                }

                if (ItemStack.Children.Count > 0)
                {
                    for (int i = 0; i < ItemStack.Children.Count; i++)
                    {
                        ItemDesign SenderDesign = ItemStack.Children[i] as ItemDesign;
                        SenderDesign.ResetWarningLabels();
                    }

                    GI.GraphColunm NewDataSet = new GI.GraphColunm(DateTime.Now, new List <GI.GraphElement>());
                    try
                    {
                        if (IsTimeOver(DateTime.Now, GraphData[0].TimeTable, TimeFrameCombobox.SelectedIndex) || ManualRefresh)
                        {
                            for (int i = 0; i < ItemStack.Children.Count; i++)
                            {
                                if (ExitSave)
                                {
                                    break;
                                }

                                ItemDesign SenderDesign = ItemStack.Children[i] as ItemDesign;

                                SenderDesign.URLErrorLabel.Foreground   = (Brush)Application.Current.FindResource("StandartItemDesignBadColor");
                                SenderDesign.XPathErrorLabel.Foreground = (Brush)Application.Current.FindResource("StandartItemDesignBadColor");

                                if (SenderDesign.ItemURLTextBox.Text != "" && SenderDesign.ItemXPathTextBox.Text != "")
                                {
                                    HtmlWeb      web = new HtmlWeb();
                                    HtmlDocument doc = await web.LoadFromWebAsync(SenderDesign.ItemURLTextBox.Text);

                                    SenderDesign.URLErrorLabel.Visibility = Visibility.Hidden;

                                    HtmlNode node = doc.DocumentNode.SelectSingleNode(SenderDesign.ItemXPathTextBox.Text.Replace("/tbody", ""));

                                    if (node == null)
                                    {
                                        break;
                                    }

                                    SenderDesign.XPathErrorLabel.Visibility = Visibility.Hidden;

                                    double[] NewData = new double[GraphModes.Count];
                                    for (int j = 0; j < GraphModes.Count; j++)
                                    {
                                        NewData[j] = RunCommandList(j, GraphModes[j].ValueProcessingList, node, GraphData, i);
                                    }

                                    NewDataSet.GraphElements.Add(new GI.GraphElement(NewData, SenderDesign.ItemNameTextBox.Text, (SolidColorBrush)SenderDesign.ItemFillColorButton.Background, (SolidColorBrush)SenderDesign.ItemBorderColorButton.Background));

                                    doc = null;
                                    GC.Collect();
                                }
                            }
                        }

                        if (!ExitSave)
                        {
                            if (IsTimeOver(DateTime.Now, GraphData[0].TimeTable, TimeFrameCombobox.SelectedIndex) || ManualRefresh)
                            {
                                for (int i = GraphData.Count - 1; i > 0; i--)
                                {
                                    GraphData[i] = GraphData[i - 1];
                                }
                                GraphData[0] = NewDataSet;
                            }

                            if (EqualizeColorsData)
                            {
                                EqualizeColorsData = false;
                                for (int i = 1; i < DataCacheSize; i++)
                                {
                                    for (int j = 0; j < ItemStack.Children.Count; j++)
                                    {
                                        int TargetJ = j;
                                        while (GraphData[i].GraphElements[TargetJ].Name != GraphData[0].GraphElements[j].Name)
                                        {
                                            TargetJ++;
                                            if (TargetJ > ItemStack.Children.Count - 1)
                                            {
                                                TargetJ = 0;
                                            }
                                            if (TargetJ == j)
                                            {
                                                break;
                                            }
                                        }
                                        GraphData[i].GraphElements[TargetJ] = new GI.GraphElement(GraphData[i].GraphElements[TargetJ].Value, GraphData[i].GraphElements[TargetJ].Name, GraphData[0].GraphElements[j].FillColor, GraphData[0].GraphElements[j].BorderColor);
                                    }
                                }
                            }

                            UpdateVisualData(GraphData);
                        }

                        SaveAndLoadClass.SaveSettings(GraphData, this, DataCacheSize, CurrentGraphMode, CurrentThemeIndex);
                        SettingsSavedLabel.Visibility = Visibility.Visible;
                        await GI.FadeIn(SettingsSavedLabel);

                        await Task.Delay(1000);

                        await GI.FadeOut(SettingsSavedLabel);

                        SettingsSavedLabel.Visibility = Visibility.Hidden;
                    }
                    catch
                    {
                        ErrorInLoading = true;
                    }
                }

                NewLoading.DoRemove();
                if (GMCValues.IsPieChartEnabled)
                {
                    NewLoading2.DoRemove();
                }

                ManualRefresh = false;

                if (ErrorInLoading)
                {
                    await Task.Delay(10000);

                    ErrorInLoading = false;
                }
                else
                {
                    await WaitUntil(TimeFrameCombobox.SelectedIndex, GraphData);
                }
            }
        }
Exemplo n.º 4
0
        public static void LoadSettings(List <GI.GraphColunm> GraphData, MainWindow SenderWindow, int DataCacheSize, int GraphModeCount)
        {
            try
            {
                FI SaveConfigs = new FI();
                SaveConfigs.LoadFromFile("cfg.txt");
                FI.CategoryData CurrentCategory = new FI.CategoryData("MainWindow Data", 0);
                Application.Current.MainWindow.Left             = SaveConfigs.FindtItemInItemstack_INT(CurrentCategory, new FI.ItemData("Location X", 0));
                Application.Current.MainWindow.Top              = SaveConfigs.FindtItemInItemstack_INT(CurrentCategory, new FI.ItemData("Location Y", 0));
                SenderWindow.TimeFrameCombobox.SelectedIndex    = SaveConfigs.FindtItemInItemstack_INT(CurrentCategory, new FI.ItemData("TimeFrame Index", 0));
                SenderWindow.TimeElementsCombobox.SelectedIndex = SaveConfigs.FindtItemInItemstack_INT(CurrentCategory, new FI.ItemData("Time Elements Index", 0));
                SenderWindow.CurrentGraphMode  = SaveConfigs.FindtItemInItemstack_INT(CurrentCategory, new FI.ItemData("Current Mode", 0));
                SenderWindow.CurrentThemeIndex = SaveConfigs.FindtItemInItemstack_INT(CurrentCategory, new FI.ItemData("Theme Index", 0));

                CurrentCategory = new FI.CategoryData("Item", 0);
                while (SaveConfigs.IsAnyMoreOfCat(CurrentCategory))
                {
                    GI.MakeNewItemPanel(
                        SenderWindow,
                        SaveConfigs.FindtItemInItemstack_STR(CurrentCategory, new FI.ItemData("Name", 0)),
                        SaveConfigs.FindtItemInItemstack_STR(CurrentCategory, new FI.ItemData("URL", 0)),
                        SaveConfigs.FindtItemInItemstack_STR(CurrentCategory, new FI.ItemData("XPath", 0)),
                        (SolidColorBrush)SaveConfigs.FindtItemInItemstack_BRS(CurrentCategory, new FI.ItemData("BorderColor", 0)),
                        (SolidColorBrush)SaveConfigs.FindtItemInItemstack_BRS(CurrentCategory, new FI.ItemData("FillColor", 0)),
                        true
                        );

                    CurrentCategory.Offset++;
                }

                CurrentCategory = new FI.CategoryData("HistoricData", 0);
                while (SaveConfigs.IsAnyMoreOfCat(CurrentCategory))
                {
                    GI.GraphColunm NewData = new GI.GraphColunm();
                    NewData.TimeTable     = SaveConfigs.FindtItemInItemstack_DAT(CurrentCategory, new FI.ItemData("Timestamp", 0));
                    NewData.GraphElements = new List <GI.GraphElement>();

                    FI.ItemData MomentItem = new FI.ItemData("Name", 0);
                    while (SaveConfigs.IsAnyMoreWithinCat(CurrentCategory, MomentItem))
                    {
                        GI.GraphElement NewElement = new GI.GraphElement();
                        NewElement.Name = SaveConfigs.FindtItemInItemstack_STR(CurrentCategory, MomentItem);
                        double[] MomentValues = new double[2];
                        MomentValues[0]        = SaveConfigs.FindtItemInItemstack_INT(CurrentCategory, new FI.ItemData("Value1", MomentItem.Offset));
                        MomentValues[1]        = SaveConfigs.FindtItemInItemstack_INT(CurrentCategory, new FI.ItemData("Value2", MomentItem.Offset));
                        NewElement.Value       = MomentValues;
                        NewElement.BorderColor = (SolidColorBrush)SaveConfigs.FindtItemInItemstack_BRS(CurrentCategory, new FI.ItemData("BorderColor", MomentItem.Offset));
                        NewElement.FillColor   = (SolidColorBrush)SaveConfigs.FindtItemInItemstack_BRS(CurrentCategory, new FI.ItemData("FillColor", MomentItem.Offset));
                        NewData.GraphElements.Add(NewElement);

                        MomentItem.Offset++;
                    }

                    GraphData[CurrentCategory.Offset] = NewData;
                    CurrentCategory.Offset++;
                }
            }
            catch
            {
                MessageBox.Show("Could not load cfg");
                Application.Current.Shutdown();
            }
        }