Exemple #1
0
        private void LoadPublicAgents(string filePath, out List <AgentInfo> publicAgents)
        {
            int num = 20;

            if (string.IsNullOrEmpty(filePath))
            {
                publicAgents = new List <AgentInfo>();
                return;
            }
            for (;;)
            {
                XmlDocument xmlDocument = new SafeXmlDocument();
                xmlDocument.Schemas = MExConfiguration.Schemas;
                try
                {
                    using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        xmlDocument.Load(fileStream);
                        xmlDocument.Validate(delegate(object sender, ValidationEventArgs args)
                        {
                            throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfigurationFile(filePath), args.Exception);
                        });
                        this.LoadSettings(xmlDocument.SelectSingleNode("/configuration/mexRuntime/settings"));
                        this.LoadMonitoringOptions(xmlDocument.SelectSingleNode("/configuration/mexRuntime/monitoring"));
                        publicAgents = this.LoadAgentList(xmlDocument.SelectSingleNode("/configuration/mexRuntime/agentList"), false);
                    }
                }
                catch (XmlException innerException)
                {
                    throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfigurationFile(filePath), innerException);
                }
                catch (FormatException innerException2)
                {
                    throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfigurationFile(filePath), innerException2);
                }
                catch (UnauthorizedAccessException innerException3)
                {
                    throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfigurationFile(filePath), innerException3);
                }
                catch (IOException innerException4)
                {
                    if (num <= 0)
                    {
                        throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfigurationFile(filePath), innerException4);
                    }
                    num--;
                    Thread.Sleep(50);
                    continue;
                }
                break;
            }
        }
Exemple #2
0
        public FactoryTable(IEnumerable agents, FactoryInitializer factoryInitializer)
        {
            this.factoriesByAgentId     = new Dictionary <string, AgentFactory>();
            this.agentManagersByAgentId = new Dictionary <string, AgentManager>();
            Dictionary <string, AgentFactory> dictionary = new Dictionary <string, AgentFactory>();
            DateTime      utcNow        = DateTime.UtcNow;
            StringBuilder stringBuilder = new StringBuilder();

            foreach (object obj in agents)
            {
                AgentInfo agentInfo = (AgentInfo)obj;
                if (this.factoriesByAgentId.ContainsKey(agentInfo.Id))
                {
                    throw new ExchangeConfigurationException(MExRuntimeStrings.DuplicateAgentName(agentInfo.AgentName));
                }
                DateTime     utcNow2 = DateTime.UtcNow;
                AgentFactory agentFactory;
                if (!dictionary.TryGetValue(agentInfo.FactoryTypeName, out agentFactory))
                {
                    agentFactory = FactoryTable.CreateAgentFactory(agentInfo);
                    if (factoryInitializer != null)
                    {
                        factoryInitializer(agentFactory);
                    }
                    dictionary.Add(agentInfo.FactoryTypeName, agentFactory);
                }
                this.factoriesByAgentId.Add(agentInfo.Id, agentFactory);
                AgentManager agentManagerInstance = FactoryTable.GetAgentManagerInstance(agentInfo);
                if (agentManagerInstance != null)
                {
                    this.agentManagersByAgentId.Add(agentInfo.Id, agentManagerInstance);
                }
                TimeSpan timeSpan = DateTime.UtcNow - utcNow2;
                stringBuilder.AppendLine();
                stringBuilder.Append(agentInfo.AgentName);
                stringBuilder.Append(": ");
                stringBuilder.Append(timeSpan);
            }
            this.startupDiagnosticInfo = stringBuilder.ToString();
            TimeSpan timeSpan2 = DateTime.UtcNow - utcNow;

            if (timeSpan2 > FactoryTable.StartupThreshold)
            {
                MExDiagnostics.EventLog.LogEvent(EdgeExtensibilityEventLogConstants.Tuple_MExAgentFactoryStartupDelay, null, new object[]
                {
                    timeSpan2,
                    this.startupDiagnosticInfo
                });
            }
            this.factories = new AgentFactory[this.factoriesByAgentId.Count];
            this.factoriesByAgentId.Values.CopyTo(this.factories, 0);
        }
Exemple #3
0
        internal void Load(string filePath)
        {
            if (!string.IsNullOrEmpty(filePath) && !File.Exists(filePath))
            {
                throw new ExchangeConfigurationException(MExRuntimeStrings.MissingConfigurationFile(filePath), new FileNotFoundException());
            }
            List <AgentInfo> preExecutionInternalAgents;
            List <AgentInfo> postExecutionInternalAgents;

            this.LoadInternalAgents(out preExecutionInternalAgents, out postExecutionInternalAgents);
            List <AgentInfo> publicAgents;

            this.LoadPublicAgents(filePath, out publicAgents);
            this.agentList = this.CreateFinalAgentsList(publicAgents, preExecutionInternalAgents, postExecutionInternalAgents);
        }
Exemple #4
0
        internal void Save(string filePath)
        {
            XmlDocument xmlDocument = this.CreateXmlDocument();

            xmlDocument.Schemas = MExConfiguration.Schemas;
            xmlDocument.Validate(delegate(object sender, ValidationEventArgs args)
            {
                throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfiguration, args.Exception);
            });
            int num = 20;

            try
            {
IL_38:
                using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    xmlDocument.Save(fileStream);
                }
            }
            catch (XmlException innerException)
            {
                throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfigurationFile(filePath), innerException);
            }
            catch (UnauthorizedAccessException innerException2)
            {
                throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfigurationFile(filePath), innerException2);
            }
            catch (IOException innerException3)
            {
                if (num <= 0)
                {
                    throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfigurationFile(filePath), innerException3);
                }
                num--;
                Thread.Sleep(50);
                goto IL_38;
            }
        }
Exemple #5
0
 private void LoadInternalAgents(out List <AgentInfo> preExecutionInternalAgents, out List <AgentInfo> postExecutionInternalAgents)
 {
     preExecutionInternalAgents  = new List <AgentInfo>();
     postExecutionInternalAgents = new List <AgentInfo>();
     try
     {
         XmlDocument xmlDocument = new SafeXmlDocument();
         xmlDocument.Schemas = MExConfiguration.InternalSchemas;
         Assembly executingAssembly = Assembly.GetExecutingAssembly();
         using (Stream manifestResourceStream = executingAssembly.GetManifestResourceStream("internalAgents.config"))
         {
             xmlDocument.Load(manifestResourceStream);
             xmlDocument.Validate(delegate(object sender, ValidationEventArgs args)
             {
                 throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfigurationFile("internalAgents.config"), args.Exception);
             });
             string xmlMarkups = this.GetXmlMarkups(this.exchangeSku, this.transportProcessRole);
             if (xmlMarkups != null)
             {
                 preExecutionInternalAgents  = this.LoadAgentList(xmlDocument.SelectSingleNode("/internalConfiguration/internalMexRuntime/" + xmlMarkups + "/preExecution"), true);
                 postExecutionInternalAgents = this.LoadAgentList(xmlDocument.SelectSingleNode("/internalConfiguration/internalMexRuntime/" + xmlMarkups + "/postExecution"), true);
             }
         }
     }
     catch (XmlException innerException)
     {
         throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfigurationFile("internalAgents.config"), innerException);
     }
     catch (UnauthorizedAccessException innerException2)
     {
         throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfigurationFile("internalAgents.config"), innerException2);
     }
     catch (IOException innerException3)
     {
         throw new ExchangeConfigurationException(MExRuntimeStrings.InvalidConfigurationFile("internalAgents.config"), innerException3);
     }
 }
Exemple #6
0
        private Agent CreateAgentInstance(AgentRecord agentRecord)
        {
            AgentFactory agentFactory = this.settings.AgentFactories[agentRecord.Id];
            object       state        = (this.hostState == null) ? null : this.hostState.Clone();
            Agent        agent;

            try
            {
                agent = agentFactory.CreateAgent(agentRecord.Type, state);
            }
            catch (LocalizedException ex)
            {
                MExDiagnostics.EventLog.LogEvent(EdgeExtensibilityEventLogConstants.Tuple_MExAgentInstanceCreationFailure, null, new object[]
                {
                    agentRecord.Name,
                    ex.Message
                });
                throw;
            }
            if (agent == null || agent.Id != null)
            {
                string error             = (agent == null) ? "agent instance cannot be null" : "agent instance already in use";
                ApplicationException ex2 = new ApplicationException(MExRuntimeStrings.AgentCreationFailure(agentRecord.Name, error));
                MExDiagnostics.EventLog.LogEvent(EdgeExtensibilityEventLogConstants.Tuple_MExAgentInstanceCreationFailure, null, new object[]
                {
                    agentRecord.Name,
                    ex2.Message
                });
                throw ex2;
            }
            agent.Id              = agent.GetHashCode().ToString(CultureInfo.InvariantCulture);
            agent.Name            = agentRecord.Name;
            agent.SnapshotEnabled = this.settings.MonitoringOptions.MessageSnapshotEnabled;
            agent.HostState       = state;
            ExTraceGlobals.DispatchTracer.Information <string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "agent '{0}' created from factory '{1}'", agent.GetType().FullName, agentFactory.GetType().FullName);
            return(agent);
        }
Exemple #7
0
        private static AgentFactory CreateAgentFactory(AgentInfo agentInfo)
        {
            string       assembly2;
            Exception    ex;
            AgentFactory agentFactory = FactoryTable.LoadAssemblyAndCreateInstance <AgentFactory>(agentInfo, (Assembly assembly) => (AgentFactory)assembly.CreateInstance(agentInfo.FactoryTypeName), out assembly2, out ex);

            if (agentFactory == null)
            {
                ExEventLog.EventTuple tuple = EdgeExtensibilityEventLogConstants.Tuple_MExAgentFactoryCreationFailure;
                if (ex is InvalidCastException)
                {
                    tuple = EdgeExtensibilityEventLogConstants.Tuple_MExAgentVersionMismatch;
                }
                ExchangeConfigurationException ex2 = new ExchangeConfigurationException(MExRuntimeStrings.InvalidTypeInConfiguration(agentInfo.FactoryTypeName, assembly2, (ex == null) ? "type not found" : ex.Message), ex);
                MExDiagnostics.EventLog.LogEvent(tuple, null, new object[]
                {
                    agentInfo.AgentName,
                    ex2.Message
                });
                throw ex2;
            }
            return(agentFactory);
        }
Exemple #8
0
 private void AgentAsyncCompletionCallback(AgentAsyncContext context)
 {
     if (this.resumeAgentCallback != null && this.resumeAgentCallback())
     {
         MExDiagnostics.EventLog.LogEvent(EdgeExtensibilityEventLogConstants.Tuple_MExAgentDidNotCallResume, this.lastAgentName, new object[]
         {
             this.lastAgentName,
             this.eventTopic
         });
     }
     ExTraceGlobals.DispatchTracer.TraceDebug <string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "async completed, async result {0}, exception {1}", this.isSyncInvoke ? "n/a" : this.pendingResult.GetHashCode().ToString(CultureInfo.InvariantCulture), (context.AsyncException == null) ? "n/a" : context.AsyncException.GetType().FullName);
     if (this.isSyncInvoke)
     {
         if (context.AsyncException != null)
         {
             MExAsyncResult.WrapAndRethrowException(context.AsyncException, new LocalizedString(MExRuntimeStrings.AgentFault(this.currentAgent.Name, this.eventTopic)));
         }
         this.syncWaitHandle.Set();
         return;
     }
     if (context.AsyncException != null)
     {
         this.pendingResult.AsyncException = context.AsyncException;
         this.HaltExecution();
         MExSession.LogMexAgentFaultEvent(MExDiagnostics.EventLog, context.AsyncException, this.currentAgent.Name, this.eventTopic);
     }
     if (this.completeAsyncAgentCallback != null)
     {
         this.completeAsyncAgentCallback();
     }
     this.Dispatcher.AgentInvokeCompleted(this);
     this.ResumeExecution();
 }
Exemple #9
0
        internal void EndInvoke()
        {
            if (this.asyncException != null)
            {
                MExAsyncResult.WrapAndRethrowException(this.asyncException, new LocalizedString(MExRuntimeStrings.AgentFault(this.faultyAgentName, this.eventTopic)));
            }
            WaitHandle waitHandle = null;

            lock (this.syncRoot)
            {
                if (!this.isCompleted)
                {
                    waitHandle = this.AsyncWaitHandle;
                }
            }
            if (waitHandle != null)
            {
                waitHandle.WaitOne();
            }
            if (this.asyncException != null)
            {
                MExAsyncResult.WrapAndRethrowException(this.asyncException, new LocalizedString(MExRuntimeStrings.AgentFault(this.faultyAgentName, this.eventTopic)));
            }
        }