Esempio n. 1
0
 private void EnsureTransportServiceIsSupported()
 {
     if (this.TransportService != TransportService.Hub && this.TransportService != TransportService.Edge && this.TransportService != TransportService.FrontEnd)
     {
         base.ThrowTerminatingError(new LocalizedException(AgentStrings.TransportServiceNotSupported(this.TransportService.ToString())), ErrorCategory.InvalidOperation, null);
     }
 }
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            base.InternalProcessRecord();
            this.cleanIdentity = base.ValidateAndNormalizeAgentIdentity(this.Identity.ToString());
            if (!base.AgentExists(this.cleanIdentity))
            {
                base.WriteError(new ArgumentException(AgentStrings.AgentNotFound(this.Identity.ToString()), "Identity"), ErrorCategory.InvalidArgument, null);
            }
            IList <AgentInfo> publicAgentList = base.MExConfiguration.GetPublicAgentList();

            if (this.Priority != null)
            {
                if (this.Priority < 1 || this.Priority > publicAgentList.Count)
                {
                    base.WriteError(new ArgumentOutOfRangeException(AgentStrings.PriorityOutOfRange(publicAgentList.Count.ToString())), ErrorCategory.InvalidArgument, null);
                }
                foreach (AgentInfo agentInfo in publicAgentList)
                {
                    if (string.Compare(agentInfo.AgentName, this.cleanIdentity, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        base.MExConfiguration.AgentList.Remove(agentInfo);
                        int index = this.Priority.Value - 1 + base.MExConfiguration.GetPreExecutionInternalAgents().Count;
                        base.MExConfiguration.AgentList.Insert(index, agentInfo);
                        base.Save();
                        this.WriteWarning(AgentStrings.RestartServiceForChanges(base.GetTransportServiceName()));
                        TaskLogger.LogExit();
                        return;
                    }
                }
                base.WriteError(new ArgumentException(AgentStrings.AgentNotFound(this.Identity.ToString()), "Identity"), ErrorCategory.InvalidArgument, null);
                return;
            }
        }
        private void ValidateDeliveryAgent(AgentInfo agentInfo)
        {
            HashSet <string> hashSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (AgentInfo agentInfo2 in base.MExConfiguration.AgentList)
            {
                DeliveryAgentManager deliveryAgentManager = FactoryTable.GetAgentManagerInstance(agentInfo2) as DeliveryAgentManager;
                if (deliveryAgentManager != null)
                {
                    if (string.IsNullOrEmpty(deliveryAgentManager.SupportedDeliveryProtocol))
                    {
                        this.WriteWarning(AgentStrings.DeliveryProtocolNotValid(agentInfo2.AgentName));
                    }
                    else
                    {
                        hashSet.Add(deliveryAgentManager.SupportedDeliveryProtocol);
                    }
                }
            }
            DeliveryAgentManager deliveryAgentManager2 = FactoryTable.GetAgentManagerInstance(agentInfo) as DeliveryAgentManager;

            if (deliveryAgentManager2 == null)
            {
                base.WriteError(new ArgumentException(AgentStrings.InvalidDeliveryAgentManager(this.Name)), ErrorCategory.InvalidArgument, null);
            }
            if (string.IsNullOrEmpty(deliveryAgentManager2.SupportedDeliveryProtocol))
            {
                base.WriteError(new ArgumentException(AgentStrings.DeliveryProtocolNotSpecified(this.Name)), ErrorCategory.InvalidArgument, null);
            }
            if (hashSet.Contains(deliveryAgentManager2.SupportedDeliveryProtocol))
            {
                base.WriteError(new ArgumentException(AgentStrings.MustHaveUniqueDeliveryProtocol(this.Name, deliveryAgentManager2.SupportedDeliveryProtocol)), ErrorCategory.InvalidArgument, null);
            }
        }
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            base.InternalProcessRecord();
            string text = base.ValidateAndNormalizeAgentIdentity(this.Name);

            if (base.AgentExists(text))
            {
                base.WriteError(new ArgumentException(AgentStrings.AgentAlreadyExist(this.Name), "Name"), ErrorCategory.InvalidArgument, null);
            }
            Type      type      = this.ReflectAgentType(this.absoluteAssemblyPath, this.TransportAgentFactory);
            AgentInfo agentInfo = new AgentInfo(text, type.ToString(), this.TransportAgentFactory, this.absoluteAssemblyPath, false, false);

            if (base.TransportService == TransportService.FrontEnd && type != typeof(SmtpReceiveAgent))
            {
                base.WriteError(new InvalidOperationException(AgentStrings.AgentTypeNotSupportedOnFrontEnd(type.ToString())), ErrorCategory.InvalidOperation, null);
            }
            if (type == typeof(DeliveryAgent))
            {
                this.ValidateDeliveryAgent(agentInfo);
            }
            TransportAgent sendToPipeline = new TransportAgent(text, false, base.MExConfiguration.GetPublicAgentList().Count + 1, this.TransportAgentFactory, this.absoluteAssemblyPath);
            int            index          = base.MExConfiguration.GetPublicAgentList().Count + base.MExConfiguration.GetPreExecutionInternalAgents().Count;

            base.MExConfiguration.AgentList.Insert(index, agentInfo);
            base.Save();
            base.WriteObject(sendToPipeline);
            if (base.MissingConfigFile)
            {
                this.WriteWarning(AgentStrings.MissingConfigurationFileCreate(base.MExConfigPath));
            }
            this.WriteWarning(AgentStrings.ReleaseAgentBinaryReference);
            this.WriteWarning(AgentStrings.RestartServiceForChanges(base.GetTransportServiceName()));
            TaskLogger.LogExit();
        }
Esempio n. 5
0
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter();
     base.InternalProcessRecord();
     base.SetAgentEnabled(this.Identity.ToString(), true);
     base.Save();
     this.WriteWarning(AgentStrings.RestartServiceForChanges(base.GetTransportServiceName()));
     TaskLogger.LogExit();
 }
        private Type ReflectAgentType(string assemblyPath, string transportAgentFactory)
        {
            Assembly assembly;

            try
            {
                assembly = Assembly.LoadFrom(assemblyPath);
            }
            catch (FileNotFoundException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidArgument, null);
                return(null);
            }
            catch (FileLoadException exception2)
            {
                base.WriteError(exception2, ErrorCategory.InvalidArgument, null);
                return(null);
            }
            catch (BadImageFormatException exception3)
            {
                base.WriteError(exception3, ErrorCategory.InvalidArgument, null);
                return(null);
            }
            catch (ArgumentException exception4)
            {
                base.WriteError(exception4, ErrorCategory.InvalidArgument, null);
                return(null);
            }
            Type type = assembly.GetType(transportAgentFactory, false);

            if (null == type)
            {
                base.WriteError(new ArgumentException(AgentStrings.AgentFactoryTypeNotExist(transportAgentFactory), "TransportAgentFactory"), ErrorCategory.InvalidArgument, null);
                return(null);
            }
            while (type != null)
            {
                if (type == typeof(SmtpReceiveAgentFactory))
                {
                    return(typeof(SmtpReceiveAgent));
                }
                if (type == typeof(RoutingAgentFactory))
                {
                    return(typeof(RoutingAgent));
                }
                if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(DeliveryAgentFactory <>))
                {
                    return(typeof(DeliveryAgent));
                }
                type = type.BaseType;
            }
            base.WriteError(new ArgumentException(AgentStrings.InvalidTransportAgentFactory(transportAgentFactory), "TransportAgentFactory"), ErrorCategory.InvalidArgument, null);
            return(null);
        }
Esempio n. 7
0
        internal void SetAgentEnabled(string identity, bool enabled)
        {
            string strB = this.ValidateAndNormalizeAgentIdentity(identity);

            if (this.mexConfig != null)
            {
                foreach (AgentInfo agentInfo in this.mexConfig.GetPublicAgentList())
                {
                    if (string.Compare(agentInfo.AgentName, strB, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        agentInfo.Enabled = enabled;
                        return;
                    }
                }
            }
            base.WriteError(new ArgumentException(AgentStrings.AgentNotFound(identity), "Identity"), ErrorCategory.InvalidArgument, null);
        }
Esempio n. 8
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            base.InternalProcessRecord();
            string strB = base.ValidateAndNormalizeAgentIdentity(this.Identity.ToString());

            foreach (AgentInfo agentInfo in base.MExConfiguration.GetPublicAgentList())
            {
                if (string.Compare(agentInfo.AgentName, strB, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    base.MExConfiguration.AgentList.Remove(agentInfo);
                    base.Save();
                    this.WriteWarning(AgentStrings.RestartServiceForChanges(base.GetTransportServiceName()));
                    TaskLogger.LogExit();
                    return;
                }
            }
            base.WriteError(new ArgumentException(AgentStrings.AgentNotFound(this.Identity.ToString()), "Identity"), ErrorCategory.InvalidArgument, null);
        }
        protected override void InternalValidate()
        {
            if (this.Name.Length > 64)
            {
                base.WriteError(new ArgumentException(AgentStrings.AgentNameTooLargeArgument, "Name"), ErrorCategory.InvalidArgument, null);
            }
            if (!InstallTransportAgent.IsValidAgentName(this.Name))
            {
                base.WriteError(new ArgumentException(AgentStrings.AgentNameContainsInvalidCharacters, "Name"), ErrorCategory.InvalidArgument, null);
            }
            this.absoluteAssemblyPath = this.AssemblyPath;
            Server serverObject = base.GetServerObject();
            bool   flag         = serverObject != null && serverObject.IsEdgeServer;

            try
            {
                if (flag)
                {
                    string currentPathProviderName = base.SessionState.CurrentPathProviderName;
                    if (string.Compare(currentPathProviderName, "FileSystem", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        this.absoluteAssemblyPath = Path.Combine(base.SessionState.CurrentPath, this.AssemblyPath);
                    }
                }
                else if (!Path.IsPathRooted(this.AssemblyPath))
                {
                    base.WriteError(new ArgumentException(AgentStrings.AssemblyFilePathRelativeOnHub(this.AssemblyPath), "AssemblyPath"), ErrorCategory.InvalidArgument, null);
                }
            }
            catch (ArgumentException)
            {
                base.WriteError(new ArgumentException(AgentStrings.AssemblyFileNotExist(this.AssemblyPath), "AssemblyPath"), ErrorCategory.InvalidArgument, this.AssemblyPath);
            }
            if (new Uri(this.absoluteAssemblyPath).IsUnc)
            {
                base.WriteError(new ArgumentException(AgentStrings.AssemblyFilePathCanNotBeUNC(this.AssemblyPath), "AssemblyPath"), ErrorCategory.InvalidArgument, this.AssemblyPath);
            }
            if (!File.Exists(this.absoluteAssemblyPath))
            {
                base.WriteError(new ArgumentException(AgentStrings.AssemblyFileNotExist(this.AssemblyPath), "AssemblyPath"), ErrorCategory.InvalidArgument, null);
            }
            base.InternalValidate();
        }
Esempio n. 10
0
 public LocDescriptionAttribute(AgentStrings.IDs ids) : base(AgentStrings.GetLocalizedString(ids))
 {
 }