ErrorLog() публичный статический Метод

public static ErrorLog ( Exception exception ) : void
exception System.Exception
Результат void
Пример #1
0
 public static string LiveStatus(bool wait = false)
 {
     try {
         return(LiveStatus(GetLiveApi(), DateTime.UtcNow, wait));
     } catch (Exception e) {
         Logger.ErrorLog("Live check failed.");
         Logger.ErrorLog(e);
         return("Live check failed.");
     }
 }
Пример #2
0
        public static string FallibleCode(Func <string> inputFunc)
        {
            string r;

            try {
                r = inputFunc();
            } catch (Exception e) {
                r = "A server somewhere is choking on a hairball";
                Logger.ErrorLog(e);
            }
            return(r);
        }
Пример #3
0
        public static string PrettyDeltaTime(TimeSpan span, string rough = "")
        {
            int day    = Convert.ToInt32(span.ToString("%d"));
            int hour   = Convert.ToInt32(span.ToString("%h"));
            int minute = Convert.ToInt32(span.ToString("%m"));

            if (span.CompareTo(TimeSpan.Zero) == -1)
            {
                Logger.ErrorLog($"Time to sync the clock?{span}");
                return("a few seconds");
            }

            if (day > 1)
            {
                if (hour == 0)
                {
                    return($"{day} days");
                }
                return($"{day} days {hour}h");
            }

            if (day == 1)
            {
                if (hour == 0)
                {
                    return("1 day");
                }
                return($"1 day {hour}h");
            }

            if (hour == 0)
            {
                return($"{rough}{minute}m");
            }
            if (minute == 0)
            {
                return($"{rough}{hour}h");
            }

            return($"{rough}{hour}h {minute}m");
        }
Пример #4
0
        public static string LiveStatus(bool liveStatus, DateTime compareTime, bool wait = false)
        {
            var onTime  = Epoch().AddSeconds(Datastore.OnTime());
            var offTime = Epoch().AddSeconds(Datastore.OffTime());

            var onTimeDelta  = compareTime - onTime;
            var offTimeDelta = compareTime - offTime;

            var time = (Int32)(compareTime - Epoch()).TotalSeconds;

            if (liveStatus && Datastore.OnTime() != 0) //we've been live for some time
            {
                Datastore.UpdateStateVariable(MagicStrings.OffTime, 0, wait);
                return($"Live with {Datastore.Viewers} viewers for {PrettyDeltaTime(onTimeDelta, "~")}");
            }
            if (liveStatus && Datastore.OnTime() == 0) // we just went live
            {
                Datastore.UpdateStateVariable(MagicStrings.OnTime, time, wait);
                Datastore.UpdateStateVariable(MagicStrings.OffTime, 0, wait);
                return($"Destiny is live! With {Datastore.Viewers} viewers for ~0m");
            }
            if (!liveStatus && Datastore.OnTime() != 0 && Datastore.OffTime() == 0) //we've just gone offline
            {
                Datastore.UpdateStateVariable(MagicStrings.OffTime, time, wait);
                return("Stream went offline in the past ~10m");
            }
            if (!liveStatus && offTimeDelta < TimeSpan.FromMinutes(10))
            {
                return("Stream went offline in the past ~10m");
            }
            if (!liveStatus && Datastore.OffTime() != 0) //we've been not live for a while
            {
                Datastore.UpdateStateVariable(MagicStrings.OnTime, 0, wait);
                return($"Stream offline for {PrettyDeltaTime(offTimeDelta, "~")}");
            }
            Logger.ErrorLog($"LiveStatus()'s ifs failed. LiveStatus: {liveStatus}. In minutes: OnTimeΔ {onTimeDelta.TotalMinutes}. OffTimeΔ {offTimeDelta.TotalMinutes}");
            return("Live check failed");
        }
Пример #5
0
        public static bool GetLiveApi()
        {
            var     answer      = DownloadData("https://api.twitch.tv/kraken/streams/destiny").Result;
            dynamic dyn         = JsonConvert.DeserializeObject(answer);
            var     streamState = (JObject)dyn.stream;

            if (streamState != null)
            {
                var delayJvalue   = (JValue)dyn.stream.delay;
                var viewersJvalue = (JValue)dyn.stream.viewers;
                int delay;
                int viewers;
                var parseDelay = Int32.TryParse(delayJvalue.Value.ToString(), out delay);
                if (parseDelay)
                {
                    Datastore.Delay = delay;
                }
                else
                {
                    Datastore.Delay = -1;
                    Logger.ErrorLog("Tryparse on Delay failed");
                }
                var parseViewers = Int32.TryParse(viewersJvalue.Value.ToString(), out viewers);
                if (parseViewers)
                {
                    Datastore.Viewers = viewers;
                }
                else
                {
                    Datastore.Viewers = -1;
                    Logger.ErrorLog("Tryparse on Viewers failed");
                }
                return(true);
            }
            return(false);
        }