Example #1
0
        public IEnumerable<FileSystemChange> DetermineChangesToSource(IEnumerable<FileSystemEntry> sourceEntries, IEnumerable<FileSystemEntry> destinationEntries, ConflictBehavior conflictBehavior)
        {
            List<FileSystemChange> result = new List<FileSystemChange>();

            var sourceDictionary = sourceEntries.ToDictionary(p => p.RelativePath.ToLower());

            foreach (var destEntry in destinationEntries)
            {
                FileSystemEntry matchingSource = null;
                if (sourceDictionary.TryGetValue(destEntry.RelativePath.ToLower(), out matchingSource))
                {
                    // exists on source

                    // determine if we have a conflict
                    if (destEntry.IsInConflictWith(matchingSource))
                    {
                        if (conflictBehavior == ConflictBehavior.Skip)
                            continue;

                        if (conflictBehavior == ConflictBehavior.TakeDestination)
                            result.Add(FileSystemChange.ForOverwrite(destEntry));

                        if (conflictBehavior == ConflictBehavior.TakeNewest &&
                            destEntry.Created != null && matchingSource.Created != null &&
                            destEntry.Created.Value > matchingSource.Created.Value)
                        {
                            result.Add(FileSystemChange.ForOverwrite(destEntry));
                            continue;
                        }

                        if (conflictBehavior == ConflictBehavior.TakeNewest &&
                            destEntry.Modified != null && matchingSource.Modified != null &&
                            destEntry.Modified.Value > matchingSource.Modified.Value)
                        {
                            result.Add(FileSystemChange.ForOverwrite(destEntry));
                            continue;
                        }
                    }
                }
                else
                {
                    // does not exist on source
                    result.Add(FileSystemChange.ForCreate(destEntry));
                }
            }

            return result;
        }
        /// <summary>
        /// if controller is null, use CreatorController.
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="newFolderName"></param>
        /// <param name="conflict"></param>
        /// <param name="controller"></param>
        /// <param name="pageSize">default value was 200, max value was 1000 ( test on 2015-07-27 ).</param>
        /// <returns></returns>
        public async static Task<WebResult<Item>> CreateFolderAsync(this IRoot folder,
            string newFolderName, ConflictBehavior conflict = ConflictBehavior.Fail, OneDriveWebController controller = null)
        {
            var entity = new CreateFolderEntity()
            {
                Name = newFolderName,
                Folder = new EmptyEntity(),
                NameconflictBehavior = conflict.GetValue()
            };

            var json = entity.ObjectToJson();
            Debug.WriteLine(json);

            return await (controller ?? folder.CreatorController)
                .WrapRequestAsync<Item>($"drive/items/{folder.Id}/children",
                    HttpWebRequestResourceString.Method.Post,
                    json.GetBytes());
        }