Ejemplo n.º 1
0
        private static void OnFileMetaReady(
            DropNetClient client,
            SyncInfo info, MetaData meta,
            Action<SyncCompleteInfo> report)
        {
            // No change from server side
            if (meta.Modified == info.Modified)
            {
                if (!info.HasLocalChanges)
                {
                    report(new SyncCompleteInfo
                    {
                        Path = info.Path,
                        Result = SyncResults.NoChange,
                    });

                    return;
                }

                // Has local change, upload to server
                client.UploadFileAsync(info.Path,
                    info.Database,
                    x => report(new SyncCompleteInfo
                    {
                        Path = info.Path,
                        Modified = x.Modified,
                        Result = SyncResults.Uploaded,
                    }),
                    x => report(new SyncCompleteInfo
                    {
                        Path = info.Path,
                        Result = SyncResults.Failed,
                    }));

                return;
            }

            // Has changes from server
            if (!info.HasLocalChanges)
            {
                // Database should be updated
                client.GetFileAsync(info.Path,
                    x => report(new SyncCompleteInfo
                    {
                        Path = info.Path,
                        Database = x.RawBytes,
                        Modified = meta.Modified,
                        Result = SyncResults.Downloaded,
                    }),
                    ex => report(new SyncCompleteInfo
                    {
                        Path = info.Path,
                        Result = SyncResults.Failed,
                    }));

                return;
            }

            // Conflict
            var path = GetNonConflictPath(info.Path);

            client.UploadFileAsync(path, info.Database,
                x => report(new SyncCompleteInfo
                {
                    Modified = x.Modified,
                    Path = client.GetUrl(path),
                    Result = SyncResults.Conflict,
                }),
                x => report(new SyncCompleteInfo
                {
                    Path = info.Path,
                    Result = SyncResults.Failed,
                }));
        }