Пример #1
0
        public static string SyncOutlookToCalDav_EventsExistsInCalDav(string existingEventData, IEntityRelationDataAccess <string, DateTime, Uri, string> entityRelationDataAccess = null)
        {
            string            roundTrippedData = null;
            ICalDavDataAccess calDavDataAccess = MockRepository.GenerateMock <ICalDavDataAccess>();
            var entityUri = new Uri("/e1", UriKind.Relative);

            calDavDataAccess
            .Expect(r => r.GetEvents(null))
            .IgnoreArguments()
            .Return(Task.FromResult <IReadOnlyList <EntityIdWithVersion <Uri, string> > > (
                        new[] { EntityIdWithVersion.Create(entityUri, "v1") }));

            calDavDataAccess
            .Expect(r => r.GetEntities(Arg <ICollection <Uri> > .List.Equal(new[] { entityUri })))
            .Return(Task.FromResult <IReadOnlyList <EntityWithVersion <Uri, string> > > (
                        new[] { EntityWithVersion.Create(entityUri, existingEventData) }));

            calDavDataAccess
            .Expect(r => r.UpdateEntity(new Uri("http://bla.com"), null))
            .IgnoreArguments()
            .Return(Task.FromResult <EntityIdWithVersion <Uri, string> > (
                        EntityIdWithVersion.Create(new Uri("http://bla.com"), "blubb")))
            .WhenCalled(a => { roundTrippedData = (string)a.Arguments[1]; });

            ISynchronizer synchronizer = OutlookTestContext.CreateEventSynchronizer(
                SynchronizationMode.ReplicateOutlookIntoServer,
                calDavDataAccess,
                entityRelationDataAccess);

            WaitForTask(synchronizer.Synchronize());

            return(roundTrippedData);
        }
        public Task <IReadOnlyList <EntityIdWithVersion <string, DateTime> > > GetVersions()
        {
            var entities = new List <EntityIdWithVersion <string, DateTime> >();

            using (var tableWrapper = GenericComObjectWrapper.Create((Table)_taskFolder.GetTable()))
            {
                var table = tableWrapper.Inner;
                table.Columns.RemoveAll();
                table.Columns.Add(c_entryIdColumnName);

                var storeId = _taskFolder.StoreID;

                while (!table.EndOfTable)
                {
                    var row     = table.GetNextRow();
                    var entryId = (string)row[c_entryIdColumnName];
                    using (var appointmentWrapper = GenericComObjectWrapper.Create((TaskItem)_mapiNameSpace.GetItemFromID(entryId, storeId)))
                    {
                        entities.Add(EntityIdWithVersion.Create(appointmentWrapper.Inner.EntryID, appointmentWrapper.Inner.LastModificationTime));
                    }
                }
            }

            return(Task.FromResult <IReadOnlyList <EntityIdWithVersion <string, DateTime> > > (entities));
        }
Пример #3
0
        public static List <string> SyncOutlookToCalDav_CalDavIsEmpty(
            IEntityRelationDataAccess <string, DateTime, Uri, string> entityRelationDataAccess = null,
            Action <Options> optionsModifier = null)
        {
            var calDavEvents = new List <string>();

            ICalDavDataAccess calDavDataAccess = MockRepository.GenerateMock <ICalDavDataAccess>();


            calDavDataAccess
            .Expect(r => r.GetEvents(null))
            .IgnoreArguments()
            .Return(Task.FromResult <IReadOnlyList <EntityIdWithVersion <Uri, string> > > (
                        new EntityIdWithVersion <Uri, string>[] { }));
            calDavDataAccess
            .Expect(r => r.CreateEntity(null))
            .IgnoreArguments()
            .Return(Task.FromResult(
                        EntityIdWithVersion.Create(new Uri("http://bla.com"), "blubb")))
            .WhenCalled(a => calDavEvents.Add((string)a.Arguments[0]));
            ISynchronizer synchronizer = CreateEventSynchronizer(
                SynchronizationMode.ReplicateOutlookIntoServer,
                calDavDataAccess,
                entityRelationDataAccess,
                optionsModifier);

            WaitForTask(synchronizer.Synchronize());
            return(calDavEvents);
        }
        public async Task <IReadOnlyList <EntityIdWithVersion <Uri, string> > > GetContacts()
        {
            var entities = new List <EntityIdWithVersion <Uri, string> >();

            try
            {
                var responseXml = await _webDavClient.ExecuteWebDavRequestAndReadResponse(
                    _serverUrl,
                    request =>
                {
                    request.Method = new System.Net.Http.HttpMethod("PROPFIND");
                    request.Headers.Add("Depth", "1");
                },
                    "application/xml",
                    @"<?xml version='1.0'?>
                        <D:propfind xmlns:D=""DAV:"">
                            <D:prop>
                              <D:getetag/>
                            </D:prop>
                        </D:propfind>
                 "
                    );

                XmlNodeList responseNodes = responseXml.XmlDocument.SelectNodes("/D:multistatus/D:response", responseXml.XmlNamespaceManager);

                // ReSharper disable once LoopCanBeConvertedToQuery
                // ReSharper disable once PossibleNullReferenceException
                foreach (XmlElement responseElement in responseNodes)
                {
                    var urlNode  = responseElement.SelectSingleNode("D:href", responseXml.XmlNamespaceManager);
                    var etagNode = responseElement.SelectSingleNode("D:propstat/D:prop/D:getetag", responseXml.XmlNamespaceManager);
                    if (urlNode != null && etagNode != null)
                    {
                        var eTag = etagNode.InnerText;
                        // the directory is also included in the list. It has a etag of '"None"' and is skipped
                        if (String.Compare(eTag, @"""None""", StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            var uri = UriHelper.UnescapeRelativeUri(_serverUrl, urlNode.InnerText);
                            entities.Add(EntityIdWithVersion.Create(uri, eTag));
                        }
                    }
                }
            }
            catch (WebException x)
            {
                if (x.Response != null)
                {
                    var httpWebResponse = (HttpWebResponse)x.Response;

                    if (httpWebResponse.StatusCode == HttpStatusCode.NotFound)
                    {
                        return(entities);
                    }
                }

                throw;
            }
            return(entities);
        }
        public void Synchronize_GetVersionsAndGetReturnDuplicateEntries_RemovesDuplicates()
        {
            var builder = new SynchronizerBuilder();

            builder.AtypeIdComparer = StringComparer.InvariantCultureIgnoreCase;

            builder.AtypeRepository
            .Expect(r => r.GetVersions(DateTime.Now, DateTime.Now))
            .IgnoreArguments()
            .Return(new[] { EntityIdWithVersion.Create("A1", "v1"), EntityIdWithVersion.Create("a1", "v3") });

            builder.BtypeRepository
            .Expect(r => r.GetVersions(DateTime.Now, DateTime.Now))
            .IgnoreArguments()
            .Return(new[] { EntityIdWithVersion.Create("b1", "v2") });


            Task <IReadOnlyList <EntityWithVersion <string, string> > > aTypeLoadTask = new Task <IReadOnlyList <EntityWithVersion <string, string> > > (
                () => new List <EntityWithVersion <string, string> > {
                EntityWithVersion.Create("A1", "AAAA"), EntityWithVersion.Create("a1", "____")
            });

            aTypeLoadTask.RunSynchronously();
            builder.AtypeRepository
            .Expect(r => r.Get(Arg <ICollection <string> > .Matches(c => c.Count == 1 && c.First() == "A1")))
            .Return(aTypeLoadTask);

            Task <IReadOnlyList <EntityWithVersion <string, string> > > bTypeLoadTask = new Task <IReadOnlyList <EntityWithVersion <string, string> > > (
                () => new List <EntityWithVersion <string, string> > {
                EntityWithVersion.Create("b1", "BBBB"),
            });

            bTypeLoadTask.RunSynchronously();
            builder.BtypeRepository
            .Expect(r => r.Get(Arg <ICollection <string> > .Matches(c => c.Count == 1 && c.First() == "b1")))
            .Return(bTypeLoadTask);


            var knownData = new EntityRelationDataString("A1", "v1", "b1", "v2");

            builder.InitialEntityMatcher
            .Expect(m => m.FindMatchingEntities(null, null, null, null, null))
            .IgnoreArguments()
            .Return(new List <IEntityRelationData <string, string, string, string> > {
                knownData
            });

            builder.InitialSyncStateCreationStrategy
            .Expect(s => s.CreateFor_Unchanged_Unchanged(knownData))
            .Return(new DoNothing <string, string, string, string, string, string> (knownData));

            var synchronizer = builder.Build();

            synchronizer.Synchronize().Wait();

            builder.SynchronizerContext.AssertWasCalled(
                c => c.SaveEntityRelationData(Arg <List <IEntityRelationData <string, string, string, string> > > .Matches(l => l.Count == 1 && l[0] == knownData)));
        }
Пример #6
0
        public static void SyncCalDavToOutlook(string eventData, IEntityRelationDataAccess <string, DateTime, Uri, string> entityRelationDataAccess)
        {
            var calDavDataAccess = MockRepository.GenerateMock <ICalDavDataAccess>();

            var entityUri = new Uri("/e1", UriKind.Relative);

            calDavDataAccess
            .Expect(r => r.GetEvents(null))
            .IgnoreArguments()
            .Return(Task.FromResult <IReadOnlyList <EntityIdWithVersion <Uri, string> > > (
                        new[] { EntityIdWithVersion.Create(entityUri, "v1") }));

            calDavDataAccess
            .Expect(r => r.GetEntities(Arg <ICollection <Uri> > .List.Equal(new[] { entityUri })))
            .Return(Task.FromResult <IReadOnlyList <EntityWithVersion <Uri, string> > > (
                        new[] { EntityWithVersion.Create(entityUri, eventData) }));

            var synchronizer = OutlookTestContext.CreateEventSynchronizer(
                SynchronizationMode.ReplicateServerIntoOutlook,
                calDavDataAccess,
                entityRelationDataAccess);

            WaitForTask(synchronizer.Synchronize());
        }
        private IReadOnlyList <EntityIdWithVersion <Uri, string> > GetEntities(DateTime?from, DateTime?to, string entityType)
        {
            if (from.HasValue != to.HasValue)
            {
                throw new ArgumentException("Either both or no boundary has to be set");
            }

            var entities = new List <EntityIdWithVersion <Uri, string> >();

            try
            {
                var responseXml = _calDavWebClient.ExecuteCalDavRequestAndReadResponse(
                    _calendarUrl,
                    request =>
                {
                    request.Method      = "REPORT";
                    request.ContentType = "text/xml; charset=UTF-8";
                    request.Headers.Add("Depth", 1.ToString());
                    request.ServicePoint.Expect100Continue = false;
                },
                    string.Format(
                        @"<?xml version=""1.0""?>
                    <C:calendar-query xmlns:C=""urn:ietf:params:xml:ns:caldav"">
                        <D:prop xmlns:D=""DAV:"">
                            <D:getetag/>
                        </D:prop>
                        <C:filter>
                            <C:comp-filter name=""VCALENDAR"">
                                <C:comp-filter name=""{0}"">
                                  {1}
                                </C:comp-filter>
                            </C:comp-filter>
                        </C:filter>
                    </C:calendar-query>
                    ",
                        entityType,
                        from == null ? string.Empty : string.Format(@"<C:time-range start=""{0}"" end=""{1}""/>",
                                                                    from.Value.ToString(s_calDavDateTimeFormatString),
                                                                    to.Value.ToString(s_calDavDateTimeFormatString))
                        ));


                XmlNodeList responseNodes = responseXml.XmlDocument.SelectNodes("/D:multistatus/D:response", responseXml.XmlNamespaceManager);

                // ReSharper disable once LoopCanBeConvertedToQuery
                // ReSharper disable once PossibleNullReferenceException
                foreach (XmlElement responseElement in responseNodes)
                {
                    var urlNode  = responseElement.SelectSingleNode("D:href", responseXml.XmlNamespaceManager);
                    var etagNode = responseElement.SelectSingleNode("D:propstat/D:prop/D:getetag", responseXml.XmlNamespaceManager);
                    if (urlNode != null && etagNode != null)
                    {
                        var uri = UriHelper.UnescapeRelativeUri(_calendarUrl, urlNode.InnerText);
                        entities.Add(EntityIdWithVersion.Create(uri, etagNode.InnerText));
                    }
                }
            }
            catch (WebException x)
            {
                if (x.Response != null)
                {
                    var httpWebResponse = (HttpWebResponse)x.Response;

                    if (httpWebResponse.StatusCode == HttpStatusCode.NotFound)
                    {
                        return(entities);
                    }
                }

                throw;
            }
            return(entities);
        }
 public IReadOnlyList <EntityIdWithVersion <string, int> > GetVersions(DateTime @from, DateTime to)
 {
     return(EntityVersionAndContentById.Select(kv => EntityIdWithVersion.Create(kv.Key, kv.Value.Item1)).ToList());
 }
        private async Task <IReadOnlyList <EntityIdWithVersion <Uri, string> > > GetEntities(DateTimeRange?range, string entityType)
        {
            var entities = new List <EntityIdWithVersion <Uri, string> >();

            try
            {
                var responseXml = await _webDavClient.ExecuteWebDavRequestAndReadResponse(
                    _serverUrl,
                    request =>
                {
                    request.Method = new System.Net.Http.HttpMethod("REPORT");
                    request.Headers.Add("Depth", 1.ToString());
                },
                    "application/xml",
                    string.Format(
                        @"<?xml version=""1.0""?>
                    <C:calendar-query xmlns:C=""urn:ietf:params:xml:ns:caldav"">
                        <D:prop xmlns:D=""DAV:"">
                            <D:getetag/>
                        </D:prop>
                        <C:filter>
                            <C:comp-filter name=""VCALENDAR"">
                                <C:comp-filter name=""{0}"">
                                  {1}
                                </C:comp-filter>
                            </C:comp-filter>
                        </C:filter>
                    </C:calendar-query>
                    ",
                        entityType,
                        range == null ? string.Empty : string.Format(@"<C:time-range start=""{0}"" end=""{1}""/>",
                                                                     range.Value.From.ToString(s_calDavDateTimeFormatString),
                                                                     range.Value.To.ToString(s_calDavDateTimeFormatString))
                        ));


                XmlNodeList responseNodes = responseXml.XmlDocument.SelectNodes("/D:multistatus/D:response", responseXml.XmlNamespaceManager);

                // ReSharper disable once LoopCanBeConvertedToQuery
                // ReSharper disable once PossibleNullReferenceException
                foreach (XmlElement responseElement in responseNodes)
                {
                    var urlNode  = responseElement.SelectSingleNode("D:href", responseXml.XmlNamespaceManager);
                    var etagNode = responseElement.SelectSingleNode("D:propstat/D:prop/D:getetag", responseXml.XmlNamespaceManager);
                    if (urlNode != null && etagNode != null)
                    {
                        var uri = UriHelper.UnescapeRelativeUri(_serverUrl, urlNode.InnerText);
                        entities.Add(EntityIdWithVersion.Create(uri, etagNode.InnerText));
                    }
                }
            }
            catch (WebException x)
            {
                if (x.Response != null)
                {
                    var httpWebResponse = (HttpWebResponse)x.Response;

                    if (httpWebResponse.StatusCode == HttpStatusCode.NotFound)
                    {
                        return(entities);
                    }
                }

                throw;
            }
            return(entities);
        }
Пример #10
0
 public Task <IReadOnlyList <EntityIdWithVersion <Identifier, int> > > GetVersions()
 {
     return(Task.FromResult <IReadOnlyList <EntityIdWithVersion <Identifier, int> > > (
                EntityVersionAndContentById.Select(kv => EntityIdWithVersion.Create(kv.Key, kv.Value.Item1)).ToList()));
 }