Exemple #1
0
 public void Login(string user, string password, AjaxCallback callback)
 {
     Dictionary<string, string> data = new Dictionary<string, string> { { "tbxUser", user }, { "tbxPasswd", password } };
       _ajaxConn.Post("/auth_login", data, callback);
 }
Exemple #2
0
 public void CloseCard(Guid id, AjaxCallback callback)
 {
     _ajaxConn.Put("/card_close", JsonHelper.ToJson(new { cardId = id.ToString() }), callback);
 }
Exemple #3
0
 public void LinkIer(ClientIer ier, Guid cardId, AjaxCallback callback)
 {
     ier.CardId = cardId;
       _ajaxConn.Put("/ier_update_active/", JsonHelper.ToJson(ier), callback);
 }
Exemple #4
0
 public void SetCCsStatus(bool mode, AjaxCallback callback)
 {
     JsonCcsMode ccsMode = new JsonCcsMode { isOn = mode };
       _ajaxConn.Put("/ccs_status/1", JsonHelper.ToJson(ccsMode), callback);
 }
Exemple #5
0
 public void AcceptIer(ClientIer ier, AjaxCallback callback)
 {
     ier.IsAccepted = true;
       _ajaxConn.Put("/ier_accept", JsonHelper.ToJson(new IerIdContainer(ier.Id)), callback);
 }
Exemple #6
0
        public void RequestCard(Guid cardId, AjaxCallback callback)
        {
            string url = "/card";

              if (cardId != Guid.Empty)
            url += "?id=" + cardId;

              _ajaxConn.Get(url, null, callback);
        }
Exemple #7
0
 public void Put(string req, string data, AjaxCallback callback)
 {
     CreateAndSendRequest("PUT", req, data, callback);
 }
Exemple #8
0
 public void Delete(string req, string data, AjaxCallback callback)
 {
     CreateAndSendRequest("DELETE", req, data, callback);
 }
Exemple #9
0
 public void RequestCardList(Dictionary<string, string> parameters, AjaxCallback callback)
 {
     _ajaxConn.Get("/card_list", parameters, callback);
 }
Exemple #10
0
        private void CreateAndSendRequest(string type, string req, string contentType, List<byte> sentData, AjaxCallback callback)
        {
            ++ReqCount;

              req = "http://" + Ip + ":" + Port + req;

              _log.DebugFormat("want to send {0}: {1}", type, req);

              HttpWebRequest reqPost = (HttpWebRequest)WebRequest.Create(req);

              reqPost.ServicePoint.ConnectionLimit = 10000;
              reqPost.Method = type;
              reqPost.Timeout = 360000;
              reqPost.CookieContainer = _cookie;
              reqPost.ContentType = contentType;
              reqPost.UserAgent = "TestUtility";
              reqPost.ContentLength = sentData.Count;

              try
              {
            using (Stream newStream = reqPost.GetRequestStream())
            {
              newStream.Write(sentData.ToArray(), 0, sentData.Count);
            }
              }
              catch (Exception e)
              {
            _log.Debug("Exception", e);

            lock (_locker)
            {
              _log.Debug("Posting error");

              if (Ctx != null)
            Ctx.Post(ProcessErrorInWinContext, new Callback(callback.Error, e.Message, _log));
            }
            return;
              }

              _log.Debug("call SendRequest");

              SendRequest(reqPost, callback);
        }
Exemple #11
0
        private void SendRequest(WebRequest req, AjaxCallback callback)
        {
            ThreadPool.QueueUserWorkItem(state =>
              {
            _log.Debug("real sending request " + req.RequestUri);

            string res = "";

            try
            {
              using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
              {
            if (resp.ResponseUri.LocalPath.Contains("auth_login"))
            {
              Ctx.Post(ProcessErrorInWinContext, new Callback(callback.Error, "Authentication error", _log));
              return;
            }

            callback.Cookies = req.Headers.GetValues("Cookie");

            using (var stream = resp.GetResponseStream())
            {
              _log.Debug("Got an answer " + req.RequestUri);

              StreamReader sr = new StreamReader(stream);

              res = sr.ReadToEnd();
              sr.Close();
            }
              }
              //Post message to windows thread
              _log.Debug("Waiting locker to ctx");

              lock (_locker)
              {
            _log.Debug("Posting");

            if (Ctx != null)
            {
              if (!res.Equals("\"error\""))
                Ctx.Post(ProcessSuccessInWinContext, new Callback(callback.Success, res, _log));
              else
                Ctx.Post(ProcessErrorInWinContext, new Callback(callback.Error, "Server sent error", _log));
            }
              }
            }
            catch (Exception e)
            {
              _log.Debug("Exception", e);

              lock (_locker)
              {
            _log.Debug("Posting error");

            if (Ctx != null)
              Ctx.Post(ProcessErrorInWinContext, new Callback(callback.Error, res, _log));
              }
            }
              });
        }
Exemple #12
0
        private void CreateAndSendRequest(string type, string req, string data, AjaxCallback callback)
        {
            List<byte> sentData = new List<byte>();
              sentData.AddRange(Encoding.UTF8.GetBytes(data));

              CreateAndSendRequest(type, req, "application/json", sentData, callback);
        }
Exemple #13
0
        private void CreateAndSendRequest(string type, string req, Dictionary<string, string> data, AjaxCallback callback)
        {
            List<byte> sentData = new List<byte>();
              if (data != null)
              {
            foreach (var kvp in data)
              sentData.AddRange(Encoding.GetEncoding(1251).GetBytes(kvp.Key + "=" + kvp.Value + "&"));

            if (sentData.Count != 0)
              sentData.RemoveAt(sentData.Count - 1);
              }

              CreateAndSendRequest(type, req, "application/x-www-form-urlencoded", sentData, callback);
        }
Exemple #14
0
 public void Put(string req, Dictionary<string, string> data, AjaxCallback callback)
 {
     CreateAndSendRequest("PUT", req, data, callback);
 }
Exemple #15
0
 public void Logout(AjaxCallback callback)
 {
     _ajaxConn.Get("/auth_logout", null, callback);
 }
Exemple #16
0
 public void RequestConnectionStatus(AjaxCallback callback)
 {
     _ajaxConn.Get("/connStatus", null, callback);
 }
Exemple #17
0
 public void RejectIer(Guid ierId, ClientIer ier, AjaxCallback callback)
 {
     ier.IsAccepted = false;
       _ajaxConn.Put("/ier_reject", JsonHelper.ToJson(new IerIdContainer(ier.Id)), callback);
 }
Exemple #18
0
 public void SaveCardCommonData(ClientIncidentCard card, AjaxCallback callback)
 {
     string msg = JsonHelper.ToJson(new {cardId = card.Id, data = card.CommonData});
       _ajaxConn.Put("/card_update_common_data", msg, callback);
 }
Exemple #19
0
 protected override void InvokeInternal()
 {
     StatisticsGatherer.StartLogin();
       _callback = new AjaxCallback(OnLogin, OnLoginError);
       _ajaxHelper.Login(_user, _passwd, _callback);
 }
Exemple #20
0
        public void Get(string req, Dictionary<string, string> parameters, AjaxCallback callback)
        {
            ++ReqCount;

              req = "http://" + Ip + ":" + Port + req;

              if (parameters != null)
              {
            req += "?";

            int iterationCount = 0;

            foreach (var pair in parameters)
            {
              req += pair.Key + "=" + pair.Value;

              ++iterationCount;

              if (iterationCount != parameters.Count)
            req += "&";
            }
              }

              _log.Debug("want to send get: " + req);

              HttpWebRequest reqGet = (HttpWebRequest)WebRequest.Create(req);

              reqGet.ServicePoint.ConnectionLimit = 10000;
              reqGet.CookieContainer = _cookie;
              reqGet.UserAgent = "TestUtility";

              _log.Debug("call SendRequest");

              SendRequest(reqGet, callback);
        }