コード例 #1
0
        public static AsyncGetListContext GetRegisteredContext(string progressId)
        {
            AsyncGetListContext result = null;

            AsyncServiceManager.WorkItem workItem = null;
            if (!string.IsNullOrEmpty(progressId) && AsyncServiceManager.workItems.TryGetValue(progressId, out workItem))
            {
                result = workItem.AsyncGetListContext;
            }
            return(result);
        }
コード例 #2
0
        public static PowerShellResults <PSObject> GetCurrentResult(string progressId)
        {
            AsyncServiceManager.WorkItem workItem     = null;
            PowerShellResults <PSObject> progressImpl = AsyncServiceManager.GetProgressImpl <PSObject>(progressId, out workItem);

            if (!string.IsNullOrEmpty(progressId) && workItem != null)
            {
                List <PSObject>     list = null;
                AsyncGetListContext asyncGetListContext      = workItem.AsyncGetListContext;
                List <string>       unicodeOutputColumnNames = asyncGetListContext.UnicodeOutputColumnNames;
                bool flag = unicodeOutputColumnNames != null && unicodeOutputColumnNames.Count > 0;
                int  num  = 0;
                int  num2 = 0;
                lock (workItem)
                {
                    list = asyncGetListContext.PsObjectCollection;
                    if (list != null)
                    {
                        num  = asyncGetListContext.NextFetchStartAt;
                        num2 = list.Count;
                        asyncGetListContext.NextFetchStartAt = num2;
                        if (flag && asyncGetListContext.UnicodeColumns == null)
                        {
                            asyncGetListContext.UnicodeColumns = new List <Tuple <int, string[], string> >(num2);
                        }
                        progressImpl.AsyncGetListContext = asyncGetListContext;
                        if (progressImpl.ProgressRecord == null || progressImpl.ProgressRecord.HasCompleted)
                        {
                            asyncGetListContext.Completed = true;
                            workItem.AsyncGetListContext  = null;
                        }
                    }
                }
                progressImpl.StartIndex = num;
                progressImpl.EndIndex   = num2;
                progressImpl.Output     = new PSObject[num2 - num];
                if (list != null)
                {
                    int i    = num;
                    int num3 = 0;
                    while (i < num2)
                    {
                        progressImpl.Output[num3] = list[i];
                        list[i] = null;
                        i++;
                        num3++;
                    }
                }
            }
            return(progressImpl);
        }
コード例 #3
0
        public static void RegisterWorkflow(Workflow workflow, AsyncGetListContext asyncGetListContext = null)
        {
            if (workflow == null)
            {
                throw new InvalidOperationException("Only BulkEditWorkflow is allowed to do async execution.");
            }
            int managedThreadId = Thread.CurrentThread.ManagedThreadId;

            if (AsyncServiceManager.workerThreads.Contains(managedThreadId))
            {
                AsyncServiceManager.WorkItem workItem = (AsyncServiceManager.WorkItem)AsyncServiceManager.workerThreads[managedThreadId];
                workItem.ProgressCalculator         = (ProgressCalculatorBase)Activator.CreateInstance(workflow.ProgressCalculator);
                workflow.ProgressCalculatorInstance = workItem.ProgressCalculator;
                workItem.AsyncGetListContext        = asyncGetListContext;
                workflow.ProgressChanged           += delegate(object sender, ProgressReportEventArgs e)
                {
                    workItem.ProgressCalculator.CalculateProgress(e);
                };
            }
        }