Ejemplo n.º 1
0
        public ServerInfoControl(ServerMonitorModel model)
        {
            InitializeComponent();

            _model      = model;
            DataContext = _model;
            Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
        }
Ejemplo n.º 2
0
 protected virtual void DisposeManagedResources()
 {
     if (_model != null)
     {
         _model.Dispose();
         _model.Cleanup();
         _model = null;
     }
 }
Ejemplo n.º 3
0
        protected virtual void DisposeManagedResources()
        {
            if (_model != null)
            {
                _model.Dispose();
                _model.Cleanup();
                _model = null;
            }

            Dispatcher.ShutdownStarted -= Dispatcher_ShutdownStarted;
        }
Ejemplo n.º 4
0
        private static ServerMonitorModel OpenServerInfo(ServerInfo obj, ILog log)
        {
            var model = new ServerMonitorModel(obj, log, true);

            model.ChatViewModel.ChatMessageEventHandler += (s, e) =>
            {
                Console.WriteLine(@"{0} {1:t}:{2}", model.CurrentServer.Name, e.Message.Date.ToLocalTime(), e.Message);
                Console.WriteLine();
            };

            return(model);
        }
Ejemplo n.º 5
0
 private static void Run(ServerMonitorModel model)
 {
     while (true)
     {
         if (!model.Connected)
         {
             model.Connect();
             Console.WriteLine(@"Connectiong to {0}", model.CurrentServer.Name);
         }
         Thread.Sleep(123000);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Handles the NotifyCollectionChangedEventArgs event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event.</param>
        /// <param name="region">The region.</param>
        /// <param name="regionTarget">The region target.</param>
        void OnViewsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, IRegion region, DockingManager regionTarget)
        {
            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (var eOldItem in e.OldItems)
                {
                    var disposables = new[]
                    {
                        eOldItem as IDisposable,
                        (eOldItem as FrameworkElement)?.DataContext as IDisposable,
                        (eOldItem as ContentControl)?.Content as IDisposable,
                        ((eOldItem as ContentControl)?.Content as FrameworkElement)?.DataContext as IDisposable
                    };

                    foreach (var disposable in disposables)
                    {
                        disposable?.Dispose();
                    }
                }
            }

            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (FrameworkElement item in e.NewItems)
                {
                    UIElement view = item;

                    if (view != null)
                    {
                        //Create a new layout document to be included in the LayoutDocuemntPane (defined in xaml)
                        LayoutDocument newLayoutDocument = new LayoutDocument();
                        //Set the content of the LayoutDocument
                        newLayoutDocument.Content = item;
                        newLayoutDocument.Title   = (item.DataContext as ITitledItem)?.Title;

                        ServerMonitorModel viewModel = item.DataContext as ServerMonitorModel;
                        if (viewModel != null)
                        {
                            //All my viewmodels have properties DisplayName and IconKey
                            newLayoutDocument.Title = viewModel.CurrentServer.Name;
                            viewModel.OpenServer();
                            newLayoutDocument.Closed += (s, a) =>
                            {
                                Task.Factory.StartNew(() =>
                                {
                                    viewModel.CloseServer();
                                    viewModel.Cleanup();
                                });
                            };
                        }

                        //Store all LayoutDocuments already pertaining to the LayoutDocumentPane (defined in xaml)
                        List <LayoutDocument> oldLayoutDocuments = new List <LayoutDocument>();
                        //Get the current ILayoutDocumentPane ... Depending on the arrangement of the views this can be either
                        //a simple LayoutDocumentPane or a LayoutDocumentPaneGroup
                        ILayoutDocumentPane currentILayoutDocumentPane = (ILayoutDocumentPane)regionTarget.Layout.RootPanel.Children[0];

                        if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPaneGroup))
                        {
                            //If the current ILayoutDocumentPane turns out to be a group
                            //Get the children (LayoutDocuments) of the first pane
                            LayoutDocumentPane oldLayoutDocumentPane = (LayoutDocumentPane)currentILayoutDocumentPane.Children.ToList()[0];
                            foreach (LayoutDocument child in oldLayoutDocumentPane.Children)
                            {
                                oldLayoutDocuments.Insert(0, child);
                            }
                        }
                        else if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPane))
                        {
                            //If the current ILayoutDocumentPane turns out to be a simple pane
                            //Get the children (LayoutDocuments) of the single existing pane.
                            foreach (LayoutDocument child in currentILayoutDocumentPane.Children)
                            {
                                oldLayoutDocuments.Insert(0, child);
                            }
                        }

                        //Create a new LayoutDocumentPane and inserts your new LayoutDocument
                        LayoutDocumentPane newLayoutDocumentPane = new LayoutDocumentPane();
                        newLayoutDocumentPane.InsertChildAt(0, newLayoutDocument);

                        //Append to the new LayoutDocumentPane the old LayoutDocuments
                        foreach (LayoutDocument doc in oldLayoutDocuments)
                        {
                            newLayoutDocumentPane.InsertChildAt(0, doc);
                        }

                        //Traverse the visual tree of the xaml and replace the LayoutDocumentPane (or LayoutDocumentPaneGroup) in xaml
                        //with your new LayoutDocumentPane (or LayoutDocumentPaneGroup)
                        if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPane))
                        {
                            regionTarget.Layout.RootPanel.ReplaceChildAt(0, newLayoutDocumentPane);
                        }
                        else if (currentILayoutDocumentPane.GetType() == typeof(LayoutDocumentPaneGroup))
                        {
                            currentILayoutDocumentPane.ReplaceChild(currentILayoutDocumentPane.Children.ToList()[0], newLayoutDocumentPane);
                            regionTarget.Layout.RootPanel.ReplaceChildAt(0, currentILayoutDocumentPane);
                        }

                        newLayoutDocument.IsActive = true;
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public async Task <IActionResult> Get(ServerMonitorModel serverMonitor)
 {
     return(Ok(await _service.GetInfo(serverMonitor)));
 }
Ejemplo n.º 8
0
        public async Task <ServerInfoModel> GetInfo(ServerMonitorModel serverMonitor)
        {
            var responce = await ByondTopic.GetData(serverMonitor.Ip, serverMonitor.Port, GetStatusCommand);

            return(ParseByondResponce(responce));
        }