Esempio n. 1
0
        public async Task <Dictionary <PluginInstance, bool> > OnLoggerConfigUpdatedAsync()
        {
            try
            {
                var plugins     = new List <PluginInstance>(RunningPluginMap.Values);
                var remoteTasks = plugins.AsParallel().Select(p => p.Plugin.OnMessage(PluginMessage.OnLoggerConfigUpdated));

                // ReSharper disable once ConstantConditionalAccessQualifier
                var results = (await RemoteTask.WhenAll(remoteTasks).ConfigureAwait(false))?.Cast <bool>()?.ToList();

                if (results == null)
                {
                    return(null);
                }

                if (results.Count != plugins.Count)
                {
                    throw new InvalidOperationException($"results.Count is {results.Count} while plugins.Count is {plugins.Count}");
                }

                Dictionary <PluginInstance, bool> pluginCallSuccessMap = new Dictionary <PluginInstance, bool>();

                for (int i = 0; i < results.Count; i++)
                {
                    pluginCallSuccessMap[plugins[i]] = results[i];
                }

                return(pluginCallSuccessMap);
            }
            catch (RemotingException ex)
            {
                LogTo.Warning(ex, "Remoting exception thrown in OnLoggerConfigUpdated");

                return(null);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex, "Exception thrown in OnLoggerConfigUpdated");

                return(null);
            }
        }