Esempio n. 1
0
        private void Run_UpdateStats(object sender, RoutedEventArgs e)
        {
            UC_RunBook_Item reporter = sender as UC_RunBook_Item;

            Total               += reporter.ElapsedTime;
            Succeed             += reporter.Succeed;
            Failed              += reporter.Failed;
            ElapsedTime         += reporter.ElapsedTime;
            AverageTime         += reporter.AverageTime;
            DeliveredPercentage += reporter.DeliveredPercentage;

            TB_NMessages.Text   = string.Format(CultureInfo.InvariantCulture, "{0:### ### ###.#}", Total).Trim();
            TB_N_Delivered.Text = string.Format(CultureInfo.InvariantCulture, "{0:###}", DeliveredPercentage);
            TB_N_AVG.Text       = TextHandler.GetTimeFormattedFromMilseconds(AverageTime);
            TB_N_Elapsed.Text   = TextHandler.GetTimeFormattedFromMilseconds(ElapsedTime);
            TB_N_Failed.Text    = string.Format(CultureInfo.InvariantCulture, "{0:### ### ###.#}", Failed).Trim();
            TB_N_Succeed.Text   = string.Format(CultureInfo.InvariantCulture, "{0:### ### ###.#}", Succeed).Trim();
        }
Esempio n. 2
0
        private async void DoWork()
        {
            int index = 1;

            KeyValuePair <bool, string> result = new KeyValuePair <bool, string>();

            double stopAt = Math.Floor(Item.Devices.Count / Item.NRuns);

            foreach (var device in Item.Devices)
            {
                if (Status.Equals(RunBookItem.Status.STP))
                {
                    Status = RunBookItem.Status.STP;
                    SetStatusControlsStyle();
                    return;
                }

                Stopwatch timer = new Stopwatch();

                timer.Start();

                while (Status.Equals(RunBookItem.Status.PAU))
                {
                    await Task.Run(() => Thread.Sleep(1000)).ConfigureAwait(false);

                    Debug.WriteLine("PAUSED...");
                }

                if (index % stopAt == 0)
                {
                    Status = RunBookItem.Status.WAI;
                    SetStatusControlsStyle();

                    await Task.Run(() => Thread.Sleep((int)Item.NSeconds * 1000)).ConfigureAwait(false);

                    Status = RunBookItem.Status.RUN;
                    SetStatusControlsStyle();
                }

                switch (Item.D2CMessagesKind)
                {
                case D2CMessagesConfig.Kind.REG:
                    result = ExedraLibCoreHandler.RegisterDevice(device.DeviceName, new BasicGeoposition()
                    {
                        Latitude = device.DevicePosition.Latitude, Longitude = device.DevicePosition.Longitude
                    }, Item.Environment);
                    break;

                case D2CMessagesConfig.Kind.TEL:
                    result = ExedraLibCoreHandler.SendDimmingProfile(device.DeviceID, DateTime.Now, 100, 0, 0, 0, 0, Item.Environment);
                    break;

                case D2CMessagesConfig.Kind.ALR:
                    result = ExedraLibCoreHandler.SendAlarm(device.DeviceID, DateTime.Now, 0, Item.Environment);
                    break;

                case D2CMessagesConfig.Kind.BTEL:
                    result = ExedraLibCoreHandler.SendDimmingProfile(device.DeviceID, DateTime.Now, 100, 0, 0, 0, 0, Item.Environment);
                    break;

                case D2CMessagesConfig.Kind.BALR:
                    result = ExedraLibCoreHandler.SendAlarm(device.DeviceID, DateTime.Now, 0, Item.Environment);
                    break;

                case D2CMessagesConfig.Kind.BREG:
                    result = ExedraLibCoreHandler.RegisterDevice(device.DeviceName, new BasicGeoposition()
                    {
                        Latitude = device.DevicePosition.Latitude, Longitude = device.DevicePosition.Longitude
                    }, Item.Environment);
                    break;

                default:
                    Debug.WriteLine($"DoWork() -> {Item.D2CMessagesKind}");
                    break;
                }

                if (!result.Key)
                {
                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                                                                                                                () =>
                    {
                        Failed++;
                        TB_N_Failed.Text = string.Format(CultureInfo.InvariantCulture, "{0:### ### ###.#}", Failed).Trim();
                    });
                }
                else
                {
                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                                                                                                                () =>
                    {
                        Succeed++;
                        TB_N_Succeed.Text = string.Format(CultureInfo.InvariantCulture, "{0:### ### ###.#}", Succeed).Trim();
                    });

                    Debug.WriteLine(result.Value);
                }

                timer.Stop();

                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                                                                                                            () =>
                {
                    ElapsedTime        += timer.ElapsedMilliseconds;
                    AverageTime         = ElapsedTime / index;
                    DeliveredPercentage = Math.Round((double)index / Item.NMessages * 100, 0);
                    double elapsedTime  = Math.Round((double)ElapsedTime / 1000, 2);

                    TB_N_Delivered.Text = string.Format(CultureInfo.InvariantCulture, "{0:###}", DeliveredPercentage);
                    TB_N_AVG.Text       = TextHandler.GetTimeFormattedFromMilseconds(AverageTime);
                    TB_N_Elapsed.Text   = TextHandler.GetTimeFormattedFromMilseconds(ElapsedTime);
                });

                index++;
            }

            Status = RunBookItem.Status.FIN;
            SetStatusControlsStyle();

            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                                                                                                        () =>
            {
                SB_DoWork_Done.Begin();
            });
        }