Exemple #1
0
 void AddDirectoryItemVM()
 {
     if (!CloudDirectories.Any() || CloudModel.IsBackingUpToCloud == false)
     {
         var newDir = new DirectoryItemViewModel(new DirectoryItemModel());
         if (CloudDirectories.Any())
         {
             newDir.AllowBlank = true;
         }
         newDir.PropertyChanged += DirectoryItem_NewPropertyChanged;
         CloudDirectories.Add(newDir);
     }
 }
Exemple #2
0
        public void Backup()
        {
            string   bakFileName = _dbContext.BackupDb();
            FileInfo bakFile     = new FileInfo(bakFileName);

            if (!bakFile.Exists)
            {
                return;
            }
#if DEBUG
            if (!(CloudDirectories.Count() == 1))
            {
                throw new InvalidOperationException("Backup called without cloud directories set to a single directory");
            }
#endif
            string uniqueFileNameSuffix = '_' + LocalStudyCentres.First().DuplicateIdCheck.ToString("N");
            string cloudDir             = CloudDirectories.First();
            string cloudZipName         = cloudDir + '\\' + Path.GetFileNameWithoutExtension(bakFileName) + uniqueFileNameSuffix + ".zip";

            var cloudFile = new FileInfo(cloudZipName);

            if (cloudFile.Exists)
            {
                DateTime?mostRecentEntry = SyncronisationResult.MostRecentEntry(_dbContext);
                if (mostRecentEntry == null || cloudFile.LastWriteTimeUtc >= mostRecentEntry)
                {
                    return;
                }
            }
            _dbContext.Dispose(); // only necessary for ce
            SyncronisationResult.RepairDb(bakFileName);
            int    dotPos         = bakFileName.LastIndexOf('.');
            string copiedFileName = bakFileName.Insert(dotPos, uniqueFileNameSuffix);
            File.Copy(bakFileName, copiedFileName, true);

            void work()
            {
                BackupHelper.ZipVerifyAndPutInCloudDir(copiedFileName, cloudDir);
            }

            new Thread(work).Start();
            _dbContext = _createContext.Invoke();
        }