Exemplo n.º 1
0
        public Document Serialize(IContent content, ContentTypeDescriptor contentType)
        {
            var globalInterfaces = new List <DocumentInterface>();

            foreach (var coreInterface in contentType.CoreInterfaces)
            {
                globalInterfaces.Add(DocumentInterface.CreateFrom(coreInterface.Id, GetProperties(content, coreInterface.PropertyDefinitions)));
            }

            var global = DocumentFacet.CreateFrom(DocumentLanguageConstants.Global, globalInterfaces, GetProperties(content, contentType.PropertyDefinitions));

            return(Document.CreateFrom(content.Id, global, Enumerable.Empty <DocumentFacet>().ToDictionary(f => f.Language, f => f)));
        }
Exemplo n.º 2
0
        public void GetLinksTest()
        {
            var fileContent = File.ReadAllText("Data/vr.html");
            var doc         = new HtmlDocument();

            doc.LoadHtml(fileContent);

            var docInterface = new DocumentInterface(doc);
            var res          = docInterface.GetLinksByCssQuery("#videoCategory > li.pcVideoListItem div.phimage > a").ToArray();

            Assert.Equal(res, new List <string>
            {
                "/view_video.php?viewkey=ph5ef30590cc6f3",
                "/view_video.php?viewkey=ph5ef68e7ae2505",
                "/view_video.php?viewkey=ph5ebb2dad6dd97",
                "/view_video.php?viewkey=ph5e5e8af45d0ae",
                "/view_video.php?viewkey=ph5ee7df55702fc",
                "/view_video.php?viewkey=ph5ef10ebb89995",
                "/view_video.php?viewkey=ph5cda761263d21",
                "/view_video.php?viewkey=ph5e2a3c9e66f29",
                "/view_video.php?viewkey=ph5eeea49e8705a",
                "/view_video.php?viewkey=ph5de7e50f8eb6c",
                "/view_video.php?viewkey=ph5eebb82fbf99b",
                "/view_video.php?viewkey=ph5ee7509d893f2",
                "/view_video.php?viewkey=ph5d9751240ff7b",
                "/view_video.php?viewkey=ph5eef09d2e329b",
                "/view_video.php?viewkey=ph5e5e47dc50c7c",
                "/view_video.php?viewkey=ph5eeeb0228bea9",
                "/view_video.php?viewkey=ph5ee8d568a6696",
                "/view_video.php?viewkey=ph5eec4164e8080",
                "/view_video.php?viewkey=ph5eee0e5ec2b54",
                "/view_video.php?viewkey=ph5eaaae3742891",
                "/view_video.php?viewkey=ph5eec9bc959756",
                "/view_video.php?viewkey=ph5eb14839a343f",
                "/view_video.php?viewkey=ph5eceb106501b7",
                "/view_video.php?viewkey=ph5eeba83b8e45d",
                "/view_video.php?viewkey=ph5ef0a5b8af2d5",
                "/view_video.php?viewkey=ph5eef210de5ad5",
                "/view_video.php?viewkey=ph5eec61d9606c3",
                "/view_video.php?viewkey=ph5eec2d7867c85",
                "/view_video.php?viewkey=ph5eeb05cd560d3",
                "/view_video.php?viewkey=ph5eb6fdf1ba383",
                "/view_video.php?viewkey=ph5ed512d8bc1c6",
                "/view_video.php?viewkey=ph5dbb9441b8645"
            });
        }
        public async Task Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "v1/good")] HttpRequest req,
            ILogger log)
        {
            // POSTデータからパラメータを取得
            var jsonContent = await req.ReadAsStringAsync();

            log.LogInformation($"Request:{jsonContent}");

            var feedOptions = new FeedOptions
            {
                MaxItemCount = 1,
                EnableCrossPartitionQuery = true
            };

            try
            {
                dynamic data     = JsonConvert.DeserializeObject(jsonContent);
                string  image_id = data?.id;

                // バリデーションチェック
                if (string.IsNullOrWhiteSpace(image_id) || !(Regex.IsMatch(image_id, @"^[0-9]{14}$")))
                {
                    log.LogInformation("バリデーションエラー");
                    return;
                }

                var doc = _documentClient.CreateDocumentQuery <DocumentInterface>(
                    UriFactory.CreateDocumentCollectionUri(AppSettings.Instance.DATABASE_ID, AppSettings.Instance.COLLECTION_ID), feedOptions)
                          .Where(x => x.ImageId == image_id)
                          .AsEnumerable()
                          .FirstOrDefault();

                if (doc == null)
                {
                    log.LogInformation("更新対象なし");
                    return;
                }

                var requestOptions = new RequestOptions()
                {
                    PartitionKey    = new PartitionKey(doc.ImageId),
                    AccessCondition = new AccessCondition()
                    {
                        Condition = doc.Etag,
                        Type      = AccessConditionType.IfMatch
                    }
                };

                TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");

                var update = new DocumentInterface()
                {
                    Id              = doc.Id,
                    ImageId         = doc.ImageId,
                    User            = doc.User,
                    UserIcon        = doc.UserIcon,
                    PictureUrl      = doc.PictureUrl,
                    Score           = doc.Score,
                    GoodCnt         = doc.GoodCnt + 1,
                    CreatedDatatime = doc.CreatedDatatime,
                    UpdatedDatatime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.ToUniversalTime(), tst)
                };

                await _documentClient.ReplaceDocumentAsync(
                    UriFactory.CreateDocumentUri(AppSettings.Instance.DATABASE_ID, AppSettings.Instance.COLLECTION_ID, doc.Id), update, requestOptions);

                var imageInfo = _documentClient.CreateDocumentQuery <DocumentInterface>(UriFactory.CreateDocumentCollectionUri(AppSettings.Instance.DATABASE_ID, AppSettings.Instance.COLLECTION_ID), feedOptions)
                                .OrderByDescending(x => x.Score)
                                .ToList();

                var rank = new RankResponseInterface();
                rank.Images = new List <Images>();
                var count = 0;
                foreach (var res in imageInfo)
                {
                    var image = new Images
                    {
                        ImageId    = res.ImageId,
                        User       = res.User,
                        UserIcon   = res.UserIcon,
                        PictureUrl = res.PictureUrl,
                        Score      = res.Score,
                        GoodCnt    = res.GoodCnt,
                        Rank       = count += 1
                    };
                    rank.Images.Add(image);
                }

                await _httpClientService.PostJsonAsync <RankResponseInterface>(AppSettings.Instance.SIGNALR_URL, rank);
            }
            catch (Exception ex)
            {
                log.LogError($"Error:{ex.Message}");
                log.LogError($"StackTrace:{ex.StackTrace}");
            }
        }
Exemplo n.º 4
0
        public static async void RegisterToCosmosdb([ActivityTrigger] IDurableActivityContext context, ILogger log)
        {
            var feedOptions = new FeedOptions
            {
                MaxItemCount = 1,
                EnableCrossPartitionQuery = true
            };

            var input = context.GetInput <(string user_id, string url, string score, string image_id)>();

            var httpClient = HttpStart.GetInstance();
            var userInfo   = await httpClient.GetAsync($"https://api.line.me/v2/bot/profile/{input.user_id}");

            var data = JsonConvert.DeserializeObject <LineUserInfoInterface>(userInfo);

            TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");

            var item = new DocumentInterface()
            {
                ImageId         = input.image_id,
                User            = data.Name,
                UserIcon        = data.PictureUrl,
                PictureUrl      = input.url.Replace(AppSettings.Instance.BLOB_URL, AppSettings.Instance.PROXY_URL),
                Score           = double.Parse(input.score),
                GoodCnt         = 0,
                CreatedDatatime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.ToUniversalTime(), tst),
                UpdatedDatatime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.ToUniversalTime(), tst)
            };

            var ducumentClient = HttpStart.GetDocumentInstance();
            await ducumentClient.CreateDatabaseIfNotExistsAsync(new Database { Id = AppSettings.Instance.DATABASE_ID });

            PartitionKeyDefinition pkDefn = new PartitionKeyDefinition()
            {
                Paths = new Collection <string>()
                {
                    "/image_id"
                }
            };
            await ducumentClient.CreateDocumentCollectionIfNotExistsAsync(
                UriFactory.CreateDatabaseUri(AppSettings.Instance.DATABASE_ID), new DocumentCollection { Id = AppSettings.Instance.COLLECTION_ID, PartitionKey = pkDefn },
                new RequestOptions { OfferThroughput = 400, PartitionKey = new PartitionKey("/image_id") });

            await ducumentClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(AppSettings.Instance.DATABASE_ID, AppSettings.Instance.COLLECTION_ID), item);

            var documentQuery = ducumentClient.CreateDocumentQuery <DocumentInterface>(UriFactory.CreateDocumentCollectionUri(AppSettings.Instance.DATABASE_ID, AppSettings.Instance.COLLECTION_ID), feedOptions)
                                .OrderByDescending(x => x.Score)
                                .ToList();

            var rank = new RankResponseInterface();

            rank.Images = new List <Images>();
            var count = 0;

            foreach (var res in documentQuery)
            {
                var image = new Images
                {
                    ImageId    = res.ImageId,
                    User       = res.User,
                    UserIcon   = res.UserIcon,
                    PictureUrl = res.PictureUrl,
                    Score      = res.Score,
                    GoodCnt    = res.GoodCnt,
                    Rank       = count += 1
                };
                rank.Images.Add(image);
            }

            await httpClient.PostJsonAsync <RankResponseInterface>(AppSettings.Instance.SIGNALR_URL, rank);
        }