コード例 #1
0
        public void DoGridTransferCancelTask(Guid guid)
        {
            TransferEntry transfer = ReturnTransfer(guid);

            transfer.tokenSource.Cancel();
            transfer.State = TransferState.Cancelling;
        }
コード例 #2
0
        private void DoGridTransferUpdateProgressText(string progresstext, double progress, Guid guid)
        {
            TransferEntry transfer = ReturnTransfer(guid);

            transfer.ProgressText = progresstext;
            DoGridTransferUpdateProgress(progress, guid);
        }
コード例 #3
0
        private static List<int> _MyListTransferQueue; // List of transfers in the queue. It contains the index in the order of schedule

        #endregion Fields

        #region Methods

        public int DoGridTransferAddItem(string text, TransferType TType, bool PutInTheQueue)
        {
            TransferEntry myTE = new TransferEntry()
            {
                Name = text,
                SubmitTime = DateTime.Now,
                Type = TType
            };

            dataGridViewTransfer.Invoke(new Action(() =>
            {
                _MyListTransfer.Add(myTE);

            }
                ));
            int indexloc = _MyListTransfer.IndexOf(myTE);

            if (PutInTheQueue)
            {
                _MyListTransferQueue.Add(indexloc);
                myTE.processedinqueue = true;
                myTE.State = TransferState.Queued;

            }
            else
            {
                myTE.processedinqueue = false;
                myTE.State = TransferState.Processing;
                myTE.StartTime = DateTime.Now;
            }

            // refresh number in tab
            tabPageTransfers.Invoke(new Action(() => tabPageTransfers.Text = string.Format(Constants.TabTransfers + " ({0})", _MyListTransfer.Count())));
            return indexloc;
        }
コード例 #4
0
        public int DoGridTransferAddItem(string text, TransferType TType, bool PutInTheQueue)
        {
            TransferEntry myTE = new TransferEntry()
            {
                Name       = text,
                SubmitTime = DateTime.Now,
                Type       = TType
            };

            dataGridViewTransfer.Invoke(new Action(() =>
            {
                _MyListTransfer.Add(myTE);
            }
                                                   ));
            int indexloc = _MyListTransfer.IndexOf(myTE);

            if (PutInTheQueue)
            {
                _MyListTransferQueue.Add(indexloc);
                myTE.processedinqueue = true;
                myTE.State            = TransferState.Queued;
            }
            else
            {
                myTE.processedinqueue = false;
                myTE.State            = TransferState.Processing;
                myTE.StartTime        = DateTime.Now;
            }

            // refresh number in tab
            tabPageTransfers.Invoke(new Action(() => tabPageTransfers.Text = string.Format(Constants.TabTransfers + " ({0})", _MyListTransfer.Count())));
            return(indexloc);
        }
コード例 #5
0
        private void DoGridTransferUpdateProgress(double progress, Guid guid)
        {
            TransferEntry transfer = ReturnTransfer(guid);

            transfer.Progress = progress;
            if (progress > 3 && transfer.StartTime != null)
            {
                TimeSpan interval = (TimeSpan)(DateTime.UtcNow - ((DateTime)transfer.StartTime).ToUniversalTime());
                DateTime ETA      = DateTime.UtcNow.AddSeconds((100d / progress - 1d) * interval.TotalSeconds);
                transfer.EndTime = ETA.ToLocalTime().ToString("G") + " ?";
            }
        }
コード例 #6
0
        private void DoGridTransferDeclareTransferStarted(Guid guid)  // Process is started
        {
            if (DoGridTransferIsQueueRequested(guid))
            {
                _MyListTransferQueue.Remove(guid);
            }

            TransferEntry transfer = ReturnTransfer(guid);

            transfer.Progress  = 0;
            transfer.State     = TransferState.Processing;
            transfer.StartTime = DateTime.Now;
            this.TextBoxLogWriteLine(string.Format("Transfer '{0}': started", transfer.Name));
        }
コード例 #7
0
        private void DoGridTransferDeclareCancelled(Guid guid)  // Process is completed
        {
            TransferEntry transfer = ReturnTransfer(guid);

            transfer.Progress     = 101d;
            transfer.State        = TransferState.Cancelled;
            transfer.EndTime      = DateTime.Now.ToString();
            transfer.ProgressText = string.Empty;

            this.BeginInvoke(new Action(() =>
            {
                this.TextBoxLogWriteLine(string.Format("Transfer '{0}' cancelled by user.", transfer.Name), true);
            }));
        }
コード例 #8
0
        private void DoGridTransferDeclareTransferStarted(Guid guid)  // Process is started
        {
            if (DoGridTransferIsQueueRequested(guid))
            {
                _MyListTransferQueue.Remove(guid);
            }

            TransferEntry transfer = ReturnTransfer(guid);

            transfer.Progress  = 0;
            transfer.State     = TransferState.Processing;
            transfer.StartTime = DateTime.Now;
            this.TextBoxLogWriteLine(string.Format(AMSExplorer.Properties.Resources.Mainform_DoGridTransferDeclareTransferStarted_Transfer0Started, transfer.Name));
        }
コード例 #9
0
        private void DoGridTransferDeclareCancelled(Guid guid)  // Process is completed
        {
            TransferEntry transfer = ReturnTransfer(guid);

            transfer.Progress     = 101d;
            transfer.State        = TransferState.Cancelled;
            transfer.EndTime      = DateTime.Now.ToString();
            transfer.ProgressText = string.Empty;

            this.BeginInvoke(new Action(() =>
            {
                this.TextBoxLogWriteLine(string.Format(AMSExplorer.Properties.Resources.Mainform_DoGridTransferDeclareCancelled_Transfer0CancelledByUser, transfer.Name), true);
            }));
        }
コード例 #10
0
        private void DoGridTransferDeclareCompleted(Guid guid, string DestLocation)  // Process is completed
        {
            TransferEntry transfer = ReturnTransfer(guid);

            transfer.Progress     = 101d;
            transfer.State        = TransferState.Finished;
            transfer.EndTime      = DateTime.Now.ToString();
            transfer.DestLocation = DestLocation;
            transfer.ProgressText = string.Empty;

            this.BeginInvoke(new Action(() =>
            {
                this.Notify("Transfer completed", string.Format("{0}", transfer.Name));
                this.TextBoxLogWriteLine(string.Format("Transfer '{0}' completed.", transfer.Name));
            }));
        }
コード例 #11
0
        private void DoGridTransferDeclareError(Guid guid, string ErrorDesc = "")  // Process is completed
        {
            TransferEntry transfer = ReturnTransfer(guid);

            transfer.Progress         = 101d;
            transfer.EndTime          = DateTime.Now.ToString();
            transfer.State            = TransferState.Error;
            transfer.ProgressText     = "Error: " + ErrorDesc;
            transfer.ErrorDescription = ErrorDesc;

            this.BeginInvoke(new Action(() =>
            {
                this.Notify("Transfer Error", string.Format("{0}", transfer.Name), true);
                this.TextBoxLogWriteLine(string.Format("Transfer '{0}': Error", transfer.Name), true);
                this.TextBoxLogWriteLine(ErrorDesc, true);
            }));
        }
コード例 #12
0
        public TransferEntryResponse DoGridTransferAddItem(string text, TransferType TType, bool CanBePutInTheQueue)
        {
            TransferEntry myTE = new TransferEntry()
            {
                Name       = text,
                SubmitTime = DateTime.Now,
                Type       = TType
            };

            dataGridViewTransfer.Invoke(new Action(() =>
            {
                _MyListTransfer.Add(myTE);
            }
                                                   ));
            myTE.Id = Guid.NewGuid();             // _MyListTransfer.IndexOf(myTE);

            if (CanBePutInTheQueue)
            {
                _MyListTransferQueue.Add(myTE.Id);
                myTE.processedinqueue = true;
                myTE.State            = TransferState.Queued;
            }
            else
            {
                myTE.processedinqueue = false;
                myTE.State            = TransferState.Processing;
                myTE.StartTime        = DateTime.Now;
            }

            // refresh number in tab
            tabPageTransfers.Invoke(new Action(() => tabPageTransfers.Text = string.Format(Constants.TabTransfers + " ({0})", _MyListTransfer.Count())));

            // to cancel task if needed
            CancellationTokenSource tokenSource = new CancellationTokenSource();
            CancellationToken       tokenloc    = tokenSource.Token;

            myTE.tokenSource = tokenSource;

            return(new TransferEntryResponse()
            {
                Id = myTE.Id, token = tokenloc
            });
        }