Пример #1
0
 public SyncService(StorageFolder startFolder, ResourceInfo resourceInfo, FolderSyncInfo syncInfo)
 {
     this.baseFolder     = startFolder;
     this.folderSyncInfo = syncInfo;
     this.resourceInfo   = resourceInfo;
     sidList             = new List <SyncInfoDetail>();
 }
 public SyncService(StorageFolder startFolder, ResourceInfo resourceInfo, FolderSyncInfo syncInfo, IResourceLoader resourceLoader)
 {
     _baseFolder     = startFolder;
     _folderSyncInfo = syncInfo;
     _resourceInfo   = resourceInfo;
     _resourceLoader = resourceLoader;
     _sidList        = new List <SyncInfoDetail>();
 }
Пример #3
0
 public static void DeleteFolderSyncInfo(FolderSyncInfo folderSyncInfo)
 {
     // Create a new connection
     using (var db = DbConnection)
     {
         // Object model:
         db.Delete(folderSyncInfo);
         db.Execute("DELETE FROM SyncInfoDetail WHERE FsiID = ?", folderSyncInfo.Id);
     }
 }
Пример #4
0
 public static List <SyncInfoDetail> GetAllSyncInfoDetails(FolderSyncInfo fsi)
 {
     using (var db = DbConnection)
     {
         IEnumerable <SyncInfoDetail> sidList = (from detail in db.Table <SyncInfoDetail>()
                                                 where detail.FsiID == fsi.Id
                                                 select detail);
         return(sidList.ToList());
     }
 }
Пример #5
0
 public static FolderSyncInfo GetFolderSyncInfoByPath(string Path)
 {
     // Create a new connection
     using (var db = DbConnection)
     {
         FolderSyncInfo m = (from fsi in db.Table <FolderSyncInfo>()
                             where fsi.Path == Path
                             select fsi).FirstOrDefault();
         return(m);
     }
 }
Пример #6
0
 public static SyncInfoDetail GetSyncInfoDetail(IStorageItem file, FolderSyncInfo fsi)
 {
     // Create a new connection
     using (var db = DbConnection)
     {
         SyncInfoDetail sid = (from detail in db.Table <SyncInfoDetail>()
                               where detail.FilePath == file.Path && detail.FsiID == fsi.Id
                               select detail).FirstOrDefault();
         return(sid);
     }
 }
Пример #7
0
 public static int GetErrorConflictCount(FolderSyncInfo folderSyncInfo)
 {
     // Create a new connection
     using (var db = DbConnection)
     {
         return((from sid in db.Table <SyncInfoDetail>()
                 where sid.FsiID == folderSyncInfo.Id &&
                 (sid.ConflictType != ConflictType.NONE ||
                  sid.Error != null)
                 select sid).Count());
     }
 }
Пример #8
0
        internal static void ShowSyncSuspendedNotification(FolderSyncInfo fsi)
        {
            if (fsi == null)
            {
                return;
            }
            var          loader  = new ResourceLoader();
            var          title   = loader.GetString("SyncSuspendedTitle");
            var          content = string.Format(loader.GetString("SyncSuspendedDescription"), fsi.Path);
            const string action  = SyncAction;

            // Construct the visuals of the toast
            var visual = new ToastVisual
            {
                BindingGeneric = new ToastBindingGeneric
                {
                    Children =
                    {
                        new AdaptiveText
                        {
                            Text = title
                        },
                        new AdaptiveText
                        {
                            Text = content
                        }
                    }
                }
            };
            var toastContent = new ToastContent
            {
                Visual = visual,

                // Arguments when the user taps body of toast
                Launch = new QueryString
                {
                    { "action", action }
                }.ToString()
            };
            var toast = new ToastNotification(toastContent.GetXml())
            {
                ExpirationTime = DateTime.Now.AddMinutes(30),
                Group          = action
            };

            // TODO Replace with syncinterval from settings.
            // TODO groups/tags?
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
Пример #9
0
 public static void SaveFolderSyncInfo(FolderSyncInfo fsi)
 {
     // Create a new connection
     using (var db = DbConnection)
     {
         if (fsi.Id == 0)
         {
             // New
             db.Insert(fsi);
         }
         else
         {
             // Update
             db.Update(fsi);
         }
     }
 }
Пример #10
0
        public static SyncInfoDetail GetSyncInfoDetail(ResourceInfo info, FolderSyncInfo fsi)
        {
            // Create a new connection
            string fullPath = info.Path;

            if (!info.IsDirectory)
            {
                fullPath = info.Path + "/" + info.Name;
            }

            using (var db = DbConnection)
            {
                SyncInfoDetail sid = (from detail in db.Table <SyncInfoDetail>()
                                      where detail.Path == fullPath && detail.FsiID == fsi.Id
                                      select detail).FirstOrDefault();
                return(sid);
            }
        }
Пример #11
0
 internal static bool LockFolderSyncInfo(FolderSyncInfo folderSyncInfo)
 {
     lock (fsiLock)
     {
         using (var db = DbConnection)
         {
             FolderSyncInfo m = (from fsi in db.Table <FolderSyncInfo>()
                                 where fsi.Id == folderSyncInfo.Id
                                 select fsi).FirstOrDefault();
             if (m == null || m.Active)
             {
                 return(false);
             }
             else
             {
                 m.Active = true;
                 db.Update(m);
                 return(true);
             }
         }
     }
 }
Пример #12
0
        private async Task SychronizeFolder(ResourceInfo resourceInfo)
        {
            if (resourceInfo == null)
            {
                return;
            }

            var           syncInfo = SyncDbUtils.GetFolderSyncInfoByPath(resourceInfo.Path);
            StorageFolder folder;

            try
            {
                Task <ContentDialogResult> firstRunDialog = null;
                if (syncInfo == null)
                {
                    // try to Get parent or initialize
                    syncInfo = SyncDbUtils.GetFolderSyncInfoBySubPath(resourceInfo.Path);

                    if (syncInfo == null)
                    {
                        // Initial Sync
                        syncInfo = new FolderSyncInfo()
                        {
                            Path = resourceInfo.Path
                        };

                        var folderPicker = new FolderPicker()
                        {
                            SuggestedStartLocation = PickerLocationId.Desktop
                        };

                        folderPicker.FileTypeFilter.Add(".txt");
                        StorageFolder newFolder = await folderPicker.PickSingleFolderAsync();

                        if (newFolder == null)
                        {
                            return;
                        }

                        StorageApplicationPermissions.FutureAccessList.AddOrReplace(syncInfo.AccessListKey, newFolder);
                        IReadOnlyList <IStorageItem> subElements = await newFolder.GetItemsAsync();

                        NextcloudClient.NextcloudClient client = await ClientService.GetClient();

                        var remoteElements = await client.List(resourceInfo.Path);

                        if (subElements.Count > 0 && remoteElements.Count > 0)
                        {
                            var dialogNotEmpty = new ContentDialog
                            {
                                Title   = _resourceLoader.GetString("SyncFoldersNotEmptyWarning"),
                                Content = new TextBlock()
                                {
                                    Text         = _resourceLoader.GetString("SyncFoldersNotEmptyWarningDetail"),
                                    TextWrapping = TextWrapping.WrapWholeWords,
                                    Margin       = new Thickness(0, 20, 0, 0)
                                },
                                PrimaryButtonText   = _resourceLoader.GetString("OK"),
                                SecondaryButtonText = _resourceLoader.GetString("Cancel")
                            };

                            var dialogResult = await _dialogService.ShowAsync(dialogNotEmpty);

                            if (dialogResult != ContentDialogResult.Primary)
                            {
                                return;
                            }
                        }

                        folder = newFolder;
                        SyncDbUtils.SaveFolderSyncInfo(syncInfo);
                        StartDirectoryListing(); // This is just to update the menu flyout - maybe there is a better way

                        var dialog = new ContentDialog
                        {
                            Title   = _resourceLoader.GetString("SyncStarted"),
                            Content = new TextBlock()
                            {
                                Text         = _resourceLoader.GetString("SyncStartedDetail"),
                                TextWrapping = TextWrapping.WrapWholeWords,
                                Margin       = new Thickness(0, 20, 0, 0)
                            },
                            PrimaryButtonText = _resourceLoader.GetString("OK")
                        };
                        firstRunDialog = _dialogService.ShowAsync(dialog);
                    }
                    else
                    {
                        string        subPath    = resourceInfo.Path.Substring(syncInfo.Path.Length);
                        StorageFolder tempFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(syncInfo.AccessListKey);

                        foreach (string foldername in subPath.Split('/'))
                        {
                            if (foldername.Length > 0)
                            {
                                tempFolder = await tempFolder.GetFolderAsync(foldername);
                            }
                        }
                        folder = tempFolder;
                    }
                }
                else
                {
                    folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(syncInfo.AccessListKey);

                    // TODO catch exceptions
                }

                SyncService service = new SyncService(folder, resourceInfo, syncInfo);
                await service.StartSync();

                if (firstRunDialog != null)
                {
                    await firstRunDialog;
                }
            }
            catch (Exception e)
            {
                // ERROR Maybe AccessList timed out.
                Debug.WriteLine(e.Message);
            }
        }