private void BeginProcess(string spreadSheetPath, IProgress <double> progress)
        {
            var process = new ProcessController(spreadSheetPath);

            process.OnProgressChanged += (d) =>
            {
                progress?.Report(d);
                ProgressBar1.Invoke((Action)(() => ProgressBar1.Value = d));
                return(d);
            };
            process.OnProgressFinished += (s, e) =>
            {
                TxtFilePath.Invoke((Action)(() => TxtFilePath.IsEnabled = true));
                BtnBrowse.Invoke((Action)(() => BtnBrowse.IsEnabled = true));
                BtnStartProcess.Invoke((Action)(() => BtnStartProcess.IsEnabled = true));
                System.Windows.MessageBox.Show("Operation Done Successfully.");

                System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    var report = new OperationReport(new OperationReportContext()
                    {
                        Success = e.SuccessEmails,
                        Errors  = e.FailedEmails
                    });
                    report.ShowDialog();
                }));
            };
            process.BeginProcessing();
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Performs initialization.
        /// </summary>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var buttonWidth = (int)(Data.HorizontalDlu * 60 * Data.HDpiScale);
            var btnHrzSpace = (int)(Data.HorizontalDlu * 3);

            ClientSize = new Size(3 * buttonWidth + 4 * btnHrzSpace, (int)(400 * Data.VDpiScale));
            BtnBrowse.Focus();
        }
        /// <summary>
        /// Performs initialization.
        /// </summary>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var buttonWidth = (int)(Data.HorizontalDLU * 60);
            var btnHrzSpace = (int)(Data.HorizontalDLU * 3);

            ClientSize = new Size(3 * buttonWidth + 4 * btnHrzSpace, 400);
            BtnBrowse.Focus();
        }
Ejemplo n.º 4
0
        private async void ClientInstance(TcpClient client)
        {
            string ip = (client.Client.RemoteEndPoint as IPEndPoint)?.ToString();

            Log($"Connected from {ip}\r\n");
            try
            {
                var stream = client.GetStream();
                await PushTrackList(stream);

                Task <object> readTask  = stream.ReadObjAsync();
                Task <bool>   knockTask = Dispatcher.WaitAsync();

                var token = WorkerAbort.Token;
                token.Register(() => stream.Close());
                while (!token.IsCancellationRequested)
                {
                    await Task.WhenAny(readTask, knockTask);

                    if (readTask.IsCompleted)
                    {
                        if (readTask.IsFaulted)
                        {
                            return;
                        }
                        switch (await readTask)
                        {
                        case DownloadRequest req:
                            var item = await UIDispatcher.Send(() => LvTracks.Items[req.Index].Tag) as TrackMetadata;

                            var blob = new FileBlob()
                            {
                                Name = Path.GetFileName(item.Path),
                                Body = File.ReadAllBytes(item.Path)
                            };
                            Log($"{ip} requested {blob.Name}\r\n");
                            await stream.WriteObjAsync(new Announcement($"Downloading {blob.Name}"));

                            await new MemoryStream(SerialUtility.GetPrefixedSerial(blob))
                            .ThrottleCopyTo(stream, 2 * 1024 * 1024, token);
                            //await stream.WriteObjAsync(blob);
                            break;

                        case FileBlob file:
                            var repo = await UIDispatcher.Send(() =>
                            {
                                TbLog.AppendText($"{ip} is uploading {file.Name}\r\n");
                                return(TbPath.Text);
                            });

                            var path      = Path.Combine(repo, file.Name);
                            var preExists = File.Exists(path);
                            try
                            {
                                using (FileStream fs = File.Create(path))
                                {
                                    await fs.WriteAsync(file.Body, 0, file.Body.Length).ConfigureAwait(false);
                                }
                                UIDispatcher.Post(() =>
                                {
                                    TbLog.AppendText($"{ip} uploaded {file.Name}\r\n");
                                    BtnBrowse.PerformClick();
                                });
                            }
                            catch (Exception e)
                            {
                                Log(e.Message + "\r\n");
                            }
                            break;
                        }
                        readTask = stream.ReadObjAsync();
                    }
                    if (knockTask.IsCompleted)
                    {
                        await PushTrackList(stream);

                        knockTask = Dispatcher.WaitAsync();
                    }
                }
            }
            catch (Exception e)
            {
                Log(e.Message + "\r\n");
            }
            finally
            {
                client.Close();
                Log($"Disconnected from {ip}\r\n");
            }
        }