protected void Page_Load(object sender, EventArgs e) { APIResponse ResponseENUM = APIResponse.NOT_OK; string ResponseString = ""; try { CookieProxy.Instance().RemoveKey("Cart"); ResponseENUM = APIResponse.OK; ResponseString = "SUCCESS"; } catch (Exception ex) { Logger.Instance().Log(Warn.Instance(), ex); ResponseENUM = APIResponse.NOT_OK; ResponseString = "ERROR"; } finally { var ReturnObj = new { Response = ResponseENUM.ToString(), ResponseString }; Response.Write(new JavaScriptSerializer().Serialize(ReturnObj)); } }
public string getAccessToken(string client_id, string client_secret, string audience) { Dictionary <string, string> body = new Dictionary <string, string>(); body.Add("client_id", client_id); body.Add("client_secret", client_secret); body.Add("audience", audience); body.Add("grant_type", "client_credentials"); // Need to do a POST to auth0 to get our credentials APIRequest credential_request = new POST(uri: "oauth/token", body: JsonConvert.SerializeObject(body)) .authorize(false); APIResponse response = execute(credential_request); Dictionary <string, string> responseData = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.ToString()); // Save token string access_token = responseData["access_token"]; return(access_token); }
public List <Feed> getFeeds(Dictionary <String, String> parameters = null) { APIResponse response = this.execute(new GET(uri: FeedService.URI, parameters: parameters)); List <Feed> ret = JsonConvert.DeserializeObject <List <Feed> >(response.ToString()); return(ret); }
public WeatherLocation getLocationInfo(int location_id) { object[] uriChunks = { "locations", location_id }; APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks))); WeatherLocation ret = JsonConvert.DeserializeObject <WeatherLocation>(response.ToString()); return(ret); }
public object getRun(int run_id) { object[] uriChunks = { "runs", run_id }; APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks))); dynamic ret = JArray.Parse(response.ToString()); return(ret); }
public object getForecast(int location_id) { object[] uriChunks = { "locations", location_id, "forecast", "daily" }; APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks))); dynamic ret = JArray.Parse(response.ToString()); return(ret); }
public SetpointData getSetPointsForZone(string zone_id) { object[] uriChunks = { "zones", zone_id, "runs", "data" }; APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks))); var ret = new SetpointData(JObject.Parse(response.ToString())); return(ret); }
public Feed getFeed(int id) { string uri = FeedService.URI + "/" + id; APIResponse response = this.execute(new GET(uri)); Feed ret = JsonConvert.DeserializeObject <Feed>(response.ToString()); return(ret); }
public FieldMetrics getFieldMetrics(List <int> output_ids, List <string> labels) { var body = JsonConvert.SerializeObject(new Dictionary <string, object> { { "output_id_list", output_ids }, { "labels", labels } }); APIResponse response = this.execute(new POST(uri: "metrics/fieldDataMetrics", body: body)); return(JsonConvert.DeserializeObject <FieldMetrics>(response.ToString())); }
protected void Page_Load(object sender, EventArgs e) { APIResponse ResponseENUM = APIResponse.NOT_OK; string ResponseString = ""; try { Cart CartObj = null; if (CookieProxy.Instance().HasKey("Cart")) { int PBSId = int.Parse(Request.Form["pbsid"].ToString()); CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString()); int Iterator = 0; foreach (CartItems Cart in CartObj.CartItems) { if (Cart.ProductObj.pbsID == PBSId) { CartObj.CartItems.RemoveAt(Iterator); ResponseENUM = APIResponse.OK; ResponseString = "SUCCESS"; break; } Iterator += 1; } CookieProxy.Instance().SetValue("Cart", new JavaScriptSerializer().Serialize(CartObj), DateTime.Now.AddDays(5)); } else { ResponseENUM = APIResponse.NOT_OK; ResponseString = "AN ERROR OCCURED WHILE READING THE CART, PLEASE CLEAR YOUR COOKIES"; } } catch (Exception ex) { Logger.Instance().Log(Warn.Instance(), ex); ResponseENUM = APIResponse.NOT_OK; ResponseString = "AN ERROR OCCURED WHILE READING THE CART, PLEASE CLEAR YOUR COOKIES"; } finally { var ReturnObj = new { Response = ResponseENUM.ToString(), ResponseString }; Response.Write(new JavaScriptSerializer().Serialize(ReturnObj)); } }
public JObject getFieldDescriptors(int feed_id, int limit = 100, int offset = 0) { object[] uriChunks = { FeedService.URI, feed_id, "fields" }; Dictionary <string, string> requestParams = new Dictionary <string, string>() { { "limit", limit.ToString() }, { "offset", offset.ToString() } }; APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks), parameters: requestParams)); return(JObject.Parse(response.ToString())); }
public object createRun(int facility_id, string solver_type, string name, DateTime ran_at) { object[] uriChunks = { "runs" }; JObject body = new JObject { { "facility_id", facility_id.ToString() }, { "solver_type", solver_type }, { "name", name }, { "ran_at", ran_at.ToString("yyyy-MM-dd HH:mm:ss") } }; APIResponse response = this.execute(new POST(uri: String.Join("/", uriChunks), body: body.ToString())); dynamic ret = JObject.Parse(response.ToString()); return(ret); }
public JObject getUnprovisionedData(int feed_id, string field_descriptor, int window, DateTime time_start, DateTime?time_end = null) { object[] uriChunks = { "feeds", feed_id, "fields", field_descriptor, "data" }; Dictionary <string, string> requestParams = new Dictionary <string, string>() { // Convert to epoch-seconds { "timeStart", time_start.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds.ToString() }, }; if (time_end != null) { requestParams.Add("timeEnd", time_end.Value.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds.ToString()); } APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks), parameters: requestParams)); return(JObject.Parse(response.ToString())); }
public Dictionary <string, SetpointData> getSetPointsForSystem(string system_id) { object[] uriChunks = { "systems", system_id, "runs", "data" }; APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks))); var ret = new Dictionary <string, SetpointData>(); // Decode and package response data JObject responseData = JObject.Parse(response.ToString()); foreach (var data in responseData) { ret.Add(data.Key, new SetpointData(data.Value.ToObject <JObject>())); } return(ret); }
protected void Page_Load(object sender, EventArgs e) { APIResponse ResponseAPI = APIResponse.NOT_OK; try { if (CookieProxy.Instance().HasKey("t")) { IUserProfile UserProfileObj = new UserProfile(CookieProxy.Instance().GetValue("t").ToString()); IAddress AddressObj = new Address(Request.Form["Name"].ToString(), Request.Form["Street"].ToString(), Request.Form["Appt"].ToString(), Request.Form["PostalCode"].ToString(), Request.Form["PhoneNumber"].ToString(), int.Parse(Request.Form["c"])); CRUDBusinessLayerTemplate <IAddress> AddressCRUD = new AddressBusinessLayerTemplate(UserProfileObj); ResponseAPI = AddressCRUD.Insert(AddressObj); } else { ResponseAPI = APIResponse.NOT_AUTHENTICATED; } } catch (NullReferenceException) { ResponseAPI = APIResponse.NOT_AUTHENTICATED; } catch (Exception) { ResponseAPI = APIResponse.NOT_OK; } finally { if (ResponseAPI == APIResponse.NOT_AUTHENTICATED) { CookieProxy.Instance().SetValue("LoginMessage", "For security reasons, please relogin".ToString(), DateTime.Now.AddDays(2)); } var ResponseObj = new { Response = ResponseAPI.ToString() }; Response.Write(new JavaScriptSerializer().Serialize(ResponseObj)); } }
protected void Page_Load(object sender, EventArgs e) { APIResponse ResponseAPI = APIResponse.NOT_OK; try { if (CookieProxy.Instance().HasKey("t")) { IUserProfile UserProfileObj = new UserProfile(CookieProxy.Instance().GetValue("t").ToString()); ICardDetails CardObj = new CardDetails(int.Parse(Request.Form["cid"].ToString())); CRUDBusinessLayerTemplate <ICardDetails> CardCRUD = new CardDetailsBusinessLayerTemplate(UserProfileObj); ResponseAPI = CardCRUD.Delete(CardObj); } else { ResponseAPI = APIResponse.NOT_AUTHENTICATED; } } catch (NullReferenceException) { ResponseAPI = APIResponse.NOT_AUTHENTICATED; } catch (Exception) { ResponseAPI = APIResponse.NOT_OK; } finally { if (ResponseAPI == APIResponse.NOT_AUTHENTICATED) { CookieProxy.Instance().SetValue("LoginMessage", "For security reasons, please relogin".ToString(), DateTime.Now.AddDays(2)); } var ResponseObj = new { Response = ResponseAPI.ToString() }; Response.Write(new JavaScriptSerializer().Serialize(ResponseObj)); } }
public DataResponse getData(int output_id, string field_human_name, int window, DateTime time_start, DateTime?time_end = null) { object[] uriChunks = { "outputs", output_id, "fields", field_human_name, "data" }; Dictionary <string, string> requestParams = new Dictionary <string, string>() { // Convert to epoch-seconds { "timeStart", time_start.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds.ToString() }, { "window", window.ToString() } }; if (time_end != null) { requestParams.Add("timeEnd", time_end.Value.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds.ToString()); } APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks), parameters: requestParams)); return(new DataResponse(JObject.Parse(response.ToString()))); }
public Tuple <string, Dictionary <string, SetpointData> > getSchemesForSystem(string system_id) { object[] uriChunks = { "systems", system_id, "schemes", "data" }; APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks))); var zone_data = new Dictionary <string, SetpointData>(); // Decode and package response data JObject responseData = JObject.Parse(response.ToString()); string scheme_output_type = responseData.GetValue("scheme_output_type").ToObject <string>(); foreach (var data in responseData.GetValue("data_by_zone").ToObject <JObject>()) { zone_data.Add(data.Key, new SetpointData(data.Value.ToObject <JObject>())); } return(Tuple.Create(scheme_output_type, zone_data)); }
public Dictionary <int, List <FlywheelingNode> > getNodes() { object[] uriChunks = { "systems", "node" }; APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks))); var responseData = JObject.Parse(response.ToString()); int facility_id = (int)responseData["facility_id"]; var ret = new Dictionary <int, List <FlywheelingNode> >(); var nodeList = new List <FlywheelingNode>(); ret.Add(facility_id, nodeList); foreach (var node in responseData["FlywheelingNodes"]) { nodeList.Add(new FlywheelingNode((JObject)node)); } return(ret); }
protected void Page_Load(object sender, EventArgs e) { APIResponse ResponseAPI = APIResponse.NOT_OK; IOrderCreaterStatus OrderStatus = null; try { ICart CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString()); IAddress AddressObj = new Address(int.Parse(Request.Form["aid"].ToString())); ICardDetails CardObj = new CardDetails(int.Parse(Request.Form["cID"].ToString())); IUserProfile UserProfileObj = new UserProfile(CookieProxy.Instance().GetValue("t").ToString()); OrderStatus = new OrderCreator().CreateOrder(AddressObj, CardObj, UserProfileObj, CartObj); if (OrderStatus.GetIsOrderCreated() == true) { // empty the cart CookieProxy.Instance().RemoveKey("Cart"); ResponseAPI = APIResponse.OK; } else { ResponseAPI = APIResponse.NOT_OK; } } catch (Exception) { ResponseAPI = APIResponse.NOT_OK; } finally { var ResponseObj = new { Response = ResponseAPI.ToString(), data = OrderStatus }; Response.Write(new JavaScriptSerializer().Serialize(ResponseObj)); } }
public Feed getFeed(string key) { string uri = FeedService.URI; Dictionary <string, string> requestParams = new Dictionary <string, string>() { { "key", key } }; APIResponse response = this.execute(new GET(uri: uri, parameters: requestParams)); // TODO: fix when feed doesn't exist JObject feed = (JObject)JObject.Parse(response.ToString())["records"][0]; Feed ret = new Feed(); ret.Key = (string)feed["key"]; ret.Timezone = (string)feed["timezone"]; ret.Token = (string)feed["token"]; return(ret); }
protected void Page_Load(object sender, EventArgs e) { APIResponse ApiResponse = APIResponse.NOT_OK; int Quantity = 0; Cart CartObj = new Cart(); try { if (CookieProxy.Instance().HasKey("Cart")) { CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString()); foreach (CartItems Items in CartObj.CartItems) { IProductByStore PBSObj = new ProductByStore(); PBSObj.SetProductByStoreID(Items.ProductObj.pbsID); Products DBProductQty = new ProductByStoreBusinessLayerTemplate().Select(PBSObj); if (GetMaxQty < DBProductQty.Quantity) { Items.DBQuantity = GetMaxQty; } else { Items.DBQuantity = DBProductQty.Quantity; } if (Items.ProductObj.Quantity < 0) { CartObj.HasValidationErrors = true; Items.ProductObj.Quantity = -1; Items.HasQuantity = false; } else if (DBProductQty.Quantity < Items.ProductObj.Quantity && Items.ProductObj.Quantity <= 0) { CartObj.HasValidationErrors = true; Items.ProductObj.Quantity = -1; Items.HasQuantity = false; } else if (DBProductQty.Quantity < Items.ProductObj.Quantity) { CartObj.HasValidationErrors = true; Items.HasQuantity = false; } Quantity = CartObj.CartItems.Count; } } ApiResponse = APIResponse.OK; } catch (Exception ex) { Logger.Instance().Log(Warn.Instance(), ex); ApiResponse = APIResponse.NOT_OK; } finally { var Cart = new { Response = ApiResponse.ToString(), Quantity, Cart = new JavaScriptSerializer().Serialize(CartObj) }; Response.Write(new JavaScriptSerializer().Serialize(Cart)); } }
public List <WeatherLocation> getLocations() { object[] uriChunks = { "locations" }; APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks))); List <WeatherLocation> ret = JsonConvert.DeserializeObject <List <WeatherLocation> >(response.ToString()); return(ret); }
public List <OutputField> getOutputFields(int output_id) { object[] uriChunks = { "outputs", output_id, "fields" }; APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks))); PagedResponse <OutputField> ret = JsonConvert.DeserializeObject <PagedResponse <OutputField> >(response.ToString()); return(ret.records); }
public List <Output> getFeedOutputs(int feed_id, int limit = 100, int offset = 0) { object[] uriChunks = { FeedService.URI, feed_id, "outputs" }; Dictionary <string, string> requestParams = new Dictionary <string, string>() { { "limit", limit.ToString() }, { "offset", offset.ToString() } }; APIResponse response = this.execute(new GET(uri: String.Join("/", uriChunks), parameters: requestParams)); PagedResponse <Output> ret = JsonConvert.DeserializeObject <PagedResponse <Output> >(response.ToString()); return(ret.records); }
protected void Page_Load(object sender, EventArgs e) { APIResponse ResponseENUM = APIResponse.NOT_OK; string ResponseString = ""; try { Cart CartObj = null; if (CookieProxy.Instance().HasKey("Cart")) { int PBSId = int.Parse(Request.Form["pbsid"].ToString()); CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString()); int Iterator = 0; foreach (CartItems Cart in CartObj.CartItems) { if (Cart.ProductObj.pbsID == PBSId) { int Quantity = int.Parse(Request.Form["qty"].ToString()); IProductByStore PBSObj = new ProductByStore(); PBSObj.SetProductByStoreID(PBSId); Products DBProductQty = new ProductByStoreBusinessLayerTemplate().Select(PBSObj); if (Quantity <= DBProductQty.Quantity) { Cart.ProductObj.Quantity = Quantity; ResponseENUM = APIResponse.OK; ResponseString = "SUCCESS"; } else { Cart.ProductObj.Quantity = Quantity; ResponseENUM = APIResponse.NOT_OK; ResponseString = "CURRENT QUANTITY NOT AVAILABLE, PLEASE REFRESH THE PAGE TO SEE UPDATED QUANTITY"; } break; } Iterator += 1; } CookieProxy.Instance().SetValue("Cart", new JavaScriptSerializer().Serialize(CartObj), DateTime.Now.AddDays(5)); } else { ResponseENUM = APIResponse.NOT_OK; ResponseString = "AN ERROR OCCURED WHILE READING THE CART, PLEASE CLEAR YOUR COOKIES"; } } catch (Exception ex) { Logger.Instance().Log(Warn.Instance(), ex); ResponseENUM = APIResponse.NOT_OK; ResponseString = "AN ERROR OCCURED WHILE READING THE CART, PLEASE CLEAR YOUR COOKIES"; } finally { var ReturnObj = new { Response = ResponseENUM.ToString(), ResponseString }; Response.Write(new JavaScriptSerializer().Serialize(ReturnObj)); } }
protected void Page_Load(object sender, EventArgs e) { APIResponse ResponseENUM = APIResponse.NOT_OK; string ResponseString = ""; try { Cart CartObj = null; if (CookieProxy.Instance().HasKey("Cart")) { int PBSId = int.Parse(Request.Form["pbsid"].ToString()); CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString()); bool AlreadyHasProductInCart = false; foreach (CartItems Cart in CartObj.CartItems) { if (Cart.ProductObj.pbsID == PBSId) { ResponseENUM = APIResponse.NOT_OK; ResponseString = "PRODUCT ALREADY ADDED TO CART, PLEASE MODIFY THE QUANTITY"; AlreadyHasProductInCart = true; break; } } if (AlreadyHasProductInCart == false) { ProductByStore PBSPbj = new ProductByStore(); PBSPbj.SetProductByStoreID(PBSId); CartItems CartItemsObj = new CartItems { HasQuantity = true, ProductObj = new ProductByStoreBusinessLayerTemplate().Select(PBSPbj) }; // reset the quantity to 1, we want the user quantity not the product quantity CartItemsObj.ProductObj.Quantity = 1; CartObj.CartItems.Add(CartItemsObj); CookieProxy.Instance().SetValue("Cart", new JavaScriptSerializer().Serialize(CartObj), DateTime.Now.AddDays(5)); ResponseENUM = APIResponse.OK; ResponseString = "SUCCESS"; } } else { CartObj = new Cart { CartItems = new List <CartItems>() }; int PBSId = int.Parse(Request.Form["pbsid"].ToString()); CartItems CartItemsObj = new CartItems { HasQuantity = true, ProductObj = new ProductByStoreBusinessLayerTemplate().Select(new ProductByStore() { ProductByStoreID = PBSId }) }; // reset the quantity to 1, we want the user quantity (user has initially selected the quantity) not the product quantity CartItemsObj.ProductObj.Quantity = 1; CartObj.CartItems.Add(CartItemsObj); CookieProxy.Instance().SetValue("Cart", new JavaScriptSerializer().Serialize(CartObj), DateTime.Now.AddDays(5)); ResponseENUM = APIResponse.OK; ResponseString = "SUCCESS"; } } catch (Exception ex) { Logger.Instance().Log(Warn.Instance(), ex); ResponseENUM = APIResponse.NOT_OK; ResponseString = "ERROR"; } finally { var ReturnObj = new { Response = ResponseENUM.ToString(), ResponseString }; Response.Write(new JavaScriptSerializer().Serialize(ReturnObj)); } }