Пример #1
0
        private static void MergeAndProcessOrgs(List <Organization> orgs)
        {
            var result = "";

            foreach (var organization in orgs)
            {
                result += organization.orgDisplayName + "," + organization.shortName + "," + organization.filespaceId + "," +
                          organization.orgId + "\n";
            }
            //Filter out all stopped\completed tasks
            lock (OrgListLocker)
            {
                OrgProcessingTasks.Where(o => o.Key.IsCompleted || o.Key.IsFaulted || o.Key.IsCanceled)
                .Select(d => d.Key)
                .ForEach(d => OrgProcessingTasks.Remove(d));
                log.LogInformation("Currently processing orgs: {0} ",
                                   OrgProcessingTasks.Select(o => o.Value.Item1).DefaultIfEmpty(new Organization())
                                   .Select(t => t.shortName).Aggregate((current, next) => current + ", " + next));
                log.LogDebug("Tasks status when trying to add new orgs is {0} in Queue1 and {1} in Queue2 on {2} Threads",
                             Container.Resolve <IHarvesterTasks>().Status().Item1,
                             Container.Resolve <IHarvesterTasks>().Status().Item2, GetUsedThreads());
                //do merge here - if there is no org in the list of tasks - build it. If there is no org but there in the list but there is a task - kill the task
                orgs.Where(o => !OrgProcessingTasks.Select(t => t.Value.Item1).Contains(o))
                .Where(o => string.IsNullOrEmpty(ShortOrgName) || o.shortName == ShortOrgName).ForEach(o =>
                {
                    log.LogInformation("Adding {0} org for processing", o.shortName);
                    var cancellationToken = new CancellationTokenSource();
                    OrgProcessingTasks.Add(Container.Resolve <IHarvesterTasks>().StartNewLimitedConcurrency2(() =>
                    {
                        new OrgProcessorTask(Container, o, cancellationToken, OrgProcessingTasks).ProcessOrg(false,
                                                                                                             t => log
                                                                                                             .LogInformation("Tasks status is {0} in Queue1 and {1} in Queue2 on {2} Threads",
                                                                                                                             Container.Resolve <IHarvesterTasks>().Status().Item1,
                                                                                                                             Container.Resolve <IHarvesterTasks>().Status().Item2, GetUsedThreads()));
                    }, cancellationToken.Token, false), new Tuple <Organization, CancellationTokenSource>(o, cancellationToken));
                });
                //Reversed situation - org has been removed from filespaces but there is a task - cancel it
                if (OrgProcessingTasks.Any(o => !orgs.Contains(o.Value.Item1)))
                {
                    OrgProcessingTasks.Where(o => !orgs.Contains(o.Value.Item1)).ForEach(o => o.Value.Item2.Cancel());
                    log.LogInformation("Removing {0} org from processing",
                                       OrgProcessingTasks.Select(o => o.Value.Item1)
                                       .Where(y => !orgs.Contains(y))
                                       .Select(t => t.shortName)
                                       .Aggregate((current, next) => current + ", " + next));
                    OrgProcessingTasks.Where(o => !orgs.Contains(o.Value.Item1))
                    .Select(d => d.Key)
                    .ForEach(t => OrgProcessingTasks.Remove(t));
                }
            }
        }
Пример #2
0
 public static void Clean()
 {
     OrgProcessingTasks.Clear();
 }