private async Task <bool> StartProcessing(StartProcessing msg)
        {
            if (_cws == null)
            {
                var cancellationTokenSource = new CancellationTokenSource(msg.ConnectionTimeout);
                _cws = new ClientWebSocket();

                try
                {
                    await _cws.ConnectAsync(_url, cancellationTokenSource.Token);
                }
                catch (OperationCanceledException opEx)
                {
                    throw new TimeoutException($"No connection withing {msg.ConnectionTimeout.TotalSeconds} seconds", opEx);
                }

                _recvBuffer     = new byte[1024 * 4];
                _receiveSegment = new ArraySegment <byte>(_recvBuffer);

                // Start reading messages
                Self.Tell(new ContinueProcessing());
            }

            return(true);
        }
Пример #2
0
        public void Start(string inPath, string outPath)
        {
            if (Directory.Exists(inPath))
            {
                var files = _sourceStorage.Directory.GetFiles(inPath, SearchOption.TopDirectoryOnly).ToArray();
                StartProcessing?.Invoke(this, new ProgressEventArgs(inPath, files.Length));

                foreach (var file in files)
                {
                    var targetDirectory = ProcessFile(file, outPath);
                    //if (!string.IsNullOrEmpty(targetDirectory) && _targetStorage is MtpStorage)
                    //{
                    //    CopyToDevice(file, targetDirectory, outPath);
                    //}
                }
            }
            if (File.Exists(inPath))
            {
                StartProcessing?.Invoke(this, new ProgressEventArgs(inPath, 1));
                var targetDirectory = ProcessFile(inPath, outPath);
                //if (!string.IsNullOrEmpty(targetDirectory) && _targetStorage is MtpStorage)
                //{
                //    CopyToDevice(inPath, targetDirectory, outPath);
                //}
            }
        }
Пример #3
0
        /// <summary>
        /// Starts the DeliveryProcessor
        /// </summary>
        public static void Start(ref List <Delivery> deliveries)
        {
            if (Processing)
            {
                return;
            }

            Processing = true;

            deliveryList = deliveries;

            StartProcessing?.Invoke();
        }
Пример #4
0
        internal static void StartMessageLoop()
        {
            if (MessageLoopRunning)
            {
                ABSLog.ThrowError("An attempt to made to start a message loop while one was already running!");
            }
            MessageLoopRunning = true;

            Task.Run(async() =>
            {
                while (true)
                {
                    // Run immediate processes.
                    while (ImmediateProcesses.TryPeek(out Process immediateProcess))
                    {
                        immediateProcess.ProcessIsRunning = true;
                        await immediateProcess.ExecuteAsync();
                        ImmediateProcesses.TryDequeue(out _);
                    }

                    // Run background processes.
                    if (BackgroundProcesses.TryPeek(out Process backgroundProcess))
                    {
                        backgroundProcess.ProcessIsRunning = true;
                        await backgroundProcess.ExecuteAsync();
                        BackgroundProcesses.TryDequeue(out _);
                    }
                    else
                    {
                        StopProcessing?.Invoke(null, null);

                        waitForNext.Wait();

                        if (!MessageLoopRunning)
                        {
                            return;
                        }

                        waitForNext.Reset();

                        StartProcessing?.Invoke(null, null);
                    }
                }
            });
        }
        private void Handle(StartProcessing m)
        {
            this.logger.Info($"Start processing of order {m.OrderId}");

            Context.SetReceiveTimeout(TimeSpan.FromSeconds(120));
            this.initiatorActorRef = Context.Sender;
            this.orderId           = m.OrderId;

            Become(ReceiveOrderDetailsState);
            Uri?orderServiceUri = this.serviceSettings.OrderServiceUri ?? new Uri("http://unknown/");

            this.httpRequestActor.Tell(
                new HttpRequestActor.Get
            {
                ServiceUrl = orderServiceUri.Port == 443 ? $"https://{orderServiceUri.Host}" : $"http://{orderServiceUri.Host}:{orderServiceUri.Port}",
                Path       = $"/private/order/{m.OrderId}"
            });
        }
 protected void OnStartProcessing(EventArgs e)
 {
     StartProcessing?.Invoke(this, e);
 }