// Special MySQL actions public void Ping(GingerAction GingerAction, string aa) // !!!!!!!! aa { MySqlConnection MySqlConnection = new MySqlConnection(); bool b = MySqlConnection.Ping(); GingerAction.AddOutput("Ping", b); }
private void ParseCommandOutput() { try { //Error if (!string.IsNullOrEmpty(mCommandOutputErrorBuffer.Trim().Trim('\n'))) { GingerAction.AddError(string.Format("Console Errors: \n{0}", mCommandOutputErrorBuffer)); } //Output values Regex rg = new Regex(@"Microsoft.*\n.*All rights reserved."); string stringToProcess = rg.Replace(mCommandOutputBuffer, ""); string[] values = stringToProcess.Split('\n'); foreach (string dataRow in values) { if (dataRow.Length > 0) // Ignore empty lines { string param; string value; int signIndex = -1; if (string.IsNullOrEmpty(mDelimeter)) { signIndex = dataRow.IndexOf("="); } else { signIndex = dataRow.IndexOf(mDelimeter); } if (signIndex > 0) { param = dataRow.Substring(0, signIndex); //the rest is the value value = dataRow.Substring(param.Length + 1); GingerAction.AddOutput(param, value, "Console Output"); } } } } catch (Exception ex) { GingerAction.AddError(string.Format("Failed to parse all command console outputs, Error:'{0}'", ex.Message)); } }
public override void RunAction(GingerAction act) { switch (act.ID) { case cStart: if (SV != null) { SV.MockProviderService.Stop(); } string port = "0"; if (!Boolean.Parse(act.GetOrCreateParam("DynamicPort").Value.ToString())) { port = act.GetOrCreateParam("Port").GetValueAsString(); } SV = new ServiceVirtualization(int.Parse(port)); act.ExInfo = "Mock Service Started: " + SV.MockProviderServiceBaseUri; break; case cStop: if (SV == null) { act.Error += "Error: Service Virtualization not started yet"; return; } SV.MockProviderService.Stop(); SV = null; act.ExInfo += "Mock Server stopped"; break; case cLoadInteractionsFile: if (SV == null) { act.Error += "Error: Service Virtualization not started yet"; return; } string s = act.GetOrCreateParam("FileName").GetValueAsString(); if (s.StartsWith("~")) { s = Path.GetFullPath(s.Replace("~", act.SolutionFolder)); } if (File.Exists(s)) { int count = SV.LoadInteractions(s); act.ExInfo += "Interaction file loaded: '" + s + "', " + count + " Interactions loaded"; act.AddOutput("Interaction Loaded", count + ""); } else { act.Error += "Interaction file not found - " + s; } break; case cLoadInteractionsFolder: if (SV == null) { act.Error += "Error: Service Virtualization not started yet"; return; } break; case cClearInteractions: if (SV == null) { act.Error += "Error: Service Virtualization not started yet"; return; } SV.ClearInteractions(); act.ExInfo += "Interactions cleared"; break; case cAddInteraction: if (SV == null) { act.Error += "Error: Service Virtualization not started yet"; return; } //TODO: get it from the edit page ProviderServiceInteraction PSI = new ProviderServiceInteraction(); PSI.ProviderState = act.GetOrCreateParam("ProviderState").GetValueAsString(); PSI.Description = act.GetOrCreateParam("Description").GetValueAsString(); PSI.Request = new ProviderServiceRequest(); string HTTPType = act.GetOrCreateParam("RequestType").GetValueAsString(); switch (HTTPType) { case "Get": PSI.Request.Method = HttpVerb.Get; break; case "Post": PSI.Request.Method = HttpVerb.Post; break; case "PUT": PSI.Request.Method = HttpVerb.Put; break; //TODO: add all the rest and include default for err } PSI.Request.Path = act.GetOrCreateParam("Path").GetValueAsString(); Dictionary <string, string> d = new Dictionary <string, string>(); d.Add("Accept", "application/json"); //TODO: fixme PSI.Request.Headers = d; PSI.Response = new ProviderServiceResponse(); PSI.Response.Status = 200; //TODO: fixme Dictionary <string, string> r = new Dictionary <string, string>(); r.Add("Content-Type", "application/json; charset=utf-8"); //TODO: fixme PSI.Response.Headers = r; PSI.Response.Body = act.GetOrCreateParam("ResposneBody").GetValueAsString(); SV.AddInteraction(PSI); act.ExInfo += "Interaction added"; break; case cSaveInteractions: SV.SaveInteractions(); act.ExInfo += "Interactions saved to file"; // TODO: add file name to ex info break; default: act.Error += "Unknown PlugIn action ID - " + act.ID; break; } }
public void Echo(GingerAction act, string text) { Console.WriteLine("Echo"); act.AddOutput("echo", text); act.AddExInfo("Echo - " + text); }