Exemplo n.º 1
0
        public Boolean login(String mail, String password, Boolean safeMode)
        {
            if (String.IsNullOrEmpty(mail) || String.IsNullOrEmpty(password))
            {
                return false;
            }

            Dictionary<String, String> dict = new Dictionary<String, String>();

            dict.Add("mail", mail);
            dict.Add("pass", MD5Core.GetHashString(password, Encoding.UTF8).ToLower());

            reaktorRequest req = null;
            if (safeMode)
                req = new reaktorRequest(_baseUrl + "/login", json.toJSON(dict));
            else
                req = new reaktorRequest(_baseUrl + "/login", json.toJSON(dict), this.loginCallback);

            req.run();

            if (safeMode)
            {
                req.asyncState.WaitOne();

                Boolean ok = req.result["ok"] == "true" ? true : false;

                if (!ok)
                    throw new Exception(req.result["reason"]);
                else
                {
                    _token = req.result["token"];
                    _isLoggedIn = true;
                }

                return ok;
            }

            return true;
        }
Exemplo n.º 2
0
        public Boolean trigger(String trigger, Dictionary<String, String> parameters, Boolean safeMode)
        {
            if (!_isLoggedIn)
            {
                this.login();
                return false;
            }

            Dictionary<String, String> dict = new Dictionary<String, String>();
            dict.Add("token", _token);
            dict.Add("client", "net");
            dict.Add("safe", safeMode ? "true" : "false");
            dict.Add("name", trigger);
            dict.Add("data", json.toJSON(parameters));

            reaktorRequest req = null;
            if (safeMode)
                req = new reaktorRequest(_baseUrl + "/trigger", json.toJSON(dict));
            else
                req = new reaktorRequest(_baseUrl + "/trigger", json.toJSON(dict), triggerCallback);

            req.run();

            if (safeMode)
            {
                req.asyncState.WaitOne();
                Boolean ok = req.result["ok"] == "true" ? true : false;

                if (!ok)
                    throw new Exception(req.result["reason"]);

                return ok;
            }

            return true;
        }