public void TestSyncQueryProperties()
        {
            SyncQuery syncQuery = new SyncQuery(
                10,
                null);

            Assert.IsTrue(syncQuery.InitialQuery);
            Assert.AreEqual(
                string.Empty,
                syncQuery.Query);

            syncQuery.SelectedProperties = new SelectQuery("prop1");
            Assert.AreEqual(
                "$select=prop1",
                syncQuery.Query);

            SyncToken syncToken = new SyncToken(
                "abcdefg",
                SyncTokenType.DeltaToken);

            syncQuery = new SyncQuery(
                10,
                syncToken);

            Assert.AreEqual(
                "$deltatoken=abcdefg",
                syncQuery.Query);

            syncQuery.SelectedProperties = new SelectQuery("prop1");
            Assert.AreEqual(
                "$select=prop1&$deltatoken=abcdefg",
                syncQuery.Query);
        }
        public void Sync(ObjectClass objClass, SyncToken token,
                         SyncResultsHandler handler,
                         OperationOptions options)
        {
            int remaining = _config.numResults;

            for (int i = 0; i < _config.numResults; i++)
            {
                ConnectorObjectBuilder obuilder =
                    new ConnectorObjectBuilder();
                obuilder.SetUid(i.ToString());
                obuilder.SetName(i.ToString());
                obuilder.ObjectClass = (objClass);

                SyncDeltaBuilder builder =
                    new SyncDeltaBuilder();
                builder.Object    = (obuilder.Build());
                builder.DeltaType = (SyncDeltaType.CREATE_OR_UPDATE);
                builder.Token     = (new SyncToken("mytoken"));
                SyncDelta rv = builder.Build();
                if (handler.Handle(rv))
                {
                    remaining--;
                }
                else
                {
                    break;;
                }
            }
            if (handler is SyncTokenResultsHandler)
            {
                ((SyncTokenResultsHandler)handler).HandleResult(new SyncToken(remaining));
            }
        }
Exemplo n.º 3
0
        public virtual SyncToken GetLatestSyncToken(ObjectClass objectClass)
        {
            Trace.TraceInformation("Invoke GetLatestSyncToken ObjectClass:{0}", objectClass.GetObjectClassValue());
            SyncToken token = null;

            try
            {
                Object result = ExecuteGetLatestSyncToken(_configuration.SyncScriptFileName, objectClass);
                if (result is SyncToken)
                {
                    token = result as SyncToken;
                }
                else if (null != result)
                {
                    token = new SyncToken(result);
                }
                Trace.TraceInformation("GetLatestSyncToken ok");
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
                throw;
            }
            return(token);
        }
Exemplo n.º 4
0
 public void Sync(ObjectClass objClass, SyncToken token,
                  SyncResultsHandler handler,
                  OperationOptions options)
 {
     ((SyncApiOp)this.GetOperationCheckSupported(SafeType <APIOperation> .Get <SyncApiOp>()))
     .Sync(objClass, token, handler, options);
 }
    public override int GetHashCode()
    {
        int hashcode = 157;

        unchecked {
            if (__isset.subscriptionId)
            {
                hashcode = (hashcode * 397) + SubscriptionId.GetHashCode();
            }
            if (__isset.squareChatMid)
            {
                hashcode = (hashcode * 397) + SquareChatMid.GetHashCode();
            }
            if (__isset.syncToken)
            {
                hashcode = (hashcode * 397) + SyncToken.GetHashCode();
            }
            if (__isset.limit)
            {
                hashcode = (hashcode * 397) + Limit.GetHashCode();
            }
            if (__isset.direction)
            {
                hashcode = (hashcode * 397) + Direction.GetHashCode();
            }
        }
        return(hashcode);
    }
        /// <summary>
        /// Implementation of SynOp.Sync
        /// </summary>
        /// <param name="objClass">Object class</param>
        /// <param name="token">Sync token</param>
        /// <param name="handler">Sync results handler</param>
        /// <param name="options">Operation options</param>
        public void Sync(
            ObjectClass oclass, SyncToken token, SyncResultsHandler handler, OperationOptions options)
        {
            const string operation = "Sync";

            ExchangeUtility.NullCheck(oclass, "oclass", this._configuration);

            LOG.Info("Exchange.Sync method; oclass = {0}, token = {1}", oclass, token);

            SyncOpContext context = new SyncOpContext()
            {
                Connector = this,
                ConnectorConfiguration = _configuration,
                ObjectClass            = oclass,
                OperationName          = operation,
                Options            = options,
                SyncToken          = token,
                SyncResultsHandler = handler
            };

            try {
                _scripting.ExecutePowerShell(context, Scripting.Position.BeforeMain);
                if (!_scripting.ExecutePowerShell(context, Scripting.Position.InsteadOfMain))
                {
                    SyncMain(context);
                }
                _scripting.ExecutePowerShell(context, Scripting.Position.AfterMain);
            } catch (Exception e) {
                LOG.Error(e, "Exception while executing Sync operation: {0}");
                throw;
            }

            // TODO what about executing a script on each returned item?
        }
Exemplo n.º 7
0
    public override int GetHashCode()
    {
        int hashcode = 157;

        unchecked {
            if (__isset.createdTime)
            {
                hashcode = (hashcode * 397) + CreatedTime.GetHashCode();
            }
            if (__isset.type)
            {
                hashcode = (hashcode * 397) + Type.GetHashCode();
            }
            if (__isset.payload)
            {
                hashcode = (hashcode * 397) + Payload.GetHashCode();
            }
            if (__isset.syncToken)
            {
                hashcode = (hashcode * 397) + SyncToken.GetHashCode();
            }
            if (__isset.eventStatus)
            {
                hashcode = (hashcode * 397) + EventStatus.GetHashCode();
            }
        }
        return(hashcode);
    }
 public void Sync(ObjectClass objectClass, SyncToken token, SyncResultsHandler handler, OperationOptions options)
 {
     if (handler is SyncTokenResultsHandler)
     {
         ((SyncTokenResultsHandler)handler).HandleResult(GetLatestSyncToken(objectClass));
     }
 }
Exemplo n.º 9
0
 public void Sync(ObjectClass objectClass, SyncToken token, SyncResultsHandler handler, OperationOptions options)
 {
     Assert.IsNotNull(objectClass);
     Assert.IsNotNull(token);
     Assert.IsNotNull(handler);
     Assert.IsNotNull(options);
     AddCall("Sync", objectClass, token, handler, options);
 }
        public void TestSyncToken()
        {
            SyncToken v1 = new SyncToken("mytoken");
            SyncToken v2 = (SyncToken)CloneObject(v1);

            Assert.AreEqual(v1.Value, v2.Value);
            Assert.AreEqual(v1, v2);
        }
    public override string ToString()
    {
        var  sb      = new StringBuilder("FetchSquareChatEventsRequest(");
        bool __first = true;

        if (__isset.subscriptionId)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("SubscriptionId: ");
            SubscriptionId.ToString(sb);
        }
        if (SquareChatMid != null && __isset.squareChatMid)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("SquareChatMid: ");
            SquareChatMid.ToString(sb);
        }
        if (SyncToken != null && __isset.syncToken)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("SyncToken: ");
            SyncToken.ToString(sb);
        }
        if (__isset.limit)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Limit: ");
            Limit.ToString(sb);
        }
        if (__isset.direction)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Direction: ");
            Direction.ToString(sb);
        }
        sb.Append(")");
        return(sb.ToString());
    }
Exemplo n.º 12
0
    public override string ToString()
    {
        var  sb      = new StringBuilder("SquareEvent(");
        bool __first = true;

        if (__isset.createdTime)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("CreatedTime: ");
            CreatedTime.ToString(sb);
        }
        if (__isset.type)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Type: ");
            Type.ToString(sb);
        }
        if (Payload != null && __isset.payload)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Payload: ");
            Payload.ToString(sb);
        }
        if (SyncToken != null && __isset.syncToken)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("SyncToken: ");
            SyncToken.ToString(sb);
        }
        if (__isset.eventStatus)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("EventStatus: ");
            EventStatus.ToString(sb);
        }
        sb.Append(")");
        return(sb.ToString());
    }
 /// <summary>
 /// Implementation of SynOp.Sync
 /// </summary>
 /// <param name="objClass">Object class</param>
 /// <param name="token">Syncronization token</param>
 /// <param name="handler">Handler for syncronization results</param>
 /// <param name="options">Operation options, can be null</param>
 public override void Sync(
     ObjectClass objClass,
     SyncToken token,
     SyncResultsHandler handler,
     OperationOptions options)
 {
     // TODO: implement Sync
     base.Sync(objClass, token, handler, options);
 }
        public void TestSyncTokenProperties()
        {
            SyncToken syncToken = new SyncToken(
                "abcde",
                SyncTokenType.DeltaToken);

            Assert.AreEqual(
                "$deltatoken=abcde",
                syncToken.Query);
        }
        /// <summary>
        /// Implementation of SynOp.Sync
        /// </summary>
        /// <param name="objClass">Object class</param>
        /// <param name="token">Sync token</param>
        /// <param name="handler">Sync results handler</param>
        /// <param name="options">Operation options</param>
        public override void Sync(
            ObjectClass objClass, SyncToken token, SyncResultsHandler handler, OperationOptions options)
        {
            ExchangeUtility.NullCheck(objClass, "oclass", this.configuration);

            // we handle accounts only
            if (!objClass.Is(ObjectClass.ACCOUNT_NAME))
            {
                base.Sync(objClass, token, handler, options);
                return;
            }

            ICollection <string> attsToGet = null;

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

            // delegate to get the exchange attributes if requested
            SyncResultsHandler xchangeHandler = delegate(SyncDelta delta)
            {
                if (delta.DeltaType == SyncDeltaType.DELETE)
                {
                    return(handler(delta));
                }

                // replace the ad attributes with exchange one and add recipient type
                ConnectorObject updated = ExchangeUtility.ReplaceAttributes(delta.Object, attsToGet, AttMapFromAD);
                updated = this.AddExchangeAttributes(objClass, updated, attsToGet);
                if (updated != delta.Object)
                {
                    // build new sync delta, cause we changed the object
                    SyncDeltaBuilder deltaBuilder = new SyncDeltaBuilder
                    {
                        DeltaType = delta.DeltaType,
                        Token     = delta.Token,
                        Uid       = delta.Uid,
                        Object    = updated
                    };
                    delta = deltaBuilder.Build();
                }

                return(handler(delta));
            };

            // call AD sync, use xchangeHandler
            base.Sync(objClass, token, xchangeHandler, options);
        }
Exemplo n.º 16
0
        protected void ExecuteSync(String scriptName, ObjectClass objectClass, SyncToken token,
                                   SyncResultsHandler handler, OperationOptions options)
        {
            var arguments = new Dictionary <String, Object>
            {
                { Result, new MsPowerShellSyncResults(objectClass, handler) }
            };

            if (token != null)
            {
                arguments.Add(Token, token.Value);
            }

            ExecuteScript(GetScript(scriptName), CreateBinding(arguments, OperationType.SYNC, objectClass, null, null, options));
        }
        public void TestSyncNull(ObjectClass objectClass)
        {
            var       result    = new List <SyncDelta>();
            SyncToken lastToken = GetFacade().Sync(objectClass, new SyncToken(5), new SyncResultsHandler()
            {
                Handle = delta =>
                {
                    result.Add(delta);
                    return(true);
                }
            }, null);

            Assert.AreEqual(10, lastToken.Value);
            Assert.AreEqual(0, result.Count);
        }
        public void TestSyncSample()
        {
            var       result    = new List <SyncDelta>();
            SyncToken lastToken = GetFacade().Sync(Sample, new SyncToken(5), new SyncResultsHandler()
            {
                Handle = delta =>
                {
                    result.Add(delta);
                    return(true);
                }
            }, null);

            Assert.AreEqual("SAMPLE", lastToken.Value);
            //Assert.AreEqual(4, result.Count);
        }
Exemplo n.º 19
0
    public override string ToString()
    {
        var  sb      = new StringBuilder("FetchMyEventsRequest(");
        bool __first = true;

        if (__isset.subscriptionId)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("SubscriptionId: ");
            SubscriptionId.ToString(sb);
        }
        if (SyncToken != null && __isset.syncToken)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("SyncToken: ");
            SyncToken.ToString(sb);
        }
        if (__isset.limit)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Limit: ");
            Limit.ToString(sb);
        }
        if (ContinuationToken != null && __isset.continuationToken)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("ContinuationToken: ");
            ContinuationToken.ToString(sb);
        }
        sb.Append(")");
        return(sb.ToString());
    }
    public override string ToString()
    {
        var  sb      = new StringBuilder("FetchSquareChatEventsResponse(");
        bool __first = true;

        if (Subscription != null && __isset.subscription)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Subscription: ");
            Subscription.ToString(sb);
        }
        if (Events != null && __isset.events)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Events: ");
            Events.ToString(sb);
        }
        if (SyncToken != null && __isset.syncToken)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("SyncToken: ");
            SyncToken.ToString(sb);
        }
        if (ContinuationToken != null && __isset.continuationToken)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("ContinuationToken: ");
            ContinuationToken.ToString(sb);
        }
        sb.Append(")");
        return(sb.ToString());
    }
        public void TestSyncTokenParser()
        {
            Uri        url   = new Uri("https://outlook.office365.com/api/beta/delta?$skiptoken=fasdlfjflds");
            ISyncToken token = null;

            Assert.IsTrue(
                SyncToken.TryParseFromUrl(
                    url,
                    SyncTokenType.SkipToken,
                    out token));

            Assert.AreEqual(
                "$skiptoken=fasdlfjflds",
                token.Query);

            Assert.AreEqual(
                "fasdlfjflds",
                token.Value);

            Assert.IsFalse(
                SyncToken.TryParseFromUrl(
                    "abcd",
                    SyncTokenType.DeltaToken,
                    out token));

            Assert.IsFalse(
                SyncToken.TryParseFromUrl(
                    "",
                    SyncTokenType.DeltaToken,
                    out token));

            url = new Uri("https://outlook.office365.com/api/beta/delta?$select=Something&$deltatoken=fasdlfjflds&$filter=A");

            Assert.IsTrue(
                SyncToken.TryParseFromUrl(
                    url,
                    SyncTokenType.DeltaToken,
                    out token));

            Assert.AreEqual(
                "$deltatoken=fasdlfjflds",
                token.Query);
        }
Exemplo n.º 22
0
        public virtual void Sync(ObjectClass objectClass, SyncToken token, SyncResultsHandler handler,
                                 OperationOptions options)
        {
            if (ObjectClass.ALL.Equals(objectClass))
            {
                //
            }
            else if (ObjectClass.ACCOUNT.Equals(objectClass))
            {
                var builder = new ConnectorObjectBuilder();
                builder.SetUid("3f50eca0-f5e9-11e3-a3ac-0800200c9a66");
                builder.SetName("Foo");
                builder.AddAttribute(ConnectorAttributeBuilder.BuildEnabled(true));

                var deltaBuilder = new SyncDeltaBuilder
                {
                    Object    = builder.Build(),
                    DeltaType = SyncDeltaType.CREATE,
                    Token     = new SyncToken(10)
                };

                foreach (SyncDelta connectorObject in CollectionUtil.NewSet(deltaBuilder.Build()))
                {
                    if (!handler.Handle(connectorObject))
                    {
                        // Stop iterating because the handler stopped processing
                        break;
                    }
                }
            }
            else
            {
                Trace.TraceWarning("Sync of type {0} is not supported",
                                   _configuration.ConnectorMessages.Format(objectClass.GetDisplayNameKey(),
                                                                           objectClass.GetObjectClassValue()));
                throw new NotSupportedException("Sync of type" + objectClass.GetObjectClassValue() + " is not supported");
            }
            ((SyncTokenResultsHandler)handler).HandleResult(new SyncToken(10));
        }
        public void TestSyncTokenSerializeDeserialize()
        {
            string    serialized = "RGVsdGFUb2tlbnxhYmNkZWY=";
            SyncToken syncToken  = SyncToken.Deserialize(serialized);

            Assert.AreEqual(
                SyncTokenType.DeltaToken,
                syncToken.Type);

            Assert.AreEqual(
                "abcdef",
                syncToken.Value);

            Assert.AreEqual(
                "$deltatoken=abcdef",
                syncToken.Query);

            Assert.IsNull(SyncToken.Deserialize(null));
            Assert.IsNull(SyncToken.Deserialize("abc"));                                      // this is incorrect (when it comes to formatting) base64 string
            Assert.IsNull(SyncToken.Deserialize("abcd"));                                     // this is correct (when it comes to formatting) base64 string
            Assert.IsNull(SyncToken.Deserialize("bm9uZXhpc3Rpbmd0b2tlbnR5cGV8cGF5bG9hZA==")); // "nonexistingtokentype|payload" as base64

            string payload = "dG9rZW5wYXlsb2Fk";

            syncToken = new SyncToken(
                payload,
                SyncTokenType.DeltaToken);

            serialized = syncToken.Serialize();

            Assert.IsTrue(syncToken.Equals(
                              SyncToken.Deserialize(serialized)));

            Assert.IsFalse(
                syncToken.Equals(SyncToken.Deserialize("U2tpcFRva2VufHRva2VucGF5bG9hZA==")));

            Assert.IsFalse(
                syncToken.Equals("a"));
        }
Exemplo n.º 24
0
        public virtual void Sync(ObjectClass objectClass, SyncToken token,
                                 SyncResultsHandler handler, OperationOptions options)
        {
            Trace.TraceInformation("Invoke Sync ObjectClass:{0}->{1}", objectClass.GetObjectClassValue(), token);

            try
            {
                ExecuteSync(_configuration.SyncScriptFileName, objectClass, token, handler, options);
                Trace.TraceInformation("Sync ok");
            }
            catch (ConnectorException)
            {
                throw;
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
                throw;
            }
        }
        public void TestSyncTokenResults()
        {
            foreach (ConnectorFacade facade in CreateStateFulFacades())
            {
                Uid uid = facade.Create(ObjectClass.ACCOUNT, CollectionUtil.NewReadOnlySet <ConnectorAttribute>(), null);

                SyncToken latest = facade.GetLatestSyncToken(ObjectClass.ACCOUNT);
                Assert.AreEqual(uid.GetUidValue(), latest.Value);

                for (int i = 0; i < 10; i++)
                {
                    SyncToken lastToken = facade.Sync(ObjectClass.ACCOUNT, null, new SyncResultsHandler()
                    {
                        Handle = obj =>
                        {
                            return(true);
                        }
                    }, null);
                    Assert.IsNotNull(lastToken);
                    Assert.AreEqual(lastToken.Value, latest.Value);
                }
            }
        }
Exemplo n.º 26
0
    public override int GetHashCode()
    {
        int hashcode = 157;

        unchecked {
            if (__isset.subscriptionId)
            {
                hashcode = (hashcode * 397) + SubscriptionId.GetHashCode();
            }
            if (__isset.syncToken)
            {
                hashcode = (hashcode * 397) + SyncToken.GetHashCode();
            }
            if (__isset.limit)
            {
                hashcode = (hashcode * 397) + Limit.GetHashCode();
            }
            if (__isset.continuationToken)
            {
                hashcode = (hashcode * 397) + ContinuationToken.GetHashCode();
            }
        }
        return(hashcode);
    }
    public override int GetHashCode()
    {
        int hashcode = 157;

        unchecked {
            if (__isset.subscription)
            {
                hashcode = (hashcode * 397) + Subscription.GetHashCode();
            }
            if (__isset.events)
            {
                hashcode = (hashcode * 397) + TCollections.GetHashCode(Events);
            }
            if (__isset.syncToken)
            {
                hashcode = (hashcode * 397) + SyncToken.GetHashCode();
            }
            if (__isset.continuationToken)
            {
                hashcode = (hashcode * 397) + ContinuationToken.GetHashCode();
            }
        }
        return(hashcode);
    }
Exemplo n.º 28
0
 public void Sync(ObjectClass objectClass, SyncToken token, SyncResultsHandler handler, OperationOptions options)
 {
     Assert.IsNotNull(objectClass);
     Assert.IsNotNull(token);
     Assert.IsNotNull(handler);
     Assert.IsNotNull(options);
     AddCall("Sync", objectClass, token, handler, options);
     if (ObjectClass.ALL.Equals(objectClass))
     {
         if (null != CollectionUtil.GetValue(options.Options, "FAIL_DELETE", null))
         {
             //Require ObjectClass when delta is 'delete'
             var builder = new SyncDeltaBuilder();
             builder.DeltaType = SyncDeltaType.DELETE;
             builder.Uid       = new Uid("DELETED");
             builder.Token     = new SyncToken(99);
             handler.Handle(builder.Build());
         }
         else
         {
             ((SyncTokenResultsHandler)handler).HandleResult(new SyncToken(100));
         }
     }
 }
        public void TestSyncAll()
        {
            var       result    = new List <SyncDelta>();
            SyncToken lastToken =
                GetFacade().Sync(ObjectClass.ALL, new SyncToken(0), new SyncResultsHandler()
            {
                Handle = delta =>
                {
                    result.Add(delta);
                    return(true);
                }
            }, null);

            Assert.AreEqual(17, lastToken.Value);
            Assert.AreEqual(7, result.Count);
            int index = 10;

            foreach (var delta in result)
            {
                Assert.AreEqual(index++, delta.Token.Value);
                Assert.AreEqual(((int)delta.Token.Value) % 2 == 0 ? ObjectClass.ACCOUNT : ObjectClass.GROUP,
                                delta.Object.ObjectClass);
            }
        }
Exemplo n.º 30
0
        public void Sync(ObjectClass objClass, SyncToken token,
                         SyncResultsHandler handler,
                         OperationOptions options)
        {
            for (int i = 0; i < _config.numResults; i++)
            {
                ConnectorObjectBuilder obuilder =
                    new ConnectorObjectBuilder();
                obuilder.SetUid(i.ToString());
                obuilder.SetName(i.ToString());
                obuilder.ObjectClass = (objClass);

                SyncDeltaBuilder builder =
                    new SyncDeltaBuilder();
                builder.Object    = (obuilder.Build());
                builder.DeltaType = (SyncDeltaType.CREATE_OR_UPDATE);
                builder.Token     = (new SyncToken("mytoken"));
                SyncDelta rv = builder.Build();
                if (!handler(rv))
                {
                    break;
                }
            }
        }