예제 #1
0
        protected override void ProcessRecord()
        {
            SyncRelationship relationship = CmdletCommon.GetSyncRelationship(this.RelationshipId);

            if (this.SyncHistoryId > 0)
            {
                this.WriteObject(
                    relationship.GetSyncJobHistory().FirstOrDefault(r => r.Id == this.SyncHistoryId));
                return;
            }

            using (var db = relationship.GetDatabase())
            {
                if (this.SyncHistoryId > 0)
                {
                    this.WriteObject(
                        db.History.FirstOrDefault(h => h.Id == this.SyncHistoryId));
                    return;
                }

                // Copy all history items to a list to prevent enumerating multiple
                // tables at the same time.
                var histories = db.History.ToList();
                foreach (var history in histories)
                {
                    this.WriteObject(history);
                }
            }
        }
예제 #2
0
        private void ProcessInternalOffline()
        {
            string localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string appDataRoot      = Path.Combine(localAppDataPath, "SyncPro");

            DirectoryInfo    appDataRootDir = new DirectoryInfo(appDataRoot);
            SyncRelationship relationship   = null;

            foreach (DirectoryInfo relationshipDir in appDataRootDir.GetDirectories())
            {
                Guid guid;
                if (Guid.TryParse(relationshipDir.Name, out guid) && guid == this.RelationshipId)
                {
                    relationship = SyncRelationship.Load(guid);
                    break;
                }
            }

            if (relationship == null)
            {
                throw new RelationshipNotFoundException(
                          "The relationship with ID " + this.RelationshipId + " was not found");
            }

            using (var db = relationship.GetDatabase())
            {
                foreach (SyncEntry syncEntry in db.Entries)
                {
                    this.WriteObject(syncEntry);
                }
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: yvanam/SyncPro
        private static void DumpDatabase(Dictionary <string, string> args)
        {
            Global.Initialize(false);

            SyncRelationship relationship = GetRelationship(args);

            using (var db = relationship.GetDatabase())
            {
                int i = 0;
                foreach (SyncEntry syncEntry in db.Entries)
                {
                    i++;
                    Console.WriteLine(
                        "| {0} | {1} | {2} | {3} | {4} ",
                        syncEntry.Id,
                        syncEntry.ParentId,
                        syncEntry.Name,
                        syncEntry.State,
                        syncEntry.Type);
                }

                Console.WriteLine("Total Entries: " + i);

                Console.WriteLine("----------------------------------");

                var historyList = db.History.ToList();
                foreach (var history in historyList)
                {
                    Console.WriteLine(
                        "History: {0}, {1}, {2}",
                        history.Id,
                        history.TotalFiles,
                        history.TotalBytes);

                    i = 0;
                    foreach (SyncHistoryEntryData entryData in db.HistoryEntries.Where(e => e.SyncHistoryId == history.Id))
                    {
                        i++;
                        Console.WriteLine(
                            "| {0} | {1} | {2} | {3} | {4} ",
                            entryData.Id,
                            entryData.PathNew,
                            entryData.Result,
                            entryData.Flags,
                            entryData.SyncEntryId);
                    }

                    Console.WriteLine("Total history entries: " + i);
                    Console.WriteLine("----------------------------------");
                }
            }
        }
예제 #4
0
        protected override void ProcessRecord()
        {
            SyncRelationship relationship = CmdletCommon.GetSyncRelationship(this.RelationshipId);

            using (var db = relationship.GetDatabase())
            {
                if (this.SyncHistory != null && this.SyncHistoryId == 0)
                {
                    this.SyncHistoryId = this.SyncHistory.Id;
                }

                var entries = db.HistoryEntries.Where(e => e.SyncHistoryId == this.SyncHistoryId).ToList();
                foreach (SyncHistoryEntryData entry in entries)
                {
                    this.WriteObject(new PSSyncHistoryEntry(entry));
                }
            }
        }
예제 #5
0
파일: Program.cs 프로젝트: yvanam/SyncPro
        private static void Reset(Dictionary <string, string> args)
        {
            Global.Initialize(false);

            SyncRelationship relationship = GetRelationship(args);

            using (var db = relationship.GetDatabase())
            {
                var rootEntry = db.Entries.First(e => e.ParentId == null || e.ParentId == 0);

                var entryCount = db.Entries.Count();
                Console.WriteLine("Removing {0} entries", entryCount);

                foreach (SyncEntry syncEntry in db.Entries.Where(e => e.ParentId != null && e.ParentId != 0))
                {
                    db.Entries.Remove(syncEntry);
                }

                var entryACount = db.AdapterEntries.Count();
                Console.WriteLine("Removing {0} adapter entries", entryACount);

                foreach (SyncEntryAdapterData adapterData in db.AdapterEntries.Where(e => e.SyncEntryId != rootEntry.Id))
                {
                    db.AdapterEntries.Remove(adapterData);
                }

                var historyCount = db.History.Count();
                Console.WriteLine("Removing {0} histories", historyCount);

                db.Database.ExecuteSqlCommand("TRUNCATE TABLE [HistoryEntries]");

                var historyEntryCount = db.HistoryEntries.Count();
                Console.WriteLine("Removing {0} history entries", historyEntryCount);

                db.Database.ExecuteSqlCommand("TRUNCATE TABLE [History]");

                db.SaveChanges();
            }
        }
예제 #6
0
        public void BasicSyncLocalToOneDrive()
        {
            if (!GlobalTestSettings.RunNetworkTests)
            {
                Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage);
            }

            string testRootPath = Path.Combine(this.TestContext.TestLogsDir, this.TestContext.TestName);

            Directory.CreateDirectory(testRootPath);

            string syncSourcePath = Path.Combine(testRootPath, "Source");

            Directory.CreateDirectory(syncSourcePath);

            // Create temp files/folders
            List <string> syncFileList = new List <string>
            {
                TestHelper.CreateDirectory(syncSourcePath, "dir1"),
                TestHelper.CreateFile(syncSourcePath, "dir1\\file1.txt"),
                TestHelper.CreateFile(syncSourcePath, "dir1\\file2.txt"),
                TestHelper.CreateFile(syncSourcePath, "dir1\\file3.txt"),
                TestHelper.CreateDirectory(syncSourcePath, "dir2"),
                TestHelper.CreateFile(syncSourcePath, "dir2\\file1.txt"),
                TestHelper.CreateFile(syncSourcePath, "dir2\\file2.txt"),
                TestHelper.CreateFile(syncSourcePath, "dir2\\file3.txt")
            };

            TokenResponse currentToken = GetCurrentToken();

            Guid remoteTestFolderName = Guid.NewGuid();
            Item remoteTestFolder     = CreateOneDriveTestDirectory(currentToken, remoteTestFolderName.ToString("D")).Result;

            SyncRelationship newRelationship = SetupRelationship(testRootPath, syncSourcePath, remoteTestFolder);

            AnalyzeJob analyzeJob = new AnalyzeJob(newRelationship);

            analyzeJob.ContinuationJob = new SyncJob(newRelationship, analyzeJob.AnalyzeResult)
            {
                TriggerType = SyncTriggerType.Manual
            };

            analyzeJob.Start();

            SyncJob syncJob = (SyncJob)analyzeJob.WaitForCompletion();

            Assert.IsTrue(syncJob.HasFinished);

            Assert.AreEqual(syncFileList.Count, syncJob.AnalyzeResult.AdapterResults.SelectMany(r => r.Value.EntryResults).Count());
            OneDriveAdapter oneDriveAdapter =
                newRelationship.Adapters.First(a => !a.Configuration.IsOriginator) as OneDriveAdapter;

            OneDriveClient client = new OneDriveClient(GetCurrentToken());

            foreach (string syncFile in syncFileList.Where(f => f.EndsWith(".txt")))
            {
                string localPath = Path.Combine(syncSourcePath, syncFile);

                using (var sha1 = new SHA1Managed())
                {
                    byte[] content       = File.ReadAllBytes(localPath);
                    byte[] localFileHash = sha1.ComputeHash(content);

                    EntryUpdateInfo entryResult;
                    using (var db = newRelationship.GetDatabase())
                    {
                        entryResult = syncJob.AnalyzeResult.AdapterResults.SelectMany(r => r.Value.EntryResults).FirstOrDefault(
                            r => r.Entry.GetRelativePath(db, "\\") == syncFile);
                    }

                    Assert.IsNotNull(entryResult);

                    byte[] databaseHash = entryResult.Entry.OriginalSha1Hash;

                    Assert.AreEqual(
                        TestHelper.HashToHex(localFileHash),
                        TestHelper.HashToHex(databaseHash),
                        "Local file hash does not match database hash.");

                    Pre.Assert(oneDriveAdapter != null, "oneDriveAdapter != null");
                    var adapterEntry =
                        entryResult.Entry.AdapterEntries.First(e => e.AdapterId == oneDriveAdapter.Configuration.Id);
                    string itemId       = adapterEntry.AdapterEntryId;
                    var    item         = client.GetItemByItemIdAsync(itemId);
                    var    oneDriveHash = "0x" + item.Result.File.Hashes.Sha1Hash;

                    Assert.AreEqual(
                        TestHelper.HashToHex(localFileHash),
                        oneDriveHash,
                        "Local file hash does not match OneDrive hash.");
                }
            }
        }