/// <summary> /// This method will set up the ShipManifest object and wrap all the methods/functions /// </summary> /// <returns> /// Bool indicating success of call /// </returns> public static Boolean InitSMWrapper() { try { //reset the internal objects _SMWrapped = false; actualSM = null; ShipManifestAPI = null; LogFormatted_DebugOnly("Attempting to Grab ShipManifest Types..."); //find the base type SMType = getType("ShipManifest.SMAddon"); if (SMType == null) { return(false); } LogFormatted("ShipManifest Version:{0}", SMType.Assembly.GetName().Version.ToString()); //now the KerbalInfo Type TransferCrewType = getType("ShipManifest.Process.TransferCrew"); if (TransferCrewType == null) { return(false); } //now grab the running instance LogFormatted_DebugOnly("Got Assembly Types, grabbing Instance"); try { actualSM = SMType.GetField("Instance", BindingFlags.Public | BindingFlags.Static).GetValue(null); } catch (Exception) { LogFormatted("No Instance found - most likely you have an old ShipManifest installed"); return(false); } if (actualSM == null) { LogFormatted("Failed grabbing SMAddon Instance"); return(false); } //If we get this far we can set up the local object and its methods/functions LogFormatted_DebugOnly("Got Instance, Creating Wrapper Objects"); ShipManifestAPI = new SMAPI(actualSM); _SMWrapped = true; return(true); } catch (Exception ex) { LogFormatted("Unable to setup InitSMrapper Reflection"); LogFormatted("Exception: {0}", ex); _SMWrapped = false; return(false); } }
/// <summary> /// This method will set up the ShipManifest object and wrap all the methods/functions /// </summary> /// <returns> /// Bool indicating success of call /// </returns> public static Boolean InitSMWrapper() { try { //reset the internal objects _SMWrapped = false; actualSM = null; ShipManifestAPI = null; LogFormatted("Attempting to Grab ShipManifest Types..."); //find the base type SMType = AssemblyLoader.loadedAssemblies .Select(a => a.assembly.GetExportedTypes()) .SelectMany(t => t) .FirstOrDefault(t => t.FullName == "ShipManifest.SMAddon"); if (SMType == null) { return false; } LogFormatted("ShipManifest Version:{0}", SMType.Assembly.GetName().Version.ToString()); //now the KerbalInfo Type TransferCrewType = AssemblyLoader.loadedAssemblies .Select(a => a.assembly.GetExportedTypes()) .SelectMany(t => t) .FirstOrDefault(t => t.FullName == "ShipManifest.Process.TransferCrew"); if (TransferCrewType == null) { return false; } //now grab the running instance LogFormatted("Got Assembly Types, grabbing Instance"); try { actualSM = SMType.GetField("Instance", BindingFlags.Public | BindingFlags.Static).GetValue(null); } catch (Exception) { LogFormatted("No Instance found - most likely you have an old ShipManifest installed"); return false; } if (actualSM == null) { LogFormatted("Failed grabbing SMAddon Instance"); return false; } //If we get this far we can set up the local object and its methods/functions LogFormatted("Got Instance, Creating Wrapper Objects"); ShipManifestAPI = new SMAPI(actualSM); _SMWrapped = true; return true; } catch (Exception ex) { LogFormatted("Unable to setup InitSMrapper Reflection"); LogFormatted("Exception: {0}", ex); _SMWrapped = false; return false; } }
public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) { string data = inputData.ReadToEnd(); // this is where the POST requests are handled, regardless of the actual URL // step 1: find out which SMAPI method is called by taking a look at the SOAPACTION Header if (p.httpHeaders.ContainsKey("SOAPACTION")) { // we got a SOAPACTION key, now retrieve it String rawSOAPACTION = (String)p.httpHeaders ["SOAPACTION"]; // the SOAPACTION header will be in this format: // SOAPACTION: "http://www.sonos.com/Services/1.1#$command" // // we only have to filter it for the #$command part String SOAPACTION = rawSOAPACTION.Remove(0, rawSOAPACTION.LastIndexOf("#") + 1); SOAPACTION = SOAPACTION.Remove(SOAPACTION.Length - 1); //ConsoleOutputLogger.WriteLine (SOAPACTION.ToUpper ()); String SMAPIAnswer = ""; switch (SOAPACTION.ToUpper()) { case "GETLASTUPDATE": //ConsoleOutputLogger.WriteLine ("GetLastUpdate called"); SMAPIAnswer = SMAPI.GetLastUpdate(xsnCurrentData, data); break; case "GETMETADATA": //ConsoleOutputLogger.WriteLine("getMetadata called"); SMAPIAnswer = SMAPI.getMetadata(xsnCurrentData, data); break; case "GETMEDIAMETADATA": //ConsoleOutputLogger.WriteLine ("getMediaMetadata called"); SMAPIAnswer = SMAPI.getMediaMetadata(xsnCurrentData, data); break; case "GETMEDIAURI": //ConsoleOutputLogger.WriteLine ("getMediaURI called"); SMAPIAnswer = SMAPI.getMediaURI(xsnCurrentData, data); break; default: //ConsoleOutputLogger.WriteLine ("Unknown: " + SOAPACTION); break; } if (SMAPIAnswer.Length > 0) { // we got an answer from the SMAPI handlers, pipe it out p.writeSuccess("Content-Type: text/xml; charset=utf-8"); p.outputStream.WriteLine(SMAPIAnswer); } else { p.writeFailure(); } } else { p.writeFailure(); } }