示例#1
0
        public async Task <Article> Insert(ArticleEntry value)
        {
            var result = await _articleData.Insert(new commons.models.Article
            {
                Id           = value.Id,
                Description  = value.Description,
                Name         = value.Name,
                Price        = value.Price,
                StoreId      = value.StoreId,
                TotalInShelf = value.TotalInShelf,
                TotalInVault = value.TotalInVault
            });

            var response = new sz.api.Models.Article
            {
                Id           = result.Id,
                Description  = result.Description,
                Name         = result.Name,
                Price        = result.Price,
                StoreId      = result.StoreId,
                StoreName    = result.Store?.Name,
                TotalInShelf = result.TotalInShelf,
                TotalInVault = result.TotalInVault
            };

            return(response);
        }
        public async Task InvokesPersistToBlobStoreWhenSuccessfullyCreated()
        {
            var entryContent = new EntryContentFixture().Build();
            var entry        = new ArticleEntry();
            var createMock   = new Mock <ICreateArticleEntryCoordinator>();
            var uploadMock   = new Mock <IUploadArticleEntryCoordinator>();
            var uploadUrl    = "someUrl";

            createMock.Setup(c => c.CreateArticleEntry(It.IsAny <Guid>(), It.IsAny <ArticleEntry>()))
            .ReturnsAsync(entryContent);

            createMock.Setup(c => c.MarkUploadSuccess(It.IsAny <EntryContent>(), It.IsAny <string>()))
            .ReturnsAsync(entryContent);

            uploadMock.Setup(u => u.UploadMarkdownArticleEntry(entryContent, It.IsAny <ArticleEntry>()))
            .ReturnsAsync(uploadUrl)
            .Verifiable();

            var persistArticleEntryStrategy = new CreateAndPersistArticleEntryStrategyFixture
            {
                CreateEntryCoordinator = createMock.Object,
                UploadCoordinator      = uploadMock.Object
            }.Build();

            var result = await persistArticleEntryStrategy.PersistArticleEntryAsync(Guid.NewGuid(), new ArticleEntry());

            uploadMock.VerifyAll();
            createMock.Verify(c => c.MarkUploadSuccess(entryContent, uploadUrl));
            Assert.Equal(entryContent, result);
        }
示例#3
0
        public override void Parse(VoidPtr address)
        {
            VoidPtr addr = BaseAddress + DataOffset;

            for (int i = 0; i < Count; i++)
            {
                ArticleEntry d = new ArticleEntry()
                {
                    Static = true
                };
                d.Initialize(this, addr + i * 56, 56);
            }
        }
示例#4
0
        public async Task <IActionResult> AddArticleEntry(Guid articleId, [FromBody] ArticleEntry post)
        {
            var result = await _persistArticleEntryStrategy.PersistArticleEntryAsync(articleId, post);

            if (result == null)
            {
                return(BadRequest());
            }

            var response = MapEntryResponse(result);

            return(Ok(response));
        }
        private async Task <EntryContent> CreateNewEntryFor(Article article, ArticleEntry entry)
        {
            var entryContent = new EntryContent
            {
                ArticleId = article.Id,
                Created   = _clock.Now,
            };

            await _context.Add(entryContent);

            await _context.SaveChanges();

            return(entryContent);
        }
示例#6
0
        public async Task <IActionResult> Post([FromBody] ArticleEntry value)
        {
            try
            {
                var result = await _articleProvider.Insert(value);

                var response = new ArticleResponseModel(result);
                return(Ok(response));
            }
            catch (Exception)
            {
                var result = new FailureModel(success: false, code: (int)HttpStatusCode.BadRequest, response: "Bad Request");
                return(BadRequest(result));
            }
        }
示例#7
0
        public ArticleInfo(ArticleEntry article, MDL0Node model, bool running)
        {
            _article = article;
            _model   = model;
            _running = running;

            _chr0List = new List <CHR0Node>();
            _srt0List = new List <SRT0Node>();
            _shp0List = new List <SHP0Node>();
            _vis0List = new List <VIS0Node>();
            _pat0List = new List <PAT0Node>();
            _clr0List = new List <CLR0Node>();

            _article._info = this;
        }
        public async Task <EntryContent> CreateArticleEntry(Guid articleId, ArticleEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            var article = await _context.Find <Article>(articleId);

            if (article == null)
            {
                return(null);
            }

            return(await CreateNewEntryFor(article, entry));
        }
        private static EntryContent BuildTestSetup(ArticleEntry articleEntry, out string base64, out Mock <IBlobStore> mock,
                                                   out UploadArticleEntryCoordinator coordinator)
        {
            base64 = string.IsNullOrWhiteSpace(articleEntry.Content)? "foo" : StringUtilities.ToBase64(articleEntry.Content);
            var entryContent     = new EntryContentFixture().Build();
            var blobStoreFixture = new BlobStoreFixture();

            mock = blobStoreFixture.Mock;
            var uploadFixture = new UploadArticleEntryCoordinatorFixture
            {
                BlobStore = blobStoreFixture.Build()
            };

            coordinator = uploadFixture.Build();
            return(entryContent);
        }
        public async Task DoesNotStoreContentIfContentEmpty()
        {
            var articleEntry = new ArticleEntry
            {
                Content = string.Empty
            };

            var entryContent = BuildTestSetup(articleEntry, out var base64, out var mock, out var coordinator);

            var result = await coordinator.UploadMarkdownArticleEntry(entryContent, articleEntry);

            Assert.Null(result);
            mock.Verify(m => m.PersistArticleEntryAsync(BlobStorageContainer.MARKDOWN_ARTICLE_ENTRIES_CONTAINER,
                                                        entryContent.ArticleId,
                                                        entryContent.Id,
                                                        base64), Times.Never);
        }
示例#11
0
        public override async Task <InputFormatterResult> ReadAsync(InputFormatterContext context)
        {
            var httpContextRequest = context.HttpContext.Request;

            if (!httpContextRequest.ContentLength.HasValue || httpContextRequest.ContentLength == 0)
            {
                return(await InputFormatterResult.FailureAsync());
            }

            using (var reader = context.ReaderFactory(httpContextRequest.Body, Encoding.UTF8))
            {
                var    blogPost       = new ArticleEntry();
                string readToEndAsync = await reader.ReadToEndAsync();

                blogPost.Content = readToEndAsync;
                return(await InputFormatterResult.SuccessAsync(blogPost));
            }
        }
        public async Task CallsDownToPersistEntryContentToBlobStore()
        {
            var articleEntry = new ArticleEntry
            {
                Content = "Blog Content"
            };

            var entryContent = BuildTestSetup(articleEntry, out var base64, out var mock, out var coordinator);

            var result = await coordinator.UploadMarkdownArticleEntry(entryContent, articleEntry);

            mock.Verify(m => m.PersistArticleEntryAsync(BlobStorageContainer.MARKDOWN_ARTICLE_ENTRIES_CONTAINER,
                                                        entryContent.ArticleId,
                                                        entryContent.Id,
                                                        base64));

            Assert.NotNull(result);
        }
        public async Task <EntryContent> PersistArticleEntryAsync(Guid articleId, ArticleEntry entry)
        {
            var result = await _createEntryCoordinator.CreateArticleEntry(articleId, entry);

            if (result != null)
            {
                string uploadUrl = await _uploadCoordinator.UploadMarkdownArticleEntry(result, entry);

                if (string.IsNullOrWhiteSpace(uploadUrl))
                {
                    return(result);
                }

                return(await _createEntryCoordinator.MarkUploadSuccess(result, uploadUrl));
            }

            return(result);
        }
        public async Task UpdateEntry(string entryFilePath)
        {
            entryFilePath = Path.GetFullPath(entryFilePath);
            Console.WriteLine($"attempting to load entry file: {entryFilePath}");

            if (!File.Exists(entryFilePath))
            {
                throw new FileNotFoundException($"Could not load entry file: {entryFilePath}");
            }

            var articleContext = await _getArticleContextWorkflow.GetArticleContext();

            if (articleContext == null)
            {
                return;
            }

            var entryFileBytes = await File.ReadAllBytesAsync(entryFilePath);

            var entryContentsUtf8 = Encoding.UTF8.GetString(entryFileBytes);

            var entry = new ArticleEntry
            {
                Content = entryContentsUtf8
            };

            var updateEntryResponse = await _client.PostMessage(articleContext.GetApiLink(LinkRelValueObject.ENTRY), entry);

            if (!updateEntryResponse.IsSuccessStatusCode)
            {
                throw new HttpRequestException($"failed HTTP request: {updateEntryResponse.StatusCode}\n{updateEntryResponse.ReasonPhrase}");
            }

            var entryResponseContents = await updateEntryResponse.Content.ReadAsStringAsync();

            entryResponseContents = JsonUtility.Prettify <ArticleEntryResponse>(entryResponseContents);

            Console.WriteLine(entryResponseContents);

            await Task.CompletedTask;
        }
示例#15
0
 public Script()
 {
     _build         = false;
     _parentArticle = null;
     _scriptor      = new Scriptor(this);
 }
示例#16
0
 public Script(ArticleEntry article)
 {
     _build         = false;
     _parentArticle = article;
     _scriptor      = new Scriptor(this);
 }
示例#17
0
        public async Task <string> UploadMarkdownArticleEntry(EntryContent entryContent, ArticleEntry articleEntry)
        {
            if (articleEntry == null)
            {
                throw new ArgumentNullException(nameof(articleEntry));
            }

            if (string.IsNullOrWhiteSpace(articleEntry.Content))
            {
                return(null);
            }

            return(await UploadArticleEntry(entryContent, articleEntry.Content, BlobStorageContainer.MARKDOWN_ARTICLE_ENTRIES_CONTAINER));
        }