Exemplo n.º 1
0
        public void ExecuteQuery(ExecuteQueryContext context)
        {
            ExchangeConnector        exconn = (ExchangeConnector)context.Connector;
            ActiveDirectoryConnector adconn = exconn.ActiveDirectoryConnector;

            adconn.ExecuteQuery(context.ObjectClass, context.Query, context.ResultsHandler, context.Options);
        }
        public void ExecuteQuery(ExecuteQueryContext context)
        {
            ExchangeConnector exconn = (ExchangeConnector)context.Connector;

            LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "SimplePowerShellObjectHandler: Executing query: query={0}", context.Query);

            Command cmdGet = ExchangeUtility.GetCommand(
                new PSExchangeConnector.CommandInfo(GetGetCommandName()), exconn.Configuration);

            if (context.Query != null)
            {
                cmdGet.Parameters.Add("Identity", context.Query);
            }
            ICollection <PSObject> objects;

            try {
                objects = _helper.InvokePipeline(exconn, cmdGet);
            } catch (ObjectNotFoundException e) {
                LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "SimplePowerShellObjectHandler: Executing query: got 'ObjectNotFound' exception ({0}), assuming suitable objects do not exist", e);
                return;
            }
            LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "SimplePowerShellObjectHandler: Executing query: got {0} objects", objects.Count);
            foreach (PSObject psobject in objects)
            {
                if (psobject != null)
                {
                    context.ResultsHandler.Handle(_helper.CreateConnectorObject(exconn, psobject, context.ObjectClass));
                }
            }
        }
        public void ExecuteQueryMain(ExecuteQueryContext context)
        {
            LOG.Trace("Exchange.ExecuteQueryMain starting");
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            GetHandler(context).ExecuteQuery(context);

            LOG.Trace("Exchange.ExecuteQuery method exiting, took {0} ms", stopWatch.ElapsedMilliseconds);
        }
Exemplo n.º 4
0
        public void ExecuteQueryMain(ExecuteQueryContext context)
        {
            LOGGER_API.TraceEvent(TraceEventType.Information, CAT_DEFAULT, "Exchange.ExecuteQueryMain starting");
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            GetHandler(context).ExecuteQuery(context);

            LOGGER_API.TraceEvent(TraceEventType.Information, CAT_DEFAULT,
                                  "Exchange.ExecuteQuery method exiting, took {0} ms", stopWatch.ElapsedMilliseconds);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Implementation of SearchOp.ExecuteQuery
        /// </summary>
        /// <param name="oclass">Object class</param>
        /// <param name="query">Query to execute</param>
        /// <param name="handler">Results handler</param>
        /// <param name="options">Operation options</param>
        public void ExecuteQuery(ObjectClass oclass, string query, ResultsHandler handler, OperationOptions options)
        {
            const string operation = "ExecuteQuery";

            ExchangeUtility.NullCheck(oclass, "oclass", this._configuration);
            if (options == null)
            {
                options = new OperationOptions(new Dictionary <string, object>());
            }

            LOGGER_API.TraceEvent(TraceEventType.Information, CAT_DEFAULT,
                                  "Exchange.ExecuteQuery method; oclass = {0}, query = {1}", oclass, query);

            ExecuteQueryContext context = new ExecuteQueryContext()
            {
                Connector = this,
                ConnectorConfiguration = _configuration,
                ObjectClass            = oclass,
                OperationName          = operation,
                Options        = options,
                Query          = query,
                ResultsHandler = handler
            };

            try {
                _scripting.ExecutePowerShell(context, Scripting.Position.BeforeMain);
                if (!_scripting.ExecutePowerShell(context, Scripting.Position.InsteadOfMain))
                {
                    ExecuteQueryMain(context);
                }
                _scripting.ExecutePowerShell(context, Scripting.Position.AfterMain);
            } catch (Exception e) {
                LOGGER.TraceEvent(TraceEventType.Error, CAT_DEFAULT, "Exception while executing ExecuteQuery operation: {0}", e);
                throw;
            }

            // TODO what about executing a script on each returned item?
        }
Exemplo n.º 6
0
        public void ExecuteQuery(ExecuteQueryContext context)
        {
            ExchangeConnector        exconn = (ExchangeConnector)context.Connector;
            ActiveDirectoryConnector adconn = exconn.ActiveDirectoryConnector;

            ICollection <string> attsToGet = null;

            if (context.Options != null && context.Options.AttributesToGet != null)
            {
                attsToGet = CollectionUtil.NewList(context.Options.AttributesToGet);
            }

            // delegate to get the exchange attributes if requested
            ResultsHandler filter = new SearchResultsHandler()
            {
                Handle = cobject =>
                {
                    LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Object returned from AD connector: {0}", CommonUtils.DumpConnectorAttributes(cobject.GetAttributes()));
                    ConnectorObject filtered = ExchangeUtility.ConvertAdAttributesToExchange(cobject);
                    //filtered = AddExchangeAttributes(exconn, context.ObjectClass, filtered, attsToGet);
                    LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Object as passed from Exchange connector: {0}", CommonUtils.DumpConnectorAttributes(filtered.GetAttributes()));
                    return(context.ResultsHandler.Handle(filtered));
                },

                HandleResult = result =>
                {
                    if (context.ResultsHandler is SearchResultsHandler)
                    {
                        ((SearchResultsHandler)context.ResultsHandler).HandleResult(result);
                    }
                }
            };

            ResultsHandler   handler2use = filter;
            OperationOptions options2use = context.Options;

            // mapping AttributesToGet from Exchange to AD "language"
            // actually, we don't need this code any more, because there are no attribute that are not retrieved by default
            // Uncomment this code if necessary in the future.
            if (context.Options != null && context.Options.AttributesToGet != null)
            {
                /*
                 * ISet<string> mappedExchangeAttributesToGet = new HashSet<string>(AttMap2AD.Keys);
                 * mappedExchangeAttributesToGet.IntersectWith(options.AttributesToGet);
                 * if (mappedExchangeAttributesToGet.Count > 0 || attsToGet.Contains(AttRecipientType))
                 * {
                 *  // replace Exchange attributes with AD names
                 *  var newAttsToGet = ExchangeUtility.FilterReplace(attsToGet, AttMap2AD);
                 *
                 *  // we have to remove recipient type, as it is unknown to AD
                 *  newAttsToGet.Remove(AttRecipientType);
                 *
                 *  // build new op options
                 *  var builder = new OperationOptionsBuilder(options);
                 *  string[] attributesToGet = new string[newAttsToGet.Count];
                 *  newAttsToGet.CopyTo(attributesToGet, 0);
                 *  builder.AttributesToGet = attributesToGet;
                 *  options2use = builder.Build();
                 * } */

                /*
                 * if (attsToGet.Contains(ExchangeConnectorAttributes.AttDatabase))
                 * {
                 *  attsToGet.Remove(ExchangeConnectorAttributes.AttDatabase);
                 *
                 *  // build new op options
                 *  var builder = new OperationOptionsBuilder(context.Options);
                 *  string[] attributesToGet = new string[attsToGet.Count];
                 *  attsToGet.CopyTo(attributesToGet, 0);
                 *  builder.AttributesToGet = attributesToGet;
                 *  options2use = builder.Build();
                 * }
                 */
            }

            adconn.ExecuteQueryInternal(context.ObjectClass,
                                        context.Query, handler2use, options2use,
                                        GetAdAttributesToReturn(adconn, context.ObjectClass, context.Options));
        }