protected override void OnResume() { //CheckNeWVersion (); // FileInfo fi = new FileInfo (Path.Combine(Common.DatabaseFileDir(), "presents.xml")); // Zip.Compress (fi); UploadFiles uf = new UploadFiles(this); uf.CheckFiles(); base.OnResume(); }
protected override void OnResume() { //CheckNeWVersion (); // FileInfo fi = new FileInfo (Path.Combine(Common.DatabaseFileDir(), "presents.xml")); // Zip.Compress (fi); UploadFiles uf = new UploadFiles (this); uf.CheckFiles (); base.OnResume (); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.SyncView); Window.AddFlags(WindowManagerFlags.KeepScreenOn); settings = Common.GetSettings(); files = new Dictionary <string, DLFile>(); files.Add("App", new DLFile() { path = Path.Combine(Common.DatabaseFileDir(), settings.packageName), isNew = false }); files.Add("Prs", new DLFile() { path = Path.Combine(Common.DatabaseFileDir(), "presents.xml.gz"), isNew = false }); // filePath = Path.Combine(Common.DatabaseFileDir(), settings.packageName); vrsnAppCurr = PackageManager.GetPackageInfo(PackageName, PackageInfoFlags.Activities).VersionName; // vrsnPrsCurr = settings.vrsnOfPresents; client = new WebClient(); client.DownloadStringCompleted += (object sender, DownloadStringCompletedEventArgs e) => { if (File.Exists(files["Prs"].path)) { string fileText = File.ReadAllText(files["Prs"].path); vrsnPrsCurr = UploadFiles.GetMd5Hash(fileText); } else { vrsnPrsCurr = ""; }; try { XmlDocument doc = new XmlDocument(); doc.LoadXml(e.Result); files["App"].vrsnNew = doc.GetElementById("versionApp").InnerText; files["Prs"].vrsnNew = doc.GetElementById("versionPrs").InnerText; files["App"].isNew = !bool.Equals(vrsnAppCurr, files["App"].vrsnNew); files["Prs"].isNew = !bool.Equals(vrsnPrsCurr, files["Prs"].vrsnNew); if ((files["App"].isNew) || (files["Prs"].isNew)) { RunOnUiThread(() => CheckLoadPackage()); } } catch (Exception exc) { RunOnUiThread(() => Toast.MakeText(this, exc.Message, ToastLength.Long).Show()); } }; client.DownloadDataCompleted += (object sender, DownloadDataCompletedEventArgs e) => { if (File.Exists(filePath)) { File.Delete(filePath); } ; try { File.WriteAllBytes(filePath, e.Result); RunOnUiThread(() => txtProgress.Text = "Загрузка окончена"); RunOnUiThread(() => Toast.MakeText(this, "ALL", ToastLength.Short).Show()); RunOnUiThread(() => pB.Visibility = ViewStates.Gone); RunOnUiThread(() => CheckLoadPackage()); } catch (Exception exc) { RunOnUiThread(() => Toast.MakeText(this, exc.Message, ToastLength.Long).Show()); } }; client.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) => { if (pB.Visibility == ViewStates.Visible) { RunOnUiThread(() => pB.Activated = true); RunOnUiThread(() => pB.Max = (int)e.TotalBytesToReceive); RunOnUiThread(() => pB.Progress = (int)e.BytesReceived); } }; pB = FindViewById <ProgressBar> (Resource.Id.StatusProgress); pB.Visibility = ViewStates.Gone; txtVersion = FindViewById <TextView> (Resource.Id.txtVersion); txtVersion.Text = "Текущая версия программы: " + PackageManager.GetPackageInfo(PackageName, PackageInfoFlags.Activities).VersionName; btnUpdateApp = FindViewById <Button> (Resource.Id.btnUpdateApp); btnUpdateApp.Visibility = ViewStates.Gone; btnDownLoadPresents = FindViewById <Button> (Resource.Id.btnDownLoadPresents); btnDownLoadPresents.Visibility = ViewStates.Gone; btnDownLoadPresents.Click += (object sender, EventArgs e) => { pB.Visibility = ViewStates.Visible; if (DownLoad.HasConnection(this) && !client.IsBusy) { filePath = files ["Prs"].path; client.DownloadDataAsync(new Uri(settings.dlSite + "presents.xml.gz")); files ["Prs"].isNew = false; btnDownLoadPresents.Visibility = ViewStates.Gone; } else { btnDownLoadPresents.Text = "Подождите окончания другой загрузки..."; } }; txtProgress = FindViewById <TextView> (Resource.Id.txtProgress); txtProgress.Text = "Идет сверка информации с сервером..."; btnUploadFiles = FindViewById <Button> (Resource.Id.btnUploadFiles); btnUploadFiles.Visibility = ViewStates.Gone; btnUploadFiles.Click += (object sender, EventArgs e) => { var t = new Thread(() => { string loadResult = ""; RunOnUiThread(() => pB.Visibility = ViewStates.Visible); RunOnUiThread(() => pB.Activated = true); RunOnUiThread(() => pB.Max = 5); RunOnUiThread(() => pB.Progress = 0); RunOnUiThread(() => txtProgress.Text = "Идет синхронизация с сервером..."); loadResult = UploadFiles.LoadFile("Settings"); Console.WriteLine(loadResult); RunOnUiThread(() => pB.Progress = 1); //RunOnUiThread(() => txtProgress.Text = loadResult); Thread.Sleep(1000); loadResult = UploadFiles.LoadFile("DoctorDB"); Console.WriteLine(loadResult); RunOnUiThread(() => pB.Progress = 2); //RunOnUiThread(() => txtProgress.Text = loadResult); Thread.Sleep(1000); //RunOnUiThread(() => txtProgress.Text = "load HospitalDB"); loadResult = UploadFiles.LoadFile("HospitalDB"); Console.WriteLine(loadResult); RunOnUiThread(() => pB.Progress = 3); //RunOnUiThread(() => txtProgress.Text = loadResult); Thread.Sleep(1000); //RunOnUiThread(() => txtProgress.Text = "load Demonstration"); loadResult = UploadFiles.LoadFile("Demonstration"); Console.WriteLine(loadResult); RunOnUiThread(() => pB.Progress = 4); //RunOnUiThread(() => txtProgress.Text = loadResult); Thread.Sleep(1000); if (loadResult.Contains("FILE SAVED")) { string reportString = UploadFiles.DownLoadReport(); DemonstrationManager.CurrentDemonstrationToArchive(); var serializer = new XmlSerializer(typeof(List <Report>)); using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(reportString))) { List <Report> dlReport = (List <Report>)serializer.Deserialize(stream); List <Report> curReport = (List <Report>)ReportManager.GetReports(); if (curReport.Count == 0) { curReport = dlReport; } else { for (int dl = 0; dl < dlReport.Count; dl++) { var report = curReport.Find(r => r.doctorID == dlReport[dl].doctorID); if (report == null) { curReport.Add(dlReport[dl]); } else { for (int i = 0; i < dlReport[dl].rItems.Count; i++) { var rItem = report.rItems.Find(ri => ri.weekNum == dlReport[dl].rItems[i].weekNum); if (rItem == null) { report.rItems.Add(dlReport[dl].rItems[i]); } else { rItem.visitCount = rItem.visitCount + dlReport[dl].rItems[i].visitCount; } } } } } if (ReportManager.SaveReports(curReport)) { Console.WriteLine("Report saved..."); //RunOnUiThread(() => txtProgress.Text = "Report saved..."); } else { Console.WriteLine("Report not saved..."); //RunOnUiThread(() => txtProgress.Text = "Report not saved..."); } } } RunOnUiThread(() => pB.Progress = 5); Thread.Sleep(2500); Console.WriteLine("Uploading finished..."); RunOnUiThread(() => pB.Visibility = ViewStates.Gone); RunOnUiThread(() => txtProgress.Visibility = ViewStates.Visible); RunOnUiThread(() => txtProgress.Text = "Синхронизация успешно завершена."); RunOnUiThread(() => btnUploadFiles.Visibility = ViewStates.Invisible); } ); t.Start(); //RunOnUiThread(() => pB.Activated = true); //RunOnUiThread(() => pB.Max = (int)e.TotalBytesToReceive); //RunOnUiThread(() => pB.Progress = (int)e.BytesReceived); //txtProgress.Text = "load DoctorDB"; //txtProgress.Text = UploadFiles.LoadFile("DoctorDB");//Toast.MakeText(this, "Toast within progress dialog.", ToastLength.Long).Show()); //txtProgress.Text = "load HospitalDB"; //txtProgress.Text = UploadFiles.LoadFile("HospitalDB"); //Console.WriteLine ("Uploading finished..."); }; }