Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Commit

Permalink
Fix Issue #21 - Other Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ari Madian committed Dec 4, 2018
1 parent 67941e3 commit 6db9ac9
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 36 deletions.
4 changes: 2 additions & 2 deletions AlexaComp/AlexaCompSERVER.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static void DeserializeRequest(string data, Stopwatch timer) {
else {
Clog("Auth Valid.");
req.ProcessRequest(req);
StopServer();
//StopServer();
}
}

Expand All @@ -119,7 +119,7 @@ public static void StopServer() {
* @param json - The json string to send back to the lambda instance, usually sent from a request object.
* @param customStream - If defined, sends the response over a provided network stream instead of the most current stream.
*/
public static void SendToLambda(string json, NetworkStream customStream) {
public static void SendToLambda(string json, NetworkStream customStream = null) {
Clog("Sending Back To Lambda - " + json);
byte[] message = Encoding.UTF8.GetBytes(json);
int messageLength = Encoding.UTF8.GetBytes(json).Length;
Expand Down
17 changes: 10 additions & 7 deletions AlexaComp/Core/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,26 @@ public Request() {
processRequest(this);
}*/

public Request(string AUTH_, string COMMAND_, string PRIMARY_ = "", string SECONDARY_ = "", string TERTIARY_ = "") {
AUTH = AUTH_;
COMMAND = COMMAND_;
PRIMARY = PRIMARY_;
SECONDARY = SECONDARY_;
TERTIARY = TERTIARY_;
ProcessRequest(this);
public Request(string AUTH, string COMMAND, string PRIMARY = "", string SECONDARY = "", string TERTIARY = "") {
this.AUTH = AUTH;
this.COMMAND = COMMAND;
this.PRIMARY = PRIMARY;
this.SECONDARY = SECONDARY;
this.TERTIARY = TERTIARY;
}
#endregion

#region Methods
public void LogTimeElapsed() {
Clog("Request Constructed");
sw.Stop();
Clog("Request Completed, Time Elapsed(ms) - " + sw.ElapsedMilliseconds.ToString());
}

public void ProcessRequest(Request req) {
if (AUTH != "testAuth") {
AlexaCompSERVER.StopServer();
} else { Clog("IS Test Request"); }
switch (req.COMMAND) {
case "LAUNCH":
Launch unused = new Launch(req.PRIMARY);
Expand Down
12 changes: 5 additions & 7 deletions AlexaComp/Core/RequestTypes/AudioCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@ public class AudioCommand : AlexaCompCore {

#region Properties
private string command;

private int setVolAmt;

#endregion

#region Constructors
public AudioCommand(string command_, string setVolAmt_ = "0") {
command = command_;
setVolAmt = Convert.ToInt32(setVolAmt_);
public AudioCommand(string command, string setVolAmt = "0") {
this.command = command;
this.setVolAmt = Convert.ToInt32(setVolAmt);

try{
process();
} catch (Exception e) {
Clog(e.ToString());
Response res = new Response(false, "Oops! Something went wrong...");
}
}
#endregion

#region Methods
public void process() {
switch (this.command) {
switch (command) {
case "PLAYPAUSE":
AudioController.TogglePlayPause();
break;
Expand Down Expand Up @@ -55,7 +54,6 @@ public void process() {
AudioController.ToggleMute();
break;
}
Response res = new Response(true, "Done!");
}
#endregion
}
Expand Down
2 changes: 0 additions & 2 deletions AlexaComp/Core/RequestTypes/CompStat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ namespace AlexaComp.Core.Requests {
public class CompStat : AlexaCompCore {

private string part;

private string stat;

private string TERTIARY;

public CompStat(string part_, string stat_, string TERTIARY_) {
Expand Down
11 changes: 1 addition & 10 deletions AlexaComp/Core/RequestTypes/Launch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,31 @@ public class Launch : AlexaCompCore {
private string programName;

public Launch(string programName_) {
Clog("LaunchCommand Constructed");
programName = programName_;
process();
}

public void process() {
if (programName == "SHUTDOWN") {
AlexaCompSERVER.StopServer();
Process.Start("shutdown", "/s /t .5");
}

// For starting a
try {
string programPath = GetProgramPath(programName);
Clog("ProgramPath - " + programPath);
Clog("req Program - " + programName);
Process.Start(GetProgramPath(programName));
Clog("Program Launched");
Response res = new Response(true, "Program Launched!", "", "");
AlexaCompSERVER.StopServer(); // Restart Server to Handle Next Request
}
catch (NullReferenceException) {
Clog("NullReferenceException caught during attempt to launch program, " +
"null most likely returned from GetProgramPath.");
Response res = new Response(false, "");
AlexaCompSERVER.StopServer();
}
catch (System.ComponentModel.Win32Exception e) {
Clog("Win32Exception Caught during attempt to launch program " + e.Message);
Response res = new Response(false, "");
AlexaCompSERVER.StopServer();
}catch (InvalidOperationException e) {
Clog("InvalidOperationException Caught during attempt to launch program " + e.Message);
Response res = new Response(false, "");
AlexaCompSERVER.StopServer();
}
}

Expand Down
5 changes: 4 additions & 1 deletion AlexaComp/Core/RequestTypes/OpenDevTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

namespace AlexaComp.Core.Requests {

public class OpenDevTools {
public class OpenDevTools : AlexaCompCore {

public OpenDevTools(){
Clog("OpenDevTools Constructed");
process();
}

public void process() {
Thread AdvancedSettingsThread = new Thread(AdvancedSettingsForm.startAdvToolsThread) {
Name = "AdvancedSettingsThread"
};
Clog("Starting Window...");
AdvancedSettingsThread.Start();
Clog("Window Started");
}
}
}
13 changes: 6 additions & 7 deletions AlexaComp/Core/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ class Response : AlexaCompCore {
#endregion

#region Constructors
public Response(bool passorfail_, string message_, string primary_ = "", string secondary_ = "") {
passorfail = passorfail_;
message = message_;
primary = primary_;
secondary = secondary_;

public Response(bool passorfail, string message, string primary = "", string secondary = "") {
this.passorfail = passorfail;
this.message = message;
this.primary = primary;
this.secondary = secondary;
json = Newtonsoft.Json.JsonConvert.SerializeObject(this);
Console.WriteLine(json);
}
Expand All @@ -31,7 +30,7 @@ public void SendResponse(System.Net.Sockets.NetworkStream customStream) {
AlexaCompSERVER.SendToLambda(json, customStream);
}
else {
AlexaCompSERVER.SendToLambda(json, null);
AlexaCompSERVER.SendToLambda(json);
}
}
#endregion
Expand Down

0 comments on commit 6db9ac9

Please sign in to comment.