Beispiel #1
0
        public async Task WriteJsonAsync(JsonTextWriter writer, object entity, IExpressionTree fields)
        {
            var content = entity as Metadata;

            await writer.WriteStartObjectAsync();

            {
                await writer.WritePropertyNameAsync(GetKey(nameof(Metadata.Header)), true);

                await writer.WriteStartObjectAsync();

                {
                    await writer.WritePropertyNameAsync(GetKey(nameof(MetadataHeader.Generated)), true);

                    await writer.WriteValueAsync(DateTime.SpecifyKind(content.Header.Generated, DateTimeKind.Unspecified));

                    await writer.WritePropertyNameAsync(GetKey(nameof(MetadataHeader.Principal)), true);

                    await writer.WriteValueAsync(content.Header.Principal);
                }
                await writer.WriteEndObjectAsync();

                await writer.WritePropertyNameAsync(GetKey(nameof(Metadata.Data)), true);

                await SerializerProvider.ResolveSerializer(content.Data).WriteJsonAsync(writer, content.Data, fields);
            }
            await writer.WriteEndObjectAsync();
        }
Beispiel #2
0
        /// <summary>
        /// The flush documents to batch file.
        /// </summary>
        /// <param name="documentCacheItems">
        /// The document cache items.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        private async Task FlushDocumentsToBatchFile(List <IJsonObjectQueueItem> documentCacheItems)
        {
            var docs = documentCacheItems.Select(c => c.Document).ToList();

            var stream = new MemoryStream(); // do not use using since we'll pass it to next queue

            using (var textWriter = new StreamWriter(stream, Encoding.UTF8, 1024, true))
                using (var writer = new JsonTextWriter(textWriter))
                {
                    foreach (var doc in docs)
                    {
                        var entityId = doc[this.Config.TopLevelKeyColumn].Value <string>();

                        await writer.WriteStartObjectAsync();

                        using (new JsonPropertyWrapper(writer, "update"))
                        {
                            await writer.WritePropertyNameAsync("_id");

                            await writer.WriteValueAsync(entityId);
                        }
                        await writer.WriteEndObjectAsync();

                        await writer.WriteRawAsync("\n");

                        await writer.WriteStartObjectAsync(); // <update>

                        //-- start writing doc
                        await writer.WritePropertyNameAsync("doc");

                        await doc.WriteToAsync(writer);

                        //writer.WriteRaw(doc.ToString());

                        // https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
                        await writer.WritePropertyNameAsync("doc_as_upsert");

                        await writer.WriteValueAsync(true);

                        await writer.WriteEndObjectAsync(); // </update>

                        await writer.WriteRawAsync("\n");
                    }
                }

            var batchNumber = Interlocked.Increment(ref currentBatchFileNumber);

            await this.AddToOutputQueueAsync(new FileUploadQueueItem
            {
                BatchNumber = batchNumber,
                Stream      = stream
            });

            this.MyLogger.Verbose($"Wrote batch: {batchNumber}");
        }
Beispiel #3
0
        public static async Task <Dictionary <string, object> > WriteAttachment(
            Stream attachmentStream, long totalSize, string attachmentId,
            string collectionName, string contentType, long attachmentNumber,
            JsonTextWriter jsonTextWriter, StreamWriter streamWriter)
        {
            var hash = Blake2BFactory.Value.ComputeHash(attachmentStream).AsBase64String();
            var tag  = $"{AttachmentTagPrefix}{attachmentNumber}";
            await jsonTextWriter.WriteStartObjectAsync();

            await jsonTextWriter.WritePropertyNameAsync(MetadataProperty);

            await jsonTextWriter.WriteStartObjectAsync();

            await jsonTextWriter.WritePropertyNameAsync(ExportTypeProperty);

            await jsonTextWriter.WriteValueAsync(ExportTypeValue);

            await jsonTextWriter.WriteEndObjectAsync();

            await jsonTextWriter.WritePropertyNameAsync(HashProperty);

            await jsonTextWriter.WriteValueAsync(hash);

            await jsonTextWriter.WritePropertyNameAsync(SizeProperty);

            await jsonTextWriter.WriteValueAsync(totalSize);

            await jsonTextWriter.WritePropertyNameAsync(TagProperty);

            await jsonTextWriter.WriteValueAsync(tag);

            await jsonTextWriter.WriteEndObjectAsync();

            await jsonTextWriter.FlushAsync();

            await streamWriter.FlushAsync();

            attachmentStream.Position = 0;
            await attachmentStream.CopyToAsync(streamWriter.BaseStream);

            var attachmentInfo = new Dictionary <string, object>
            {
                { AttachmentInfoName, attachmentId },
                { AttachmentInfoHash, hash },
                { AttachmentInfoContentType, contentType },
                { AttachmentInfoSize, totalSize }
            };

            return(attachmentInfo);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktCertification obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (!string.IsNullOrEmpty(obj.Name))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_NAME, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Name, cancellationToken).ConfigureAwait(false);
            }

            if (!string.IsNullOrEmpty(obj.Slug))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SLUG, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Slug, cancellationToken).ConfigureAwait(false);
            }

            if (!string.IsNullOrEmpty(obj.Description))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_DESCRIPTION, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Description, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktSyncRatingsPostShowEpisode obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.RatedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_RATED_AT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.RatedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            if (obj.Rating.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_RATING, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Rating, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_NUMBER, cancellationToken).ConfigureAwait(false);

            await jsonWriter.WriteValueAsync(obj.Number, cancellationToken).ConfigureAwait(false);

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktSyncHistoryPostResponse obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Added != null)
            {
                var syncPostResponseGroupObjectJsonWriter = new SyncPostResponseGroupObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_HISTORY_POST_RESPONSE_PROPERTY_NAME_ADDED, cancellationToken).ConfigureAwait(false);

                await syncPostResponseGroupObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Added, cancellationToken).ConfigureAwait(false);
            }

            if (obj.NotFound != null)
            {
                var syncPostResponseNotFoundGroupObjectJsonWriter = new SyncPostResponseNotFoundGroupObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_HISTORY_POST_RESPONSE_PROPERTY_NAME_NOT_FOUND, cancellationToken).ConfigureAwait(false);

                await syncPostResponseNotFoundGroupObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.NotFound, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Beispiel #7
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktUserCustomListItemsPost obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Movies != null)
            {
                var customListItemsPostMovieArrayJsonWriter = new ArrayJsonWriter <ITraktUserCustomListItemsPostMovie>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_MOVIES, cancellationToken).ConfigureAwait(false);

                await customListItemsPostMovieArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Movies, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Shows != null)
            {
                var customListItemsPostShowArrayJsonWriter = new ArrayJsonWriter <ITraktUserCustomListItemsPostShow>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SHOWS, cancellationToken).ConfigureAwait(false);

                await customListItemsPostShowArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Shows, cancellationToken).ConfigureAwait(false);
            }

            if (obj.People != null)
            {
                var personArrayJsonWriter = new ArrayJsonWriter <ITraktPerson>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_PEOPLE, cancellationToken).ConfigureAwait(false);

                await personArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.People, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Beispiel #8
0
        public static async Task WriteToAsync(this SecsMessage msg, JsonTextWriter jwtr)
        {
            await jwtr.WriteStartObjectAsync();

            await jwtr.WritePropertyNameAsync(nameof(msg.S));

            await jwtr.WriteValueAsync(msg.S);

            await jwtr.WritePropertyNameAsync(nameof(msg.F));

            await jwtr.WriteValueAsync(msg.S);

            await jwtr.WritePropertyNameAsync(nameof(msg.ReplyExpected));

            await jwtr.WriteValueAsync(msg.ReplyExpected);

            await jwtr.WritePropertyNameAsync(nameof(msg.Name));

            await jwtr.WriteValueAsync(msg.Name);

            if (msg.SecsItem != null)
            {
                await jwtr.WritePropertyNameAsync(nameof(msg.SecsItem));

                await msg.SecsItem.WriteToAsync(jwtr);
            }

            await jwtr.WriteEndObjectAsync();
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, TCheckinResponseObjectType obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_ID, cancellationToken).ConfigureAwait(false);

            await jsonWriter.WriteValueAsync(obj.Id, cancellationToken).ConfigureAwait(false);

            if (obj.WatchedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_WATCHED_AT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.WatchedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            if (obj.Sharing != null)
            {
                var sharingObjectJsonWriter = new SharingObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SHARING, cancellationToken).ConfigureAwait(false);

                await sharingObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Sharing, cancellationToken).ConfigureAwait(false);
            }

            await WriteCheckinResponseObjectAsync(jsonWriter, obj, cancellationToken).ConfigureAwait(false);

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Beispiel #10
0
        protected override async Task Write(TextWriter writer, string dataValue, ICitylineProducer provider, TicketHolder ticket, CancellationToken cancellationToken = default(CancellationToken))
        {
            using (var jsonWriter = new JsonTextWriter(writer)
            {
                Formatting = Formatting.None
            })
            {
                await jsonWriter.WriteStartObjectAsync(cancellationToken);

                await jsonWriter.WritePropertyNameAsync("id", cancellationToken);

                await jsonWriter.WriteValueAsync(ticket.AsString(), cancellationToken);

                await jsonWriter.WritePropertyNameAsync("event", cancellationToken);

                await jsonWriter.WriteValueAsync(provider.Name, cancellationToken);

                await jsonWriter.WritePropertyNameAsync("data", cancellationToken);

                await jsonWriter.WriteValueAsync(dataValue, cancellationToken);

                await jsonWriter.WriteEndObjectAsync(cancellationToken);

                await writer.WriteAsync('\n');
            }
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktError obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (!string.IsNullOrEmpty(obj.Error))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.ERROR_PROPERTY_NAME_ERROR, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Error, cancellationToken).ConfigureAwait(false);
            }

            if (!string.IsNullOrEmpty(obj.Description))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.ERROR_PROPERTY_NAME_ERROR_DESCRIPTION, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Description, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktTrendingShow obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Watchers.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.TRENDING_SHOW_PROPERTY_NAME_WATCHERS, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Watchers, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Show != null)
            {
                var showObjectJsonWriter = new ShowObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.TRENDING_SHOW_PROPERTY_NAME_SHOW, cancellationToken).ConfigureAwait(false);

                await showObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Show, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktShowCastMember obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Characters != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_CHARACTERS, cancellationToken).ConfigureAwait(false);

                await JsonWriterHelper.WriteStringArrayAsync(jsonWriter, obj.Characters, cancellationToken).ConfigureAwait(false);
            }

            if (obj.EpisodeCount.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_EPISODE_COUNT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.EpisodeCount.Value, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Person != null)
            {
                var personObjectJsonWriter = new PersonObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_PERSON, cancellationToken).ConfigureAwait(false);

                await personObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Person, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktRecentlyUpdatedMovie obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.RecentlyUpdatedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.RECENTLY_UPDATED_MOVIE_PROPERTY_NAME_UPDATED_AT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.RecentlyUpdatedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            if (obj.Movie != null)
            {
                var movieObjectJsonWriter = new MovieObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.RECENTLY_UPDATED_MOVIE_PROPERTY_NAME_MOVIE, cancellationToken).ConfigureAwait(false);

                await movieObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Movie, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Beispiel #15
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktSyncWatchlistPost obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Movies != null)
            {
                var syncWatchlistPostMovieArrayJsonWriter = new ArrayJsonWriter <ITraktSyncWatchlistPostMovie>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_WATCHLIST_POST_PROPERTY_NAME_MOVIES, cancellationToken).ConfigureAwait(false);

                await syncWatchlistPostMovieArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Movies, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Shows != null)
            {
                var syncWatchlistPostShowArrayJsonWriter = new ArrayJsonWriter <ITraktSyncWatchlistPostShow>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_WATCHLIST_POST_PROPERTY_NAME_SHOWS, cancellationToken).ConfigureAwait(false);

                await syncWatchlistPostShowArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Shows, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Episodes != null)
            {
                var syncWatchlistPostEpisodeArrayJsonWriter = new ArrayJsonWriter <ITraktSyncWatchlistPostEpisode>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_WATCHLIST_POST_PROPERTY_NAME_EPISODES, cancellationToken).ConfigureAwait(false);

                await syncWatchlistPostEpisodeArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Episodes, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Beispiel #16
0
        /// <inheritdoc />
        public async Task WriteMappingToStreamAsync(List <ColumnInfo> columnList, string propertyPath, StreamWriter textWriter, string propertyType, string entity)
        {
            using (var writer = new JsonTextWriter(textWriter))
            {
                await writer.WriteStartObjectAsync(); // begin

                using (new JsonPropertyWrapper(writer, "mappings", propertyPath != null))
                {
                    using (new JsonPropertyWrapper(writer, entity, propertyPath != null))
                    {
                        using (new JsonPropertyWrapper(writer, "properties"))
                        {
                            // see if propertyPath was specified
                            if (!string.IsNullOrEmpty(propertyPath))
                            {
                                var queue = new Queue <string>();
                                foreach (var property in propertyPath.Split('.'))
                                {
                                    queue.Enqueue(property);
                                }

                                await this.WriteNestedPropertyAsync(columnList, queue, writer, propertyType);
                            }
                            else
                            {
                                await this.InternalWriteColumnsToJson(columnList, writer);
                            }
                        }
                    }
                }

                await writer.WriteEndObjectAsync(); // end
            }
        }
Beispiel #17
0
        protected static async Task WriteProperty <TValue>(JsonTextWriter writer, string propertyName, Dictionary <string, TValue>[] values)
        {
            await writer.WritePropertyNameAsync(propertyName);

            if (values == null)
            {
                await writer.WriteNullAsync();

                return;
            }

            await writer.WriteStartArrayAsync();

            foreach (var dictionary in values)
            {
                await writer.WriteStartObjectAsync();

                foreach (var(name, value) in dictionary)
                {
                    await WriteProperty(writer, name, value);
                }

                await writer.WriteEndObjectAsync();
            }

            await writer.WriteEndArrayAsync();
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktUserFollowRequest obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_ID, cancellationToken).ConfigureAwait(false);

            await jsonWriter.WriteValueAsync(obj.Id, cancellationToken).ConfigureAwait(false);

            if (obj.RequestedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_REQUESTED_AT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.RequestedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            if (obj.User != null)
            {
                var userObjectJsonWriter = new UserObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_USER, cancellationToken).ConfigureAwait(false);

                await userObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.User, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktRating obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Rating.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_RATING, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Rating, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Votes.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_VOTES, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Votes, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Distribution?.Count > 0)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_DISTRIBUTION, cancellationToken).ConfigureAwait(false);

                await JsonWriterHelper.WriteDistributionAsync(jsonWriter, obj.Distribution, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktShowTranslation obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (!string.IsNullOrEmpty(obj.Title))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SHOW_TRANSLATION_PROPERTY_NAME_TITLE, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Title, cancellationToken).ConfigureAwait(false);
            }

            if (!string.IsNullOrEmpty(obj.Overview))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SHOW_TRANSLATION_PROPERTY_NAME_OVERVIEW, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Overview, cancellationToken).ConfigureAwait(false);
            }

            if (!string.IsNullOrEmpty(obj.LanguageCode))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SHOW_TRANSLATION_PROPERTY_NAME_LANGUAGE_CODE, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.LanguageCode, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Beispiel #21
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktUserHiddenItemsPostResponseNotFoundGroup obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Movies != null)
            {
                var notFoundMovieArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundMovie>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_MOVIES, cancellationToken).ConfigureAwait(false);

                await notFoundMovieArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Movies, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Shows != null)
            {
                var notFoundShowArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundShow>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SHOWS, cancellationToken).ConfigureAwait(false);

                await notFoundShowArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Shows, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Seasons != null)
            {
                var notFoundSeasonArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundSeason>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SEASONS, cancellationToken).ConfigureAwait(false);

                await notFoundSeasonArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Seasons, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktCastMember obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (!string.IsNullOrEmpty(obj.Character))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.CAST_MEMBER_PROPERTY_NAME_CHARACTER, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Character, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Person != null)
            {
                var personObjectJsonWriter = new PersonObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.CAST_MEMBER_PROPERTY_NAME_PERSON, cancellationToken).ConfigureAwait(false);

                await personObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Person, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktSyncHistoryPostShowSeason obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.WatchedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_HISTORY_POST_SHOW_SEASON_PROPERTY_NAME_WATCHED_AT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.WatchedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_HISTORY_POST_SHOW_SEASON_PROPERTY_NAME_NUMBER, cancellationToken).ConfigureAwait(false);

            await jsonWriter.WriteValueAsync(obj.Number, cancellationToken).ConfigureAwait(false);

            if (obj.Episodes != null)
            {
                var syncHistoryPostShowEpisodeArrayJsonWriter = new ArrayJsonWriter <ITraktSyncHistoryPostShowEpisode>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_HISTORY_POST_SHOW_SEASON_PROPERTY_NAME_EPISODES, cancellationToken).ConfigureAwait(false);

                await syncHistoryPostShowEpisodeArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Episodes, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Beispiel #24
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktBoxOfficeMovie obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Revenue.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.BOX_OFFICE_MOVIE_PROPERTY_NAME_REVENUE, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Revenue, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Movie != null)
            {
                var movieObjectJsonWriter = new MovieObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.BOX_OFFICE_MOVIE_PROPERTY_NAME_MOVIE, cancellationToken).ConfigureAwait(false);

                await movieObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Movie, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Beispiel #25
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktUserNetworkStatistics obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Friends.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_FRIENDS, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Friends, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Followers.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_FOLLOWERS, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Followers, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Following.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_FOLLOWING, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Following, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktSyncHistoryPostMovie obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.WatchedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_WATCHED_AT, cancellationToken).ConfigureAwait(false);
                await jsonWriter.WriteValueAsync(obj.WatchedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            if (!string.IsNullOrEmpty(obj.Title))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_TITLE, cancellationToken).ConfigureAwait(false);
                await jsonWriter.WriteValueAsync(obj.Title, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Year.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_YEAR, cancellationToken).ConfigureAwait(false);
                await jsonWriter.WriteValueAsync(obj.Year, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Ids != null)
            {
                var movieIdsObjectJsonWriter = new MovieIdsObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_IDS, cancellationToken).ConfigureAwait(false);
                await movieIdsObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Ids, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktSyncRatingsPostEpisode obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.RatedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_RATINGS_POST_EPISODE_PROPERTY_NAME_RATED_AT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.RatedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            if (obj.Rating.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_RATINGS_POST_EPISODE_PROPERTY_NAME_RATING, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Rating, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Ids != null)
            {
                var episodeIdsObjectJsonWriter = new EpisodeIdsObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_RATINGS_POST_EPISODE_PROPERTY_NAME_IDS, cancellationToken).ConfigureAwait(false);

                await episodeIdsObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Ids, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Beispiel #28
0
        /// <summary>
        /// Creates an IoTCentral JSON message for a event change notification, based on the event configuration for the endpoint.
        /// </summary>
        private async Task <string> CreateIoTCentralJsonForEventChangeAsync(EventMessageData messageData, CancellationToken shutdownToken)
        {
            try
            {
                // build the JSON message for IoTCentral
                StringBuilder jsonStringBuilder = new StringBuilder();
                StringWriter  jsonStringWriter  = new StringWriter(jsonStringBuilder);
                using (JsonWriter jsonWriter = new JsonTextWriter(jsonStringWriter))
                {
                    await jsonWriter.WriteStartObjectAsync(shutdownToken).ConfigureAwait(false);

                    await jsonWriter.WritePropertyNameAsync(messageData.DisplayName, shutdownToken).ConfigureAwait(false);

                    var eventValues = string.Join(",", messageData.EventValues.Select(s => new {
                        s.Name,
                        s.Value
                    }));
                    await jsonWriter.WriteValueAsync(eventValues, shutdownToken).ConfigureAwait(false);

                    await jsonWriter.WritePropertyNameAsync("messageType", shutdownToken).ConfigureAwait(false);

                    await jsonWriter.WriteValueAsync("event", shutdownToken).ConfigureAwait(false);

                    await jsonWriter.WriteEndObjectAsync(shutdownToken).ConfigureAwait(false);

                    await jsonWriter.FlushAsync(shutdownToken).ConfigureAwait(false);
                }
                return(jsonStringBuilder.ToString());
            }
            catch (Exception e)
            {
                _logger.Error(e, "Generation of IoTCentral JSON message failed.");
            }
            return(string.Empty);
        }
Beispiel #29
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktWatchedShowEpisode obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Number.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_NUMBER, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Number, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Plays.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_PLAYS, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Plays, cancellationToken).ConfigureAwait(false);
            }

            if (obj.LastWatchedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_LAST_WATCHED_AT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.LastWatchedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        internal static async Task WriteDistributionAsync(JsonTextWriter jsonWriter, IDictionary <string, int> distribution, CancellationToken cancellationToken = default)
        {
            CheckValues(jsonWriter, distribution);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            for (int i = 1; i <= 10; i++)
            {
                string key = i.ToString();
                await jsonWriter.WritePropertyNameAsync(key, cancellationToken).ConfigureAwait(false);

                if (distribution.TryGetValue(key, out int value))
                {
                    if (value > 0)
                    {
                        await jsonWriter.WriteValueAsync(value, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        await jsonWriter.WriteValueAsync(0, cancellationToken).ConfigureAwait(false);
                    }
                }
                else
                {
                    await jsonWriter.WriteValueAsync(0, cancellationToken).ConfigureAwait(false);
                }
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }