- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
using DocsTaskInfo = System.Collections.Generic.KeyValuePair<int, bool>;
using DocAndContentType = System.Collections.Generic.KeyValuePair<int, string>;
using DocAndContentTypeToCount = System.Collections.Generic.Dictionary<System.Collections.Generic.KeyValuePair<int, string>, System.Collections.Generic.KeyValuePair<int, bool>>;
//...
private void DocsCountInternal(RefNetDbContainerDirect db, int docType, string contentType,  int status, int count, bool Checked = true){/*...*/}
//...
private DocAndContentTypeToCount[] _docCheckTasks;
private RefNetDbContainerDirect _dbForCheck;
private void ClearAllDocCounts(RefNetDbContainerDirect dbForCheck)
        {
            _dbForCheck = dbForCheck;
            _docCheckTasks = Enumerable.Repeat(new DocAndContentTypeToCount(), 2).ToArray();
                //new DocAndContentTypeToCount[2] { new DocAndContentTypeToCount(), new DocAndContentTypeToCount() };
        }
private void DocsCount(RefNetDbContainerDirect db, int docType, string contentType, int status, int count, bool Checked = true)
        {
            var taskHistory = _docCheckTasks[status];
            var taskKey = new DocAndContentType(docType, contentType);
            var taskInfo = new DocsTaskInfo(count, Checked);
            if(taskHistory.ContainsKey(taskKey))
                _exceptions.Add(new Exception(string.Format(
                                 "CheckDocsTask with (_.idDocType == {0}) && (_.contentType == \"{1}\") && (_.status == {2}) ) already contained",
                                 docType, contentType, status)));
            taskHistory.Add(taskKey, taskInfo);
        }
private void CheckAllDocCounts()
        {
            if (AllDocumentsMadeByServer)
            {
                //1
                var taskKeys = _docCheckTasks.SelectMany(_ => _.Keys)/*.Distinct()*/.ToArray();
                foreach (var taskKey in taskKeys)
                {
                    DocAndContentType key = taskKey;
                    foreach (var statusedTask in _docCheckTasks.Where(statusedTask => !statusedTask.ContainsKey(key)))
                        statusedTask.Add(taskKey, new DocsTaskInfo(0, true));
                }
                taskKeys.Select(_ => new
                {
                    docAndContentType = _,
                    count = _docCheckTasks[0][_].Key + _docCheckTasks[1][_].Key,
                    Checked = _docCheckTasks[0][_].Value && _docCheckTasks[1][_].Value
                }).ForEach(_ => DocsCountInternal(_dbForCheck, _.docAndContentType.Key, _.docAndContentType.Value, 1, _.count, _.Checked));
        }
            else
                //0 и 1
                foreach(var statusedTask in _docCheckTasks.Select((tasks, status) => new {tasks, status}))
                    foreach (var task in statusedTask.tasks)
                        DocsCountInternal(_dbForCheck, task.Key.Key, task.Key.Value, statusedTask.status, task.Value.Key, task.Value.Value);
            _docCheckTasks = null;
            _dbForCheck = null;
        }
                                     
        
            Автору я бы посоветовал утопиться, но как посоветуете отрефакторить?
Планировалось, что чувак вызывает ClearAllDocCounts, затем много раз метод DocsCount, а потом CheckAllDocCounts.