コード例 #1
0
        public void Check()
        {
            IsBusy = true;

            //刷新账户信息
            Action action = () =>
            {
                bool isOpen = false;
                try
                {
                    isOpen = CommunicationProxy.GetCreditOpenStatus(true);
                }
                catch (Exception ex)
                {
                    UIManager.ShowErr(ex);
                }
                if (isOpen)
                {
                    var setVisible = new Action(() => { Visibility = System.Windows.Visibility.Collapsed; });
                    DispatcherHelper.UIDispatcher.BeginInvoke(setVisible);
                }
                else
                {
                    var setVisible = new Action(() => { Visibility = System.Windows.Visibility.Visible; });
                    DispatcherHelper.UIDispatcher.BeginInvoke(setVisible);
                }
            };

            Task.Factory.StartNew(action).ContinueWith(task =>
            {
                var setBusy = new Action(() => { IsBusy = false; });
                DispatcherHelper.UIDispatcher.Invoke(setBusy);
            });
        }
 public async Task <bool> ShutDownServer(string ip, uint port)
 {
     try
     {
         Thread.Sleep(30000);
         this.Clients.All.ChangeServer(ip, port);
         Server.ShutDown();
         if (await CommunicationProxy.ConnectToServer(ip, port))
         {
             BsaContext.Initialize(ip, BsaContext.GetUserName(), ApplicationRole.Client);
             MessageBox.Show("Sie sind jetz nicht mehr Server, sondern nur noch Client!");
             return(true);
         }
         else
         {
             MessageBox.Show("Der Wechsel hat nicht funktioniert! Bitte starten Sie neu und verbinden sich manuell!");
             Cursor.Current = Cursors.Default;
             return(false);
         }
     }
     catch (SystemException e)
     {
         return(false);
     }
 }
コード例 #3
0
ファイル: HomeViewModel.cs プロジェクト: goldmon/BPiaoBao
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void Initialize()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            Action action = () =>
            {
                CommunicateManager.Invoke <ITPosService>(service =>
                {
                    //获取帐户信息
                    AccountStatData = service.GetAccountStat();

                    //获取客服电话
                    var tempService = CommunicationProxy.GetCustomerService();
                    var serviceMode = tempService.HotlinePhone.FirstOrDefault(m => m.Key != null && m.Key.ToLower().Contains("pos"));
                    if (serviceMode != null)
                    {
                        ServiceHotline = serviceMode.Value;
                    }

                    //获取统计数据
                    int totalDays      = 7;//统计的天数
                    var tempServerData = service.GainStat(DateTime.Today.AddDays(-totalDays), DateTime.Now);
                    if (tempServerData == null)
                    {
                        return;
                    }

                    Collection <TradeStatDataObject> tempCollection = new Collection <TradeStatDataObject>();
                    for (int i = 0; i < totalDays; i++)
                    {
                        var tempDate    = DateTime.Today.AddDays(-totalDays + i + 1);
                        var serverModel = tempServerData.FirstOrDefault(m => m.Date.Year == tempDate.Year && m.Date.DayOfYear == tempDate.DayOfYear);

                        var displayModel  = new TradeStatDataObject();
                        displayModel.Date = tempDate;
                        if (serverModel != null)
                        {
                            displayModel.TradeGain  = serverModel.TradeGain;
                            displayModel.TradeMoney = serverModel.TradeMoney;
                            displayModel.TradeTimes = serverModel.TradeTimes;
                        }

                        tempCollection.Add(displayModel);
                    }
                    TradeStatData = tempCollection;
                }, UIManager.ShowErr);
            };

            Task.Factory.StartNew(action).ContinueWith((task) =>
            {
                Action setAction = () => { IsBusy = false; };
                DispatcherHelper.UIDispatcher.Invoke(setAction);
            });
        }
        public void SaveJob(Job job)
        {
            if (BsaContext.GetUserRole() != ApplicationRole.Standalone)
            {
                CommunicationProxy.SendJobChange(job);
            }

            if (BsaContext.GetUserRole() != ApplicationRole.Client)
            {
                this.SaveJobLocal(job);
            }
        }
コード例 #5
0
        public void SaveForces(Force forces)
        {
            if (BsaContext.GetUserRole() != ApplicationRole.Standalone)
            {
                CommunicationProxy.SendForceChanged(forces);
            }

            if (BsaContext.GetUserRole() != ApplicationRole.Client)
            {
                this.SaveForcesLocal(forces);
            }
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceCenterViewModel"/> class.
        /// </summary>
        public ServiceCenterViewModel()
        {
            if (IsInDesignMode)
            {
                return;
            }

            IsBusy = true;
            Action action = () =>
            {
                Customer = CommunicationProxy.GetCustomerService();
                if (Customer == null)
                {
                    UIManager.ShowMessage("获取信息失败");
                    return;
                }

                if (Customer.AdvisoryQQ == null)
                {
                    return;
                }

                Parallel.For(0, Customer.AdvisoryQQ.Count, delegate(int i)
                {
                    var model = new Usher()
                    {
                        Name = Customer.AdvisoryQQ[i].Key,
                        QQ   = Customer.AdvisoryQQ[i].Value
                    };

                    var uri            = GetImageUri(Customer.AdvisoryQQ[i].Value);
                    model.QQStateImage = uri;

                    DispatcherHelper.UIDispatcher.Invoke(new Action(() => Ushers.Add(model)));
                });
            };

            Task.Factory.StartNew(action).ContinueWith(task =>
            {
                Action setBusyAction = () => { IsBusy = false; };
                DispatcherHelper.UIDispatcher.Invoke(setBusyAction);
            });
        }
            private async Task <bool> ConnectToServerAsync()
            {
                string ipAddress = string.Empty;
                var    result    = this.InputBox("IP angeben", "Bitte geben Sie die neue IP Adresse an", ref ipAddress);

                if (result == DialogResult.OK)
                {
                    if (await CommunicationProxy.ConnectToServer(ipAddress, 8081) == false)
                    {
                        MessageBox.Show(
                            @"Die Anwendung konnte nicht mit dem angegebenen Server verbunden werden! Bitte überprüfen Sie ihre Angaben!");
                    }
                    else
                    {
                        return(true);
                    }
                }

                return(false);
            }
        public void ChangeToServer(string ipAddress)
        {
            if (ipAddress.Length > 15)
            {
                MessageBox.Show("Bitte wählen Sie eine IP Adresse aus");
                return;
            }

            if (Role == ApplicationRole.Client)
            {
                if (CommunicationProxy.PermitServerChange())
                {
                    Settings.Default.LastUserName      = this.UserName;
                    Settings.Default.LastServerAddress = this.IpAddress;
                    Settings.Default.Save();
                    switch (CommunicationProxy.AcquireServer(ipAddress))
                    {
                    case 0:

                        break;

                    case 1:
                        MessageBox.Show("Beim Serverwechsel ist ein Fehler aufgetreten!");
                        break;

                    case 2:
                        MessageBox.Show("Es ist ein Fehler aufgetreten, bitte nochmal versuchen!");
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("Der jetzige Server möchte nicht Client werden");
                }
            }
            else
            {
                MessageBox.Show("Sie sind bereits Server!");
            }
        }
コード例 #9
0
        public HomeViewModel()
        {
            Mediator.Register("GetAlarmSignals", GetAlarmSignals);
            Mediator.Register("GetAllSignals", GetAllSignals);
            Mediator.Register("SCADAData", GetSignalsFromProxy);
            Mediator.Register("NMSNetworkModelData", GetNetworkModelFromProxy);
            Mediator.Register("SCADACommanding", SCADACommanding);

            /*ClientSideProxy = new ClientSideProxy();
             * CalculationEnginePubSub = new CalculationEnginePubSub();
             * ClientSideProxy.StartServiceHost(CalculationEnginePubSub);
             * ClientSideProxy.Subscribe(1);*/

            proxy = new CommunicationProxy();
            proxy.Open();

            Points = new List <DataPoint>();

            #region TreeView
            EnergyNetworks = new List <EnergyNetwork>()
            {
                new EnergyNetwork()
            };
            EnergyNetworkCommand      = new MyICommand <long>(myEnergyNetworkCommand);
            GeographicalRegionCommand = new MyICommand <long>(myGeographicalRegionCommand);
            SubstationCommand         = new MyICommand <long>(mySubstationCommand);
            FeederCommand             = new MyICommand <long>(myFeederCommand);
            #endregion

            #region Model Management
            IsMenuOpen  = true;
            _dataSource = new[]
            {
                new SampleGroupVm
                {
                    Name  = "Model Management",
                    Items = new[]
                    {
                        new SampleVm("CIM Profile Creator", typeof(View.CimProfileCreator)),
                        new SampleVm("Create/Apply Delta", typeof(View.CreateApplyDelta))
                    }
                },
                new SampleGroupVm
                {
                    Name  = "Create new entites",
                    Items = new []
                    {
                        new SampleVm("Terminal", typeof(View.AddNewTerminal)),
                        new SampleVm("Connectivity Node", typeof(View.AddNewConnectivityNode)),
                        new SampleVm("Energy Consumer", typeof(View.AddNewEnergyConsumer)),
                        new SampleVm("Synchronous Machine", typeof(View.AddNewGenerator)),
                        new SampleVm("Breaker", typeof(View.AddNewBreaker)),
                        new SampleVm("Geographical Region", typeof(View.AddNewGeoRegion)),
                        new SampleVm("Analog Signal", typeof(View.AddNewAnalogSignal)),
                        new SampleVm("Digital Signal", typeof(View.AddNewDigitalSignal)),
                        new SampleVm("Feeder", typeof(View.AddNewFeederObject)),
                        new SampleVm("Substation", typeof(View.AddNewSubstation)),
                    }
                }
            };

            _samples = _dataSource;
            #endregion
            #region Scada
            IsMenuOpen2  = true;
            _dataSource2 = new[]
            {
                new SampleGroupVm
                {
                    Name  = "Data",
                    Items = new []
                    {
                        new SampleVm("SCADA Data", typeof(View.SCADAView)),
                        new SampleVm("SCADA Alarms", typeof(View.Alarms)),
                    }
                }
            };

            _samples2 = _dataSource2;
            #endregion
            #region Monitoring
            IsMenuOpen3  = true;
            _dataSource3 = new[]
            {
                new SampleGroupVm
                {
                    Name  = "Create new entites",
                    Items = new []
                    {
                        new SampleVm("Terminal", typeof(View.AddNewTerminal)),
                    }
                }
            };

            _samples3 = _dataSource3;
            #endregion
            #region Loggs
            IsMenuOpen4  = true;
            _dataSource4 = new[]
            {
                new SampleGroupVm
                {
                    Name  = "Loggs",
                    Items = new[]
                    {
                        new SampleVm("SCADA Loggs", typeof(View.SCADALoggs)),
                        new SampleVm("Calculate Engine Loggs", typeof(View.CELoggs)),
                        new SampleVm("NMS Loggs", typeof(View.NMSLoggs)),
                        new SampleVm("Transaction Manager Loggs", typeof(View.TMLoggs)),
                        new SampleVm("UI Loggs", typeof(View.UILoggs)),
                    }
                },
            };

            _samples4 = _dataSource4;
            #endregion

            Logger.Log("UI is started.", DERMSCommon.Enums.Component.UI, DERMSCommon.Enums.LogLevel.Info);
        }
コード例 #10
0
        public void GetCoordinatesOnMouseClick(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            UIElement           iElement = null;
            UIElementCollection ee       = ((Map)sender).Children;

            foreach (UIElement uIElement in ee)
            {
                if (uIElement.IsMouseOver)
                {
                    iElement = uIElement;
                    break;
                }
            }

            if (iElement == null)
            {
                return;
            }

            TreeNode <NodeData> selected = _tree.Where(x => x.Data.IdentifiedObject.GlobalId.ToString() == iElement.Uid).FirstOrDefault();

            if (selected.Data.Type == DMSType.BREAKER)
            {
                Breaker breaker = (Breaker)selected.Data.IdentifiedObject;
                Window  window  = new BreakerControlThroughGISWindow();
                long    GIDm    = breaker.Measurements.FirstOrDefault();

                Discrete discrete = (Discrete)Tree.Where(t => t.Data.IdentifiedObject.GlobalId == GIDm).FirstOrDefault().Data.IdentifiedObject;

                if (discrete.NormalValue == 0)
                {
                    ((BreakerControlThroughGISWindowViewModel)window.DataContext).Close = true;
                }
                else
                {
                    ((BreakerControlThroughGISWindowViewModel)window.DataContext).Open = true;
                }

                ((BreakerControlThroughGISWindowViewModel)window.DataContext).GID = breaker.GlobalId;

                window.Show();
            }
            else if (selected.Data.Type == DMSType.GENERATOR)
            {
                bool      canManualCommand = true;
                string    text             = "";
                Generator generator        = (Generator)selected.Data.IdentifiedObject;
                proxy = new CommunicationProxy();
                proxy.Open2();
                TurnedOffGenerators = proxy.sendToCE.GeneratorOffCheck();
                foreach (Generator g in TurnedOffGenerators)
                {
                    if (g.GlobalId.Equals(generator.GlobalId))
                    {
                        canManualCommand = false;
                        //return;
                    }
                }
                if (canManualCommand)
                {
                    Window w = new ManualCommandingWindow(generator.MaxFlexibility, generator.MinFlexibility, selected.Data.IdentifiedObject.GlobalId);
                    w.Show();
                }
                else
                {
                    text = "Generator is disconnected from network";
                    PopUpWindow popUpWindow = new PopUpWindow(text);
                    popUpWindow.ShowDialog();
                }
            }
        }
            public DisconnectMessageBox()
            {
                this.reconnectButton.Text    = @"Erneut verbinden";
                this.getServerButton.Text    = @"Server werden";
                this.connectOtherButton.Text = @"Mit anderem Server verbinden";

                this.reconnectButton.Click += async(a, b) =>
                {
                    this.ChangeButtonIsEnabled(false);
                    var success = await CommunicationProxy.ConnectToServer(BsaContext.GetURL(), 8081);

                    if (success)
                    {
                        this.Close();
                    }

                    this.ChangeButtonIsEnabled(true);
                };

                this.getServerButton.Click += (a, b) =>
                {
                    this.ChangeButtonIsEnabled(false);
                    if (UacHelper.RestartWithAdminRights("") == false)
                    {
                        this.ChangeButtonIsEnabled(true);
                        return;
                    }

                    Process.GetCurrentProcess().Kill();
                };

                this.connectOtherButton.Click += async(a, b) =>
                {
                    this.ChangeButtonIsEnabled(false);
                    var success = await this.ConnectToServerAsync();

                    if (success == false)
                    {
                        this.ChangeButtonIsEnabled(true);
                    }
                    else
                    {
                        this.Close();
                    }
                };

                var l = new Label {
                    Text = @"Die Verbindung zum Server ist getrennt. Was möchten Sie jetzt tun?"
                };

                l.SetBounds(100, 30, 450, 50);
                this.reconnectButton.SetBounds(50, 100, 150, 50);
                this.getServerButton.SetBounds(250, 100, 150, 50);
                this.connectOtherButton.SetBounds(450, 100, 150, 50);

                this.connectOtherButton.Anchor = this.connectOtherButton.Anchor | AnchorStyles.Right;
                this.reconnectButton.Anchor    = AnchorStyles.Bottom | AnchorStyles.Right;
                this.getServerButton.Anchor    = AnchorStyles.Bottom | AnchorStyles.Right;
                this.Text       = @"Fehler";
                this.ClientSize = new Size(650, 200);
                this.Controls.AddRange(new Control[] { l, this.reconnectButton, this.getServerButton, this.connectOtherButton });
                this.FormBorderStyle = FormBorderStyle.FixedDialog;
                this.StartPosition   = FormStartPosition.CenterScreen;
                this.MinimizeBox     = false;
                this.MaximizeBox     = false;

                this.ShowDialog();
            }