Ejemplo n.º 1
0
        public static unsafe void FillStencilByColor <TBitVector2D>(IRenderer <ColorBgra> sampleSource, TBitVector2D stencilBuffer, ColorBgra basis, byte tolerance, ICancellationToken cancelToken, RectInt32 clipRect) where TBitVector2D : IBitVector2D
        {
            cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
            int left   = clipRect.Left;
            int top    = clipRect.Top;
            int right  = clipRect.Right;
            int bottom = clipRect.Bottom;

            using (ISurface <ColorBgra> surface = sampleSource.UseTileOrToSurface(clipRect))
            {
                for (int i = top; i < bottom; i++)
                {
                    cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                    int        row        = i - clipRect.Top;
                    ColorBgra *rowPointer = (ColorBgra *)surface.GetRowPointer <ColorBgra>(row);
                    for (int j = left; j < right; j++)
                    {
                        bool      flag;
                        ColorBgra b = rowPointer[0];
                        if (b == basis)
                        {
                            flag = true;
                        }
                        else
                        {
                            flag = GetDistance(basis, b) <= tolerance;
                        }
                        stencilBuffer.SetUnchecked(j, i, flag);
                        rowPointer++;
                    }
                }
            }
        }
        public async Task ExportAsync(Stream outStream, ExportImportOptions options, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var progressInfo = new ExportImportProgressInfo {
                Description = "loading data..."
            };

            progressCallback(progressInfo);

            var batchSize = await GetBatchSize();

            using (var sw = new StreamWriter(outStream, Encoding.UTF8))
                using (var writer = new JsonTextWriter(sw))
                {
                    writer.WriteStartObject();

                    progressInfo.Description = "Members exporting...";
                    progressCallback(progressInfo);

                    var members = await _memberSearchService.SearchMembersAsync(new MembersSearchCriteria { Take = 0, DeepSearch = true });

                    var memberCount = members.TotalCount;
                    writer.WritePropertyName("MembersTotalCount");
                    writer.WriteValue(memberCount);

                    cancellationToken.ThrowIfCancellationRequested();

                    writer.WritePropertyName("Members");
                    writer.WriteStartArray();

                    for (var i = 0; i < memberCount; i += batchSize)
                    {
                        var searchResponse = await _memberSearchService.SearchMembersAsync(new MembersSearchCriteria { Skip = i, Take = batchSize, DeepSearch = true });

                        foreach (var member in searchResponse.Results)
                        {
                            _serializer.Serialize(writer, member);
                        }
                        writer.Flush();
                        progressInfo.Description = $"{ Math.Min(memberCount, i + batchSize) } of { memberCount } members exported";
                        progressCallback(progressInfo);
                    }
                    writer.WriteEndArray();

                    writer.WriteEndObject();
                    writer.Flush();
                }
        }
Ejemplo n.º 3
0
        public static async Task SerializeJsonArrayWithPagingAsync <T>(this JsonTextWriter writer, JsonSerializer serializer, int pageSize, Func <int, int, Task <GenericSearchResult <T> > > pagedDataLoader, Action <int, int> progressCallback, ICancellationToken cancellationToken)
        {
            //Evaluate total items counts
            var result = await pagedDataLoader(0, 1);

            var totalCount = result.TotalCount;

            await writer.WriteStartArrayAsync();

            // Prevent infinity loop
            if (pageSize <= 0)
            {
                pageSize = DefaultPageSize;
            }

            for (var i = 0; i < totalCount; i += pageSize)
            {
                var nextPage = await pagedDataLoader(i, pageSize);

                foreach (var data in nextPage.Results)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    serializer.Serialize(writer, data);
                }
                writer.Flush();
                progressCallback(Math.Min(totalCount, i + pageSize), totalCount);
            }
            await writer.WriteEndArrayAsync();
        }
Ejemplo n.º 4
0
        protected virtual async Task <IList <ImageChange> > GetChangeFiles(ThumbnailTask task, DateTime?changedSince,
                                                                           ICancellationToken token)
        {
            var options = await GetOptionsCollection();

            var allBlobInfos = await ReadBlobFolderAsync(task.WorkPath, token);

            var orignalBlobInfos = GetOriginalItems(allBlobInfos, options.Select(x => x.FileSuffix).ToList());

            var result = new List <ImageChange>();

            foreach (var blobInfo in orignalBlobInfos)
            {
                token?.ThrowIfCancellationRequested();

                var imageChange = new ImageChange
                {
                    Name         = blobInfo.Name,
                    Url          = blobInfo.Url,
                    ModifiedDate = blobInfo.ModifiedDate,
                    ChangeState  = !changedSince.HasValue ? EntryState.Added : GetItemState(blobInfo, changedSince, task.ThumbnailOptions)
                };
                result.Add(imageChange);
            }
            return(result.Where(x => x.ChangeState != EntryState.Unchanged).ToList());
        }
Ejemplo n.º 5
0
        protected virtual async Task <IndexingResult> ProcessChangesAsync(IEnumerable <IndexDocumentChange> changes, BatchIndexingOptions batchOptions, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var result = new IndexingResult();

            var groups = GetLatestChangesForEachDocumentGroupedByChangeType(changes);

            foreach (var group in groups)
            {
                var changeType  = group.Key;
                var documentIds = group.Value;

                var groupResult = await ProcessDocumentsAsync(changeType, documentIds, batchOptions, cancellationToken);

                if (groupResult?.Items != null)
                {
                    if (result.Items == null)
                    {
                        result.Items = new List <IndexingResultItem>();
                    }

                    result.Items.AddRange(groupResult.Items);
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
        public async Task DoExportAsync(Stream outStream, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var progressInfo = new ExportImportProgressInfo {
                Description = "Loading data..."
            };

            progressCallback(progressInfo);

            using (var sw = new StreamWriter(outStream, Encoding.UTF8))
                using (var writer = new JsonTextWriter(sw))
                {
                    await writer.WriteStartObjectAsync();

                    await writer.WritePropertyNameAsync("DynamicAssociations");

                    await writer.SerializeJsonArrayWithPagingAsync(_serializer, _batchSize, async (skip, take) =>
                                                                   (GenericSearchResult <Association>) await _associationSearchService.SearchAssociationsAsync(new AssociationSearchCriteria {
                        Skip = skip, Take = take
                    })
                                                                   , (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } dynamic associations have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    await writer.WriteEndObjectAsync();

                    await writer.FlushAsync();
                }
        }
Ejemplo n.º 7
0
        public async Task ExportAsync(Stream outStream, ExportImportOptions options, Action <ExportImportProgressInfo> progressCallback,
                                      ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo {
                Description = "Orders are loading"
            };

            progressCallback(progressInfo);

            using (var sw = new StreamWriter(outStream, Encoding.UTF8))
                using (var writer = new JsonTextWriter(sw))
                {
                    writer.WriteStartObject();

                    var orders = await _customerOrderSearchService.SearchCustomerOrdersAsync(new CustomerOrderSearchCriteria { Take = int.MaxValue });

                    writer.WritePropertyName("OrderTotalCount");
                    writer.WriteValue(orders.TotalCount);

                    writer.WritePropertyName("CustomerOrders");
                    writer.WriteStartArray();

                    foreach (var order in orders.Results)
                    {
                        _serializer.Serialize(writer, order);
                    }

                    writer.WriteEndArray();

                    writer.WriteEndObject();
                    writer.Flush();
                }
        }
Ejemplo n.º 8
0
        protected virtual async Task <IList <IndexDocument> > GetDocumentsAsync(IList <string> documentIds, IIndexDocumentBuilder primaryDocumentBuilder, IEnumerable <IIndexDocumentBuilder> secondaryDocumentBuilders, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var primaryDocuments = (await primaryDocumentBuilder.GetDocumentsAsync(documentIds))
                                   ?.Where(d => d != null)
                                   .ToList();

            if (primaryDocuments?.Any() == true)
            {
                if (secondaryDocumentBuilders != null)
                {
                    var primaryDocumentIds = primaryDocuments.Select(d => d.Id).ToArray();
                    var secondaryDocuments = await GetSecondaryDocumentsAsync(secondaryDocumentBuilders, primaryDocumentIds, cancellationToken);

                    MergeDocuments(primaryDocuments, secondaryDocuments);
                }

                // Add system fields
                foreach (var document in primaryDocuments)
                {
                    document.Add(new IndexDocumentField(KnownDocumentFields.IndexationDate, DateTime.UtcNow)
                    {
                        IsRetrievable = true,
                        IsFilterable  = true
                    });
                }
            }

            return(primaryDocuments);
        }
Ejemplo n.º 9
0
        protected virtual async Task <IndexingResult> ProcessDocumentsAsync(IndexDocumentChangeType changeType,
                                                                            string[] changedIds, BatchIndexingOptions batchOptions, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            IndexingResult result = null;

            if (changeType == IndexDocumentChangeType.Deleted)
            {
                result = await DeleteDocumentsAsync(batchOptions.DocumentType, changedIds);
            }
            else if (changeType is IndexDocumentChangeType.Modified or IndexDocumentChangeType.Created)
            {
                var documents = await GetDocumentsAsync(changedIds, batchOptions.PrimaryDocumentBuilder, batchOptions.SecondaryDocumentBuilders, cancellationToken);

                if (batchOptions.Reindex && _searchProvider is ISupportIndexSwap supportIndexSwapProvider)
                {
                    result = await supportIndexSwapProvider.IndexWithBackupAsync(batchOptions.DocumentType, documents);
                }
                else
                {
                    result = await _searchProvider.IndexAsync(batchOptions.DocumentType, documents);
                }
            }

            return(result);
        }
Ejemplo n.º 10
0
        public async Task DoImportAsync(Stream inputStream, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo();

            using (var streamReader = new StreamReader(inputStream))
                using (var reader = new JsonTextReader(streamReader))
                {
                    while (reader.Read())
                    {
                        if (reader.TokenType == JsonToken.PropertyName)
                        {
                            if (reader.Value.ToString() == "TaxProviders")
                            {
                                await reader.DeserializeJsonArrayWithPagingAsync <TaxProvider>(_jsonSerializer, _batchSize, items => _taxProviderService.SaveChangesAsync(items.ToArray()), processedCount =>
                                {
                                    progressInfo.Description = $"{ processedCount } tax providers have been imported";
                                    progressCallback(progressInfo);
                                }, cancellationToken);
                            }
                        }
                    }
                }
        }
        private async Task ExportOptions(JsonTextWriter writer, JsonSerializer serializer, ExportImportProgressInfo progressInfo, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            progressInfo.Description = "Exporting options...";
            progressCallback(progressInfo);

            var thumbnailOption = await _optionSearchService.SearchAsync(new ThumbnailOptionSearchCriteria { Take = 0, Skip = 0 });

            var totalCount = thumbnailOption.TotalCount;

            writer.WritePropertyName("OptionsTotalCount");
            writer.WriteValue(totalCount);

            writer.WritePropertyName("Options");
            writer.WriteStartArray();

            for (int i = 0; i < totalCount; i += _batchSize)
            {
                var options = await _optionSearchService.SearchAsync(new ThumbnailOptionSearchCriteria { Take = _batchSize, Skip = i });

                foreach (var option in options.Results)
                {
                    serializer.Serialize(writer, option);
                }

                writer.Flush();
                progressInfo.Description = $"{Math.Min(totalCount, i + _batchSize)} of {totalCount} options exported";
                progressCallback(progressInfo);
            }

            writer.WriteEndArray();
        }
        public async Task ExportAsync(Stream outStream, ExportImportOptions exportOptions, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            var moduleExportOptions = exportOptions as ThumbnailExportImportOptions;

            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo {
                Description = "loading data..."
            };

            progressCallback(progressInfo);

            using (var sw = new StreamWriter(outStream, Encoding.UTF8))
            {
                using (var writer = new JsonTextWriter(sw))
                {
                    writer.WriteStartObject();

                    await ExportOptions(writer, _serializer, progressInfo, progressCallback, cancellationToken);
                    await ExportTasksAsync(writer, _serializer, progressInfo, progressCallback, cancellationToken);

                    writer.WriteEndObject();
                    writer.Flush();
                }
            }
        }
Ejemplo n.º 13
0
        protected virtual async Task <IList <ImageChange> > GetChangeFiles(ThumbnailTask task, DateTime?changedSince, ICancellationToken token)
        {
            var options = await GetOptionsCollection();

            var cacheKey = CacheKey.With(GetType(), "GetChangeFiles", task.WorkPath, changedSince?.ToString(), string.Join(":", options.Select(x => x.FileSuffix)));

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(BlobChangesCacheRegion.CreateChangeToken(task, changedSince));

                var allBlobInfos = await ReadBlobFolderAsync(task.WorkPath, token);
                var orignalBlobInfos = GetOriginalItems(allBlobInfos, options.Select(x => x.FileSuffix).ToList());

                var result = new List <ImageChange>();
                foreach (var blobInfo in orignalBlobInfos)
                {
                    token?.ThrowIfCancellationRequested();

                    var imageChange = new ImageChange
                    {
                        Name = blobInfo.Name,
                        Url = blobInfo.Url,
                        ModifiedDate = blobInfo.ModifiedDate,
                        ChangeState = !changedSince.HasValue ? EntryState.Added : GetItemState(blobInfo, changedSince, task.ThumbnailOptions)
                    };
                    result.Add(imageChange);
                }
                return result.Where(x => x.ChangeState != EntryState.Unchanged).ToList();
            }));
        }
Ejemplo n.º 14
0
        public async Task DoImportAsync(Stream inputStream, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo();

            progressInfo.Description = "Importing dynamic associations…";
            progressCallback(progressInfo);

            using (var streamReader = new StreamReader(inputStream))
                using (var reader = new JsonTextReader(streamReader))
                {
                    while (reader.Read())
                    {
                        if (reader.TokenType != JsonToken.PropertyName)
                        {
                            continue;
                        }
                        if (reader.Value.ToString() == "DynamicAssociations")
                        {
                            await reader.DeserializeJsonArrayWithPagingAsync <Association>(_serializer, _batchSize, async items =>
                            {
                                await _associationService.SaveChangesAsync(items.ToArray());
                            }, processedCount =>
                            {
                                progressInfo.Description = $"{processedCount} Tagged items have been imported";
                                progressCallback(progressInfo);
                            }, cancellationToken);
                        }
                    }
                }
        }
Ejemplo n.º 15
0
        public static async Task DeserializeJsonArrayWithPagingAsync <T>(this JsonTextReader reader, JsonSerializer serializer, int pageSize, Func <IEnumerable <T>, Task> action, Action <int> progressCallback, ICancellationToken cancellationToken)
        {
            reader.Read();
            if (reader.TokenType == JsonToken.StartArray)
            {
                reader.Read();

                var items          = new List <T>();
                var processedCount = 0;
                while (reader.TokenType != JsonToken.EndArray)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var item = serializer.Deserialize <T>(reader);
                    items.Add(item);
                    processedCount++;
                    reader.Read();
                    if (processedCount % pageSize == 0 || reader.TokenType == JsonToken.EndArray)
                    {
                        await action(items);

                        items.Clear();
                        progressCallback(processedCount);
                    }
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Generates thumbnails asynchronously
        /// </summary>
        /// <param name="sourcePath">Path to source picture</param>
        /// <param name="destPath">Target for generated thumbnail</param>
        /// <param name="options">Represents generation options</param>
        /// <param name="token">Allows cancel operation</param>
        /// <returns></returns>
        public virtual async Task <ThumbnailGenerationResult> GenerateThumbnailsAsync(string sourcePath, string destPath, IList <ThumbnailOption> options, ICancellationToken token)
        {
            token?.ThrowIfCancellationRequested();

            var originalImage = await _imageService.LoadImageAsync(sourcePath, out var format);

            if (originalImage == null)
            {
                return(new ThumbnailGenerationResult
                {
                    Errors = { $"Cannot generate thumbnail: {sourcePath} does not have a valid image format" }
                });
            }

            var result = new ThumbnailGenerationResult();

            foreach (var option in options)
            {
                var thumbnail    = GenerateThumbnail(originalImage, option);
                var thumbnailUrl = sourcePath.GenerateThumbnailName(option.FileSuffix);

                if (thumbnail != null)
                {
                    await _imageService.SaveImageAsync(thumbnailUrl, thumbnail, format, option.JpegQuality);
                }
                else
                {
                    throw new Exception($"Cannot save thumbnail image {thumbnailUrl}");
                }

                result.GeneratedThumbnails.Add(thumbnailUrl);
            }

            return(result);
        }
        public async Task ExportAsync(Stream outStream, ExportImportOptions options, Action <ExportImportProgressInfo> progressCallback,
                                      ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var progressInfo = new ExportImportProgressInfo {
                Description = "loading data..."
            };

            progressCallback(progressInfo);

            using (var sw = new StreamWriter(outStream, System.Text.Encoding.UTF8))
                using (var writer = new JsonTextWriter(sw))
                {
                    writer.WriteStartObject();

                    progressInfo.Description = "Currencies exporting...";
                    progressCallback(progressInfo);

                    var currencyResult = await _currencyService.GetAllCurrenciesAsync();

                    writer.WritePropertyName("CurrencyTotalCount");
                    writer.WriteValue(currencyResult.Count());

                    writer.WritePropertyName("Currencies");
                    writer.WriteStartArray();

                    foreach (var currency in currencyResult)
                    {
                        _serializer.Serialize(writer, currency);
                    }

                    writer.Flush();
                    progressInfo.Description = $"{currencyResult.Count()} currencies exported";
                    progressCallback(progressInfo);

                    writer.WriteEndArray();

                    var packageTypesResult = await _packageTypesService.GetAllPackageTypesAsync();

                    writer.WritePropertyName("PackageTypeTotalCount");
                    writer.WriteValue(packageTypesResult.Count());

                    writer.WritePropertyName("PackageTypes");
                    writer.WriteStartArray();

                    foreach (var packageType in packageTypesResult)
                    {
                        _serializer.Serialize(writer, packageType);
                    }

                    writer.Flush();
                    progressInfo.Description = $"{packageTypesResult.Count()} package types exported";
                    progressCallback(progressInfo);
                    writer.WriteEndArray();

                    writer.WriteEndObject();
                    writer.Flush();
                }
        }
Ejemplo n.º 18
0
        public async Task DoExportAsync(Stream outStream, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo {
                Description = "loading data..."
            };

            progressCallback(progressInfo);

            using (var sw = new StreamWriter(outStream, Encoding.UTF8))
            {
                using (var writer = new JsonTextWriter(sw))
                {
                    await writer.WriteStartObjectAsync();

                    progressInfo.Description = "Options are started to export";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Options");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchCriteria  = AbstractTypeFactory <ThumbnailOptionSearchCriteria> .TryCreateInstance();
                        searchCriteria.Take = take;
                        searchCriteria.Skip = skip;
                        var searchResult    = await _optionSearchService.SearchAsync(searchCriteria);
                        return((GenericSearchResult <ThumbnailOption>)searchResult);
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{processedCount} of {totalCount} Options have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    progressInfo.Description = "Tasks are started to export";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Tasks");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchCriteria  = AbstractTypeFactory <ThumbnailTaskSearchCriteria> .TryCreateInstance();
                        searchCriteria.Take = take;
                        searchCriteria.Skip = skip;
                        var searchResult    = await _taskSearchService.SearchAsync(searchCriteria);
                        return((GenericSearchResult <ThumbnailTask>)searchResult);
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{processedCount} of {totalCount} Tasks have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    await writer.WriteEndObjectAsync();

                    await writer.FlushAsync();
                }
            }
        }
Ejemplo n.º 19
0
        public async Task ImportAsync(Stream inputStream, ExportImportOptions options, Action <ExportImportProgressInfo> progressCallback,
                                      ICancellationToken cancellationToken)
        {
            //TDODO: Use AbstractTypeFactory for deserialization of the derived types
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo    = new ExportImportProgressInfo();
            var orderTotalCount = 0;

            using (var streamReader = new StreamReader(inputStream))
                using (var reader = new JsonTextReader(streamReader))
                {
                    while (reader.Read())
                    {
                        if (reader.TokenType == JsonToken.PropertyName)
                        {
                            if (reader.Value.ToString() == "OrderTotalCount")
                            {
                                orderTotalCount = reader.ReadAsInt32() ?? 0;
                            }
                            else if (reader.Value.ToString() == "CustomerOrders")
                            {
                                reader.Read();
                                if (reader.TokenType == JsonToken.StartArray)
                                {
                                    reader.Read();

                                    var orders     = new List <CustomerOrder>();
                                    var orderCount = 0;
                                    while (reader.TokenType != JsonToken.EndArray)
                                    {
                                        var order = _serializer.Deserialize <CustomerOrder>(reader);
                                        orders.Add(order);
                                        orderCount++;

                                        reader.Read();
                                    }

                                    for (var i = 0; i < orderCount; i += _batchSize)
                                    {
                                        await _customerOrderService.SaveChangesAsync(orders.Skip(i).Take(_batchSize).ToArray());

                                        if (orderCount > 0)
                                        {
                                            progressInfo.Description = $"{ i } of { orderCount } orders have been imported";
                                        }
                                        else
                                        {
                                            progressInfo.Description = $"{ i } orders have been imported";
                                        }
                                        progressCallback(progressInfo);
                                    }
                                }
                            }
                        }
                    }
                }
        }
        public async Task ProcessTasksAsync(ICollection <ThumbnailTask> tasks, bool regenerate, Action <ThumbnailTaskProgress> progressCallback, ICancellationToken token)
        {
            var progressInfo = new ThumbnailTaskProgress {
                Message = "Reading the tasks..."
            };

            if (_imageChangesProvider.IsTotalCountSupported)
            {
                foreach (var task in tasks)
                {
                    var changedSince = regenerate ? null : task.LastRun;
                    progressInfo.TotalCount = await _imageChangesProvider.GetTotalChangesCount(task, changedSince, token);
                }
            }

            progressCallback(progressInfo);

            var pageSize = _settingsManager.GetValue(ModuleConstants.Settings.General.ProcessBatchSize.Name, 50);

            foreach (var task in tasks)
            {
                progressInfo.Message = $"Procesing task {task.Name}...";
                progressCallback(progressInfo);

                var skip = 0;
                while (true)
                {
                    var changes = await _imageChangesProvider.GetNextChangesBatch(task, regenerate?null : task.LastRun, skip, pageSize, token);

                    if (!changes.Any())
                    {
                        break;
                    }

                    foreach (var fileChange in changes)
                    {
                        var result = await _generator.GenerateThumbnailsAsync(fileChange.Url, task.WorkPath, task.ThumbnailOptions, token);

                        progressInfo.ProcessedCount++;

                        if (!result.Errors.IsNullOrEmpty())
                        {
                            progressInfo.Errors.AddRange(result.Errors);
                        }
                    }

                    skip += changes.Length;

                    progressCallback(progressInfo);
                    token?.ThrowIfCancellationRequested();
                }
            }

            progressInfo.Message = "Finished generating thumbnails!";
            progressCallback(progressInfo);
        }
Ejemplo n.º 21
0
        protected virtual async Task <IndexingResult> IndexDocumentsAsync(string documentType, IList <string> documentIds, IIndexDocumentBuilder primaryDocumentBuilder, IEnumerable <IIndexDocumentBuilder> secondaryDocumentBuilders, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var documents = await GetDocumentsAsync(documentIds, primaryDocumentBuilder, secondaryDocumentBuilders, cancellationToken);

            var response = await _searchProvider.IndexAsync(documentType, documents);

            return(response);
        }
Ejemplo n.º 22
0
 void Process()
 {
     while (stack.Count != 0)
     {
         if (cancellationToken != null)
             cancellationToken.ThrowIfCancellationRequested();
         var o = stack.Pop();
         LoadObj(o);
     }
 }
Ejemplo n.º 23
0
        protected virtual async Task <IList <IndexDocument> > GetSecondaryDocumentsAsync(IEnumerable <IIndexDocumentBuilder> secondaryDocumentBuilders, IList <string> documentIds, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var tasks   = secondaryDocumentBuilders.Select(p => p.GetDocumentsAsync(documentIds));
            var results = await Task.WhenAll(tasks);

            var result = results.Where(r => r != null).SelectMany(r => r.Where(d => d != null)).ToList();

            return(result);
        }
Ejemplo n.º 24
0
        public async Task DoImportAsync(Stream inputStream, ExportImportOptions options, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo();

            using (var streamReader = new StreamReader(inputStream))
                using (var reader = new JsonTextReader(streamReader))
                {
                    while (reader.Read())
                    {
                        if (reader.TokenType == JsonToken.PropertyName)
                        {
                            if (reader.Value.ToString() == "MenuLinkLists")
                            {
                                await reader.DeserializeJsonArrayWithPagingAsync <MenuLinkList>(_jsonSerializer, _batchSize,
                                                                                                async items =>
                                {
                                    foreach (var item in items)
                                    {
                                        await _menuService.AddOrUpdateAsync(item);
                                    }
                                }, processedCount =>
                                {
                                    progressInfo.Description = $"{ processedCount } menu links have been imported";
                                    progressCallback(progressInfo);
                                }, cancellationToken);
                            }
                            else if (reader.Value.ToString() == "CmsContent")
                            {
                                if (options != null && options.HandleBinaryData)
                                {
                                    progressInfo.Description = "importing binary data:  themes and pages importing...";
                                    progressCallback(progressInfo);

                                    await reader.DeserializeJsonArrayWithPagingAsync <ContentFolder>(_jsonSerializer, _batchSize,
                                                                                                     items =>
                                    {
                                        foreach (var item in items)
                                        {
                                            SaveContentFolderRecursive(item, progressCallback);
                                        }
                                        return(Task.CompletedTask);
                                    }, processedCount =>
                                    {
                                        progressInfo.Description = $"{ processedCount } menu links have been imported";
                                        progressCallback(progressInfo);
                                    }, cancellationToken);
                                }
                            }
                        }
                    }
                }
        }
Ejemplo n.º 25
0
        public async Task ImportAsync(Stream inputStream, ExportImportOptions options, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo    = new ExportImportProgressInfo();
            int storeTotalCount = 0;

            using (var streamReader = new StreamReader(inputStream))
                using (var reader = new JsonTextReader(streamReader))
                {
                    while (reader.Read())
                    {
                        if (reader.TokenType == JsonToken.PropertyName)
                        {
                            if (reader.Value.ToString() == "StoresTotalCount")
                            {
                                storeTotalCount = reader.ReadAsInt32() ?? 0;
                            }
                            else if (reader.Value.ToString() == "Store")
                            {
                                var stores     = new List <Store>();
                                var storeCount = 0;
                                while (reader.TokenType != JsonToken.EndArray)
                                {
                                    var store = _serializer.Deserialize <Store>(reader);
                                    stores.Add(store);
                                    storeCount++;

                                    reader.Read();
                                }

                                for (int i = 0; i < storeCount; i += BatchSize)
                                {
                                    var batchStores = stores.Skip(i).Take(BatchSize);
                                    foreach (var store in batchStores)
                                    {
                                        await _storeService.SaveChangesAsync(new[] { store });
                                    }

                                    if (storeCount > 0)
                                    {
                                        progressInfo.Description = $"{i} of {storeCount} stores imported";
                                    }
                                    else
                                    {
                                        progressInfo.Description = $"{i} stores imported";
                                    }
                                    progressCallback(progressInfo);
                                }
                            }
                        }
                    }
                }
        }
        public async Task DoExportAsync(Stream outStream, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo {
                Description = "The fulfilmentCenters are loading"
            };

            progressCallback(progressInfo);

            using (var sw = new StreamWriter(outStream, Encoding.UTF8))
                using (var writer = new JsonTextWriter(sw))
                {
                    await writer.WriteStartObjectAsync();

                    await writer.WritePropertyNameAsync("FulfillmentCenters");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, BatchSize, async (skip, take) =>
                    {
                        var searchCriteria  = AbstractTypeFactory <FulfillmentCenterSearchCriteria> .TryCreateInstance();
                        searchCriteria.Take = take;
                        searchCriteria.Skip = skip;
                        var searchResult    = await _fulfillmentCenterSearchService.SearchCentersAsync(searchCriteria);
                        return((GenericSearchResult <FulfillmentCenter>)searchResult);
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{processedCount} of {totalCount} FulfillmentCenters have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    progressInfo.Description = "The Inventories are loading";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Inventories");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, BatchSize, async (skip, take) =>
                    {
                        var searchCriteria  = AbstractTypeFactory <InventorySearchCriteria> .TryCreateInstance();
                        searchCriteria.Take = take;
                        searchCriteria.Skip = skip;
                        var searchResult    = await _inventorySearchService.SearchInventoriesAsync(searchCriteria);
                        return((GenericSearchResult <InventoryInfo>)searchResult);
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{processedCount} of {totalCount} inventories have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    await writer.WriteEndObjectAsync();

                    await writer.FlushAsync();
                }
        }
Ejemplo n.º 27
0
        private void UpdateTileWhileLocked(TileData tileData, ICancellationToken cancelToken)
        {
            RectInt32  tileSourceRect = this.tileMathHelper.GetTileSourceRect(tileData.Offset);
            RectDouble num2           = tileSourceRect;

            cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
            object newCurrencyToken = this.renderData.CreateCurrencyToken();

            cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
            IList <int?> list  = this.renderData.GetStrokeSampleIndicesInRect(tileSourceRect, tileData.CurrencyToken, newCurrencyToken);
            int          count = list.Count;

            if (count > 0)
            {
                SizeDouble      size = this.stamp.Size;
                RectDouble      num5 = new RectDouble(PointDouble.Zero, size);
                IDrawingContext dc   = null;
                try
                {
                    for (int i = 0; i < count; i++)
                    {
                        int?nullable = list[i];
                        if (nullable.HasValue)
                        {
                            if (tileData.Mask == null)
                            {
                                cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                                tileData.Mask = new SurfaceAlpha8(tileSourceRect.Size);
                            }
                            if (tileData.MaskRenderTarget == null)
                            {
                                cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                                tileData.MaskRenderTarget = RenderTarget.FromSurface(tileData.Mask, FactorySource.PerThread);
                            }
                            if (dc == null)
                            {
                                cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                                dc = DrawingContext.FromRenderTarget(tileData.MaskRenderTarget);
                                dc.UseTranslateTransform((float)-tileSourceRect.X, (float)-tileSourceRect.Y, MatrixMultiplyOrder.Prepend);
                                dc.AntialiasMode = AntialiasMode.Aliased;
                            }
                            int        valueOrDefault = nullable.GetValueOrDefault();
                            RectDouble bounds         = this.renderData.StrokeSamples[valueOrDefault].GetBounds(size);
                            RectDouble num9           = this.stamp.Antialiased ? bounds : RectDouble.Round(bounds, MidpointRounding.AwayFromZero);
                            cancelToken.ThrowIfCancellationRequested <ICancellationToken>();
                            RectDouble?srcRect = null;
                            dc.FillOpacityMask(this.lazyStampMaskDevBitmap.CancelableValue <DeviceBitmap>(), whiteBrush, OpacityMaskContent.Graphics, new RectDouble?(num9), srcRect);
                        }
                    }
                }
                finally
                {
                    DisposableUtil.Free <IDrawingContext>(ref dc);
                }
            }
            tileData.CurrencyToken = newCurrencyToken;
        }
Ejemplo n.º 28
0
        public async Task ExportAsync(Stream outStream, ExportImportOptions options, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo {
                Description = "The store are loading"
            };

            progressCallback(progressInfo);

            using (var sw = new StreamWriter(outStream, Encoding.UTF8))
                using (var writer = new JsonTextWriter(sw))
                {
                    writer.WriteStartObject();

                    progressInfo.Description = "Evaluation the number of store records";
                    progressCallback(progressInfo);

                    var searchResult = await _storeSearchService.SearchStoresAsync(new StoreSearchCriteria { Take = BatchSize });

                    var totalCount = searchResult.TotalCount;
                    writer.WritePropertyName("StoreTotalCount");
                    writer.WriteValue(totalCount);

                    writer.WritePropertyName("Stores");
                    writer.WriteStartArray();

                    for (int i = BatchSize; i < totalCount; i += BatchSize)
                    {
                        progressInfo.Description = $"{i} of {totalCount} stores have been loaded";
                        progressCallback(progressInfo);

                        searchResult = await _storeSearchService.SearchStoresAsync(new StoreSearchCriteria { Skip = i, Take = BatchSize });

                        foreach (var store in searchResult.Results)
                        {
                            _serializer.Serialize(writer, store);
                        }
                        writer.Flush();
                        progressInfo.Description = $"{ Math.Min(totalCount, i + BatchSize) } of { totalCount } stores exported";
                        progressCallback(progressInfo);
                    }

                    writer.WriteEndArray();

                    writer.WriteEndObject();
                    writer.Flush();
                }
        }
Ejemplo n.º 29
0
        protected virtual async Task <IndexingResult> ProcessDocumentsAsync(IndexDocumentChangeType changeType, IList <string> documentIds, BatchIndexingOptions batchOptions, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            IndexingResult result = null;

            if (changeType == IndexDocumentChangeType.Deleted)
            {
                result = await DeleteDocumentsAsync(batchOptions.DocumentType, documentIds.ToArray());
            }
            else if (changeType == IndexDocumentChangeType.Modified)
            {
                result = await IndexDocumentsAsync(batchOptions.DocumentType, documentIds, batchOptions.PrimaryDocumentBuilder, batchOptions.SecondaryDocumentBuilders, cancellationToken);
            }

            return(result);
        }
Ejemplo n.º 30
0
        public async Task DoImportAsync(Stream backupStream, Action <ExportImportProgressInfo> progressCallback,
                                        ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo("Preparing for import");

            progressCallback(progressInfo);

            using (var streamReader = new StreamReader(backupStream, Encoding.UTF8))
                using (var jsonReader = new JsonTextReader(streamReader))
                {
                    while (jsonReader.Read())
                    {
                        if (jsonReader.TokenType == JsonToken.PropertyName)
                        {
                            if (jsonReader.Value.ToString() == "PaymentPlans" &&
                                TryReadCollectionOf <PaymentPlan>(jsonReader, out var paymentPlans))
                            {
                                var totalCount = paymentPlans.Count;
                                for (int skip = 0; skip < totalCount; skip += BatchSize)
                                {
                                    var currentPaymentPlans = paymentPlans.Skip(skip).Take(BatchSize).ToArray();
                                    await _paymentPlanService.SavePlansAsync(currentPaymentPlans);

                                    progressInfo.Description = $"{Math.Min(skip + BatchSize, totalCount)} of {totalCount} payment plans have been imported.";
                                    progressCallback(progressInfo);
                                }
                            }
                            else if (jsonReader.Value.ToString() == "Subscriptions" &&
                                     TryReadCollectionOf <Subscription>(jsonReader, out var subscriptions))
                            {
                                var totalCount = subscriptions.Count;
                                for (int skip = 0; skip < totalCount; skip += BatchSize)
                                {
                                    var currentSubscriptions = subscriptions.Skip(skip).Take(BatchSize).ToArray();
                                    await _subscriptionService.SaveSubscriptionsAsync(currentSubscriptions);

                                    progressInfo.Description = $"{Math.Min(skip + BatchSize, totalCount)} of {totalCount} subscriptions have been imported.";
                                    progressCallback(progressInfo);
                                }
                            }
                        }
                    }
                }
        }