示例#1
0
        protected virtual IEnumerable <uSyncAction> ImportFolder(string folder, HandlerSettings config, Dictionary <string, TObject> updates, bool force, SyncUpdateCallback callback)
        {
            List <uSyncAction> actions = new List <uSyncAction>();
            var files = syncFileService.GetFiles(folder, "*.config");

            var flags = SerializerFlags.None;

            if (force)
            {
                flags |= SerializerFlags.Force;
            }
            if (config.BatchSave)
            {
                flags |= SerializerFlags.DoNotSave;
            }

            int count = 0;
            int total = files.Count();

            foreach (string file in files)
            {
                count++;

                callback?.Invoke($"Importing {Path.GetFileNameWithoutExtension(file)}", count, total);

                var attempt = Import(file, config, flags);
                if (attempt.Success && attempt.Item != null)
                {
                    updates.Add(file, attempt.Item);
                }

                var action = uSyncActionHelper <TObject> .SetAction(attempt, file, IsTwoPass);

                if (attempt.Details != null && attempt.Details.Any())
                {
                    action.Details = attempt.Details;
                }

                actions.Add(action);
            }

            // bulk save ..
            if (flags.HasFlag(SerializerFlags.DoNotSave) && updates.Any())
            {
                callback?.Invoke($"Saving {updates.Count()} changes", 1, 1);
                serializer.Save(updates.Select(x => x.Value));
            }

            var folders = syncFileService.GetDirectories(folder);

            foreach (var children in folders)
            {
                actions.AddRange(ImportFolder(children, config, updates, force, callback));
            }

            callback?.Invoke("", 1, 1);

            return(actions);
        }
示例#2
0
        private IEnumerable <SyncHistoryView> GetHistory(string folder)
        {
            var histories = new List <SyncHistoryView>();

            foreach (var historyFile in syncFileService.GetFiles(folder, "*.history"))
            {
                var content = syncFileService.LoadContent(historyFile);
                if (!string.IsNullOrWhiteSpace(content))
                {
                    var history = JsonConvert.DeserializeObject <SyncHistoryView>(content);
                    if (history != null)
                    {
                        histories.Add(history);
                    }
                }
            }

            foreach (var subFolder in syncFileService.GetDirectories(folder))
            {
                histories.AddRange(GetHistory(subFolder));
            }

            return(histories.OrderByDescending(x => x.When));
        }
示例#3
0
        /// <summary>
        ///  Get the GUIDs for all items in a folder
        /// </summary>
        /// <remarks>
        ///  This is disk intensive, (checking the .config files all the time)
        ///  so we cache it, and if we are using the flat folder stucture, then
        ///  we only do it once, so its quicker.
        /// </remarks>
        private IList <Guid> GetFolderKeys(string folder, bool flat)
        {
            // We only need to load all the keys once per handler (if all items are in a folder that key will be used).
            var folderKey = folder.GetHashCode();

            var cacheKey = $"keycache_{this.Alias}_{folderKey}";

            return(runtimeCache.GetCacheItem(cacheKey, () =>
            {
                var keys = new List <Guid>();
                var files = syncFileService.GetFiles(folder, "*.config");
                foreach (var file in files)
                {
                    var node = XElement.Load(file);
                    var key = node.GetKey();
                    if (!keys.Contains(key))
                    {
                        keys.Add(key);
                    }
                }

                return keys;
            }, null));
        }
示例#4
0
        /// <summary>
        ///  Get the GUIDs for all items in a folder
        /// </summary>
        /// <remarks>
        ///  This is disk intensive, (checking the .config files all the time)
        ///  so we cache it, and if we are using the flat folder stucture, then
        ///  we only do it once, so its quicker.
        /// </remarks>
        private IList <Guid> GetFolderKeys(string folder, bool flat)
        {
            // if it's flat, then we only need to load all the keys once per handler
            var folderKey = flat == true ? 1 : folder.GetHashCode();

            var cacheKey = $"uSyncKeyList_{folderKey}_{this.Alias}";

            return(runtimeCache.GetCacheItem(cacheKey, () =>
            {
                var keys = new List <Guid>();
                var files = syncFileService.GetFiles(folder, "*.config");
                foreach (var file in files)
                {
                    var node = XElement.Load(file);
                    var key = node.GetKey();
                    if (!keys.Contains(key))
                    {
                        keys.Add(key);
                    }
                }

                return keys;
            }, null));
        }