Exemplo n.º 1
0
        private static void GetContactsFromResponse(WebResponse response, StatusDownload loghandler)
        {
            var httpResponse = response.GetResponseStream();

            using (var streamReader = new StreamReader(httpResponse))
            {
                var result = streamReader.ReadToEnd();

                var receivedData = JsonConvert.DeserializeObject <CustomerSyncResult>(result);
                if (receivedData.success)
                {
                    var contacts = receivedData.contacts;
                    DBLocalDataStore.GetInstance().ClearAllContacts();
                    foreach (var contact in contacts)
                    {
                        if (string.IsNullOrEmpty(contact.uid))
                        {
                            Console.WriteLine("Received contact {0} has no UID, ignoring", JsonConvert.SerializeObject(contact, Formatting.Indented));
                            continue;
                        }
                        var localContact = new DBlocalContact(contact);
                        localContact.source = ContactSource.Server;
                        DBLocalDataStore.GetInstance().AddLocalContact(localContact);
                        Console.Error.WriteLine("Contact with UID {0} added", contact.uid);
                    }
                    loghandler(true, "Contacts updated from server");
                }
                else
                {
                    loghandler(false, receivedData.error);
                }
            }
        }
Exemplo n.º 2
0
        private void DownloadEnded(object sender, DownloaderEventArgs e)
        {
            Console.WriteLine(e.Downloader.State == DownloaderState.EndedWithError
                                ? $"Download Ended With Error '{e.Downloader.LastError.Message}'"
                                : "Download Ended");

            // validate file
            SetControlPropertyValue(status, "Text", "Validating file...");
            if (FileValidator.Validate(e.Downloader.LocalFile, Hash))
            {
                SetControlPropertyValue(status, "Text", "Download finished");
            }
            else
            {
                SetControlPropertyValue(status, "Text", "Invalid file");
            }

            // update window
            SetControlPropertyValue(start, "Text", "Close");
            SetControlPropertyValue(progress, "Value", 100);
            Downloads = StatusDownload.finished;

            // force to update the persisted list
            _persistedList.Dispose();
            _manualResetEventSlim.Set();
        }
Exemplo n.º 3
0
 private void PauseDownloads()
 {
     status.Text = "Saving...";
     //pause all and force update
     _persistedList.Dispose();
     status.Text = "Paused";
     start.Text  = "Resume";
     Downloads   = StatusDownload.paused;
 }
Exemplo n.º 4
0
        private void ResumeDownloads()
        {
            var downloader = DownloadManager.Instance.Downloads.FirstOrDefault();

            downloader.Start();
            status.Text = "Downloading...";
            start.Text  = "Pause";
            Downloads   = StatusDownload.downloading;
            Thread t = new Thread(UpdateProgress);

            t.Start();
        }
Exemplo n.º 5
0
        public static async Task GetContacts(StatusDownload loghandler)
        {
            SyncContext scr = new SyncContext();

            DBAppInfo appInfo = DBLocalDataStore.GetInstance().GetAppInfo();

            var user = DBLocalDataStore.GetInstance().GetLocalUserInfo();

            scr.context = new RequestData();
            var output = scr.context;

            output.password          = user.password;
            output.username          = user.username;
            output.profile           = DBLocalDataStore.GetInstance().GetSelectProfile().shortName;
            output.tags              = new string[] { user.tags };
            output.campaignReference = appInfo.campaignReference;

            var jsonUser = JsonConvert.SerializeObject(scr);

            var httpWebRequest = (HttpWebRequest)WebRequest.Create(ServerURLs.contactsURLNew);

            try
            {
                //throw new Exception("TEST EXCEPTION");
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                httpWebRequest.Timeout     = 30000;
                httpWebRequest.KeepAlive   = false;

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    streamWriter.Write(jsonUser);
                }

                var response = await httpWebRequest.GetResponseAsync();

                NetworkRequests.GetContactsFromResponse(response, loghandler);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                throw;
            }
            finally
            {
                httpWebRequest.Abort();
            }
        }
Exemplo n.º 6
0
        private void StartDownloads()
        {
            var resourceLocation = SegmentDownloader.Core.ResourceLocation.FromURL(Url);

            // local file path
            var uri           = new Uri(Url);
            var fileName      = uri.Segments.Last();
            var localFilePath = Path.Combine(LocalFolder, fileName);

            // create downloader with 8 segments
            var downloader = DownloadManager.Instance.Add(resourceLocation, null, localFilePath, 8, false);

            // start download
            downloader.Start();
            status.Text = "Downloading...";
            start.Text  = "Pause";
            Downloads   = StatusDownload.downloading;

            Thread t = new Thread(UpdateProgress);

            t.Start();
        }