// If you have install the code sniplets, use "propvm + [tab] +[tab]" create a property propcmd for command
        // 如果您已经安装了 MVVMSidekick 代码片段,请用 propvm +tab +tab 输入属性 propcmd 输入命令

        //IDisposable _currentTaskListening;
        public MainWindow_Model()
        {
            if (IsInDesignMode)
            {
                Messages.Add(new Models.MessageEntry {
                    Time = DateTime.Now, Message = "Message Here"
                });
                return;
            }
            GreaterFileShare.Hosts.WPF.Services.FileSystemHubService.vmInstance = this;
            var source1 = GlobalEventRouter.GetEventChannel <Exception>()
                          .Select(x =>
            {
                Exception[] rval = new[] { x.EventData };
                if (x.EventData is AggregateException)
                {
                    return(rval.Union((x.EventData as AggregateException).InnerExceptions));
                }
                return(rval);
            })
                          .SelectMany(x => x)
                          .Select(x => x.Message);

            var source2 = GlobalEventRouter.GetEventChannel <string>()
                          .Where(x => x.EventName == "Logging")
                          .Select(x => x.EventData);
            var source3 = new WebLoggingSource();

            new[] { source1, source2, source3 }
            .ToObservable()
            .SelectMany(ms => ms)
            .Select(x => new MessageEntry {
                Time = DateTime.Now, Message = x
            })
            .ObserveOnDispatcher()
            .Subscribe(x =>
            {
                Messages.Add(x);
                if (Messages.Count > 500)
                {
                    Messages.RemoveAt(0);
                }

                CurrentMessageIndex = Messages.Count - 1;
            })
            .DisposeWith(this);
            //CurrentTask.DisposeWith(this);
        }
Пример #2
0
        public void Start(string path, int port)
        {
            try
            {
                if (IsHosting)
                {
                    throw new InvalidProgramException("Still Running, need shutdown first");
                }
                var l   = ServiceLocator.Instance.Resolve <ILauncher>();
                var cts = new CancellationTokenSource();

                var s = new Dictionary <string, string>();
                foreach (var item in this.AdditionalContentTypes)
                {
                    if (string.IsNullOrWhiteSpace(item.ExtensionName) || string.IsNullOrWhiteSpace(item.ContentType))
                    {
                        GlobalEventRouter.RaiseEvent(this, $"Hosting:\t\tContent Type entry Got Empty Field. Ignored. \r\n\t\t\t\t\t\t {{{nameof(item.ExtensionName)}:{item.ExtensionName ?? ""},{nameof(item.ContentType)}:{item.ContentType}}}", "Logging");
                    }
                    else if (s.ContainsKey(item.ExtensionName))
                    {
                        GlobalEventRouter.RaiseEvent(this, $"Hosting:\tContent Type entry Got Duplicate ExtensionName. Ignored.\r\n\t\t\t\t\t\t {{{nameof(item.ExtensionName)}:{item.ExtensionName ?? ""},{nameof(item.ContentType)}:{item.ContentType}}}", "Logging");
                    }
                    else
                    {
                        s.Add(item.ExtensionName, item.ContentType);
                    }
                }

                var t = l.RunWebsiteAsync(
                    path, port,
                    s,
                    cts.Token);

                SetupStarted(t, cts);
                IsHosting         = true;
                IsLastStartFailed = false;
            }
            catch (Exception ex)
            {
                this.LastException = ex;
                IsLastStartFailed  = true;
                GlobalEventRouter.RaiseEvent(this, ex);
            }
        }
Пример #3
0
 void SetupStarted(Task task, CancellationTokenSource cancelSource)
 {
     _task = task;
     _task?.ToObservable()
     .ObserveOnDispatcher()
     .Subscribe(
         e => { },
         e =>
     {
         if (!(e is TaskCanceledException))
         {
             IsLastStartFailed = true;
             LastException     = e;
             GlobalEventRouter.RaiseEvent(this, e);
         }
         IsHosting = false;
     },
         () =>
     {
         IsHosting = false;
     }
         );
     _cancelSource = cancelSource;
 }
Пример #4
0
 public void Start()
 {
     Start(this.Path, this.Port.Value);
     GlobalEventRouter.RaiseEvent(this, (ViewModel: this, Hosted: true), nameof(Start));
 }
Пример #5
0
 public void Stop()
 {
     _cancelSource?.Cancel();
     GlobalEventRouter.RaiseEvent(this, (ViewModel: this, Hosted: false), nameof(Stop));
 }