Esempio n. 1
0
        /// <summary>
        /// Partitions arguments into regular arguments and
        /// stream arguments.
        /// </summary>
        /// <param name="paramTypes">The param types of the method</param>
        /// <param name="arguments">The passed-in arguments. As a
        /// side-effect will be set to just the regular arguments.</param>
        /// <returns>The stream handler arguments.</returns>
        private static ObjectStreamHandler ExtractStreamHandler(Type[] paramTypes,
                                                                IList <Object> arguments)
        {
            ObjectStreamHandler rv = null;
            IList <Object>      filteredArguments = new List <Object>();

            for (int i = 0; i < paramTypes.Length; i++)
            {
                Type   paramType = paramTypes[i];
                object arg       = arguments[i];
                if (StreamHandlerUtil.IsAdaptableToObjectStreamHandler(paramType))
                {
                    ObjectStreamHandler handler = StreamHandlerUtil.AdaptToObjectStreamHandler(paramType, arg);
                    if (rv != null)
                    {
                        throw new InvalidOperationException("Multiple stream handlers not supported");
                    }
                    rv = handler;
                }
                else
                {
                    filteredArguments.Add(arg);
                }
            }
            arguments.Clear();
            CollectionUtil.AddAll(arguments, filteredArguments);
            return(rv);
        }
Esempio n. 2
0
        internal IList <ScriptToRun> GetScriptsFor(string operationName, ObjectClass objectClass, Scripting.Position position)
        {
            List <ScriptToRun> rv = new List <ScriptToRun>();

            foreach (OperationInfo operationInfo in OperationInfo)
            {
                // does operation name match?
                bool match;
                if (operationInfo.OpType == null || operationInfo.OpType.Length == 0)
                {
                    match = true;
                }
                else
                {
                    match = false;
                    foreach (string specifiedOpType in operationInfo.OpType)
                    {
                        if (specifiedOpType.Equals(operationName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            match = true;
                        }
                    }
                }

                if (match)
                {
                    CollectionUtil.AddAll(rv, operationInfo.GetScriptsFor(objectClass, position));
                }
            }
            rv.Sort((x, y) => x.Order.CompareTo(y.Order));
            return(rv);
        }
Esempio n. 3
0
        public LocalConnectorInfoManagerImpl()
        {
            _connectorInfo = new List <ConnectorInfo>();
            Assembly assembly         = Assembly.GetExecutingAssembly();
            FileInfo thisAssemblyFile =
                new FileInfo(assembly.Location);
            DirectoryInfo directory =
                thisAssemblyFile.Directory;

            FileInfo[] files =
                directory.GetFiles("*.Connector.dll");
            foreach (FileInfo file in files)
            {
                Assembly lib =
                    Assembly.LoadFrom(file.ToString());
                CollectionUtil.AddAll(_connectorInfo,
                                      ProcessAssembly(lib));
            }
            // also handle connector DLL file names with a version
            FileInfo[] versionedFiles = directory.GetFiles("*.Connector-*.dll");
            foreach (FileInfo versionedFile in versionedFiles)
            {
                Assembly lib =
                    Assembly.LoadFrom(versionedFile.ToString());
                CollectionUtil.AddAll(_connectorInfo,
                                      ProcessAssembly(lib));
            }
        }
Esempio n. 4
0
        private static ICollection <SafeType <APIOperation> > TranslateOperations(SafeType <SPIOperation>[] ops)
        {
            ICollection <SafeType <APIOperation> > set =
                new HashSet <SafeType <APIOperation> >();

            foreach (SafeType <SPIOperation> spi in ops)
            {
                CollectionUtil.AddAll(set, FrameworkUtil.Spi2Apis(spi));
            }
            return(set);
        }
Esempio n. 5
0
        public static ICollection <SafeType <APIOperation> > AllAPIOperations()
        {
            ICollection <SafeType <APIOperation> > set =
                new HashSet <SafeType <APIOperation> >();

            CollectionUtil.AddAll(set,
                                  SPI_TO_API.Values);
            // add Get because it doesn't have a corresponding SPI.
            set.Add(SafeType <APIOperation> .Get <GetApiOp>());
            set.Add(SafeType <APIOperation> .Get <ValidateApiOp>());
            return(CollectionUtil.AsReadOnlySet(set));
        }
Esempio n. 6
0
        public static ICollection <SafeType <APIOperation> > GetDefaultSupportedOperations(SafeType <Connector> connector)
        {
            ICollection <SafeType <APIOperation> > rv =
                new HashSet <SafeType <APIOperation> >();
            ICollection <Type> interfaces =
                ReflectionUtil.GetTypeErasure(ReflectionUtil.GetAllInterfaces(connector.RawType));

            foreach (SafeType <SPIOperation> spi in AllSPIOperations())
            {
                if (interfaces.Contains(spi.RawType))
                {
                    CollectionUtil.AddAll(rv, Spi2Apis(spi));
                }
            }
            //finally add unconditionally supported ops
            CollectionUtil.AddAll(rv, GetUnconditionallySupportedOperations());
            return(CollectionUtil.AsReadOnlySet(rv));
        }
        /// <summary>
        /// helper method to filter out all attributes used in ExchangeConnector only
        /// </summary>
        /// <param name="attributes">Connector attributes</param>
        /// <param name="cmdInfos">CommandInfo whose parameters will be used and filtered out from attributes</param>
        /// <returns>
        /// Filtered connector attributes
        /// </returns>
        private static ICollection <ConnectorAttribute> FilterOut(ICollection <ConnectorAttribute> attributes, params PSExchangeConnector.CommandInfo[] cmdInfos)
        {
            IList <string> attsToRemove = new List <string> {
                AttRecipientType, AttDatabase, AttExternalMail
            };

            if (cmdInfos != null)
            {
                foreach (PSExchangeConnector.CommandInfo cmdInfo in cmdInfos)
                {
                    if (cmdInfo != null)
                    {
                        CollectionUtil.AddAll(attsToRemove, cmdInfo.Parameters);
                    }
                }
            }

            return(ExchangeUtility.FilterOut(attributes, attsToRemove));
        }
Esempio n. 8
0
        /// <summary>
        /// helper method to filter out all attributes used in ExchangeConnector only
        /// </summary>
        /// <param name="attributes">Connector attributes</param>
        /// <param name="cmdInfos">CommandInfo whose parameters will be used and filtered out from attributes</param>
        /// <returns>
        /// Filtered connector attributes
        /// </returns>
        internal static ICollection <ConnectorAttribute> FilterOut(ICollection <ConnectorAttribute> attributes, params PSExchangeConnector.CommandInfo[] cmdInfos)
        {
            IList <string> attsToRemove = new List <string> {
                ExchangeConnectorAttributes.AttRecipientType
            };

            CollectionUtil.AddAll(attsToRemove, ExchangeConnectorAttributes.AttMap2AD.Keys);
            if (cmdInfos != null)
            {
                foreach (PSExchangeConnector.CommandInfo cmdInfo in cmdInfos)
                {
                    if (cmdInfo != null)
                    {
                        CollectionUtil.AddAll(attsToRemove, cmdInfo.Parameters);
                    }
                }
            }
            return(ExchangeUtility.FilterOut(attributes, attsToRemove));
        }
Esempio n. 9
0
        private ICollection <string> GetAdAttributesToReturn(ActiveDirectoryConnector adConnector, ObjectClass oclass, OperationOptions options)
        {
            ICollection <string> attNames = adConnector.GetAdAttributesToReturn(oclass, options);

            // In attNames there is a mix of attributes - some AD-only ones (from ObjectClasses.xml),
            // and some Exchange ones (from the schema) and some AD-only-for-Exchange ones (from the schema).
            // We should convert Exchange ones to their AD counterparts and add "hidden useful" AD attributes.

            if (oclass.Is(ObjectClass.ACCOUNT_NAME))
            {
                ICollection <string> newAttNames = new HashSet <string>(attNames);

                // IMPORTANT: we assume that "options" do not imply any additional AD attributes
                CollectionUtil.AddAll(newAttNames, ExchangeConnectorAttributes.AttMapFromAD.Keys);
                CollectionUtil.AddAll(newAttNames, ExchangeConnectorAttributes.HiddenAdAttributesToRetrieve);
                CollectionUtil.AddAll(newAttNames, ExchangeConnectorAttributes.VisibleAdAttributesToRetrieve);
                attNames = newAttNames;
            }
            return(attNames);
        }
        /// <summary>
        /// Gets Recipient Type/Database from Exchange database, this method can be more general, but it is ok
        /// for out needs
        /// </summary>
        /// <param name="oc">object class, currently the moethod works for <see cref="ObjectClass.ACCOUNT"/> only</param>
        /// <param name="cobject">connector object to get the recipient type/database for</param>
        /// <param name="attToGet">attributes to get</param>
        /// <returns>Connector Object with recipient type added</returns>
        /// <exception cref="ConnectorException">In case of some troubles in powershell (if the
        /// user is not found we get this exception too)</exception>
        private ConnectorObject AddExchangeAttributes(ObjectClass oc, ConnectorObject cobject, IEnumerable <string> attToGet)
        {
            ExchangeUtility.NullCheck(oc, "name", this.configuration);
            ExchangeUtility.NullCheck(oc, "cobject", this.configuration);

            // we support ACCOUNT only or there is nothing to add
            if (!oc.Is(ObjectClass.ACCOUNT_NAME) || attToGet == null)
            {
                return(cobject);
            }

            // check it is not deleted object
            bool?deleted = ExchangeUtility.GetAttValue(AttIsDeleted, cobject.GetAttributes()) as bool?;

            if (deleted != null && deleted == true)
            {
                // do nothing, it is deleted object
                return(cobject);
            }

            ICollection <string> lattToGet = CollectionUtil.NewCaseInsensitiveSet();

            CollectionUtil.AddAll(lattToGet, attToGet);
            foreach (string att in attToGet)
            {
                if (cobject.GetAttributeByName(att) != null && att != AttDatabase)
                {
                    lattToGet.Remove(att);
                }
            }

            if (lattToGet.Count == 0)
            {
                return(cobject);
            }

            ConnectorObjectBuilder cobjBuilder = new ConnectorObjectBuilder();

            cobjBuilder.AddAttributes(cobject.GetAttributes());

            PSExchangeConnector.CommandInfo cmdInfo = PSExchangeConnector.CommandInfo.GetUser;

            // prepare the connector attribute list to get the command
            ICollection <ConnectorAttribute> attributes = new Collection <ConnectorAttribute> {
                cobject.Name
            };

            // get the command
            Command cmd = ExchangeUtility.GetCommand(cmdInfo, attributes, this.configuration);
            ICollection <PSObject> foundObjects = this.InvokePipeline(cmd);
            PSObject user = null;

            if (foundObjects != null && foundObjects.Count == 1)
            {
                user = GetFirstElement(foundObjects);
                foreach (var info in user.Properties)
                {
                    ConnectorAttribute att = GetAsAttribute(info);
                    if (att != null && lattToGet.Contains(att.Name))
                    {
                        cobjBuilder.AddAttribute(att);
                        lattToGet.Remove(att.Name);
                    }
                }

                if (lattToGet.Count == 0)
                {
                    return(cobjBuilder.Build());
                }
            }

            if (user == null)
            {
                // nothing to do
                return(cobject);
            }

            string rcptType = user.Members[AttRecipientType].Value.ToString();

            foundObjects = null;

            // get detailed information
            if (rcptType == RcptTypeMailBox)
            {
                foundObjects = this.InvokePipeline(ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.GetMailbox, attributes, this.configuration));
            }
            else if (rcptType == RcptTypeMailUser)
            {
                foundObjects = this.InvokePipeline(ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.GetMailUser, attributes, this.configuration));
            }

            if (foundObjects != null && foundObjects.Count == 1)
            {
                PSObject userDetails = GetFirstElement(foundObjects);
                foreach (var info in userDetails.Properties)
                {
                    ConnectorAttribute att = GetAsAttribute(info);
                    if (att != null && lattToGet.Contains(att.Name))
                    {
                        cobjBuilder.AddAttribute(att);
                        lattToGet.Remove(att.Name);
                    }
                }
            }

            return(cobjBuilder.Build());
        }