} // END METHOD /// <summary> /// Asynchonous Soap Call to get the ECGridOS SessionInfo /// Uses private variable for APIKey - must be set prior to calling /// Converts EAP pattern into TAP pattern to use async/await from ECGridAPIAsync Class /// </summary> /// <param name="APIKey">String APIKey/SessionID in GUID Format for ECGridOS</param> /// <returns>net.ecgridos.SessionInfo Class: User Session information</returns> public async Task <ECGridOS_API.SessionInfo> SessionInfoAsync(string APIKey) { try { using (ECGridOS_API.ECGridOSAPIv3 ECGridOS = new ECGridOS_API.ECGridOSAPIv3()) { // Check to make sure it is in valid Guid Format if (IsValidGUID(_apiKey)) { // Make the call and return the results var AsyncTask = await ECGridAPIAsync.SessionInfoAsync(ECGridOS, APIKey); return(AsyncTask.Result); } else { throw new Exception("Invalid GUID API Key"); } } } catch (SoapException SoapEx) { // SOAP Exceptions Console.WriteLine(ECGridAPI.ShowSoapError(SoapEx)); return(null); } } // END METHOD
} // END METHOD /// <summary> /// Synchonous Soap Call to get the ECGridOS SessionInfo /// </summary> /// <param name="APIKey">String APIKey/SessionID in GUID Format for ECGridOS</param> /// <returns>net.ecgridos.SessionInfo Class: User Session information</returns> public ECGridOS_API.SessionInfo SessionInfo(string APIKey) { try { using (ECGridOS_API.ECGridOSAPIv3 ECGridOS = new ECGridOS_API.ECGridOSAPIv3()) { // Check to make sure it is in valid Guid Format if (IsValidGUID(APIKey)) { // Make the call and return the results return(ECGridOS.WhoAmI(APIKey)); } else { throw new Exception("Invalid GUID API Key"); } } } catch (SoapException SoapEx) { // SOAP Exceptions Console.WriteLine(ECGridAPI.ShowSoapError(SoapEx)); return(null); } } // END METHOD
/// <summary> /// Synchonous Soap Call to get the ECGridOS Version /// </summary> /// <returns>String: ECgridOS Version</returns> public string APIVersion() { try { using (ECGridOS_API.ECGridOSAPIv3 ECGridOS = new ECGridOS_API.ECGridOSAPIv3()) { // Make the call and return the results return(ECGridOS.Version()); } } catch (SoapException SoapEx) { // SOAP Exceptions return(ECGridAPI.ShowSoapError(SoapEx)); } } // END METHOD
} // END METHOD /// <summary> /// Asynchonous Soap Call to get the ECGridOS Version /// Converts EAP pattern into TAP pattern to use async/await from ECGridAPIAsync Class /// </summary> /// <returns>Task string: ECGridOS Version</returns> public async Task <string> APIVersionAsync() { try { using (ECGridOS_API.ECGridOSAPIv3 ECGridOS = new ECGridOS_API.ECGridOSAPIv3()) { // Make the call and await the results to return var AsyncTask = await ECGridAPIAsync.VersionAsync(ECGridOS); return(AsyncTask.Result); } } catch (SoapException SoapEx) { // SOAP Exceptions return(ECGridAPI.ShowSoapError(SoapEx)); } } // END METHOD
static void Main(string[] args) { try { #region Setup Console Window SafeNativeMethods.SetWindowPos(MyConsole, 0, 10, 10, 0, 0, SWP_NOSIZE); Console.Title = "ECGridOS .NET Framework 4.6 Examples"; Console.WindowHeight = Console.WindowHeight = 50; Console.WindowWidth = Console.WindowWidth = 100; #endregion // Diagnostic Tools Stopwatch stopW = new Stopwatch(); // Replace this with your API Key GUID in the App.config file or somewhere Secure. string MyAPIKey = ConfigurationManager.AppSettings["APIKey"].ToString(); // Instantiate ECGridOSAPI Class & Set Your APIKey in the Client ECGridAPI ECGrid = new ECGridAPI(MyAPIKey); ECGridOS_API.ECGridOSAPIv3 ECGridClient = new ECGridOS_API.ECGridOSAPIv3(); /* * Example calls from the ECGridAPI Class * Includes SOAP Calls with Web Reference above as well as WebRequest GET Sync and Async calls */ // Synchronous SOAP Version Call stopW.Start(); var version = ECGrid.APIVersion(); stopW.Stop(); Console.WriteLine($"ECGridOS Version From SOAP Synchronous: {version}"); Console.WriteLine($"Synchronous SOAP Time in Seconds: {stopW.Elapsed.TotalSeconds}{Environment.NewLine}"); // Asynchronous SOAP Version Call stopW.Restart(); var versionAsync = ECGrid.APIVersionAsync().Result; stopW.Stop(); Console.WriteLine($"ECGridOS Version From SOAP Asynchronous: {versionAsync}"); Console.WriteLine($"Asynchronous SOAP Time in Seconds: {stopW.Elapsed.TotalSeconds}{Environment.NewLine}"); // Synchronous Http GET Version Call stopW.Restart(); var versionGet = ECGrid.APIVersionHttpGet(); stopW.Stop(); Console.WriteLine($"ECGridOS Version From Http GET Synchronous: {versionGet}"); Console.WriteLine($"Syncronous Http GET Time in Seconds: {stopW.Elapsed.TotalSeconds}{Environment.NewLine}"); // Asynchronous Http GET Version Call stopW.Restart(); var versionAsyncGet = ECGrid.APIVersionHttpGetAsync().Result; stopW.Stop(); Console.WriteLine($"ECGridOS Version From Http GET Asynchronous: {versionAsyncGet}"); Console.WriteLine($"Asyncronous Http GET Time in Seconds: {stopW.Elapsed.TotalSeconds}{Environment.NewLine}"); // Asynchronous Http GET to XML Version Call stopW.Restart(); var versionAsyncGetXML = ECGrid.APIVersionHttpGetAsyncXML().Result; stopW.Stop(); Console.WriteLine($"ECGridOS Version From Http GET To XML Asynchronous: {versionAsyncGetXML?.ToString()}"); Console.WriteLine($"Asyncronous Http GET To XML Time in Seconds: {stopW.Elapsed.TotalSeconds}{Environment.NewLine}"); // Asynchronous Http GET to JSON Version Call stopW.Restart(); var versionAsyncGetJSON = ECGrid.APIVersionHttpGetAsyncJSON().Result; stopW.Stop(); Console.WriteLine($"ECGridOS Version From Http GET To JSON Asynchronous: {versionAsyncGetJSON?.ToString()}"); Console.WriteLine($"Asyncronous Http GET To JSON Time in Seconds: {stopW.Elapsed.TotalSeconds}{Environment.NewLine}"); Console.WriteLine($"{new String('-', 20)}{Environment.NewLine}"); // Synchronous SOAP WhoAmI/SessionInfo Call stopW.Restart(); var sessionInfo = ECGrid.SessionInfo(); stopW.Stop(); Console.WriteLine($"ECGrid SessionInfo UserID From SOAP Synchronous: {sessionInfo?.UserID}"); Console.WriteLine($"Synchronous Time in Seconds: {stopW.Elapsed.TotalSeconds}{Environment.NewLine}"); // Asynchronous SOAP WhoAmI/SessionInfo Call stopW.Restart(); var sessionInfoAsync = ECGrid.SessionInfoAsync().Result; stopW.Stop(); Console.WriteLine($"ECGrid SessionInfo UserID From SOAP Asynchronous: {sessionInfoAsync?.UserID}"); Console.WriteLine($"Asynchronous Time in Seconds: {stopW.Elapsed.TotalSeconds}{Environment.NewLine}"); // Synchronous Http GET WhoAmI/SessionInfo Call stopW.Restart(); var sessionInfoGet = ECGrid.SessionInfoHttpGet(); stopW.Stop(); Console.WriteLine($"ECGrid SessionInfo UserID From Http GET Sync to Sessioninfo Object: {sessionInfoGet?.UserID}"); Console.WriteLine($"Synchronous Http GET to Object Time in Seconds: {stopW.Elapsed.TotalSeconds}{Environment.NewLine}"); // Asynchronous Http GET WhoAmI/SessionInfo Call stopW.Restart(); var sessionInfoGetAsync = ECGrid.SessionInfoHttpGetAsync().Result; stopW.Stop(); Console.WriteLine($"ECGrid SessionInfo UserID From Http GET Async to Sessioninfo Object: {sessionInfoGetAsync?.UserID}"); Console.WriteLine($"Asyncronous Http GET to Object Time in Seconds: {stopW.Elapsed.TotalSeconds}{Environment.NewLine}"); // Asynchronous Http GET to XML WhoAmI/SessionInfo Call stopW.Restart(); var sessionInfoGetAsyncXML = ECGrid.SessionInfoHttpGetAsyncXML().Result; stopW.Stop(); Console.WriteLine($"ECGrid SessionInfo UserID From Http GET Async to XML: {sessionInfoGetAsyncXML?.ToString()}"); Console.WriteLine($"Asyncronous Http GET to XML Time in Seconds: {stopW.Elapsed.TotalSeconds}{Environment.NewLine}"); // Asynchronous Http GET to JSON WhoAmI/SessionInfo Call stopW.Restart(); var sessionInfoGetAsyncJSON = ECGrid.SessionInfoHttpGetAsyncJSON().Result; stopW.Stop(); Console.WriteLine($"ECGrid SessionInfo UserID From Http GET Async to JSON: {sessionInfoGetAsyncJSON?.ToString()}"); Console.WriteLine($"Asyncronous Http GET to JSON Time in Seconds: {stopW.Elapsed.TotalSeconds}{Environment.NewLine}"); Console.WriteLine($"{new String('-', 20)}{Environment.NewLine}"); } catch (Exception ex) { // Everything Else Console.WriteLine("Unhandled Exception: " + ex.ToString()); } // End Examples Console.WriteLine("Press any Key to quit..."); Console.ReadKey(); } // END MAIN