public ActionResult EvalJsonAPI(string userToken, string windowType = DefaultEvalWindow, int maxNumPolicies = 5) { if (userToken != ConfigurationManager.AppSettings[ApplicationMetadataStore.AKWebServiceToken]) { return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, "A valid token must be specified.")); } string trainerStatus = string.Empty; try { using (var wc = new TimeoutWebClient()) { var trainerStatusJson = wc.DownloadString(ConfigurationManager.AppSettings[ApplicationMetadataStore.AKTrainerURL] + "/status"); JToken jtoken = JObject.Parse(trainerStatusJson); int numLearnedExamples = (int)jtoken.SelectToken("Stage2_Learn_Total"); trainerStatus = $"Trainer OK. Total learned examples: {numLearnedExamples}"; } } catch (Exception ex) { if (ex.Message.Contains("Unable to connect to the remote server")) { trainerStatus = "Please wait as trainer has not started yet"; } else { new TelemetryClient().TrackException(ex); trainerStatus = "Error getting trainer status, check Application Insights for more details."; } } return(GetEvalData(windowType, maxNumPolicies, trainerStatus)); }
public bool RetrieveCustomLeaderboardList() { try { // The spawnset list must be retrieved first. if (Spawnsets.Count == 0) { App.Instance.ShowError("Could not retrieve custom leaderboard list", "The internal spawnset list is empty. This must be initialized before retrieving the custom leaderboard list."); return(false); } string downloadString = string.Empty; using (TimeoutWebClient client = new TimeoutWebClient(Timeout)) downloadString = client.DownloadString(UrlUtils.ApiGetCustomLeaderboards); CustomLeaderboards = JsonConvert.DeserializeObject <List <CustomLeaderboardBase> >(downloadString); foreach (SpawnsetListEntry entry in Spawnsets) { entry.HasLeaderboard = CustomLeaderboards.Any(l => l.SpawnsetFileName == entry.SpawnsetFile.FileName); } return(true); } catch (WebException ex) { App.Instance.ShowError("Error retrieving custom leaderboard list", $"Could not connect to '{UrlUtils.ApiGetCustomLeaderboards}'.", ex); return(false); } catch (Exception ex) { App.Instance.ShowError("Unexpected error", "An unexpected error occurred.", ex); return(false); } }
public static AppInstallStatus GetInstallStatus(ConnectInfo connectInfo) { using (var client = new TimeoutWebClient()) { client.Credentials = new NetworkCredential(connectInfo.User, connectInfo.Password); string query = string.Format(API_InstallStatusQuery, connectInfo.IP); string statusJSON = client.DownloadString(query); var status = JsonUtility.FromJson <InstallStatus>(statusJSON); if (status == null) { return(AppInstallStatus.Installing); } Debug.LogFormat("Install Status: {0}|{1}|{2}|{3}", status.Code, status.CodeText, status.Reason, status.Success); if (status.Success == false) { Debug.LogError(status.Reason + "(" + status.CodeText + ")"); return(AppInstallStatus.InstallFail); } return(AppInstallStatus.InstallSuccess); } }
public void DownloadStatus() { // Load info from CP xml export TimeoutWebClient web = new TimeoutWebClient(); web.TimeOut = 5000; try { string statusData = web.DownloadString(StatusUrl); // Load xml data into our class XmlDocument doc = new XmlDocument(); doc.LoadXml(statusData); // doc -> xml -> ServerStatus -> Group -> Server XmlNode node = doc.FirstChild.NextSibling.FirstChild.FirstChild; string loginServer = node.Attributes["loginServer"].Value.Trim(); string charServer = node.Attributes["charServer"].Value.Trim(); string mapServer = node.Attributes["mapServer"].Value.Trim(); string woeActive = node.Attributes["woeActive"].Value.Trim(); string playersOnline = node.Attributes["playersOnline"].Value.Trim(); LoginServer = (loginServer == "1"); CharServer = (charServer == "1"); MapServer = (mapServer == "1"); WoeActive = (woeActive == "1"); PlayerCount = int.Parse(playersOnline); } catch { // Failed, assume servers are donw Reset(); } }
private async Task UpdatePlayerbase() { try { var webClient = new TimeoutWebClient { Timeout = 120 }; var response = webClient.DownloadString(PLAYERBASE_URL).Trim(); await _log.LogMessage($"Got the following response when updating playerbase: `{response}`", color : LOG_COLOR); } catch (Exception e) { await _log.LogMessage($"Failed to update playbase!\n{e}", false, color : LOG_COLOR); } }
public bool RetrieveSpawnsetList() { try { Spawnsets.Clear(); Authors.Clear(); string downloadString = string.Empty; using (TimeoutWebClient client = new TimeoutWebClient(Timeout)) downloadString = client.DownloadString(UrlUtils.ApiGetSpawnsets); List <SpawnsetFile> spawnsetFiles = JsonConvert.DeserializeObject <List <SpawnsetFile> >(downloadString); Authors.Add(new AuthorListEntry(SpawnsetListHandler.AllAuthors, spawnsetFiles.Count)); foreach (SpawnsetFile sf in spawnsetFiles) { AuthorListEntry author = new AuthorListEntry(sf.Author, spawnsetFiles.Where(s => s.Author == sf.Author).Count()); if (!Authors.Any(a => a.Name == author.Name)) { Authors.Add(author); } } foreach (SpawnsetFile spawnsetFile in spawnsetFiles) { Spawnsets.Add(new SpawnsetListEntry { SpawnsetFile = spawnsetFile }); } return(true); } catch (WebException ex) { App.Instance.ShowError("Error retrieving spawnset list", $"Could not connect to '{UrlUtils.ApiGetSpawnsets}'.", ex); return(false); } catch (Exception ex) { App.Instance.ShowError("Unexpected error", "An unexpected error occurred.", ex); return(false); } }
private void UpdateBankCodes() { if (this.ListAge < this.options.MaxAge) { return; } // Download list from ČNB site string csv; try { using (var wc = new TimeoutWebClient(this.options.Timeout)) { csv = wc.DownloadString(this.options.ListUrl); } } catch (WebException wex) when(wex.Status == WebExceptionStatus.Timeout && !this.options.ThrowExceptionOnTimeout) { return; } catch (WebException) when(!this.options.ThrowExceptionOnFail) { return; } // Parse the data var lines = csv.Split('\r', '\n'); var list = new List <string>(); foreach (var item in lines) { if (string.IsNullOrEmpty(item)) { continue; } if (Regex.IsMatch(item, @"^\d{4};")) { list.Add(item.Substring(0, 4)); } } this.bankCodes = list; // Set last update time to now this.lastUpdate = DateTime.Now; }
public static AppDetails QueryAppDetails(string baseAppName, ConnectInfo connectInfo) { using (var client = new TimeoutWebClient()) { client.Credentials = new NetworkCredential(connectInfo.User, connectInfo.Password); string query = string.Format(kAPI_PackagesQuery, connectInfo.IP); string appListJSON = client.DownloadString(query); AppList appList = JsonUtility.FromJson <AppList>(appListJSON); for (int i = 0; i < appList.InstalledPackages.Length; ++i) { string appName = appList.InstalledPackages[i].PackageFullName; if (appName.Contains(baseAppName)) { return(appList.InstalledPackages[i]); } } } return(null); }
public static bool IsAppRunning(string baseAppName, ConnectInfo connectInfo) { using (var client = new TimeoutWebClient()) { client.Credentials = new NetworkCredential(connectInfo.User, connectInfo.Password); string query = string.Format(kAPI_ProcessQuery, connectInfo.IP); string procListJSON = client.DownloadString(query); ProcessList procList = JsonUtility.FromJson <ProcessList>(procListJSON); for (int i = 0; i < procList.Processes.Length; ++i) { string procName = procList.Processes[i].ImageName; if (procName.Contains(baseAppName)) { return(true); } } } return(false); }
public static AppDetails QueryAppDetails(string packageFamilyName, ConnectInfo connectInfo) { using (var client = new TimeoutWebClient()) { client.Credentials = new NetworkCredential(connectInfo.User, connectInfo.Password); string query = string.Format(API_PackagesQuery, connectInfo.IP); string appListJSON = client.DownloadString(query); var appList = JsonUtility.FromJson <AppList>(appListJSON); for (int i = 0; i < appList.InstalledPackages.Length; ++i) { string thisAppName = appList.InstalledPackages[i].PackageFamilyName; if (thisAppName.Equals(packageFamilyName, StringComparison.OrdinalIgnoreCase)) { return(appList.InstalledPackages[i]); } } } return(null); }
public static AppInstallStatus GetInstallStatus(ConnectInfo connectInfo) { using (var client = new TimeoutWebClient()) { client.Credentials = new NetworkCredential(connectInfo.User, connectInfo.Password); string query = string.Format(kAPI_InstallStatusQuery, connectInfo.IP); string statusJSON = client.DownloadString(query); InstallStatus status = JsonUtility.FromJson<InstallStatus>(statusJSON); if (status == null) { return AppInstallStatus.Installing; } else if (status.Success == false) { Debug.LogError(status.Reason + "(" + status.CodeText + ")"); return AppInstallStatus.InstallFail; } return AppInstallStatus.InstallSuccess; } }
public static AppDetails QueryAppDetails(string baseAppName, ConnectInfo connectInfo) { using (var client = new TimeoutWebClient()) { client.Credentials = new NetworkCredential(connectInfo.User, connectInfo.Password); string query = string.Format(kAPI_PackagesQuery, connectInfo.IP); string appListJSON = client.DownloadString(query); AppList appList = JsonUtility.FromJson<AppList>(appListJSON); for (int i = 0; i < appList.InstalledPackages.Length; ++i) { string appName = appList.InstalledPackages[i].Name; if (appName.Contains(baseAppName)) { return appList.InstalledPackages[i]; } } } return null; }
public static bool IsAppRunning(string baseAppName, ConnectInfo connectInfo) { using (var client = new TimeoutWebClient()) { client.Credentials = new NetworkCredential(connectInfo.User, connectInfo.Password); string query = string.Format(kAPI_ProcessQuery, connectInfo.IP); string procListJSON = client.DownloadString(query); ProcessList procList = JsonUtility.FromJson<ProcessList>(procListJSON); for (int i = 0; i < procList.Processes.Length; ++i) { string procName = procList.Processes[i].ImageName; if (procName.Contains(baseAppName)) { return true; } } } return false; }
//Send solutionName ,domain name, eod creation date static void Main(String[] args) { String solutionName = args[0]; String eodCreationDate = args[1]; String domainName = args[2]; Console.WriteLine("Solution Name:" + solutionName + " Domain Name:" + domainName + " EOD creation Date is:" + eodCreationDate); const string source_directory = @""; //add the directory path of dll to be injected const string backup = @""; //add directory path location to create back up of dll const string senderfile = @""; //add dll file that needs to be referenced.This can be a dll that runs your own code. const string log_file = @""; //log file path string json; string sourcefile; string source; var sender_method = (dynamic)null; Int32 count = 10; char[] pspearator = { ' ', '/', '.' }; char[] spearator = { ' ', ':', '(', ')' }; Formatter format = new Formatter(); //call the service and get the json with data of files to be injected using (TimeoutWebClient wc = new TimeoutWebClient()) { json = wc.DownloadString(""); // This block just downloads a file containg method names which need to be injected. } RootObject r = JsonConvert.DeserializeObject <RootObject>(json); //load ATSsenderfile AssemblyDefinition Sender_assembly = AssemblyDefinition.ReadAssembly(senderfile, new ReaderParameters { ReadWrite = true }); var Sender_module = Sender_assembly.MainModule; TypeDefinition[] sender_types = Sender_module.Types.ToArray(); var resolver = new DefaultAssemblyResolver(); resolver.AddSearchDirectory(source_directory); //load refrence to the send fucntion of sender dll foreach (var type in sender_types) { foreach (var method in type.Methods) { if (method.Name == "send") { sender_method = method; } } } foreach (Project projects in r.projects) { Console.WriteLine("Instrumentation Started......"); sourcefile = source_directory + projects.endStateName; source = projects.endStateName; if (File.Exists(sourcefile)) { //create backup of the source DLL File.Copy(sourcefile, backup + Path.GetFileName(source)); // handle exception dude to this folder and files inside // after coping the dll is renamed with diffrent casing. //load DLL reference AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(sourcefile, new ReaderParameters { ReadWrite = true, AssemblyResolver = resolver }); var module = assembly.MainModule; TypeDefinition[] types = module.GetTypes().ToArray(); foreach (Files dll in projects.files) // this loop is used to inject the dll reference in the start of a method and pass the method name and the varible name and type used in the method. { foreach (class_name clas in dll.classes) { //gives class name foreach (var type in types) { string[] splitClassName = type.ToString().Split('.'); string clsName = splitClassName[splitClassName.Length - 1]; string clsNameFromFile = ""; //This change is to support instrumentation both before or after separation of classname and namespace if (clas.className != null) { string[] splitClassNameFromFile = clas.className.Split('.'); clsNameFromFile = splitClassNameFromFile[splitClassNameFromFile.Length - 1]; } //check if if we require this class to be injected if (clsName == clsNameFromFile) { Console.WriteLine(type.ToString()); foreach (var method in type.Methods) { try { string methodname = method.FullName.ToString(); Console.WriteLine(methodname); //Ignore setters and getters if (!method.IsGetter && !method.IsSetter) { string variable = ""; //find all arguments foreach (var Param in method.Parameters) { string parameter_type = Param.ParameterType.ToString(); //In case of generic this garbage value gets appended parameter_type = parameter_type.Replace("`1", ""); string variable_type = ""; //This implementation is specfic to Generic in variable type e.g Memlib<MainModule.usrdefMainOrder> nSourceTable if (parameter_type.Contains("<") && parameter_type.Contains(">")) { String[] list = parameter_type.Split('<'); string pre = list[0]; string post = list[1]; String[] preList = pre.Split(pspearator, count); pre = preList[preList.Count() - 1]; String[] postList = post.Split(pspearator, count); post = postList[postList.Count() - 1]; variable_type = pre + " <" + post; } else { String[] parameter_list = parameter_type.Split(pspearator, count); variable_type = parameter_list[parameter_list.Count() - 1]; } variable_type = variable_parser(variable_type); var param_name = Param.Name; if (Param.HasConstant) { param_name = param_name + " = " + Param.Constant; } variable_type = variable_type + " " + param_name + ", "; variable = variable + variable_type; } // Removing comma and space if (variable.Length > 2) { variable = variable.Remove(variable.Length - 1); variable = variable.Remove(variable.Length - 1); } String[] strlist = methodname.Split(spearator, count); string final; string signature = format.Format("(" + variable + ")"); //string signature = "(" + variable + ")"; string[] nameSpaceAndClassName = type.ToString().Split('.'); string clazz = nameSpaceAndClassName[nameSpaceAndClassName.Length - 1]; string nameSpace_ = type.ToString().Replace("." + clazz, ""); final = strlist[3] + ';' + type.ToString() + ';' + dll.fileName + ';' + source + ";" + signature; string methodName = strlist[3]; // for constructors final = methodName + ';' + clazz + ';' + nameSpace_ + ';' + dll.fileName + ';' + source + ";" + signature; //injection log File.AppendAllText(log_file, final + Environment.NewLine); //load IL processor var processor2 = method.Body.GetILProcessor(); var call = processor2.Create(OpCodes.Call, method.Module.Import(sender_method)); var ldstr = processor2.Create(OpCodes.Ldstr, final); //Inject the code processor2.InsertBefore(method.Body.Instructions[0], ldstr); processor2.InsertAfter(method.Body.Instructions[0], call); //Console.WriteLine("Successfully Injected:" + source); Console.WriteLine("-----------------------------------------------------------------------------------------------"); } } catch (Exception e) { File.AppendAllText(log_file, e + Environment.NewLine); } } //before the try } } } } //write back the new Injected source file assembly.MainModule.AssemblyReferences.Add(AssemblyNameReference.Parse(Sender_assembly.FullName)); assembly.Write(); Console.WriteLine("--- Finished Injecting DLL ---"); } else { Console.WriteLine(""); } //Console.WriteLine(sourcefile + " doesnt exsit in cerner directory"); } Console.ReadLine(); }