Ejemplo n.º 1
0
        private void InitServer()
        {
            if (server != null)
            {
                server.Dispose();
            }

            server = webServerGenerator.GenerateInstance();
            server.StartWebServer(ipFinderResult.MyIP, Constants.CommunicationPort);
        }
Ejemplo n.º 2
0
        protected override void OnExit(ExitEventArgs e)
        {
            base.OnExit(e);
            IWebServer httpServer = ServiceLocator.Current.GetInstance <IWebServer>();

            httpServer.Dispose();

            IDocumentService docService = ServiceLocator.Current.GetInstance <IDocumentService>();

            docService.Dispose();
        }
Ejemplo n.º 3
0
 private void StopEverything()
 {
     if (_controller != null)
     {
         _controller.Stop();
         _controller.Dispose();
         _controller = null;
     }
     if (_webServer != null)
     {
         _webServer.Stop();
         _webServer.Dispose();
         _webServer = null;
     }
     _factory.CreateGarbage().Collect();
 }
Ejemplo n.º 4
0
        protected override void OnExit(ExitEventArgs e)
        {
            GlobalData.SetCulture();

            base.OnExit(e);

            IUpdateService updateService = ServiceLocator.Current.GetInstance <IUpdateService>();

            updateService.Dispose();

            IWebServer httpServer = ServiceLocator.Current.GetInstance <IWebServer>();

            httpServer.Dispose();

            IDocumentService docService = ServiceLocator.Current.GetInstance <IDocumentService>();

            docService.Dispose();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Stops this instance.
        /// </summary>
        public void Stop()
        {
            try
            {
                lock (_locker)              //prevent stop being called before start finishes
                {
                    _cancelToken?.Cancel(); //request that the web server stop
                    _webServerTask?.Wait(); //queue has shutdown - now shutdown the web server

                    //server must be disposed to release the TCP port(s)
                    _server?.Dispose();
                    _cancelToken?.Dispose();
                }
            }
            catch (Exception error)
            {
                Log.Logger.Fatal(error, $"A fatal error has occured while stopping {error}");
            }
        }
Ejemplo n.º 6
0
        // files must be a list to make the function predictable. (As we modify the FileSendInfo objects by calling their InitSlicingAsync() funciton)
        public async Task <FileTransferResult> Send(List <FileSendInfo> files, CancellationToken cancellationToken = default(CancellationToken))
        {
            IWebServer server = null;

            var transferProgress = new FileSendProgressCalculator(Constants.FileSliceMaxLength);

            transferProgress.FileTransferProgress += TransferProgress_FileTransferProgress;

            try
            {
                transferTcs = new TaskCompletionSource <FileTransferResult>();
                timeoutTcs  = new TaskCompletionSource <FileTransferResult>();
                var sessionKey = Guid.NewGuid().ToString();

                var myIp = await handshaker.Handshake(cancellationToken);

                if (myIp.Length == 0)
                {
                    return(FileTransferResult.FailedOnHandshake);
                }
                if (cancellationToken.IsCancellationRequested)
                {
                    return(FileTransferResult.Cancelled);
                }

                server = InitServer(myIp, Constants.CommunicationPort);
                await InitFileReceiveEndpoints(server, files, transferProgress, cancellationToken);
                await InitGenericEndpoints(server, sessionKey, myIp, files, cancellationToken);

                if (cancellationToken.IsCancellationRequested)
                {
                    return(FileTransferResult.Cancelled);
                }

                return(await SendFiles(sessionKey, myIp, transferProgress, cancellationToken));
            }
            finally
            {
                transferProgress.FileTransferProgress -= TransferProgress_FileTransferProgress;
                server?.Dispose();
            }
        }
Ejemplo n.º 7
0
 public void Stop()
 {
     server.Dispose();
 }
Ejemplo n.º 8
0
 public void Run()
 {
     _WebServer.Start();
     _ServerWindow.Run();
     _WebServer.Dispose();
 }
Ejemplo n.º 9
0
 public void Dispose() => _webServer?.Dispose();
Ejemplo n.º 10
0
        public async Task <FileTransferResult> SendFile(CancellationToken cancellationToken, IFile file, string directory = "", bool isQueue = false)
        {
            if ((ipFinderResult == null) || (ipFinderResult.Success == false))
            {
                await Handshake();

                if (ipFinderResult == null)
                {
                    ipFinderResult = new IPDetectionCompletedEventArgs
                    {
                        Success = false,
                    }
                }
                ;
            }

            if (ipFinderResult.Success == false)
            {
                return(FileTransferResult.FailedOnHandshake);
            }

            InitServer();

            var key = GenerateUniqueRandomKey();

            var properties = await file.GetFileStats();

            var slicesCount = (uint)Math.Ceiling(((double)properties.Length) / ((double)Constants.FileSliceMaxLength));

            keyTable.Add(key, new FileDetails
            {
                storageFile       = file,
                lastPieceAccessed = 0,
                lastSliceSize     = (uint)((ulong)properties.Length % Constants.FileSliceMaxLength),
                lastSliceId       = slicesCount - 1
            });

            InitUrls(key, slicesCount);

            queueFinishTcs = null;
            fileSendTcs    = new TaskCompletionSource <string>();

            ClearInternalEventSubscribers();
            FileTransferProgressInternal += (s, ee) =>
            {
                FileTransferProgress?.Invoke(s, ee);
            };

            cancellationToken.Register(() =>
            {
                fileSendTcs?.TrySetResult(TRANSFER_CANCELLED_MESSAGE);
                server?.Dispose();
            });

            if (!(await BeginSending(key, slicesCount, file.Name, properties, directory, false)))
            {
                return(FileTransferResult.FailedOnPrepare);
            }

            return(await WaitForFinish(cancellationToken));
        }
Ejemplo n.º 11
0
 public void Dispose()
 {
     _webServer.Dispose();
 }