示例#1
0
        public IEnumerable <uSyncAction> ImportPartial(string folder, uSyncPagedImportOptions options, out int total)
        {
            lock (_importLock)
            {
                using (var pause = new uSyncImportPause())
                {
                    var orderedNodes = LoadOrderedNodes(folder);

                    total = orderedNodes.Count;

                    var actions  = new List <uSyncAction>();
                    var lastType = string.Empty;

                    var range = options.ProgressMax - options.ProgressMin;

                    SyncHandlerOptions        syncHandlerOptions = new SyncHandlerOptions(options.HandlerSet);
                    ExtendedHandlerConfigPair handlerPair        = null;

                    var index = options.PageNumber * options.PageSize;

                    foreach (var item in orderedNodes.Skip(options.PageNumber * options.PageSize).Take(options.PageSize))
                    {
                        var itemType = item.Node.GetItemType();
                        if (!itemType.InvariantEquals(lastType))
                        {
                            lastType    = itemType;
                            handlerPair = handlerFactory.GetValidHandlerByTypeName(itemType, syncHandlerOptions);
                        }

                        options.Callbacks?.Update?.Invoke(item.Node.GetAlias(),
                                                          CalculateProgress(index, total, options.ProgressMin, options.ProgressMax), 100);

                        if (handlerPair != null)
                        {
                            if (handlerPair.Handler is ISyncItemHandler itemHandler)
                            {
                                actions.AddRange(itemHandler.ImportElement(item.Node, item.FileName, handlerPair.Settings, options));
                            }
                            else
                            {
                                actions.AddRange(handlerPair.Handler.ImportElement(item.Node, options.Flags.HasFlag(SerializerFlags.Force)));
                            }
                        }

                        index++;
                    }

                    return(actions);
                }
            }
        }
示例#2
0
        public IEnumerable <uSyncAction> ImportPartialSecondPass(IEnumerable <uSyncAction> actions, uSyncPagedImportOptions options)
        {
            lock (_importLock)
            {
                using (var pause = new uSyncImportPause())
                {
                    SyncHandlerOptions syncHandlerOptions = new SyncHandlerOptions(options.HandlerSet);
                    var secondPassActions = new List <uSyncAction>();

                    var total = actions.Count();

                    var lastType = string.Empty;
                    ExtendedHandlerConfigPair handlerPair = null;

                    var index = options.PageNumber * options.PageSize;

                    foreach (var action in actions.Skip(options.PageNumber * options.PageSize).Take(options.PageSize))
                    {
                        if (!action.HandlerAlias.InvariantEquals(lastType))
                        {
                            lastType    = action.HandlerAlias;
                            handlerPair = handlerFactory.GetValidHandler(action.HandlerAlias, syncHandlerOptions);
                        }

                        options.Callbacks?.Update?.Invoke($"Second Pass: {action.Name}",
                                                          CalculateProgress(index, total, options.ProgressMin, options.ProgressMax), 100);


                        if (handlerPair != null && handlerPair.Handler is ISyncItemHandler itemHandler)
                        {
                            secondPassActions.AddRange(itemHandler.ImportSecondPass(action, handlerPair.Settings, options));
                        }

                        index++;
                    }

                    return(secondPassActions);
                }
            }
        }