public static BoardThemeRimConfig FromJson(JsonValue json) { var config = new BoardThemeRimConfig(); config.Thickness = JsonValueReader.ReadPercentToFloat01(json["thickness"]); if (json.ContainsKey("indicators")) { config.DrawIndicatorsOnRim = true; var indicatorsJson = json["indicators"]; config.IndicatorsOnBothSides = indicatorsJson["indicators_on_both_sides"]; } else { config.DrawIndicatorsOnRim = false; } if (json.ContainsKey("inner_transition")) { var transitionJson = json["inner_transition"]; config.InnerTransition = new Transition( JsonValueReader.ReadPercentToFloat01(transitionJson["thickness"]), ColorTranslator.FromHtml(transitionJson["color"]) ); } if (json.ContainsKey("outer_transition")) { var transitionJson = json["outer_transition"]; config.OuterTransition = new Transition( JsonValueReader.ReadPercentToFloat01(transitionJson["thickness"]), ColorTranslator.FromHtml(transitionJson["color"]) ); } return(config); }
public static BoardThemeIndicatorsConfig FromJson(JsonValue json) { var config = new BoardThemeIndicatorsConfig(); FontStyle fontStyle = FontStyle.Regular; if (json["bold"]) { fontStyle |= FontStyle.Bold; } if (json["italic"]) { fontStyle |= FontStyle.Italic; } config.FontScale = JsonValueReader.ReadPercentToFloat01(json["font_scale"]); config.Font = new Font(json["font"], 10, fontStyle); config.LightSquareBrush = new SolidBrush(ColorTranslator.FromHtml(json["color_on_light_squares"])); config.DarkSquareBrush = new SolidBrush(ColorTranslator.FromHtml(json["color_on_dark_squares"])); if (json.ContainsKey("file_indicators")) { config.FileIndicators = json["file_indicators"]; } else { config.FileIndicators = "abcdefgh"; } if (json.ContainsKey("rank_indicators")) { config.RankIndicators = json["rank_indicators"]; } else { config.RankIndicators = "12345678"; } { string fileIndicatorSide = json["file_indicator_side"]; if (fileIndicatorSide == "bottom") { config.RelativeRank = 7; } else { config.RelativeRank = 0; } } { string rankIndicatorSide = json["rank_indicator_side"]; if (rankIndicatorSide == "left") { config.RelativeFile = 0; } else { config.RelativeFile = 7; } } { config.RankIndicatorFormat = new StringFormat { Alignment = ParseAlignment(json["rank_indicator_horizontal_align"]), LineAlignment = ParseAlignment(json["rank_indicator_vertical_align"]) }; config.FileIndicatorFormat = new StringFormat { Alignment = ParseAlignment(json["file_indicator_horizontal_align"]), LineAlignment = ParseAlignment(json["file_indicator_vertical_align"]) }; } return(config); }
void StreamingThread(object o) { InternalState info = (InternalState)o; string line = null; TimeSpan maxWait = TimeSpan.FromMinutes(1); TimeSpan startWait = TimeSpan.FromSeconds(2.5); TimeSpan wait = startWait; TimeSpan timeout = TimeSpan.FromSeconds(32); byte[] buffer = null; int filled = 0; while (_active) { try { info.ConnectionState = StreamingState.Connecting; using (IStreamingState state = info.Account.TwitterClient.StartStreaming(StreamingUri, "POST", info.StreamingPostData)) { info.Handle = state; info.RetryCount = 0; info.ConnectionState = StreamingState.Connected; while (_active) { try { line = ReadLineWithTimeout(state.Stream, ref buffer, ref filled, timeout); if (line == null) { break; } if (line.Length == 0) { continue; } JsonValueReader jsonReader = new JsonValueReader(line); JsonObject jsonRootObj = (JsonObject)jsonReader.Read(); if (jsonRootObj.Value.ContainsKey("delete") || jsonRootObj.Value.ContainsKey("limit")) { continue; } try { Target.Streaming_StatusArrived(this, new StatusArrivedEventArgs(JsonDeserializer.Deserialize <Status> (jsonRootObj))); } catch {} } catch { break; } } } } catch {} if (!_active) { break; } info.Handle = null; info.ConnectionState = StreamingState.Disconnected; if (info.RetryCount > 0) { wait = wait + wait; if (wait > maxWait) { wait = maxWait; } info.NextRetryTime = DateTime.Now + wait; info.ConnectionState = StreamingState.Waiting; Thread.Sleep(wait); } info.RetryCount++; } }