示例#1
0
        public static void CopySession(Session source, Session target, XPClassInfo[] classes, IBackgroundWorker worker, int maxProgress)
        {
            Dictionary <IXPSimpleObject, IXPSimpleObject> copiedObjects = new Dictionary <IXPSimpleObject, IXPSimpleObject>();
            double percentProgress = worker == null ? 0 : worker.ReportedProgress;
            Dictionary <IXPSimpleObject, bool> objectsForCopy = GetObjectsForCopy(source, classes);
            double percentInterval          = maxProgress - percentProgress;
            double percentProgressPerObject = 0.97 * percentInterval / objectsForCopy.Keys.Count;

            percentProgress += 0.03 * percentInterval;
            if (worker != null)
            {
                worker.ReportProgress((int)percentProgress);
            }
            XPObjectCloneHelper cloneHelper = new XPObjectCloneHelper(target, copiedObjects, delegate(object sender, EventArgs e) {
                percentProgress += percentProgressPerObject;
                if (worker != null)
                {
                    worker.ReportProgress((int)percentProgress);
                }
            });

            foreach (IXPSimpleObject obj in objectsForCopy.Keys)
            {
                if (!copiedObjects.ContainsKey(obj))
                {
                    cloneHelper.Clone(obj);
                }
            }
            if (worker != null)
            {
                worker.ReportProgress(maxProgress);
            }
        }
示例#2
0
        private void ReportProgress(AppFile file, ref int index, int filesCount)
        {
            int percentageDone = (int)(100.0 / filesCount * index);

            _backgroundWorker.ReportProgress(percentageDone, file);
            ++index;
        }
        ///NOTE: depricated
        //static List<string> getCDRs(string pWhereFilter, CdrExportMap pCdrExportMap, int pStartTimokDate, int pEndTimokDate, string pDecimalFormatString, BackgroundWorker pBackgroundWorker) {
        //  pBackgroundWorker.ReportStatus("Retrieving CDRs...");
        //  List<string> _records = new List<string>();
        //  if (Cdr_Db.Exists(TimokDate.ToDateTime(pStartTimokDate))) {
        //    using (Cdr_Db _db = new Cdr_Db(TimokDate.ToDateTime(pStartTimokDate))) {
        //      IDbCommand _cmd = _db.Connection.CreateCommand();
        //      _cmd.CommandText = getSQLForCDRViewExport(_db.Connection.Database, pCdrExportMap.CdrExportMapDetails, pStartTimokDate, pEndTimokDate, pWhereFilter);
        //      IDataReader _reader = _cmd.ExecuteReader();
        //      while (_reader.Read()) {
        //        if (pBackgroundWorker.CancellationPending) {
        //          throw new Exception("CDR Export canceled");
        //        }
        //        StringBuilder _record = new StringBuilder();
        //        foreach (CdrExportMapDetail _field in pCdrExportMap.CdrExportMapDetails) {
        //          object _value = _reader.GetValue(_field.Sequence - 1);
        //          _record.Append(_value);
        //          //NOTE: if need to format prices, here is the place to do that
        //          //if (_value is Decimal) {
        //          //  _record.Append(((decimal) _value).ToString(pDecimalFormatString));
        //          //}
        //          //else {
        //          //  _record.Append(_value);
        //          //}
        //          _record.Append((char) pCdrExportMap.CdrExportDelimeter);
        //        }
        //        _records.Add(_record.ToString().TrimEnd((char) pCdrExportMap.CdrExportDelimeter));
        //      }
        //    }
        //  }
        //  pBackgroundWorker.ReportStatus(string.Format("Retrieved {0} CDRs", _records.Count));
        //  return _records;
        //}
        static List <string> getCDRs(string pWhereFilter, ICdrExportInfo pCdrExportInfo, int pTimokDate, IBackgroundWorker pBackgroundWorker)
        {
            var _records = new List <string>();

            if (Cdr_Db.Exists(TimokDate.ToDateTime(pTimokDate)))
            {
                CDRViewRow[] _cdrViewRows;
                try {
                    using (var _db = new Cdr_Db(TimokDate.ToDateTime(pTimokDate))) {
                        _cdrViewRows = _db.CDRViewCollection.Get(pTimokDate, pWhereFilter);
                    }
                }
                catch (Exception _ex) {
                    TimokLogger.Instance.LogRbr(LogSeverity.Critical, GetcdrsLabel, string.Format("Exception:\r\n{0}", _ex));
                    pBackgroundWorker.ReportStatus(string.Format("Exception! Exported {0} CDRs", _records.Count));
                    return(_records);
                }
                if (_cdrViewRows == null || _cdrViewRows.Length == 0)
                {
                    TimokLogger.Instance.LogRbr(LogSeverity.Error, GetcdrsLabel, "No CDR Records found");
                    pBackgroundWorker.ReportStatus("No CDR Records found");
                    return(_records);
                }

                pBackgroundWorker.ReportStatus(string.Format("Retrieved {0} CDRs for: {1}", _cdrViewRows.Length, TimokDate.ToDateTime(pTimokDate).ToString("yyyy-MM-dd HH:mm")));

                var _recordCount = 0;
                foreach (var _cdrViewRow in _cdrViewRows)
                {
                    if (pBackgroundWorker.CancellationPending)
                    {
                        throw new Exception("CDR Export canceled");
                    }

                    if (pCdrExportInfo.WithRerating && _cdrViewRow.Duration > 0)
                    {
                        if (!rerateCDR(_cdrViewRow, pBackgroundWorker))
                        {
                            continue;
                        }
                    }

                    _records.Add(mapToExportedRecord(_cdrViewRow, pCdrExportInfo.CdrExportMap));
                    pBackgroundWorker.ReportProgress(++_recordCount * 100 / _cdrViewRows.Length);
                }

                if (_records.Count != _cdrViewRows.Length)
                {
                    pBackgroundWorker.ReportStatus(string.Format("ERROR: Exported {0} out of {1} retreived CDRs", _records.Count, _cdrViewRows.Length));
                }
                else
                {
                    pBackgroundWorker.ReportStatus(string.Format("Exported {0} CDRs for: {1}", _records.Count, TimokDate.ToDateTime(pTimokDate).ToString("yyyy-MM-dd HH:mm")));
                }
            }
            return(_records);
        }
        public void ReportProgress_InvokeFunctionWhileWorkerReportsProgressIsFalse_ThrowsInvalidOperationException()
        {
            // arrange
            IBackgroundWorker worker = InitializeWorker();

            TestDelegate testDelegate = () => worker.ReportProgress(It.IsAny <int>());

            // act, assert
            Assert.That(testDelegate, Throws.Exception.TypeOf <InvalidOperationException>());
        }
示例#5
0
        public static void CommitInBackground(UnitOfWork session, IExceptionProcesser exceptionProcesser, IBackgroundWorker worker, int maxProgress)
        {
            ICollection  objectsToSave = session.GetObjectsToSave();
            double       saveSessionPercentProgress  = worker.ReportedProgress;
            double       saveSessionPercentPerObject = 0.95 * (maxProgress - saveSessionPercentProgress) / objectsToSave.Count;
            EventHandler objectSaved = delegate(object sender, EventArgs e) {
                saveSessionPercentProgress += saveSessionPercentPerObject;
                worker.ReportProgress((int)saveSessionPercentProgress);
            };

            foreach (IXPSimpleObject obj in session.GetObjectsToSave())
            {
                ExtendedXPBaseObject vrbo = obj as ExtendedXPBaseObject;
                if (vrbo == null)
                {
                    continue;
                }
                vrbo.Saved += objectSaved;
            }
            SessionHelper.CommitSession(session, exceptionProcesser);
            worker.ReportProgress(maxProgress);
        }
示例#6
0
        private static Result ForEachNewTransaction(
            this WineMsOrderTransactionDocument[] orderTransactions,
            IBackgroundWorker backgroundWorker,
            Func <WineMsOrderTransactionDocument, Result> func)
        {
            var errors   = new StringBuilder();
            var count    = 0;
            var maxCount = orderTransactions.Length;

            foreach (var transaction in orderTransactions)
            {
                func(transaction)
                .OnFailure(err => errors.AppendLine(err));
                var percentProgress = ProgressReportFunctions.CalcPercentProgress(++count, maxCount);
                backgroundWorker.ReportProgress(percentProgress);
            }

            return(errors.Length == 0 ? Result.Ok() : Result.Fail(errors.ToString()));
        }
        public void ReportProgress_SubscribeToOnProgressChangedEventAndReportProgressWithoutUserState_ReportsExpectedProgress()
        {
            // arrange
            IBackgroundWorker worker = InitializeWorker();

            worker.WorkerReportsProgress = true;

            int expectedPercentage = 10;

            int resultPercentage = 0;

            worker.OnProgressChanged += (sender, e) =>
            {
                resultPercentage = e.ProgressPercentage;
            };

            // act
            worker.ReportProgress(expectedPercentage);

            // assert
            Assert.AreEqual(expectedPercentage, resultPercentage);
        }
示例#8
0
        void WriteHistoryToDB()
        {
            bool realTime = VideoRentDateTime.RealTime;

            VideoRentDateTime.RealTime = false;
            backgroundWorker.ReportProgress(10);
            WriteItemsToDB();
            double percentProgress = backgroundWorker.ReportedProgress;
            double percentPerDay   = (70.0 - percentProgress) / daysCount;

            VideoRentDateTime.AddDays(-daysCount - 1);
            for (int day = 0; day < daysCount; ++day)
            {
                VideoRentDateTime.AddDays(1);
                foreach (CustomerData customer in customers)
                {
                    Point point = customer.GetPoint(day);
                    if (point == null)
                    {
                        continue;
                    }
                    VideoRentDateTime.SetTimeOfDay(point.Time);
                    List <RentInfo> rentsInfo = new List <RentInfo>();
                    foreach (RentData rent in point.Rents)
                    {
                        rentsInfo.Add(new RentInfo(rent.Item.DBItem, rent.Days));
                    }
                    Receipt receipt = customer.DBCustomer.DoRent(rentsInfo);
                    foreach (RentData rent in point.Rents)
                    {
                        foreach (Rent dbRent in receipt.Rents)
                        {
                            if (dbRent.Item != rent.Item.DBItem)
                            {
                                continue;
                            }
                            rent.DBRent = dbRent;
                            break;
                        }
                    }
                    List <Rent> returns = new List <Rent>();
                    foreach (RentData rent in point.Returns)
                    {
                        returns.Add(rent.DBRent);
                    }
                    customer.DBCustomer.ReturnRents(returns);
                    List <RentInfo> sellsInfo = new List <RentInfo>();
                    foreach (RentData sell in point.Sells)
                    {
                        sellsInfo.Add(new RentInfo(sell.Item.DBItem));
                    }
                    customer.DBCustomer.Buy(sellsInfo);
                }
                foreach (LostDamageItemAction action in lostDamageItemActions)
                {
                    if (action.Day != day)
                    {
                        continue;
                    }
                    VideoRentDateTime.SetTimeOfDay(action.Time);
                    if (action.Damage)
                    {
                        action.Item.DBItem.Status = MovieItemStatus.Damaged;
                    }
                    else
                    {
                        action.Item.DBItem.Status = MovieItemStatus.Lost;
                    }
                }
                percentProgress += percentPerDay;
                backgroundWorker.ReportProgress((int)percentProgress);
            }
            backgroundWorker.ReportProgress(70);
            WriteAddedItems();
            SessionHelper.CommitInBackground(session, exceptionProcesser, backgroundWorker, 100);
            VideoRentDateTime.RealTime = realTime;
        }