public async Task ImportAsync(Stream inputStream, ExportImportOptions importOptions, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            var moduleImportOptions = importOptions as ThumbnailExportImportOptions;

            cancellationToken.ThrowIfCancellationRequested();

            var progressInfo = new ExportImportProgressInfo();

            using (var streamReader = new StreamReader(inputStream))
            {
                using (var jsonReader = new JsonTextReader(streamReader))
                {
                    while (jsonReader.Read())
                    {
                        if (jsonReader.TokenType != JsonToken.PropertyName)
                        {
                            continue;
                        }

                        switch (jsonReader.Value.ToString())
                        {
                        case "Options":
                            jsonReader.Read();
                            var options = _serializer.Deserialize <ThumbnailOption[]>(jsonReader);
                            progressInfo.Description = $"Importing {options.Length} options...";
                            progressCallback(progressInfo);
                            await _optionService.SaveOrUpdateAsync(options);

                            break;

                        case "Tasks":
                            jsonReader.Read();
                            var tasks = _serializer.Deserialize <ThumbnailTask[]>(jsonReader);
                            progressInfo.Description = $"Importing {tasks.Length} tasks...";
                            progressCallback(progressInfo);
                            await _taskService.SaveChangesAsync(tasks);

                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <ThumbnailOption> > CreateThumbnailOption([FromBody] ThumbnailOption option)
        {
            await _thumbnailOptionService.SaveOrUpdateAsync(new[] { option });

            return(Ok(option));
        }
Ejemplo n.º 3
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() == "Options")
                            {
                                await reader.DeserializeJsonArrayWithPagingAsync <ThumbnailOption>(_jsonSerializer, _batchSize, items => _optionService.SaveOrUpdateAsync(items.ToArray()), processedCount =>
                                {
                                    progressInfo.Description = $"{ processedCount } Options have been imported";
                                    progressCallback(progressInfo);
                                }, cancellationToken);
                            }
                            else if (reader.Value.ToString() == "Tasks")
                            {
                                await reader.DeserializeJsonArrayWithPagingAsync <ThumbnailTask>(_jsonSerializer, _batchSize, items => _taskService.SaveChangesAsync(items.ToArray()), processedCount =>
                                {
                                    progressInfo.Description = $"{ processedCount } Options have been imported";
                                    progressCallback(progressInfo);
                                }, cancellationToken);
                            }
                        }
                    }
                }
            }
        }