Пример #1
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);
            }
        }
Пример #2
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;
 }
Пример #3
0
 public void Start()
 {
     Start(this.Path, this.Port.Value);
     GlobalEventRouter.RaiseEvent(this, (ViewModel: this, Hosted: true), nameof(Start));
 }
Пример #4
0
 public void Stop()
 {
     _cancelSource?.Cancel();
     GlobalEventRouter.RaiseEvent(this, (ViewModel: this, Hosted: false), nameof(Stop));
 }