Ejemplo n.º 1
0
        private const int CAT_DEFAULT = 1;      // default tracing event category

        #region Initializating, reinitializating and closing runspace
        /// <summary>
        /// Initializes a new instance of the <see cref="PowerShellSupport" /> class.
        /// </summary>
        /// <param name="localSnapinNames">Local snapins to be loaded</param>
        /// <param name="useRemoteSession">Whether to use remote session (e.g. for managing Exchange)</param>
        /// <param name="createRunspaceMethod">A method used to create a new runspace (if null, a default implementation is used)</param>
        /// <param name="messageCatalog">The message catalog used for conveying localized messages.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageCatalog"/> is null.</exception>
        public PowerShellSupport(IList <string> localSnapinNames, CreateRunspaceDelegate createRunspaceMethod, ConnectorMessages messageCatalog)
        {
            Assertions.NullCheck(messageCatalog, "messageCatalog");
            _messageCatalog   = messageCatalog;
            _localSnapinNames = localSnapinNames;
            _runSpacePool     = new MyRunspacePool(createRunspaceMethod ?? DefaultRunspaceCreateMethod);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RunSpaceInstance" /> class.
        /// </summary>
        /// <param name="snapin">Type of snapin to be loaded</param>
        /// <param name="messageCatalog">The message catalog used for conveying localized messages.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageCatalog"/> is null.</exception>
        public RunSpaceInstance(SnapIn snapin, ConnectorMessages messageCatalog)
        {
            Assertions.NullCheck(messageCatalog, "messageCatalog");
            _messageCatalog = messageCatalog;

            // initialize this
            this.InitRunSpace(snapin);
        }
Ejemplo n.º 3
0
        private String FormatMessage(String key, String dflt, params object[] args)
        {
            APIConfigurationImpl apiConfig = Parent.Parent;
            ConnectorMessages    messages  =
                apiConfig.ConnectorInfo.Messages;

            return(messages.Format(key, dflt, args));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Determines if the configuration is valid.
        /// </summary>
        /// <remarks>See <see cref="Org.IdentityConnectors.Framework.Spi.Configuration"/> for the definition of a valid
        /// configuration.</remarks>
        /// <exception cref="Org.IdentityConnectors.Framework.Common.Exceptions.ConfigurationException"/>
        /// Thrown when the configuration is not valid.</exception>
        public override void Validate()
        {
            var message = new StringBuilder();

            Boolean foundError = false;

            // can't lookup the schema without the domain name
            if ((DomainName == null) || (DomainName.Length == 0))
            {
                message.Append(ConnectorMessages.Format(
                                   "confReqParam_domainName", "Domain name not supplied  "));
                foundError = true;
            }

            if ((DirectoryAdminName == null) || (DirectoryAdminName.Length == 0))
            {
                message.Append(ConnectorMessages.Format(
                                   "confReqParam_adminName", "Directory administrator name not supplied  "));
                foundError = true;
            }

            if ((DirectoryAdminPassword == null) || (DirectoryAdminPassword.Length == 0))
            {
                message.Append(ConnectorMessages.Format(
                                   "confReqParam_adminPass", "Directory administrator password not supplied  "));
                foundError = true;
            }

            if ((ObjectClass == null) || (ObjectClass.Length == 0))
            {
                message.Append(ConnectorMessages.Format(
                                   "confReqParam_objClass", "ObjectClass was not supplied  "));
                foundError = true;
            }

            if (string.IsNullOrEmpty(Container))
            {
                message.Append(ConnectorMessages.Format(
                                   "confReqParam_Container", "Container was not supplied  "));
                foundError = true;
            }
            else
            {
                if (!ActiveDirectoryUtils.IsValidDn(Container))
                {
                    message.Append(ConnectorMessages.Format(
                                       "confParam_Container_invalid_path", @"Container '{0}' could not be recognized as a distinguished name (DN)  ", Container));
                    foundError = true;
                }
            }

            if (foundError)
            {
                throw new ConfigurationException(ConnectorMessages.Format(
                                                     "ex_ConfigErrors", "Configuration errors: {0}", message.ToString()));
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Dispose/Finalize pattern
 /// </summary>
 /// <param name="disposing">true if called from <see cref="PowerShellSupport.Dispose()"/></param>
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         // Free other state (managed objects).
         // clean up the runspace with attached things:
         // the API docs show that the RunspaceInvoke will call Dispose on
         // the Runspace which in turn calls Close on the Runspace.
         _runSpacePool.Close();
     }
     _messageCatalog = null;
 }
Ejemplo n.º 6
0
        internal ExchangePowerShellSupport(string configuredExchangeVersion, string exchangeUri, ConnectorMessages messageCatalog)
        {
            if (configuredExchangeVersion == null && exchangeUri != null)
            {
                LOGGER.TraceEvent(TraceEventType.Warning, CAT_DEFAULT, "No configured Exchange version. As auto-detection is not possible in remote mode, using 2010 as a default.");
                _exchangeVersion = ExchangeVersion.E2010;
            }
            else
            {
                _exchangeVersion = GetExchangeServerVersion(configuredExchangeVersion);
            }
            IList <string> snapins = new List <string>();

            if (exchangeUri == null)
            {
                switch (_exchangeVersion)
                {
                case ExchangeVersion.E2007:
                    // used for force load of the exchange dll's (untested in current version of the connector!)
                    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolver2007);
                    snapins.Add(Exchange2007SnapIn);
                    break;

                case ExchangeVersion.E2010:
                    snapins.Add(Exchange2010SnapIn);
                    break;

                case ExchangeVersion.E2013:
                    snapins.Add(Exchange2013SnapIn);
                    break;

                default: throw new ArgumentException("Invalid server version: " + _exchangeVersion);
                }
            }
            _exchangeUri       = exchangeUri;
            _messageCatalog    = messageCatalog;
            _powerShellSupport = new PowerShellSupport(snapins, CreateExchangeRunspace, messageCatalog);
        }
 /// <summary>
 /// Dispose/Finalize pattern
 /// </summary>
 /// <param name="disposing">true if called from <see cref="RunSpaceInstance.Dispose()"/></param>
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         // Free other state (managed objects).
         // clean up the runspace with attached things:
         // the API docs show that the RunspaceInvoke will call Dispose on
         // the Runspace which in turn calls Close on the Runspace.
         if (this.runSpaceInvoke != null)
         {
             this.runSpaceInvoke.Dispose();
         }
         else
         {
             if (this.runSpace != null)
             {
                 this.runSpace.Dispose();
             }
         }
     }
     _messageCatalog = null;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="RunSpaceInstance" /> class. 
        /// </summary>
        /// <param name="snapin">Type of snapin to be loaded</param>
        /// <param name="messageCatalog">The message catalog used for conveying localized messages.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageCatalog"/> is null.</exception>
        public RunSpaceInstance(SnapIn snapin, ConnectorMessages messageCatalog)
        {
            Assertions.NullCheck( messageCatalog, "messageCatalog" );
            _messageCatalog = messageCatalog;

            // initialize this
            this.InitRunSpace(snapin);
        }
Ejemplo n.º 9
0
 internal ExchangePowerShellSupport(string configuredExchangeVersion, string exchangeUri, ConnectorMessages messageCatalog)
 {
     if (configuredExchangeVersion == null && exchangeUri != null) {
         LOGGER.TraceEvent(TraceEventType.Warning, CAT_DEFAULT, "No configured Exchange version. As auto-detection is not possible in remote mode, using 2010 as a default.");
         _exchangeVersion = ExchangeVersion.E2010;
     } else {
         _exchangeVersion = GetExchangeServerVersion(configuredExchangeVersion);
     }
     IList<string> snapins = new List<string>();
     if (exchangeUri == null) {
         switch(_exchangeVersion) {
             case ExchangeVersion.E2007:
                 // used for force load of the exchange dll's (untested in current version of the connector!)
                 AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolver2007);
                 snapins.Add(Exchange2007SnapIn);
                 break;
             case ExchangeVersion.E2010:
                 snapins.Add(Exchange2010SnapIn);
                 break;
             case ExchangeVersion.E2013:
                 snapins.Add(Exchange2013SnapIn);
                 break;
             default: throw new ArgumentException("Invalid server version: " + _exchangeVersion);
         }
     }
     _exchangeUri = exchangeUri;
     _messageCatalog = messageCatalog;
     _powerShellSupport = new PowerShellSupport(snapins, CreateExchangeRunspace, messageCatalog);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PowerShellSupport" /> class.
 /// </summary>
 /// <param name="localSnapinNames">Local snapins to be loaded</param>
 /// <param name="useRemoteSession">Whether to use remote session (e.g. for managing Exchange)</param>
 /// <param name="createRunspaceMethod">A method used to create a new runspace (if null, a default implementation is used)</param>
 /// <param name="messageCatalog">The message catalog used for conveying localized messages.</param>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="messageCatalog"/> is null.</exception>
 public PowerShellSupport(IList<string> localSnapinNames, CreateRunspaceDelegate createRunspaceMethod, ConnectorMessages messageCatalog)
 {
     Assertions.NullCheck(messageCatalog, "messageCatalog");
     _messageCatalog = messageCatalog;
     _localSnapinNames = localSnapinNames;
     _runSpacePool = new MyRunspacePool(createRunspaceMethod ?? DefaultRunspaceCreateMethod);
 }