Esempio n. 1
0
        private static void SyncMedia()
        {
            LogService.LogEvent("Sync media starting.");

            // read the library out of the server
            var scanner = new DataScanner(_localUrl);
            var results = scanner.ScanAllMediaFiles(_syncExclusions);

            // check the cache first
            var cacheService = new SyncCache(_remoteService);
            if (!cacheService.CheckCache())
            {
                RefreshCache();
            }

            // check and see what has changed and needs to be removed/updated
            var update = new List<ContentModel>();
            var delete = new List<int>();
            cacheService.Compare(results, update, delete);

            LogService.LogEvent(string.Format("{0} items found on server", results.Count()));
            LogService.LogEvent(string.Format("{0} to update", update.Count));
            LogService.LogEvent(string.Format("{0} to delete", delete.Count));

            // push the results to the server
            if (update.Any())
            {
                var updates = _remoteService.PushToServer(update.ToArray());
                LogService.LogEvent(string.Format("{0} updated.", updates.Count()));
                cacheService.UpdateCache(updates);
            }

            if (delete.Any())
            {
                _remoteService.RemoveFromServer(delete.ToArray());
                LogService.LogEvent(string.Format("{0} deleted.", delete.Count));
                cacheService.UpdateCache(removals:delete);
            }

            LogService.LogEvent("Sync complete");
            LogService.FlushLog();
        }
Esempio n. 2
0
 private static void RefreshCache()
 {
     var cacheService = new SyncCache(_remoteService);
     cacheService.RefreshCache();
 }