Exemple #1
0
 /// <summary>
 /// Send UDP when timer is tick
 /// </summary>
 /// <param name="source"></param>
 /// <param name="e"></param>
 private void Keep_Elapsed(object source, ElapsedEventArgs e)
 {
     try
     {
         byte[] data = CommonService.SendUdp(Config.ServerIP, Config.HeartBeatPort, Status.HeartBeatPacket);
         if (Config.LogLevel == SimpleLogger.LogLevel.Debug)
         {
             string content = "";
             foreach (byte i in data)
             {
                 content += "0x" + i.ToString("X2") + " ";
             }
             content = content.Remove(content.Length - 1);
             CommonService.logger.AppendLog("Timer is triggered and the heartbeat packet has been sent. The response is:\n{0}", content);
         }
     }
     catch (SocketException ex)
     {
         string result = WebRequestHelper.CreateRequest(Config.QueryUrl, "GET", "");
         if (result == "error")
         {
             CommonService.logger.AppendLog(ex);
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Fetch notify messages form server
        /// </summary>
        /// <returns></returns>
        public string GetNotifyMessage()
        {
            string result = "";

            result = WebRequestHelper.CreateRequest(Config.MessageUrl, "GET", "", Encoding.ASCII, Encoding.GetEncoding("GB2312"));
            result = HttpUtility.HtmlDecode(result);
            return(result);
        }
Exemple #3
0
        public void Get3AIP()
        {
            string result = WebRequestHelper.CreateRequest("http://freesrun.codeplex.com", "GET", "");

            //bool result = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();

            PickupAdd(result);
        }
Exemple #4
0
        /// <summary>
        /// Post uid to logout
        /// </summary>
        /// <param name="url">Logout URL</param>
        /// <param name="uid">UID, it will be recieved after login</param>
        /// <returns>logout_ok / logout_error</returns>
        public LogoutResponseResult Logout(string url, string uid)
        {
            Dictionary <string, string> form = new Dictionary <string, string>();

            form.Add("uid", uid);
            string responseText = WebRequestHelper.CreateRequest(Config.LogoutUrl, "POST", form);
            LogoutResponseResult result;

            try
            {
                result = new LogoutResponseResult(responseText);
            }
            catch (Exception ex)
            {
                result = new LogoutResponseResult(ResponseStatus.Error, ex.Message);
                result.ResponseText = responseText;
            }
            return(result);
        }
Exemple #5
0
        public async Task <ICollection <UserDTO> > Execute(int id, WebRequestHelper helper)
        {
            Query query = queryManager.Get(id);

            if (query == null)
            {
                return(null);
            }
            ICollection <UserDTO> users;
            HttpResponseMessage   httpResponseMessage = await httpClient.GetAsync(helper.CreateRequest(mapper.Map <QueryDisplayDTO>(query)));

            if (httpResponseMessage.IsSuccessStatusCode)
            {
                users = await httpResponseMessage.Content.ReadAsAsync <ICollection <UserDTO> >();

                var entities = mapper.Map <IEnumerable <User> >(users);
                query = queryManager.SetExecuted(query);
                userManager.Add(query, entities.ToArray());
                return(users);
            }
            return(null);
        }
Exemple #6
0
        /// <summary>
        /// Login
        /// </summary>
        /// <param name="url"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public LoginResponseResult Login(string url, string username, string password)
        {
            PasswordEncryptor pe = new PasswordEncryptor();
            long   ts            = CommonService.BuildTimestamp(Config.TimestampOffset);
            string enc_pwd       = pe.Encrypt(password, ts);
            Dictionary <string, string> paramList = CommonService.BuildForm(username, enc_pwd);
            string attempt = WebRequestHelper.CreateRequest(url, "POST", paramList);

            LoginResponseResult result = new LoginResponseResult(attempt);

            // There are several kinds of error, but only "password_error" should be retried with the responsed timestamp.
            if (result.Status == ResponseStatus.Error && result.Message == "password_error")
            {
                long correctTime = result.Timestamp;
                enc_pwd = pe.Encrypt(password, Convert.ToInt64(correctTime));
                paramList["password"] = enc_pwd;
                string response = WebRequestHelper.CreateRequest(url, "POST", paramList);
                result            = new LoginResponseResult(response);
                result.Timestamp  = correctTime;
                result.TimeOffset = result.Timestamp - ts;
            }
            return(result);
        }