예제 #1
0
 public void ExecuteQuery(ObjectClass oclass, String query, ResultsHandler handler, OperationOptions options)
 {
     for (int i = 0; i < _config.numResults; i++)
     {
         int?delay = (int?)CollectionUtil.GetValue(options.Options, "delay", null);
         if (delay != null)
         {
             Thread.Sleep((int)delay);
         }
         ConnectorObjectBuilder builder =
             new ConnectorObjectBuilder();
         builder.SetUid("" + i);
         builder.SetName(i.ToString());
         builder.ObjectClass = oclass;
         for (int j = 0; j < 50; j++)
         {
             builder.AddAttribute("myattribute" + j, "myvaluevaluevalue" + j);
         }
         ConnectorObject rv = builder.Build();
         if (!handler(rv))
         {
             break;
         }
     }
 }
예제 #2
0
        private void SubmitConnectorObject(String result, ResultsHandler handler)
        {
            ConnectorObjectBuilder cob = new ConnectorObjectBuilder();

            String[] resultSplit = result.Split(new char[] { '$' });
            ICollection <ConnectorAttribute> attrs = new List <ConnectorAttribute>();

            foreach (String str in resultSplit)
            {
                ConnectorAttributeBuilder cab = new ConnectorAttributeBuilder();
                cab.AddValue(str.Split(new char[] { ':' })[1]);

                if (str.StartsWith("Name"))
                {
                    cob.SetName(Name.NAME);
                    cob.SetUid(str.Split(new char[] { ':' })[1]);
                    cab.Name = Name.NAME;
                }
                else
                {
                    cab.Name = str.Split(new char[] { ':' })[0];
                }

                attrs.Add(cab.Build());
            }

            cob.AddAttributes(attrs);
            handler(cob.Build());
        }
예제 #3
0
파일: Test.cs 프로젝트: sangkyunyoon/ConnId
        /// <summary>
        /// Performs a raw, unfiltered search at the SPI level,
        /// eliminating duplicates from the result set.
        /// </summary>
        /// <param name="search">The search SPI</param>
        /// <param name="oclass">The object class - passed through to
        /// connector so it may be null if the connecor
        /// allowing it to be null. (This is convenient for
        /// unit tests, but will not be the case in general)</param>
        /// <param name="filter">The filter to search on</param>
        /// <param name="handler">The result handler</param>
        /// <param name="options">The options - may be null - will
        /// be cast to an empty OperationOptions</param>
        public SearchResult Search <T>(SearchOp <T> search,
                                       ObjectClass objectClass,
                                       Filter filter,
                                       ResultsHandler handler,
                                       OperationOptions options) where T : class
        {
            Assertions.NullCheck(objectClass, "objectClass");
            if (ObjectClass.ALL.Equals(objectClass))
            {
                throw new System.NotSupportedException("Operation is not allowed on __ALL__ object class");
            }
            Assertions.NullCheck(handler, "handler");
            //convert null into empty
            if (options == null)
            {
                options = new OperationOptionsBuilder().Build();
            }

            SearchResult result = null;

            RawSearcherImpl <T> .RawSearch(search, objectClass, filter, new SearchResultsHandler()
            {
                Handle = obj =>
                {
                    return(handler.Handle(obj));
                },
                HandleResult = obj =>
                {
                    result = obj;
                }
            }, options);

            return(result != null ? result : new SearchResult());
        }
예제 #4
0
        // TODO move to appropriate place
        /// <summary>
        /// helper method for searching object in AD by UID
        /// </summary>
        /// <param name="uid">Uid of the searched </param>
        /// <param name="oclass">Object class</param>
        /// <param name="options">Operation options</param>
        /// <returns>Connector object found by the Uid</returns>
        internal ConnectorObject ADSearchByUid(ExchangeConnector connector, Uid uid, ObjectClass oclass, OperationOptions options)
        {
            ExchangeConfiguration configuration = connector.Configuration;

            ExchangeUtility.NullCheck(uid, "uid", configuration);
            ExchangeUtility.NullCheck(oclass, "oclass", configuration);
            if (options == null)
            {
                options = new OperationOptionsBuilder().Build();
            }

            ConnectorObject ret        = null;
            Filter          filter     = FilterBuilder.EqualTo(uid);
            var             translator = connector.ActiveDirectoryConnector.CreateFilterTranslator(oclass, options);
            IList <string>  queries    = translator.Translate(filter);

            if (queries.Count == 1)
            {
                ResultsHandler handler = new ResultsHandler()
                {
                    Handle = cobject =>
                    {
                        ret = cobject;
                        return(false);
                    }
                };
                connector.ActiveDirectoryConnector.ExecuteQuery(oclass, queries[0], handler, options);
            }

            return(ret);
        }
예제 #5
0
        internal ConnectorObject GetCurrentObject(UpdateOpContext context, string query)
        {
            ConnectorObject currentObject = null;

            LOG.Trace("Fetching object using query {0}", query);

            ResultsHandler handler = new ResultsHandler()
            {
                Handle = cobject =>
                {
                    //LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Object-to-be-modified: {0}", CommonUtils.DumpConnectorAttributes(cobject.GetAttributes()));
                    if (currentObject != null)
                    {
                        throw new InvalidOperationException("More than one object complying with " + query + " was found");
                    }
                    currentObject = cobject;
                    return(true);
                }
            };

            ((ExchangeConnector)context.Connector).ExecuteQuery(context.ObjectClass, query, handler, null);
            if (currentObject == null)
            {
                throw new ObjectNotFoundException("Object with UID " + context.Uid.GetUidValue() + " was not found");
            }

            return(currentObject);
        }
        /// <summary>
        /// helper method for searching object in AD by UID
        /// </summary>
        /// <param name="uid">Uid of the searched </param>
        /// <param name="oclass">Object class</param>
        /// <param name="options">Operation options</param>
        /// <returns>Connector object found by the Uid</returns>
        private ConnectorObject ADSearchByUid(Uid uid, ObjectClass oclass, OperationOptions options)
        {
            ExchangeUtility.NullCheck(uid, "uid", this.configuration);
            ExchangeUtility.NullCheck(oclass, "oclass", this.configuration);
            if (options == null)
            {
                options = new OperationOptionsBuilder().Build();
            }

            ConnectorObject ret        = null;
            Filter          filter     = FilterBuilder.EqualTo(uid);
            var             translator = base.CreateFilterTranslator(oclass, options);
            IList <string>  queries    = translator.Translate(filter);

            if (queries.Count == 1)
            {
                ResultsHandler handler = delegate(ConnectorObject cobject)
                {
                    ret = cobject;
                    return(false);
                };
                base.ExecuteQuery(oclass, queries[0], handler, options);
            }

            return(ret);
        }
예제 #7
0
 /// <summary>
 /// Performs a raw, unfiltered search at the SPI level,
 /// eliminating duplicates from the result set.
 /// </summary>
 /// <param name="search">The search SPI</param>
 /// <param name="oclass">The object class - passed through to
 /// connector so it may be null if the connecor
 /// allowing it to be null. (This is convenient for
 /// unit tests, but will not be the case in general)</param>
 /// <param name="filter">The filter to search on</param>
 /// <param name="handler">The result handler</param>
 /// <param name="options">The options - may be null - will
 /// be cast to an empty OperationOptions</param>
 public static void Search <T>(SearchOp <T> search,
                               ObjectClass oclass,
                               Filter filter,
                               ResultsHandler handler,
                               OperationOptions options) where T : class
 {
     GetSpi().Search(search, oclass, filter, handler, options);
 }
예제 #8
0
 public void ExecuteQuery(ObjectClass oclass, string query,
                          ResultsHandler handler, OperationOptions options)
 {
     Assert.IsNotNull(oclass);
     Assert.IsNotNull(handler);
     Assert.IsNotNull(options);
     AddCall("ExecuteQuery", oclass, query, handler, options);
 }
 /// <summary>
 /// Implementation of SearchOp.ExecuteQuery
 /// </summary>
 /// <param name="oclass">Object class</param>
 /// <param name="query">Query to execute</param>
 /// <param name="handler">Result handler</param>
 /// <param name="options">Operation options</param>
 public override void ExecuteQuery(
     ObjectClass oclass,
     string query,
     ResultsHandler handler,
     OperationOptions options)
 {
     // TODO: Implement ExecuteQuery
     base.ExecuteQuery(oclass, query, handler, options);
 }
예제 #10
0
        private static void callSaveChanges(object sender, ElapsedEventArgs e)
        {
            LeaderboardHandler leaderboardHandler = new LeaderboardHandler();
            ResultsHandler     resultsHandler     = new ResultsHandler();

            resultsHandler
            .DoWork()
            .ContinueWith(async(prevTask) => { await leaderboardHandler.DoWork(); });
        }
예제 #11
0
 /// <summary>
 /// Simply return everything don't bother optimizing.
 /// </summary>
 ///
 /// <seealso cref="SearchOp.Search"/>
 public void ExecuteQuery(ObjectClass oclass, string query, ResultsHandler handler, OperationOptions options)
 {
     foreach (ConnectorObject obj in objects)
     {
         if (!handler.Handle(obj))
         {
             break;
         }
     }
 }
        /// <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 override void ExecuteQuery(
            ObjectClass oclass, string query, ResultsHandler handler, OperationOptions options)
        {
            ExchangeUtility.NullCheck(oclass, "oclass", this.configuration);

            // we handle accounts only
            if (!oclass.Is(ObjectClass.ACCOUNT_NAME))
            {
                base.ExecuteQuery(oclass, query, handler, options);
                return;
            }

            ICollection <string> attsToGet = null;

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

            // delegate to get the exchange attributes if requested
            ResultsHandler filter = delegate(ConnectorObject cobject)
            {
                ConnectorObject filtered = ExchangeUtility.ReplaceAttributes(
                    cobject, attsToGet, AttMapFromAD);
                filtered = this.AddExchangeAttributes(oclass, filtered, attsToGet);
                return(handler(filtered));
            };

            ResultsHandler   handler2use = handler;
            OperationOptions options2use = options;

            if (options != null && options.AttributesToGet != null)
            {
                if (attsToGet.Contains(AttDatabase) || attsToGet.Contains(AttExternalMail) ||
                    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();
                    handler2use             = filter;
                }
            }

            base.ExecuteQuery(oclass, query, handler2use, options2use);
        }
예제 #13
0
 public void ExecuteQuery(ObjectClass oclass, string query,
                          ResultsHandler handler, OperationOptions options)
 {
     Assert.IsNotNull(oclass);
     Assert.IsNotNull(handler);
     Assert.IsNotNull(options);
     AddCall("ExecuteQuery", oclass, query, handler, options);
     if (null != options.PageSize && options.PageSize > 0)
     {
         // This is a pages search request
         ((SearchResultsHandler)handler).HandleResult(new SearchResult("TOKEN==", 100));
     }
 }
예제 #14
0
 /// <summary>
 /// Performs a raw, unfiltered search at the SPI level,
 /// eliminating duplicates from the result set.
 /// </summary>
 /// <param name="search">The search SPI</param>
 /// <param name="oclass">The object class - passed through to
 /// connector so it may be null if the connecor
 /// allowing it to be null. (This is convenient for
 /// unit tests, but will not be the case in general)</param>
 /// <param name="filter">The filter to search on</param>
 /// <param name="handler">The result handler</param>
 /// <param name="options">The options - may be null - will
 /// be cast to an empty OperationOptions</param>
 public void Search <T>(SearchOp <T> search,
                        ObjectClass oclass,
                        Filter filter,
                        ResultsHandler handler,
                        OperationOptions options) where T : class
 {
     if (options == null)
     {
         options = new OperationOptionsBuilder().Build();
     }
     RawSearcherImpl <T> .RawSearch(
         search, oclass, filter, handler, options);
 }
예제 #15
0
        // implementation of SearchSpiOp
        public virtual void ExecuteQuery(ObjectClass objectClass, Filter query,
                                         ResultsHandler handler, OperationOptions options)
        {
            Trace.TraceInformation("Invoke ExecuteQuery ObjectClass:{0}", objectClass.GetObjectClassValue());

            try
            {
                ExecuteQuery(_configuration.SearchScriptFileName, objectClass, query, handler, options);
                Trace.TraceInformation("Search ok");
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
                throw;
            }
        }
예제 #16
0
 public void SearchCallPattern()
 {
     TestCallPattern(new TestOperationPattern()
     {
         MakeCall = facade =>
         {
             // create an empty results handler..
             ResultsHandler rh = obj =>
             {
                 return(true);
             };
             // call the search method..
             facade.Search(ObjectClass.ACCOUNT, null, rh, null);
         },
         CheckCalls = calls =>
         {
             Assert.AreEqual("CreateFilterTranslator", GetAndRemoveMethodName(calls));
             Assert.AreEqual("ExecuteQuery", GetAndRemoveMethodName(calls));
         }
     });
 }
예제 #17
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?
        }
예제 #18
0
        public virtual void ExecuteQuery(ObjectClass objectClass, string query, ResultsHandler handler,
                                         OperationOptions options)
        {
            var builder = new ConnectorObjectBuilder();

            builder.SetUid("3f50eca0-f5e9-11e3-a3ac-0800200c9a66");
            builder.SetName("Foo");
            builder.AddAttribute(ConnectorAttributeBuilder.BuildEnabled(true));

            foreach (ConnectorObject connectorObject in CollectionUtil.NewSet(builder.Build()))
            {
                if (!handler.Handle(connectorObject))
                {
                    // Stop iterating because the handler stopped processing
                    break;
                }
            }
            if (options.PageSize != null && 0 < options.PageSize)
            {
                Trace.TraceInformation("Paged Search was requested");
                ((SearchResultsHandler)handler).HandleResult(new SearchResult("0", 0));
            }
        }
 public void SearchAllCallPattern()
 {
     TestCallPattern(new TestOperationPattern()
     {
         MakeCall = facade =>
         {
             // create an empty results handler..
             ResultsHandler rh = new ResultsHandler()
             {
                 Handle = obj =>
                 {
                     return(true);
                 }
             };
             // call the search method..
             facade.Search(ObjectClass.ALL, null, rh, null);
         },
         CheckCalls = calls =>
         {
             Assert.Fail("Should not get here..");
         }
     });
 }
예제 #20
0
파일: Plan.cs 프로젝트: ptucker/WhitStream
        private static void ExecuteScheduler(string title, IScheduler sch, bool breakOut, Query[] qs)
        {
            int q;
            bool complete = false;

            AdminForm frmAdmin = new AdminForm();

            IResults[] res = sch.Init(breakOut, qs);
            ResultsHandler[] rh = new ResultsHandler[res.Length];
            for (q = 0; q < res.Length; q++)
                rh[q] = new ResultsHandler(string.Format("{0}{1}", title, q), res[q]);
            sch.Execute();
            //frmAdmin.Scheduler = sch;
            //frmAdmin.Show();

            while (!complete && !frmAdmin.ShutdownServer)
            {
                //frmAdmin.UpdateStats();
                Thread.Sleep(10000);
                complete = true;
                for (int i = 0; i < rh.Length && complete; i++)
                    complete &= rh[i].EOF;
                //Log.WriteMessage(DataItemPool.ToString(), Log.eMessageType.Debug);
            }

            double totalSec = 0;
            for (int i = 0; i < rh.Length; i++)
            {
                Log.WriteMessage(string.Format("{0} Total Rows: {1}, Time: {2}", rh[i].Name, rh[i].DataCount, rh[i].CompletionTime), Log.eMessageType.Debug);
                totalSec += (((double)rh[i].CompletionTime.Minutes) * 60) +
                    ((double)rh[i].CompletionTime.Seconds) +
                    (((double)rh[i].CompletionTime.Milliseconds) / 1000.0);
            }

            Log.WriteMessage(string.Format("Average Time: {0}", totalSec / rh.Length), Log.eMessageType.Debug);
        }
    // Start is called before the first frame update
    private void Start()
    {
        resultsHandler = GameObject.FindGameObjectWithTag("ResultsPopup").GetComponent <ResultsHandler>();

        var config = new ConnectionConfig();

        // Config the Channels we will use
        config.AddChannel(QosType.ReliableFragmented);
        config.AddChannel(QosType.UnreliableFragmented);

        // Create the client and attach the configuration
        _client = new NetworkClient();
        _client.Configure(config, 1);

        // Register the handlers for the different network messages
        RegisterHandlers();

        //start with the object offscreen and lerp onto screen
        transform.localPosition = new Vector3(0.0f, -1000.0f, 0.0f);
        StartCoroutine(LerpGameObjectY(gameObject, 0.0f, 1.0f, false, 0.0f));

        _btnSubmitScore.onClick.AddListener(BtnSubmitScorePressed);
        _btnCancel.onClick.AddListener(BtnCancelPressed);
    }
예제 #22
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));
        }
예제 #23
0
 public void Search(ObjectClass oclass, Filter filter, ResultsHandler handler, OperationOptions options)
 {
     ((SearchApiOp)this.GetOperationCheckSupported(SafeType <APIOperation> .Get <SearchApiOp>())).Search(
         oclass, filter, handler, options);
 }
예제 #24
0
 public void ExecuteQuery(ObjectClass oclass, string query, ResultsHandler handler, OperationOptions options)
 {
 }
예제 #25
0
 public void ExecuteQuery(ObjectClass oclass, string query, ResultsHandler handler, OperationOptions options)
 {
     Console.WriteLine("ExecuteQuery called");
 }
 private void Awake()
 {
     instance = this;
     DontDestroyOnLoad(this.gameObject);
 }
예제 #27
0
        public SimulationControlHandler(MainScreen screen)
        {
            Screen = screen;

            Results = new ResultsHandler(Screen);
        }
 public MsPowerShellSearchResults(ObjectClass objectClass, ResultsHandler handler)
 {
     _objectClass = objectClass;
     _handler     = handler;
 }
예제 #29
0
        protected void ExecuteQuery(String scriptName, ObjectClass objectClass, Filter query, ResultsHandler handler,
                                    OperationOptions options)
        {
            var arguments = new Dictionary <String, Object>
            {
                { Result, new MsPowerShellSearchResults(objectClass, handler) }
            };

            if (query != null)
            {
                switch (_visitor)
                {
                case Visitors.Map:
                    arguments.Add(Query, query.Accept <Dictionary <String, Object>, Hashtable>(new MapFilterVisitor(), _attrSubstitute));
                    break;

                case Visitors.AdPsModule:
                    arguments.Add(Query, query.Accept <String, Hashtable>(new AdPsModuleFilterVisitor(), _attrSubstitute));
                    break;

                case Visitors.Ldap:
                    arguments.Add(Query, query.Accept <String, Hashtable>(new LdapFilterVisitor(), _attrSubstitute));
                    break;

                case Visitors.NativeQuery:
                    arguments.Add(Query, query);
                    break;
                }
            }


            ExecuteScript(GetScript(scriptName), CreateBinding(arguments, OperationType.SEARCH, objectClass, null, null, options));
        }
        public void ExecuteQuery(ObjectClass objectClass, Filter query, ResultsHandler handler, OperationOptions options)
        {
            ICF.SortKey[] sortKeys = options.SortKeys;
            if (null == sortKeys)
            {
                sortKeys = new ICF.SortKey[] { new ICF.SortKey(Name.NAME, true) };
            }

            // Rebuild the full result set.
            SortedSet <ConnectorObject> resultSet = new SortedSet <ConnectorObject>(new ResourceComparator(sortKeys));

            if (null != query)
            {
                foreach (ConnectorObject co in collection.Values)
                {
                    if (query.Accept(co))
                    {
                        resultSet.Add(co);
                    }
                }
            }
            else
            {
                resultSet.UnionWith(collection.Values);
            }
            // Handle the results
            if (null != options.PageSize)
            {
                // Paged Search
                string pagedResultsCookie        = options.PagedResultsCookie;
                string currentPagedResultsCookie = options.PagedResultsCookie;
                int?   pagedResultsOffset        = null != options.PagedResultsOffset ? Math.Max(0, (int)options.PagedResultsOffset) : 0;
                int?   pageSize       = options.PageSize;
                int    index          = 0;
                int    pageStartIndex = null == pagedResultsCookie ? 0 : -1;
                int    handled        = 0;
                foreach (ConnectorObject entry in resultSet)
                {
                    if (pageStartIndex < 0 && pagedResultsCookie.Equals(entry.Name.GetNameValue()))
                    {
                        pageStartIndex = index + 1;
                    }
                    if (pageStartIndex < 0 || index < pageStartIndex)
                    {
                        index++;
                        continue;
                    }
                    if (handled >= pageSize)
                    {
                        break;
                    }
                    if (index >= pagedResultsOffset + pageStartIndex)
                    {
                        if (handler.Handle(entry))
                        {
                            handled++;
                            currentPagedResultsCookie = entry.Name.GetNameValue();
                        }
                        else
                        {
                            break;
                        }
                    }
                    index++;
                }

                if (index == resultSet.Count)
                {
                    currentPagedResultsCookie = null;
                }

                if (handler is SearchResultsHandler)
                {
                    ((SearchResultsHandler)handler).HandleResult(new SearchResult(currentPagedResultsCookie, resultSet.Count - index));
                }
            }
            else
            {
                // Normal Search
                foreach (ConnectorObject entry in resultSet)
                {
                    if (!handler.Handle(entry))
                    {
                        break;
                    }
                }
                if (handler is SearchResultsHandler)
                {
                    ((SearchResultsHandler)handler).HandleResult(new SearchResult());
                }
            }
        }
예제 #31
0
 /// <summary>
 /// Set the callback function from the caller to the query request
 /// </summary>
 /// <param name="finishedOperation"></param>
 public void SetFinishedEvent(ResultsHandler finishedOperation)
 {
     finishedQuery = finishedOperation;
 }