Пример #1
0
        public ProfileSyncObject SyncEvent(String token, String lastSyncTime) 
        {
            var maxLimit = 200;
            String currentTime = lastSyncTime;
            if (lastSyncTime == null) {
                currentTime = String.Format("{0:yyyy-MM-ddTHH:mm:ss.000Z}", DateTime.Now.AddDays(-2));
            }

            String url = Resource.endpoint + "wittyparrot/api/sync?from=" + currentTime + "&maxLimit=" + maxLimit + "";
            var client = new RestClient();
            client.BaseUrl = new Uri(url);

            var request = new RestRequest();
            request.Method = Method.GET;
            request.AddHeader("Authorization", "Bearer " + token);
            request.Parameters.Clear();
            request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
            request.RequestFormat = DataFormat.Json;

            // execute the request
            IRestResponse response = client.Execute(request);


            if (response.ErrorException != null || response.StatusCode == System.Net.HttpStatusCode.BadRequest)
            {
                var statusMessage = RestUtils.getErrorMessage(response.StatusCode);
                MessageBox.Show(statusMessage == "" ? response.StatusDescription : statusMessage);
                var myException = new ApplicationException(response.StatusDescription, response.ErrorException);
                throw myException;
            }

            Common.lastLocalDBSyncTime = DateTime.UtcNow.ToString();

            ProfileSyncDao profileSyncDao = new ProfileSyncDao();
            profileSyncDao.saveProfileSyncTime("success");

            ProfileSyncObject syncObj = new ProfileSyncObject();
            String content = response.Content;
            syncObj = JsonConvert.DeserializeObject<ProfileSyncObject>(content);


            return syncObj;
        }
Пример #2
0
        // check if the clicked element is refresh or logout
        // Sync thread calls the startProfileSync
        public void statusBar1_PanelClick(object sender, StatusBarPanelClickEventArgs e) {

            if (e.StatusBarPanel.Name == "refresh")
            {
                if (userName == null || password == null)
                {
                    MessageBox.Show("User not loggedin");
                }
                else {

                    ProfileSyncDao profileSyncDao = new ProfileSyncDao();                  
                    Thread thread = new Thread(() => profileSyncDao.startProfileSync());                 
                    thread.Start();   
                }

               
            }

            if (e.StatusBarPanel.Name == "logout")
            {
                if (userName == null || password == null)
                {
                    MessageBox.Show("User not loggedin");
                }
                else {

                    DialogResult dialogResult = MessageBox.Show("Do you want to logout ?", "", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        logout();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        //do something else
                    }

                   
                }
            }
        }