Esempio n. 1
0
 public TournamentAdminInfo ToTournamentAdminInfo(SanityHtmlBuilder htmlBuilder)
 {
     return(new TournamentAdminInfo {
         Slug = Slug?.Current,
         MainImage = MainImage?.Asset?.Value?.Url,
         Logo = Logo?.Asset?.Value?.Url,
         Title = Title?.GetForCurrentCulture(),
         Body = Body?.GetForCurrentCulture(htmlBuilder),
         ToornamentId = ToornamentId,
         RegistrationForm = RegistrationForm?.GetForCurrentCulture(),
         RegistrationOpen = RegistrationOpen,
         TelegramLink = TelegramLink,
         LiveStream = LiveStream,
         LiveChat = LiveChat,
         Game = Game?.Value?.ToGame(),
         Id = Id,
         SignupType = SignupType,
         RequiredInformation = RequiredInfo?.Select(s => s.GetForCurrentCulture()).ToList(),
         TeamSize = TeamSize,
         SoloPlayers = SoloPlayers?.Select(p => p.ToParticipant()).ToList(),
         CategoryIds = Categories?.Select(c => c.Ref).ToList(),
         Winner = Winner?.Value?.Name,
         Contacts = Contacts,
         Responsible = Responsible?.Value,
         ResponsibleId = Responsible?.Ref,
         ParticipantTeams = Teams?.Select(t => t.ToParticipant()).ToList(),
     });
 }
Esempio n. 2
0
        public string GetForCurrentCulture(SanityHtmlBuilder sanityHtmlBuilder)
        {
            // Current thread culture
            var lang = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;

            if (lang == "nb" || lang == "nn")
            {
                lang = "no";
            }

            string val = null;

            if (this.ContainsKey(lang))
            {
                val = this[lang].ToHtml(sanityHtmlBuilder);
            }

            // Default culture
            if (string.IsNullOrEmpty(val) && CultureInfo.DefaultThreadCurrentUICulture != null)
            {
                lang = CultureInfo.DefaultThreadCurrentUICulture.TwoLetterISOLanguageName;
                if (lang == "nb" || lang == "nn")
                {
                    lang = "no";
                }
                if (this.ContainsKey(lang))
                {
                    val = this[lang].ToHtml(sanityHtmlBuilder);
                }
            }

            // English
            if (string.IsNullOrEmpty(val))
            {
                lang = "en";
                if (this.ContainsKey(lang))
                {
                    val = this[lang].ToHtml(sanityHtmlBuilder);
                }
            }

            // German
            if (string.IsNullOrEmpty(val))
            {
                lang = "de";
                if (this.ContainsKey(lang))
                {
                    val = this[lang].ToHtml(sanityHtmlBuilder);
                }
            }

            // First non-empty
            if (string.IsNullOrEmpty(val))
            {
                val = this.Select(kv => kv.Value).FirstOrDefault(v => v != null && !(v is string))?.ToHtml(sanityHtmlBuilder);
            }

            return(val);
        }
Esempio n. 3
0
 public async Task ConvertTest()
 {
     // this test tries to serialize the Body-element of a Post-document from the Sanity demo-dataset.
     var sanity = new SanityDataContext(Options);
     var posts = await sanity.DocumentSet<Post>().ToListAsync();
     var htmlBuilder = new SanityHtmlBuilder(Options);
     foreach (var post in posts)
     {
         var html = htmlBuilder.BuildAsync(post.Body); // the serialized data
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Create a new SanityDbContext using the specified options.
 /// </summary>
 /// <param name="options"></param>
 /// <param name="isShared">Indicates that the context can be used by multiple SanityDocumentSets</param>
 public SanityDataContext(SanityOptions options, JsonSerializerSettings serializerSettings = null, SanityHtmlBuilderOptions htmlBuilderOptions = null, IHttpClientFactory clientFactory = null)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     SerializerSettings = serializerSettings ?? new JsonSerializerSettings
     {
         ContractResolver  = new CamelCasePropertyNamesContractResolver(),
         NullValueHandling = NullValueHandling.Ignore,
         Converters        = new List <JsonConverter> {
             new SanityReferenceTypeConverter()
         }
     };
     Client      = new SanityClient(options, serializerSettings, clientFactory);
     Mutations   = new SanityMutationBuilder(Client);
     HtmlBuilder = new SanityHtmlBuilder(options, null, SerializerSettings, htmlBuilderOptions);
 }
Esempio n. 5
0
        public EventInfo ToEventInfo(SanityHtmlBuilder htmlBuilder)
        {
            var responsible = new Player();

            if (this.Responsible != null)
            {
                responsible.Name     = this.Responsible.Value.Name;
                responsible.Id       = this.Responsible.Value.Id;
                responsible.Email    = this.Responsible.Value.Id;
                responsible.Nickname = this.Responsible.Value.Nickname;
            }

            return(new EventInfo {
                Id = this.Id,
                Title = this.Title?.GetForCurrentCulture(),
                Image = this.Image?.Asset?.Value?.Url,
                Responsible = this.Responsible?.Value,
                Date = this.Date,
                Description = this.Description?.GetForCurrentCulture(htmlBuilder),
                CategoryId = this.Category?.Ref,
            });
        }
Esempio n. 6
0
 public static string ToHtml(this object blockContent, SanityHtmlBuilder builder)
 {
     return(builder.BuildAsync(blockContent).Result);
 }
Esempio n. 7
0
 public static Task <string> ToHtmlAsync(this object blockContent, SanityHtmlBuilder builder)
 {
     return(builder.BuildAsync(blockContent));
 }
 public static string ToHtml(this object blockContent, SanityHtmlBuilder builder)
 {
     return(blockContent.ToHtml(builder, null));
 }