Esempio n. 1
0
    public async Task <string> CreateWebPageTranscript(WebPageTranscript webPageTranscript)
    {
        webPageTranscript.Transcript = webPageTranscript.Transcript ?? string.Empty;
        webPageTranscript.Host       = new Uri(webPageTranscript.Url).Host;
        if (!this._appConfig.PermittedDomains.Contains(webPageTranscript.Host))
        {
            throw new Exception("Not allowed");
        }
        TableQuery <WebPageTranscriptEntity> getByPartition = new TableQuery <WebPageTranscriptEntity>().Where(
            TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal,
                                               webPageTranscript.Host));
        var results = await this._cloudTable.ExecuteQuerySegmentedAsync(getByPartition, null);

        var highestIdSoFar = results.Count() > 0 ? results.Max(x => x.ReferenceNumber) : 0;

        webPageTranscript.ReferenceNumber = highestIdSoFar + 1;
        webPageTranscript.PhoneNumber     = this._appConfig.PhoneNumber;
        using (SHA256 sha256Hash = SHA256.Create())
        {
            webPageTranscript.UrlHash = GetHash(sha256Hash, webPageTranscript.Url);
        }
        var            entity = WebPageTranscriptMapper.mapToEntity(webPageTranscript);
        TableOperation insertOrMergeOperation = TableOperation.InsertOrReplace(entity);

        await this._cloudTable.ExecuteAsync(insertOrMergeOperation);

        return(entity.UrlHash);
    }