// Token: 0x060008E4 RID: 2276 RVA: 0x0003FFEF File Offset: 0x0003E1EF
 private string GetSettingsForTask(BackgroundInventory.InventoryTask task)
 {
     if (task.InventoryInput != BackgroundInventory.InventoryTask.InventoryInputSource.NodeSettings)
     {
         return(InventorySettingsDAL.GetInventorySettings(task.ObjectSettingID, task.InventorySettingName));
     }
     return(NodeSettingsDAL.GetNodeSettings(task.ObjectSettingID, task.InventorySettingName));
 }
        // Token: 0x060008E3 RID: 2275 RVA: 0x0003FFA8 File Offset: 0x0003E1A8
        private bool ProcessResults(object plugin, BackgroundInventory.InventoryTask task, InventoryResultBase result, Node node)
        {
            IBackgroundInventoryPlugin backgroundInventoryPlugin = plugin as IBackgroundInventoryPlugin;

            if (backgroundInventoryPlugin != null)
            {
                return(backgroundInventoryPlugin.ProcessResults(result, node));
            }
            IBackgroundInventoryPlugin2 backgroundInventoryPlugin2 = plugin as IBackgroundInventoryPlugin2;

            return(backgroundInventoryPlugin2 != null && backgroundInventoryPlugin2.ProcessResults(result, new BackgroundInventoryObject(node, task.ObjectID, task.ObjectType)));
        }
        // Token: 0x060008E2 RID: 2274 RVA: 0x0003FF5C File Offset: 0x0003E15C
        private InventoryResultBase DoInventory(object plugin, BackgroundInventory.InventoryTask task, GlobalSettingsBase globals, Credential credentials, Node node)
        {
            IBackgroundInventoryPlugin backgroundInventoryPlugin = plugin as IBackgroundInventoryPlugin;

            if (backgroundInventoryPlugin != null)
            {
                return(backgroundInventoryPlugin.DoInventory(globals, credentials, node));
            }
            IBackgroundInventoryPlugin2 backgroundInventoryPlugin2 = plugin as IBackgroundInventoryPlugin2;

            if (backgroundInventoryPlugin2 != null)
            {
                return(backgroundInventoryPlugin2.DoInventory(globals, credentials, new BackgroundInventoryObject(node, task.ObjectID, task.ObjectType)));
            }
            return(null);
        }
        // Token: 0x060008E0 RID: 2272 RVA: 0x0003F9F4 File Offset: 0x0003DBF4
        public void DoInventory(BackgroundInventory.InventoryTask task)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            Node      node      = this.GetNode(task.NodeID);

            if (node == null || node.PolledStatus != 1)
            {
                BackgroundInventory.log.InfoFormat("Skipping inventorying of Node {0}, status is not UP.", task.NodeID);
                return;
            }
            Credential         credentialsForNode = this.GetCredentialsForNode(node);
            GlobalSettingsBase globals            = this.snmpGlobals;

            if (node.NodeSubType == NodeSubType.WMI)
            {
                globals = this.wmiGlobals;
            }
            if (BackgroundInventory.log.IsInfoEnabled)
            {
                BackgroundInventory.log.InfoFormat("Starting inventorying of Node {0}, NeedsInventory = '{1}'", task.NodeID, task.Settings);
            }
            string[] array = task.Settings.Split(new char[]
            {
                ':'
            });
            List <string> failedTasks    = new List <string>();
            List <string> completedTasks = new List <string>();

            Func <string, bool> < > 9__0;
            foreach (string text in array)
            {
                BackgroundInventory.log.InfoFormat("Attempting to inventory with plugin '{0}' on Node {1}", text, task.NodeID);
                if (!this.inventories.ContainsKey(text))
                {
                    failedTasks.Add(text);
                    if (BackgroundInventory.log.IsErrorEnabled)
                    {
                        BackgroundInventory.log.ErrorFormat("Unable to inventory '{0}' on Node {1}", text, task.NodeID);
                    }
                }
                else
                {
                    if (this.IsScheduledTaskCanceled())
                    {
                        if (BackgroundInventory.log.IsInfoEnabled)
                        {
                            BackgroundInventory.log.InfoFormat("Inventorying of Node {0} was canceled. ElapsedTime = {1}", task.NodeID, stopwatch.ElapsedMilliseconds);
                        }
                        stopwatch.Stop();
                        return;
                    }
                    if (!this.IsValidPlugin(this.inventories[text]))
                    {
                        failedTasks.Add(text);
                        if (BackgroundInventory.log.IsErrorEnabled)
                        {
                            BackgroundInventory.log.ErrorFormat("No plugins are available to execute Inventory '{0}' on Node {1} returned null result", text, task.NodeID);
                        }
                    }
                    else
                    {
                        InventoryResultBase inventoryResultBase = this.DoInventory(this.inventories[text], task, globals, credentialsForNode, node);
                        if (inventoryResultBase == null)
                        {
                            failedTasks.Add(text);
                            if (BackgroundInventory.log.IsErrorEnabled)
                            {
                                BackgroundInventory.log.ErrorFormat("Inventory '{0}' on Node {1} returned null result", text, task.NodeID);
                            }
                        }
                        else
                        {
                            if (inventoryResultBase.Outcome == 1)
                            {
                                bool flag = false;
                                try
                                {
                                    flag = this.ProcessResults(this.inventories[text], task, inventoryResultBase, node);
                                }
                                catch (Exception ex)
                                {
                                    BackgroundInventory.log.Error(string.Format("Inventory '{0}' failed to import results for {1}", task, text), ex);
                                }
                                if (flag)
                                {
                                    completedTasks.Add(text);
                                }
                                else
                                {
                                    failedTasks.Add(text);
                                }
                            }
                            else
                            {
                                failedTasks.Add(text);
                                if (inventoryResultBase.Error != null)
                                {
                                    if (BackgroundInventory.log.IsWarnEnabled)
                                    {
                                        BackgroundInventory.log.WarnFormat("Inventory '{0}' on Node {1} failed with code {2}", text, task, inventoryResultBase.Error.ErrorCode);
                                    }
                                    if (inventoryResultBase.Error.ErrorCode != 31002U)
                                    {
                                        IEnumerable <string> source = array;
                                        Func <string, bool>  predicate;
                                        if ((predicate = < > 9__0) == null)
                                        {
                                            predicate = (< > 9__0 = ((string n) => !completedTasks.Contains(n) && !failedTasks.Contains(n)));
                                        }
                                        List <string> list = source.Where(predicate).ToList <string>();
                                        if (list.Count > 0)
                                        {
                                            failedTasks.AddRange(list);
                                            if (BackgroundInventory.log.IsWarnEnabled)
                                            {
                                                BackgroundInventory.log.WarnFormat("Skipping inventory for '{0}' on Node {1}", string.Join(":", list.ToArray()), task.NodeID);
                                                break;
                                            }
                                            break;
                                        }
                                    }
                                }
                                else if (BackgroundInventory.log.IsWarnEnabled)
                                {
                                    BackgroundInventory.log.WarnFormat("Inventory '{0}' on Node {1} failed on unknown error", text, task.NodeID);
                                }
                            }
                            BackgroundInventory.log.InfoFormat("Inventory with plugin '{0}' on Node {1} is completed", text, task.NodeID);
                        }
                    }
                }
            }
            string settingsForTask = this.GetSettingsForTask(task);

            if ((string.IsNullOrEmpty(settingsForTask) || !settingsForTask.Equals(task.Settings, StringComparison.OrdinalIgnoreCase)) && BackgroundInventory.log.IsInfoEnabled)
            {
                BackgroundInventory.log.InfoFormat("Skipping inventory result processing for {0}, NeedsInventory flag changed. OldValue = '{1}', NewValue = '{2}'.", task, task.Settings, settingsForTask);
                return;
            }
            if (failedTasks.Count == 0)
            {
                if (task.InventoryInput == BackgroundInventory.InventoryTask.InventoryInputSource.NodeSettings)
                {
                    NodeSettingsDAL.DeleteSpecificSettings(task.ObjectSettingID, task.InventorySettingName);
                }
                else
                {
                    InventorySettingsDAL.DeleteSpecificSettings(task.ObjectSettingID, task.InventorySettingName);
                }
                if (BackgroundInventory.log.IsInfoEnabled)
                {
                    BackgroundInventory.log.InfoFormat("Inventorying of {0} completed in {1}ms.", task, stopwatch.ElapsedMilliseconds);
                }
            }
            else if (failedTasks.Count < array.Length)
            {
                string text2 = string.Join(":", failedTasks.ToArray());
                if (task.InventoryInput == BackgroundInventory.InventoryTask.InventoryInputSource.NodeSettings)
                {
                    NodeSettingsDAL.UpdateSettingValue(task.ObjectSettingID, task.InventorySettingName, text2);
                }
                else
                {
                    InventorySettingsDAL.UpdateSettingValue(task.ObjectSettingID, task.InventorySettingName, text2);
                }
                if (BackgroundInventory.log.IsInfoEnabled)
                {
                    BackgroundInventory.log.InfoFormat("Inventorying of {0} partially completed in {1}ms. NeedsInventory updated to '{2}'", task, stopwatch.ElapsedMilliseconds, text2);
                }
            }
            else if (BackgroundInventory.log.IsInfoEnabled)
            {
                BackgroundInventory.log.InfoFormat("Inventorying of {0} failed. Elapsed time {1}ms.", task, stopwatch.ElapsedMilliseconds);
            }
            stopwatch.Stop();
        }