void SendToDataStore(string store) { if (CrestronDataStoreStatic.SetLocalStringValue("Local_String", store) != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.ConsoleCommandResponse("Error Storing String"); } }
void DsDel(string s) { if (CrestronDataStoreStatic.SetLocalStringValue("apikey", null) != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.PrintLine("Error removing API key"); } }
/// <summary> /// resets the datastore /// </summary> public static void ResetDataStore() { if (CrestronDataStoreStatic.clearLocal("apikey") != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.PrintLine("Error removing API key"); } }
void SendToDataStore(string store) { if (CrestronDataStoreStatic.SetGlobalStringValue("Local String", store) != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.PrintLine("Error SendToDataStore: "); } }
void SetIsValid(bool isValid) { IsValid = isValid; CrestronDataStoreStatic.SetGlobalBoolValue("MockLicense", isValid); Debug.Console(0, "Mock License is{0} valid", IsValid ? "" : " not"); LicenseIsValid.FireUpdate(); }
/// <summary> /// registers with bridge, authorizes a user based on API key from the pairing /// </summary> public static void Register() { CrestronConsole.PrintLine("registering with bridge..."); try { _url = string.Format("http://{0}/api", BridgeIp); _cmd = "{\"devicetype\":\"my_hue_app#crestron\"}"; _response = HttpConnect.Instance.Request(_url, _cmd, Crestron.SimplSharp.Net.Http.RequestType.Post); if (_response.Contains("link button not pressed")) { Authorized = false; CrestronConsole.PrintLine("Registration incomplete press button and retry..."); } else if (_response.Contains("username")) { Authorized = true; var data = JArray.Parse(_response); BridgeApi = (String)data[0]["success"]["username"]; //CrestronConsole.PrintLine("API key is {0}",BridgeApi); if (CrestronDataStoreStatic.SetLocalStringValue("apikey", BridgeApi) != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.PrintLine("error storing apikey"); } CrestronConsole.PrintLine("Bridge registration complete"); } } catch (Exception e) { CrestronConsole.PrintLine("Exception is {0}", e); } }
public static string Authorize(string username, string password) { try { string authToken = string.Empty; usr = username; pass = password; if (CrestronDataStoreStatic.GetLocalStringValue("authToken", out authToken) != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { if (usr.Length > 0 && pass.Length > 0) { using (HttpsClient authServer = new HttpsClient()) { IPHostEntry entry; if ((entry = Dns.GetHostEntry("plex.tv")) != null) { HttpsClientRequest authServerRequest = new HttpsClientRequest(); HttpsClientResponse authServerResponse; authServer.TimeoutEnabled = true; authServer.Timeout = 25; authServer.AuthenticationMethod = Crestron.SimplSharp.Net.AuthMethod.BASIC; authServer.PeerVerification = false; authServer.UserName = usr; authServer.Password = pass; authServerRequest.Url.Parse("https://plex.tv/users/sign_in.json"); authServerRequest.Header.AddHeader(new HttpsHeader("X-Plex-Client-Identifier", "Crestron")); authServerRequest.RequestType = RequestType.Post; authServerResponse = authServer.Dispatch(authServerRequest); JObject response = JObject.Parse(authServerResponse.ContentString); authToken = (string)response["user"]["authToken"]; CrestronDataStoreStatic.SetLocalStringValue("authToken", authToken); } } } } return(authToken); } catch (Exception e) { if (e.Message.Contains("Unable to resolve address")) { } else { ErrorLog.Error("Error authorizing Plex: {0}", e); } return(""); } }
void DsStore(string s) { if (CrestronDataStoreStatic.SetLocalStringValue("apikey", s) != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.PrintLine("error storing apikey"); } CrestronConsole.PrintLine("Bridge registration complete"); }
void DsDel(string s) { if (CrestronDataStoreStatic.clearLocal("apikey") != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.PrintLine("Error removing API key"); } ; }
/// <summary> /// pulls API key from datastore /// </summary> /// <returns></returns> public static string GetDataStore() { string temp; if (CrestronDataStoreStatic.GetLocalStringValue("apikey", out temp) != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.PrintLine("error getting apikey"); } return(temp); }
static Global() { // Fire up CrestronDataStoreStatic var err = CrestronDataStoreStatic.InitCrestronDataStore(); if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.PrintLine("Error starting CrestronDataStoreStatic: {0}", err); return; } }
public RequestHandler() { try { CrestronConsole.PrintLine("DataStore init: {0}", CrestronDataStoreStatic.InitCrestronDataStore()); } catch (Exception e) { CrestronConsole.PrintLine("Error in RequestHandler(): {0}", e); } }
void SetupDataStore(string unused) { if (CrestronDataStoreStatic.InitCrestronDataStore() != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.PrintLine("Error InitCrestronDataStore: "); } else { CrestronDataStoreStatic.GlobalAccess = CrestronDataStore.CSDAFLAGS.OWNERREADWRITE & CrestronDataStore.CSDAFLAGS.OWNERREADWRITE; } }
void DsInit(string s) { try { CrestronDataStoreStatic.InitCrestronDataStore(); CrestronDataStoreStatic.GlobalAccess = CrestronDataStore.CSDAFLAGS.OWNERREADWRITE; } catch (Exception e) { CrestronConsole.PrintLine("Exception is {0}", e); } }
/// <summary> /// sets up datastore for storing the bridge API key /// </summary> public static void SetupDataStore() { try { var err = CrestronDataStoreStatic.InitCrestronDataStore(); CrestronConsole.PrintLine("DataStore status: {0}", err); CrestronDataStoreStatic.GlobalAccess = CrestronDataStore.CSDAFLAGS.OWNERREADWRITE; } catch (Exception e) { CrestronConsole.PrintLine("Exception is {0}", e); } }
void RetrieveFromDataStore(string store) { string str; if (CrestronDataStoreStatic.GetGlobalStringValue("Local String", out str) != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.PrintLine("Error RetrieveFromDataStore: "); } else { CrestronConsole.PrintLine(str); } }
void RetrieveFromDataStore(string unused) { string temp; if (CrestronDataStoreStatic.GetLocalStringValue("Local_String", out temp) != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.ConsoleCommandResponse("Error Retrieving String"); } else { CrestronConsole.ConsoleCommandResponse(temp); } }
void DsRead(string s) { string temp; if (CrestronDataStoreStatic.GetLocalStringValue("apikey", out temp) == CrestronDataStore.CDS_ERROR.CDS_SUCCESS && temp.Length > 30) { CrestronConsole.PrintLine("local key: {0}", temp); } else { CrestronConsole.PrintLine("No local API key stored"); } }
/// <summary> /// pulls API key from datastore /// </summary> /// <returns></returns> public static string GetDataStore() { string temp; if (CrestronDataStoreStatic.GetLocalStringValue("apikey", out temp) == CrestronDataStore.CDS_ERROR.CDS_SUCCESS && temp.Length > 30) { //CrestronConsole.PrintLine("local key: {0}",temp); LocalKey = true; } else { CrestronConsole.PrintLine("No local API key stored"); LocalKey = false; } return(temp); }
/// <summary> /// Get the specified record from the Datastore, or create it if no record exists. Return a bool indicating /// whether the record already existed when this method was called /// </summary> /// <param name="tag"></param> /// <param name="value"></param> /// <returns></returns> bool GetOrCreateRecord(string tag, out bool value) { try { var retVal = CrestronDataStoreStatic.GetLocalBoolValue(tag, out value); if (retVal != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronDataStoreStatic.SetLocalBoolValue(tag, false); value = false; return(false); } return(true); } catch (Exception e) { CrestronConsole.PrintLine("GetOrCreateRecord: {0}", e); value = false; return(false); } }
/// <summary> /// registers with bridge, authorizes a user based on API key from the pairing /// </summary> public static void register() { CrestronConsole.PrintLine("registering with bridge..."); try { var registerBridge = new HttpClient(); registerBridge.KeepAlive = false; registerBridge.Accept = "application/json"; HttpClientRequest bridgeRequest = new HttpClientRequest(); string url = string.Format("http://{0}/api", BridgeIp); bridgeRequest.RequestType = Crestron.SimplSharp.Net.Http.RequestType.Post; bridgeRequest.Url.Parse(url); bridgeRequest.ContentString = "{\"devicetype\":\"my_hue_app#crestron\"}"; HttpClientResponse lResponse = registerBridge.Dispatch(bridgeRequest); var jsontext = lResponse.ContentString; CrestronConsole.PrintLine("response is {0}", jsontext); if (jsontext.Contains("link button not pressed")) { Authorized = false; CrestronConsole.PrintLine("Registration incomplete press button and retry..."); } else if (jsontext.Contains("username")) { Authorized = true; JArray data = JArray.Parse(jsontext); BridgeApi = (String)data[0]["success"]["username"]; CrestronConsole.PrintLine("API key is {0}", BridgeApi); if (CrestronDataStoreStatic.SetLocalStringValue("apikey", BridgeApi) != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { CrestronConsole.PrintLine("error storing apikey"); } CrestronConsole.PrintLine("Bridge registration complete"); } } catch (Exception e) { CrestronConsole.PrintLine("Exception is {0}", e); } }
public void Link(string user) { try { if (CrestronDataStoreStatic.GetLocalStringValue("username", out PhilipsHueBridge.Username) == CrestronDataStore.CDS_ERROR.CDS_RECORD_NOT_FOUND) { User u = new User(); u.devicetype = string.Format("crestron#{0}", user); string body = JsonConvert.SerializeObject(u); PhilipsHueBridge.SendCommand(String.Format("http://{0}/api", PhilipsHueBridge.IPAddress /*, PhilipsHueBridge.Username*/), body, RequestType.Post, 1, 0); } else { GetLights(); } } catch (Exception e) { CrestronConsole.PrintLine(e.Message + "\n" + e.StackTrace); } }
MockEssentialsLicenseManager() : base() { LicenseIsValid = new BoolFeedback("LicenseIsValid", () => { return(IsValid); }); CrestronConsole.AddNewConsoleCommand( s => SetFromConsole(s.Equals("true", StringComparison.OrdinalIgnoreCase)), "mocklicense", "true or false for testing", ConsoleAccessLevelEnum.AccessOperator); bool valid; var err = CrestronDataStoreStatic.GetGlobalBoolValue("MockLicense", out valid); if (err == CrestronDataStore.CDS_ERROR.CDS_SUCCESS) { SetIsValid(valid); } else if (err == CrestronDataStore.CDS_ERROR.CDS_RECORD_NOT_FOUND) { CrestronDataStoreStatic.SetGlobalBoolValue("MockLicense", false); } else { CrestronConsole.PrintLine("Error restoring Mock License setting: {0}", err); } }
void SetupDataStore(string unused) { CrestronDataStoreStatic.InitCrestronDataStore(); CrestronDataStoreStatic.GlobalAccess = CrestronDataStore.CSDAFLAGS.OWNERREADWRITE & CrestronDataStore.CSDAFLAGS.OTHERREADWRITE; }
static public void SendCommand(string url, string body, RequestType requestType, int type, int ID) { try { using (HttpClient client = new HttpClient()) { HttpClientRequest request = new HttpClientRequest(); client.TimeoutEnabled = true; client.Timeout = 10; request.RequestType = requestType; request.Url.Parse(url); request.ContentString = body; HttpClientResponse response = client.Dispatch(request); if (response.ContentString.Contains("\"error\":{\"type\":1,\"address\":\"\",\"description\":\"unauthorized user\"")) { SendErrorFn("Unauthorized user"); } else if (response.ContentString.Contains("\"error\":{\"type\":101,\"address\":\"\",\"description\":\"link button not pressed\"")) { SendErrorFn("Press link button on bridge and try again"); } else if (response.ContentString.Contains("[{\"success\":{\"username\":")) { var temp = response.ContentString.Split('"'); Username = temp[5]; CrestronDataStoreStatic.SetLocalStringValue("username", temp[5]); PhilipsHueBridgeConfig GL = new PhilipsHueBridgeConfig(); GL.GetLights(); } else if (type == 1) { DataDump DD = JsonConvert.DeserializeObject <DataDump>(response.ContentString); SendConfigFn(DD.config.name, DD.config.swversion); foreach (var item in DD.lights) { SendLightFn((ushort)item.Key, DD.lights[item.Key].name); if (LightClient.ContainsKey(DD.lights[item.Key].name)) { if (DD.lights[item.Key].state.hue > 0 || DD.lights[item.Key].state.sat > 0) { LightClient[DD.lights[item.Key].name].FireOnLightDataChange(new LightDataReceivedEventArgs(DD.lights[item.Key].name, DD.lights[item.Key].modelid, DD.lights[item.Key].type, DD.lights[item.Key].state.on, DD.lights[item.Key].state.bri, DD.lights[item.Key].state.hue, DD.lights[item.Key].state.sat, DD.lights[item.Key].state.xy, DD.lights[item.Key].state.reachable, item.Key)); } else { List <string> empty = new List <string>(); empty.Add("0.0"); empty.Add("0.0"); LightClient[DD.lights[item.Key].name].FireOnLightDataChange(new LightDataReceivedEventArgs(DD.lights[item.Key].name, DD.lights[item.Key].modelid, DD.lights[item.Key].type, DD.lights[item.Key].state.on, DD.lights[item.Key].state.bri, 0, 0, empty, DD.lights[item.Key].state.reachable, item.Key)); } } } foreach (var item in DD.groups) { SendGroupFn((ushort)item.Key, DD.groups[item.Key].name); if (GroupClient.ContainsKey(DD.groups[item.Key].name)) { if (DD.groups[item.Key].action.hue > 0 || DD.groups[item.Key].action.sat > 0) { GroupClient[DD.groups[item.Key].name].FireOnGroupDataChange(new GroupDataReceivedEventArgs(DD.groups[item.Key].name, DD.groups[item.Key].type, DD.groups[item.Key].state.all_on, DD.groups[item.Key].state.any_on, DD.groups[item.Key].action.on, DD.groups[item.Key].action.bri, DD.groups[item.Key].action.hue, DD.groups[item.Key].action.sat, DD.groups[item.Key].action.xy, item.Key)); } else { List <string> empty = new List <string>(); empty.Add("0.0"); empty.Add("0.0"); GroupClient[DD.groups[item.Key].name].FireOnGroupDataChange(new GroupDataReceivedEventArgs(DD.groups[item.Key].name, DD.groups[item.Key].type, DD.groups[item.Key].state.all_on, DD.groups[item.Key].state.any_on, DD.groups[item.Key].action.on, DD.groups[item.Key].action.bri, 0, 0, empty, item.Key)); } } } } else if (type == 3) { Lights L = JsonConvert.DeserializeObject <Lights>(response.ContentString); LightClient[L.name].FireOnLightDataChange(new LightDataReceivedEventArgs(L.name, L.modelid, L.type, L.state.on, L.state.bri, L.state.hue, L.state.sat, L.state.xy, L.state.reachable, ID)); } else if (type == 4) { Groups G = JsonConvert.DeserializeObject <Groups>(response.ContentString); GroupClient[G.name].FireOnGroupDataChange(new GroupDataReceivedEventArgs(G.name, G.type, G.state.all_on, G.state.any_on, G.action.on, G.action.bri, G.action.hue, G.action.sat, G.action.xy, ID)); } } } catch (SocketException se) { } catch (HttpException he) { } catch (Exception e) { } }