Beispiel #1
0
 public Task Delete(Uri entityId)
 {
     using (AutomaticStopwatch.StartDebug(s_logger))
     {
         return(_cardDavDataAccess.DeleteEntity(entityId));
     }
 }
 public Task Delete(Uri entityId, string version)
 {
     using (AutomaticStopwatch.StartDebug(s_logger))
     {
         return(_calDavDataAccess.DeleteEntity(entityId, version));
     }
 }
Beispiel #3
0
 public async Task <bool> TryDelete(WebResourceName entityId, string version, TContext context)
 {
     using (AutomaticStopwatch.StartDebug(s_logger))
     {
         return(await _cardDavDataAccess.TryDeleteEntity(entityId, version));
     }
 }
Beispiel #4
0
 public async Task Delete(WebResourceName entityId, string version)
 {
     using (AutomaticStopwatch.StartDebug(s_logger))
     {
         await _calDavDataAccess.DeleteEntity(entityId, version);
     }
 }
Beispiel #5
0
        public EntityIdWithVersion <Uri, string> Update(Uri entityId, IICalendar entityToUpdate, Func <IICalendar, IICalendar> entityModifier)
        {
            using (AutomaticStopwatch.StartDebug(s_logger))
            {
                IICalendar newCalendar = new iCalendar();
                newCalendar = entityModifier(newCalendar);

                if (entityToUpdate.Events.Count > 0)
                {
                    for (int i = 0, newSequenceNumber = entityToUpdate.Events.Max(e => e.Sequence) + 1; i < newCalendar.Events.Count; i++, newSequenceNumber++)
                    {
                        newCalendar.Events[i].Sequence = newSequenceNumber;
                    }
                }
                if (entityToUpdate.Todos.Count > 0)
                {
                    for (int i = 0, newSequenceNumber = entityToUpdate.Todos.Max(e => e.Sequence) + 1; i < newCalendar.Todos.Count; i++, newSequenceNumber++)
                    {
                        newCalendar.Todos[i].Sequence = newSequenceNumber;
                    }
                }

                return(_calDavDataAccess.UpdateEntity(entityId, SerializeCalendar(newCalendar)));
            }
        }
Beispiel #6
0
 public Task <EntityIdWithVersion <Uri, string> > Update(Uri entityId, IICalendar entityToUpdate, Func <IICalendar, IICalendar> entityModifier)
 {
     using (AutomaticStopwatch.StartDebug(s_logger))
     {
         var updatedEntity = entityModifier(entityToUpdate);
         return(_calDavDataAccess.UpdateEntity(entityId, SerializeCalendar(updatedEntity)));
     }
 }
Beispiel #7
0
 public async Task <EntityIdWithVersion <Uri, string> > Create(Func <IICalendar, IICalendar> entityInitializer)
 {
     using (AutomaticStopwatch.StartDebug(s_logger))
     {
         IICalendar newCalendar = new iCalendar();
         newCalendar = entityInitializer(newCalendar);
         return(await _calDavDataAccess.CreateEntity(SerializeCalendar (newCalendar)));
     }
 }
Beispiel #8
0
 public async Task <EntityIdWithVersion <Uri, string> > Create(Func <vCard, vCard> entityInitializer)
 {
     using (AutomaticStopwatch.StartDebug(s_logger))
     {
         vCard newVcard         = new vCard();
         var   initializedVcard = entityInitializer(newVcard);
         return(await _cardDavDataAccess.CreateEntity(Serialize (initializedVcard)));
     }
 }
Beispiel #9
0
 public async Task <EntityVersion <WebResourceName, string> > Create(Func <IICalendar, IICalendar> entityInitializer)
 {
     using (AutomaticStopwatch.StartDebug(s_logger))
     {
         IICalendar newCalendar = new iCalendar();
         newCalendar = entityInitializer(newCalendar);
         var uid = (newCalendar.Events.Count > 0) ? newCalendar.Events[0].UID : newCalendar.Todos[0].UID;
         return(await _calDavDataAccess.CreateEntity(SerializeCalendar (newCalendar), uid));
     }
 }
 public async Task <EntityVersion <WebResourceName, string> > Create(Func <vCard, vCard> entityInitializer)
 {
     using (AutomaticStopwatch.StartDebug(s_logger))
     {
         vCard newVcard = new vCard();
         newVcard.UniqueId = Guid.NewGuid().ToString();
         var initializedVcard = entityInitializer(newVcard);
         return(await _cardDavDataAccess.CreateEntity(Serialize (initializedVcard), newVcard.UniqueId));
     }
 }
Beispiel #11
0
        public Task <EntityIdWithVersion <Uri, string> > Update(Uri entityId, vCard entityToUpdate, Func <vCard, vCard> entityModifier)
        {
            using (AutomaticStopwatch.StartDebug(s_logger))
            {
                vCard newVcard = new vCard();
                newVcard.UniqueId = entityToUpdate.UniqueId;
                newVcard          = entityModifier(newVcard);

                return(_cardDavDataAccess.UpdateEntity(entityId, Serialize(newVcard)));
            }
        }
Beispiel #12
0
        public async Task <EntityVersion <WebResourceName, string> > Create(Func <TEntity, Task <TEntity> > entityInitializer, TContext context)
        {
            using (AutomaticStopwatch.StartDebug(s_logger))
            {
                TEntity newEntity = new TEntity();
                var     uid       = Guid.NewGuid().ToString();
                SetUid(newEntity, uid);
                var initializedVcard = await entityInitializer(newEntity);

                return(await _cardDavDataAccess.CreateEntity(Serialize(initializedVcard), uid));
            }
        }
Beispiel #13
0
        public Task <EntityVersion <Uri, string> > Update(
            Uri entityId,
            string entityVersion,
            vCard entityToUpdate,
            Func <vCard, vCard> entityModifier)
        {
            using (AutomaticStopwatch.StartDebug(s_logger))
            {
                vCard newVcard = new vCard();
                newVcard.UniqueId = (!string.IsNullOrEmpty(entityToUpdate.UniqueId)) ? entityToUpdate.UniqueId : Guid.NewGuid().ToString();
                newVcard          = entityModifier(newVcard);

                return(_cardDavDataAccess.UpdateEntity(entityId, entityVersion, Serialize(newVcard)));
            }
        }
Beispiel #14
0
        public async Task <EntityVersion <WebResourceName, string> > TryUpdate(
            WebResourceName entityId,
            string entityVersion,
            vCard entityToUpdate,
            Func <vCard, Task <vCard> > entityModifier,
            int context)
        {
            using (AutomaticStopwatch.StartDebug(s_logger))
            {
                vCard newVcard = new vCard();
                newVcard.UniqueId = (!string.IsNullOrEmpty(entityToUpdate.UniqueId)) ? entityToUpdate.UniqueId : Guid.NewGuid().ToString();
                newVcard          = await entityModifier(newVcard);

                return(await _cardDavDataAccess.TryUpdateEntity(entityId, entityVersion, Serialize (newVcard)));
            }
        }
Beispiel #15
0
        public EntityIdWithVersion <Uri, string> Create(Func <IICalendar, IICalendar> entityInitializer)
        {
            using (AutomaticStopwatch.StartDebug(s_logger))
            {
                IICalendar newCalendar = new iCalendar();
                newCalendar = entityInitializer(newCalendar);
                for (int i = 0; i < newCalendar.Events.Count; i++)
                {
                    newCalendar.Events[i].Sequence = i;
                }
                for (int i = 0; i < newCalendar.Todos.Count; i++)
                {
                    newCalendar.Todos[i].Sequence = i;
                }

                return(_calDavDataAccess.CreateEntity(SerializeCalendar(newCalendar)));
            }
        }
Beispiel #16
0
        public async Task <EntityVersion <WebResourceName, string> > TryUpdate(
            WebResourceName entityId,
            string entityVersion,
            TEntity entityToUpdate,
            Func <TEntity, Task <TEntity> > entityModifier,
            TContext context)
        {
            using (AutomaticStopwatch.StartDebug(s_logger))
            {
                var updatedEntity = await entityModifier(entityToUpdate);

                if (string.IsNullOrEmpty(GetUid(updatedEntity)))
                {
                    SetUid(updatedEntity, Guid.NewGuid().ToString());
                }
                return(await _cardDavDataAccess.TryUpdateEntity(entityId, entityVersion, Serialize (updatedEntity)));
            }
        }
Beispiel #17
0
        public async Task <EntityVersion <WebResourceName, string> > Update(
            WebResourceName entityId,
            string entityVersion,
            IICalendar entityToUpdate,
            Func <IICalendar, IICalendar> entityModifier)
        {
            using (AutomaticStopwatch.StartDebug(s_logger))
            {
                var updatedEntity = entityModifier(entityToUpdate);
                try
                {
                    return(await _calDavDataAccess.UpdateEntity(entityId, entityVersion, SerializeCalendar (updatedEntity)));
                }
                catch (WebDavClientException ex)
                {
                    if (_deleteAndCreateOnUpdateError403 && ex.StatusCode == System.Net.HttpStatusCode.Forbidden)
                    {
                        s_logger.Warn("Server returned '403' ('Forbidden') for update, trying Delete and Recreate instead...");

                        await Delete(entityId, entityVersion);

                        var uid = Guid.NewGuid().ToString();
                        if (updatedEntity.Events.Count > 0)
                        {
                            updatedEntity.Events[0].UID = uid;
                        }
                        else
                        {
                            updatedEntity.Todos[0].UID = uid;
                        }

                        return(await _calDavDataAccess.CreateEntity(SerializeCalendar (updatedEntity), uid));
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }