コード例 #1
0
        public virtual ActionResult Index()
        {
            var model = new AllModel();

            var ListUser      = RESTHelper.Get <ResultModel <List <UsersModel> > >(ConfigurationManager.AppSettings["HostAPIURL"] + ConfigurationManager.AppSettings["GetAllUser"]);
            var ListCatalogue = RESTHelper.Get <ResultModel <List <CatalogueModel> > >(ConfigurationManager.AppSettings["HostAPIURL"] + ConfigurationManager.AppSettings["GetAllCatalague"]);
            var ListInvoice   = RESTHelper.Get <ResultModel <List <InvoiceModel> > >(ConfigurationManager.AppSettings["HostAPIURL"] + ConfigurationManager.AppSettings["GetAllInvoice"]);

            ViewBag.NoInvoice = RESTHelper.Get <ResultModel <string> >(ConfigurationManager.AppSettings["HostAPIURL"] + ConfigurationManager.AppSettings["GenerateNoInvoice"]);
            if (ListCatalogue != null)
            {
                model.ListCatalogues = ListCatalogue.Value;
            }
            if (ListInvoice != null)
            {
                model.ListInvoices = ListInvoice.Value;
            }
            if (ListUser != null)
            {
                model.ListUsers = ListUser.Value;
            }
            if (TempData.ContainsKey("StatusMessage"))
            {
                ViewBag.Message = TempData["StatusMessage"];
            }

            return(View(model));
        }
コード例 #2
0
        void ChildEventListen(ChildEventHandler eventHandler)
        {
            RequestHelper req = new RequestHelper
            {
                Headers = new Dictionary <string, string>
                {
                    { "Accept", "text/event-stream" }
                },
                Uri               = FirebaseConfig.endpoint + path + ".json" + GetAuthParam(),
                DownloadHandler   = eventHandler,
                Retries           = int.MaxValue,
                RetrySecondsDelay = 1
            };

            //create an unsubscriber for events
            var unsubscriberGO = GameObject.Find("FirebaseRestUnsubscriber");

            if (unsubscriberGO == null)
            {
                unsubscriberGO = new GameObject("FirebaseRestUnsubscriber");
                unsubscriberGO.AddComponent <EventUnsubscriber>().requestHelper = req;
                MonoBehaviour.DontDestroyOnLoad(unsubscriberGO);
            }
            //Error handling are being handled internally
            RESTHelper.Get(req, err => RequestErrorHelper.ToDictionary(err).ToList().ForEach(x => Debug.LogError(x.Key + " - " + x.Value)));
        }
コード例 #3
0
        /// <summary>
        /// Order results by child value. [Firebase rules must be set]
        /// </summary>
        /// <returns>Raw Json</returns>
        public StringCallback OrderByValue()
        {
            StringCallback callbackHandler = new StringCallback();

            RequestHelper req = new RequestHelper
            {
                Uri    = FirebaseConfig.endpoint + path + ".json" + GetAuthParam(),
                Params = new Dictionary <string, string>
                {
                    { "orderBy", "\"$value\"" }
                }
            };

            //adding filters if there is
            GetFilterCollection(true)?.ToList().ForEach(x => req.Params.Add(x.Key, x.Value));

            RESTHelper.Get(req, res =>
            {
                callbackHandler.successCallback?.Invoke(res.Text);
            },
                           err =>
            {
                callbackHandler.exceptionCallback?.Invoke(err);
            });

            return(callbackHandler);
        }
コード例 #4
0
        /// <summary>
        /// Read key-value pairs
        /// </summary>
        /// <typeparam name="T">Value type</typeparam>
        /// <returns>Dictionary, key as string, value as specified type. Returns nothing if failed to deserialize.</returns>
        public DictionaryCallback <string, T> ReadKeyValuePairs <T>()
        {
            DictionaryCallback <string, T> callbackHandler = new DictionaryCallback <string, T>();

            string route = FirebaseConfig.endpoint + path + ".json" + GetAuthParam();

            RESTHelper.Get(route, res =>
            {
                var resData = fsJsonParser.Parse(res.Text);

                object deserializedRes = null;

                fsSerializer serializer = new fsSerializer();
                serializer.TryDeserialize(resData, typeof(Dictionary <string, T>), ref deserializedRes);

                Dictionary <string, T> destructuredRes = (Dictionary <string, T>)deserializedRes;

                callbackHandler.successCallback?.Invoke(destructuredRes);
            },
                           err =>
            {
                callbackHandler.exceptionCallback?.Invoke(err);
            });

            return(callbackHandler);
        }
コード例 #5
0
        /// <summary>
        /// Check for child in selected path
        /// </summary>
        /// <param name="child">child name</param>
        /// <returns>Returns true if child exists, else false</returns>
        public BooleanCallback HasChild(string child)
        {
            BooleanCallback callbackHandler = new BooleanCallback();

            string route = FirebaseConfig.endpoint + path + "/" + child + ".json" + GetAuthParam();

            RESTHelper.Get(route, res =>
            {
                //If there is no child, server return "null"
                if (res.Text != "null" && res.Text.Length > 0)
                {
                    callbackHandler.successCallback?.Invoke(true);
                }
                else
                {
                    callbackHandler.successCallback?.Invoke(false);
                }
            },
                           err =>
            {
                callbackHandler.exceptionCallback?.Invoke(err);
            });

            return(callbackHandler);
        }
コード例 #6
0
        /// <summary>
        /// Read value of key
        /// </summary>
        /// <returns>Value as Json String, else object</returns>
        public ObjectCallback ReadValue()
        {
            ObjectCallback callbackHandler = new ObjectCallback();

            string route = FirebaseConfig.endpoint + path + ".json" + GetAuthParam();

            RESTHelper.Get(route, res =>
            {
                var resData = fsJsonParser.Parse(res.Text);

                if (resData.IsDictionary)
                {
                    callbackHandler.successCallback?.Invoke(res.Text); //invoke with raw Json, as it's not a key-value pair
                    return;
                }
                //No collection
                object value = resData._value;
                callbackHandler.successCallback?.Invoke(value);
            },
                           err =>
            {
                callbackHandler.exceptionCallback?.Invoke(err);
            });

            return(callbackHandler);
        }
コード例 #7
0
        /// <summary>
        /// Read key-value pairs
        /// </summary>
        /// <returns>Dictionary, key is string and value is object, it can be any primitive types or fsData</returns>
        public DictionaryCallback <string, object> ReadKeyValuePairs()
        {
            DictionaryCallback <string, object> callbackHandler = new DictionaryCallback <string, object>();

            string route = FirebaseConfig.endpoint + path + ".json" + GetAuthParam();

            RESTHelper.Get(route, res =>
            {
                var resData = fsJsonParser.Parse(res.Text); //in JSON
                Dictionary <string, object> destructuredRes = new Dictionary <string, object>();

                if (resData.IsDictionary)
                {
                    resData.AsDictionary.ToList().ForEach(x => destructuredRes.Add(x.Key, x.Value._value));
                    callbackHandler.successCallback?.Invoke(destructuredRes);
                    return;
                }
                //No collection, single result (key-value pair)
                string[] splittedPaths = path.Split('/');
                destructuredRes.Add(splittedPaths[splittedPaths.Length - 1], resData._value); //last path as key, resData._value as object
                callbackHandler.successCallback?.Invoke(destructuredRes);
            },
                           err =>
            {
                callbackHandler.exceptionCallback?.Invoke(err);
            });

            return(callbackHandler);
        }
コード例 #8
0
        /// <summary>
        /// 1.2 Get new lights
        /// URL: http://<bridgeipaddress>/api/<username>/lights/new
        /// Method: GET
        /// Version: 1.0
        /// Permission: Whitelist
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static async Task <List <Light> > GetNewLights(string url)
        {
            url = url + "/lights/new";
            Debug.WriteLine("<Philips Hue - APIs - Lights> GetNewLights - Url to be used: " + url);

            string response = await RESTHelper.Get(url);

            Debug.WriteLine("<Philips Hue - APIs - Lights> GetNewLights - Response recieved: : " + response);

            List <Light> LightList = new List <Light>();
            JToken       token     = JToken.Parse(response);

            if (token.Type == JTokenType.Object)
            {
                var jsonResult = (JObject)token;
                var lastscan   = jsonResult.First;
                jsonResult.First.Remove();

                foreach (var prop in jsonResult.Properties())
                {
                    Light newLight = JsonConvert.DeserializeObject <Light>(prop.Value.ToString());
                    //newLight.bridgeid = prop.Name;
                    LightList.Add(newLight);
                    Debug.WriteLine("<Philips Hue - APIs - Lights> GetNewLights - Light added to list. Light name: " + newLight.name);
                }
            }
            return(LightList);
        }
コード例 #9
0
        /// <summary>
        /// 1.1 Get all lights
        /// URL: http://<bridgeipaddress>/api/<username>/lights
        /// Method: GET
        /// Version: 1.0
        /// Permission: Whitelist
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static async Task <List <Light> > GetAllLights(string ipAddress, string userName)
        {
            string url = ipBase + ipAddress + apiBase + userName + apiGroup;

            Debug.WriteLine("<Philips Hue - APIs - Lights> GetAllLights - Url to be used: " + url);

            string response = await RESTHelper.Get(url);

            Debug.WriteLine("<Philips Hue - APIs - Lights> GetAllLights - Response recieved: : " + response);

            List <Light> LightList = new List <Light>();
            JToken       token     = JToken.Parse(response);

            if (token.Type == JTokenType.Object)
            {
                var jsonResult = (JObject)token;

                foreach (var prop in jsonResult.Properties())
                {
                    Light newLight = JsonConvert.DeserializeObject <Light>(prop.Value.ToString());
                    //newLight.bridgeid = prop.Name;
                    LightList.Add(newLight);
                    Debug.WriteLine("<Philips Hue - APIs - Lights> GetAllLights - Light added to list. Light name: " + prop.Name);
                }
            }
            return(LightList);
        }
コード例 #10
0
        /// <summary>
        /// 7.2 Get configuration
        /// URL: http://<bridgeipaddress>/api/<username>/config
        /// Method: GET
        /// Version: 1.0
        /// Permission: Whitelist
        /// </summary>
        /// <param name="url"></param>
        public static async Task <Config> GetConfiguration(string ipAddress)
        {
            string url      = ipBase + ipAddress + apiBase + "/config";
            string response = await RESTHelper.Get(url);

            Config config = JsonConvert.DeserializeObject <Config>(response);

            return(config);
        }
コード例 #11
0
        /// <summary>
        /// Read Json Object
        /// </summary>
        /// <typeparam name="T">Desired type to be converted</typeparam>
        /// <returns>Result in object format</returns>
        public ObjectCallback <T> Read <T>()
        {
            ObjectCallback <T> callbackHandler = new ObjectCallback <T>();

            string route = FirebaseConfig.endpoint + path + ".json" + GetAuthParam();

            RESTHelper.Get(route, res =>
            {
                callbackHandler.successCallback?.Invoke(JsonUtility.FromJson <T>(res.Text));
            },
                           err =>
            {
                callbackHandler.exceptionCallback?.Invoke(err);
            });

            return(callbackHandler);
        }
コード例 #12
0
        /// <summary>
        /// Read raw Json
        /// </summary>
        /// <param name="shallow">If shallow, all json object will return as true. Better for surface reading.</param>
        /// <returns>Raw Json</returns>
        public StringCallback RawRead(bool shallow = false)
        {
            StringCallback callbackHandler = new StringCallback();

            string route = FirebaseConfig.endpoint + path + ".json" + GetAuthParam();

            if (shallow)
            {
                route += GetShallowParam();
            }

            RESTHelper.Get(route, res =>
            {
                callbackHandler.successCallback?.Invoke(res.Text);
            },
                           err =>
            {
                callbackHandler.exceptionCallback?.Invoke(err);
            });

            return(callbackHandler);
        }
コード例 #13
0
        /// <summary>
        /// 1.4 Get light attributes and state
        /// URL: http://<bridgeipaddress>/api/<username>/lights/<id>
        /// Method: GET
        /// Version: 1.0
        /// Permission: Whitelist
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static async Task <Light> GetLightsAttributesAndState(string url)
        {
            Debug.WriteLine("<Philips Hue - APIs - Lights> GetLightsAttributesAndState - Url to be used: " + url);

            string response = await RESTHelper.Get(url);

            Debug.WriteLine("<Philips Hue - APIs - Lights> GetLightsAttributesAndState - Response recieved: : " + response);
            Light light;

            try
            {
                light = JsonConvert.DeserializeObject <Light>(response);
                Debug.WriteLine("<Philips Hue - APIs - Lights> GetLightsAttributesAndState - Light Name: : " + light.name);
            }
            catch (Exception e)
            {
                Debug.WriteLine("<Philips Hue - APIs - Lights> Error - : " + e.Message);
                Debug.WriteLine("<Philips Hue - APIs - Lights> Error - : " + response);
                light = new Light();
            }
            return(light);
        }
コード例 #14
0
        public static async Task <Bridge> GetFullState(string ipAddress, string userName)
        {
            /// URL: /api/<username>
            /// Method: GET
            /// Version: 1.0
            /// Permission: Whitelist

            string url = ipBase + ipAddress + apiBase + userName;

            Debug.WriteLine("<Philips Hue - APIs - Lights> GetAllLights - Url to be used: " + url);

            string response = await RESTHelper.Get(url);

            Bridge       HueBridge = new Bridge();
            List <Light> lights    = new List <Light>();

            HueBridge.lights = lights;
            List <Group> groups = new List <Group>();

            HueBridge.groups = groups;
            List <Schedule> schedules = new List <Schedule>();

            HueBridge.schedules = schedules;
            List <Scene> scenes = new List <Scene>();

            HueBridge.scenes = scenes;
            List <Sensor> sensors = new List <Sensor>();

            HueBridge.sensors = sensors;
            List <Rule> rules = new List <Rule>();

            HueBridge.rules = rules;

            JToken token      = JToken.Parse(response);
            var    jsonResult = (JObject)token;

            foreach (var prop in jsonResult.Properties())
            {
                var result = (JObject)prop.Value;
                switch (prop.Path)
                {
                case "lights":
                {
                    foreach (var p in result.Properties())
                    {
                        Light newLight = JsonConvert.DeserializeObject <Light>(p.Value.ToString());
                        HueBridge.lights.Add(newLight);
                    }
                    break;
                }

                case "groups":
                {
                    foreach (var p in result.Properties())
                    {
                        Group newGroup = JsonConvert.DeserializeObject <Group>(p.Value.ToString());
                        HueBridge.groups.Add(newGroup);
                    }
                    break;
                }

                case "config":
                {
                    Config config = JsonConvert.DeserializeObject <Config>(prop.Value.ToString());
                    break;
                }

                case "schedules":
                {
                    foreach (var p in result.Properties())
                    {
                        Schedule newSchedule = JsonConvert.DeserializeObject <Schedule>(p.Value.ToString());
                        HueBridge.schedules.Add(newSchedule);
                    }
                    break;
                }

                case "scenes":
                {
                    foreach (var p in result.Properties())
                    {
                        Scene newScene = JsonConvert.DeserializeObject <Scene>(p.Value.ToString());
                        HueBridge.scenes.Add(newScene);
                    }
                    break;
                }

                case "sensors":
                {
                    foreach (var p in result.Properties())
                    {
                        Sensor newSensor = JsonConvert.DeserializeObject <Sensor>(p.Value.ToString());
                        HueBridge.sensors.Add(newSensor);;
                    }
                    break;
                }

                case "rules":
                {
                    foreach (var p in result.Properties())
                    {
                        Rule newRule = JsonConvert.DeserializeObject <Rule>(p.Value.ToString());
                        HueBridge.rules.Add(newRule);
                    }
                    break;
                }


                // As a last resort, launch the app in the foreground.
                default:
                    break;
                }
            }
            return(HueBridge);
        }