/// <summary> /// Deserializes the yaml. /// </summary> /// <param name="tr">The tr.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> public static DTO_Header DeserializeYAML(TextReader tr) { try { if (tr != null) { var deserializer = new DeserializerBuilder() .WithNodeDeserializer(inner => new ValidatingNodeDeserializer(inner), s => s.InsteadOf <ObjectNodeDeserializer>()) .Build(); DTO_Header header = deserializer.Deserialize <DTO_Header>(tr); return(header); } else { throw new ArgumentNullException(NameOf.nameof(() => tr), "The textreader object must not be null."); } } catch (Exception) { throw; } }
/// <summary> /// Wakes up website with yaml. /// </summary> /// <param name="filesLst">The files.</param> public static void WakeUpWebsiteWithYAML(List <String> filesLst) { // Setup parallel breaker variables. int currentThreadId = 0; object lockCurrentThread = new object(); // Setup parallel breaker variables. int currentSubThreadId = 0; object lockCurrentSubThread = new object(); // Parse YAML to Object. Parallel.ForEach(filesLst, (file) => { // Lock the current thread to wait for the previous threads to finish, thus bringing order. int thisCurrentThread = 0; lock (lockCurrentThread) { thisCurrentThread = currentThreadId; currentThreadId++; } // Parse YAML File and call method to wake up the website. try { using (StreamReader reader = File.OpenText(file)) { Log.Info("Validating file : " + Path.GetFileName(file)); // Deserialize YAML to object, validation is also applied. DTO_Header header = CYamlParser.Deserializer.DeserializeYAML(reader); Parallel.ForEach(header.WebSiteLst, (website) => { // Lock the current thread to wait for the previous threads to finish, thus bringing order. int thisCurrentSubThread = 0; lock (lockCurrentSubThread) { thisCurrentSubThread = currentSubThreadId; currentSubThreadId++; } Log.Info(website.Name + " waking up..."); // Stopwatch Stopwatch sw = new Stopwatch(); sw.Start(); wakeUpWebsite(website.Name, website.Url, website.PortLst); sw.Stop(); Log.Info(website.Name + " now awake... (took " + sw.Elapsed.Seconds + " seconds)"); }); } } catch (Exception ex) { if (!String.IsNullOrEmpty(ex.InnerException.Message)) { Log.Error("Error on File: " + Path.GetFileName(file) + " : " + ex.InnerException.Message); } else { Log.Error("Error on File: " + Path.GetFileName(file) + " : " + ex.ToString()); } } }); }
/// <summary> /// Wakes up website with yaml. /// </summary> /// <param name="filesLst">The files.</param> public static void CheckUpWebsiteWithYAML(List<String> filesLst) { //// Setup parallel breaker variables. //int currentThreadId = 0; //object lockCurrentThread = new object(); //// Setup parallel breaker variables. //int currentSubThreadId = 0; //object lockCurrentSubThread = new object(); // Parse YAML to Object. //Parallel.ForEach(filesLst, (file) => foreach(var file in filesLst) { // Lock the current thread to wait for the previous threads to finish, thus bringing order. //int thisCurrentThread = 0; //lock (lockCurrentThread) //{ // thisCurrentThread = currentThreadId; // currentThreadId++; //} // Parse YAML File and call method to wake up the website. try { using (StreamReader reader = File.OpenText(file)) { Log.Info("Validating file : " + Path.GetFileName(file)); // Deserialize YAML to object, validation is also applied. DTO_Header header = CYamlParser.Deserializer.DeserializeYAML(reader); Log.Info("File OK. Starting VIP Check."); //Parallel.ForEach(header.WebSiteLst, (website) => foreach (var website in header.WebSiteLst) { // Lock the current thread to wait for the previous threads to finish, thus bringing order. //int thisCurrentSubThread = 0; //lock (lockCurrentSubThread) //{ // thisCurrentSubThread = currentSubThreadId; // currentSubThreadId++; //} checkUpWebsite(website.Name, website.Url, website.PortLst); } } } catch (Exception ex) { if (ex.InnerException != null && !String.IsNullOrEmpty(ex.InnerException.Message)) { Log.Error("Error on File: " + Path.GetFileName(file) + " : " + ex.InnerException.Message); } else { Log.Error("Error on File: " + Path.GetFileName(file) + " : " + ex.ToString()); } } } }