示例#1
0
        public void CheckForDocuments()
        {
            bProcessDocuments.Enabled = false;
            bGetDocumentsDocuments.Enabled = false;

            progressBar1.Minimum = 0;
            progressBar1.Maximum = 100;
            progressBar1.Value = 0;
            GetDocumentsWorker.RunWorkerAsync();
        }
示例#2
0
        private void GetDocumentsWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            GetDocumentsWorker.ReportProgress(10);
            try
            {
                List<BO.WorkObject> workObjects = new List<BO.WorkObject>();
                DocumentSimpleContract[] documents;
                if (WCFHandler.GetInstance.isConnected())
                {
                    GetDocumentsWorker.ReportProgress(10);
                    documents = WCFHandler.GetInstance.SearchForDocuments();
                    GetDocumentsWorker.ReportProgress(20);

                    //int done = 0;
                    GetDocumentsWorker.ReportProgress(60);

                    foreach (DocumentSimpleContract siCo in documents)
                    {
                        workObjects.Add(new BO.WorkObject(siCo.Id));
                        //ReportProgress
                        //done++;
                        //var total = workObjects.Count();
                        //double progress = ((double)done / total) * 100;
                        //GetDocumentsWorker.ReportProgress(Convert.ToInt32(progress));
                    }
                    GetDocumentsWorker.ReportProgress(80);

                    //Check for cross-referenced child documents if child documents inherit parent document markerproperties.
                    if (Properties.Settings.Default.GroupingActive && Properties.Settings.Default.GroupingInheritMarkerProperties)
                    {
                        DateTime start = DateTime.Now;
                        List<DocumentContract> allAffectedDocs = new List<DocumentContract>();
                        foreach (BO.WorkObject wo in workObjects)
                        {
                            allAffectedDocs.AddRange(wo.allAffectedDocuments);
                        }
                        var duplicates = allAffectedDocs.GroupBy(x => x.Id).Where(g => g.Count() > 1).Select(y => y.Key);
                        foreach (BO.WorkObject wo in workObjects)
                        {
                            var numberOfdupesForDoc = wo.allAffectedDocuments.Where(x => duplicates.Contains(x.Id)).Count();
                            if(numberOfdupesForDoc > 0)
                                wo.AbortProcessing(string.Format("Some child-documents of this document ({0}) are referenced by other parent-documents. This is not allowed if markerproperties are inherited to child-documents.", numberOfdupesForDoc));
                        }
                        DateTime end = DateTime.Now;
                        log4.Debug(string.Format("Checking cross-references for documents took {0}ms.", (end - start).TotalMilliseconds.ToString()));
                    }
                    GetDocumentsWorker.ReportProgress(100);
                }
                e.Result = workObjects;
            }
            catch (Exception ex)
            {
                log4.Error(string.Format("An error happened while searching for documents. Message: {0}", ex.Message));
            }
        }