Ejemplo n.º 1
0
        /// <summary>
        /// Query Kiroku Storage for a single KLOG.
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static OkObjectResult Execute(HttpRequest req)
        {
            using (KLog klog = new KLog($"KQueryManager,Execute"))
            {
                if (!_configOnline)
                {
                    klog.Error("Config failed to load.");
                    return(new OkObjectResult(""));
                }

                if (req == null)
                {
                    klog.Warning("Request was empty.");
                    return(new OkObjectResult(""));
                }

                string id = req?.Query["id"];

                try
                {
                    Guid checkId = new Guid(id);

                    byte[] doc = Storage.GetLog(id);

                    var payload = Encoding.UTF8.GetString(doc, 0, doc.Length);

                    if (!string.IsNullOrEmpty(payload))
                    {
                        payload = payload.Replace("#KLOG_INSTANCE_STATUS#", "");

                        payload = payload.Replace("}", "},");

                        payload = "[" + payload + "]";

                        payload = payload.Replace("},\r\n$", "}]");

                        payload = JValue.Parse(payload).ToString(Formatting.Indented);
                    }

                    if (doc == null)
                    {
                        klog.Error($"Document is null. Id: {id}");
                    }

                    return(doc == null
                        ? new OkObjectResult($"404")
                        : new OkObjectResult(payload));
                }
                catch (Exception ex)
                {
                    klog.Error($"EXCEPTION : {ex.ToString()}");
                    return(new OkObjectResult(""));
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Saves the user data to it's file.
 /// </summary>
 public static void SaveUserData()
 {
     if (!Saving && !BotUtils.SaveInProgress)
     {
         Saving = true;
         BotUtils.WriteToJson(UserData, DataFileNames.UserDataFile);
         Saving = false;
     }
     else
     {
         KLog.Warning("Tried to save user data, but couldn't becuase it was already being saved!");
     }
 }
Ejemplo n.º 3
0
        public CrossBanDataNode(int server, string reason = "")
        {
            if (server >= Servers.Length)
            {
                KLog.Warning($"Cross-ban entry for a user had an invalid index! ({server})");
                Server = 0;
            }
            else
            {
                Server = server;
            }

            Reason = reason;
        }
        public static bool Execute(string line, Guid fileGuid, KLog uploaderLog)
        {
            uploaderLog.Warning($"Uploader => Footer Check Failed - Guid: {fileGuid.ToString()}");

            BlobFileCollection.GetFiles().First(d => d.FileGuid == fileGuid).FooterStatus = false;

            LogRecordModel record = null;

            try
            {
                record = JsonConvert.DeserializeObject <LogRecordModel>(line);
            }
            catch (Exception ex)
            {
                uploaderLog.Error($" [UploadInstanceStop] Log Record Deserialize Exception: {ex.ToString()}");
                return(false);
            }

            var newEndTime = record.EventTime;

            InstanceModel newInstanceCloser = new InstanceModel();

            newInstanceCloser.InstanceID = fileGuid;
            newInstanceCloser.EventTime  = newEndTime;

            var checkUpdateInstaceClose = DataAccessor.UpdateInstanceStop(newInstanceCloser);

            if (!checkUpdateInstaceClose.Success)
            {
                uploaderLog.Error($"SQL Expection on [UploadInstanceStop].[UpdateInstaceClose] - Message: {checkUpdateInstaceClose.Message}");
                return(false);
            }

            var checkUpdateBlockStop = DataAccessor.UpdateBlockEmptyStop(record, fileGuid);

            if (!checkUpdateBlockStop.Success)
            {
                uploaderLog.Error($"SQL Expection on [UploadInstanceStop].[UpdateBlockStop] - Message: {checkUpdateBlockStop.Message}");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Testing Static Kiroku Logger");

            KManager.Configure(Global.KirokuTagList);

            KManager.Open();

            using (KLog klog = new KLog("testing block one"))
            {
                klog.Trace("testing trace one");

                klog.Info("testing info one");

                klog.Warning("testing warning one");

                klog.Error("testing error one");

                klog.Metric("test one", 1);

                klog.Success("test one success");
            }

            KManager.Close();

            KManager.Configure(Global.KirokuTagList, dynamic: true);

            Console.WriteLine("\n\rTrying to use Static Logger while Dynamic=true Kiroku Logger");
            try
            {
                KManager.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Open Exception: {ex.ToString()}");
            }

            try
            {
                KManager.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Close Exception: {ex.ToString()}");
            }

            Console.WriteLine("\n\rTesting Non-Nested Dynamic Kiroku Logger");
            using (KLog klog = new KLog("testing block two"))
            {
                klog.Trace("testing trace two");

                klog.Info("testing info two");

                klog.Warning("testing warning two");

                klog.Error("testing error two");

                klog.Metric("test two", 1);

                klog.Success("test two success");
            }

            Console.WriteLine("\n\rTesting Nested Dynamic Kiroku Logger");
            using (KLog klog = new KLog("testing block three"))
            {
                klog.Trace("testing trace three");

                klog.Info("testing info three");

                klog.Warning("testing warning three");

                klog.Error("testing error three");

                klog.Metric("test three", 1);

                klog.Success("test three success");

                using (KLog klog2 = new KLog("nested testing block three", klog))
                {
                    klog2.Trace("nested testing trace three");

                    klog2.Info("nested testing info three");

                    klog2.Warning("nested testing warning three");

                    klog2.Error("nested testing error three");

                    klog2.Metric("nested test three", 1);

                    klog2.Success("nested test three success");
                }
            }

            Console.WriteLine("\n\rTesting Task<Nested Dynamic> Kiroku Logger");

            //#region Dynamic-False

            //for (int instanceIteration = 1; instanceIteration <= Global.InstanceLoop; instanceIteration++)
            //{
            //    KManager.Online(Global.KirokuTagList);

            //    for (int blockIteration = 1; blockIteration <= Global.BlockLoop; blockIteration++)
            //    {
            //        using (KLog klog = new KLog($"Block-{instanceIteration}-{blockIteration}"))
            //        {
            //            klog.Metric("Test Metric One", blockIteration);
            //            klog.Metric("Test Metric Two", true);
            //            klog.Metric("Test Metric Three", 2.33);

            //            if (Global.TraceOn)
            //            {
            //                try
            //                {
            //                    // Trace
            //                    for (int traceMeter = 1; traceMeter <= Global.TraceLoopCount; traceMeter++)
            //                    {
            //                        klog.Trace(Generator.Execute(Global.TraceCharCount));
            //                    }

            //                    // Info
            //                    if (Global.InfoOn)
            //                    {
            //                        for (int infoMeter = 1; infoMeter <= Global.InfoLoopCount; infoMeter++)
            //                        {
            //                            klog.Info(Generator.Execute(Global.InfoCharCount));
            //                        }
            //                    }

            //                    // Warning
            //                    if (Global.WarningOn)
            //                    {
            //                        for (int warningMeter = 1; warningMeter <= Global.WarningLoopCount; warningMeter++)
            //                        {
            //                            klog.Warning(Generator.Execute(Global.WarningCharCount));
            //                        }
            //                    }

            //                    // Error
            //                    if (Global.ErrorOn)
            //                    {
            //                        for (int errorMeter = 1; errorMeter <= Global.ErrorLoopCount; errorMeter++)
            //                        {
            //                            klog.Error(Generator.Execute(Global.ErrorCharCount));
            //                        }
            //                    }

            //                    klog.Success();
            //                }
            //                catch (Exception e)
            //                {
            //                    klog.Error($"KFlow Exception: {e.ToString()}");
            //                    klog.Failure();
            //                }
            //            }
            //        }
            //    }

            //    KManager.Offline();
            //}

            //#endregion

            var items       = new string[] { "Task1", "Task2", "Task3", "Task4" };
            var tasks       = new Task[items.Length];
            var taskCounter = 0;

            foreach (var item in items)
            {
                tasks[taskCounter] = new Task(() => DynamicLog(item));

                taskCounter++;
            }

            Parallel.ForEach(tasks, (t) => { t.Start(); });
            Task.WaitAll(tasks);

            Console.ReadKey();
        }