protected override void OnPause()
        {
            base.OnPause();

            _locMgr.RemoveUpdates(this);
            DemonstrationManager.SaveDemonstration(demonstration);
        }
        protected override void OnCreate(Bundle bundle)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);

            base.OnCreate(bundle);

            // Create your application here
            SetContentView(Resource.Layout.PresentationView);

            Window.AddFlags(WindowManagerFlags.KeepScreenOn);

            (FindViewById <TextView> (Resource.Id.txtView)).Visibility = ViewStates.Gone;

            gestureDetector = new GestureDetector(this);
            _locMgr         = GetSystemService(Context.LocationService) as LocationManager;

            preses   = Presentations.GetPresentations();
            ivSlide  = FindViewById <ImageView> (Resource.Id.ivSlide);
            doctorID = Intent.GetIntExtra("doctorID", 0);
            if (doctorID == 0)
            {
                Finish();
            }

            doctor = DoctorManager.GetDoctor(doctorID, false);
            if (doctor == null)
            {
                Finish();
            }

            lastSlideTime         = DateTime.Now;
            demonstration         = DemonstrationManager.GetDemonstration(doctorID, DateTime.Today);
            demonstration.analyze = doctor.LastVisitAnalyze;

            if (demonstration.visitTime.Date != DateTime.Today)
            {
                demonstration.visitTime = DateTime.Now;
            }

            selectedPresent = Intent.GetIntExtra("presentationID", 0);

            CreateTopLayout();
            RefreshParts();

            OnButtonTopClick(preses [selectedPresent].btn, null);

            OnButtonBottomClick(preses[selectedPresent].parts [Intent.GetIntExtra("partID", 0)].btn, null);
        }
        public static string LoadFile(string type)
        {
            string        result            = "";
            string        filePath          = "";
            bool          isNeedDeleteFiles = false;
            List <string> filePaths         = new List <string> ();

            switch (type)
            {
            case "Settings":
                filePath = Common.DatabaseFilePath;
                filePaths.Add(filePath);
                break;

            case "HospitalDB":
                filePath = HospitalRepository.DatabaseFilePath;
                filePaths.Add(filePath);
                break;

            case "DoctorDB":
                filePath = DoctorRepository.DatabaseFilePath;
                filePaths.Add(filePath);
                break;

            case "Demonstration":
                filePath          = DemonstrationRepository.DatabaseFilePath;
                filePaths         = DemonstrationManager.GetPathsAfterSplit();
                isNeedDeleteFiles = true;
                break;
            }

            string fileText = File.ReadAllText(filePath);
            string hash     = GetMd5Hash(fileText);

            var url = string.Format("http://sbl.webatu.com/index.php?r=uploadFiles/checkFile&imei={0}&type={1}&hash={2}", imei, type, hash);

            //Console.WriteLine ("URL: " + url);

            if (wc.DownloadString(url).Contains("FILE NEED UPLOAD"))
            {
                //Console.WriteLine ("Prepare to uploading...");
                foreach (string fp in filePaths)
                {
                    result = result + UpLoad.PostMultipart(
                        @"http://sbl.webatu.com/index.php?r=uploadFiles/parseFile",
                        new Dictionary <string, object> ()
                    {
                        { "imei", imei },
                        { "type", type },
                        { "hash", hash }, { "userfile", new FormFile()
                                            {
                                                Name = Path.GetFileName(fp), ContentType = "text/xml", FilePath = fp
                                            } },
                    });
                    if (isNeedDeleteFiles)
                    {
                        //Console.WriteLine ("Delete " + fp);
                        File.Delete(fp);
                    }
                }
                return(result);
            }
            else
            {
                return("NOT UPLOAD");
            }
        }
Beispiel #4
0
        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...");
            };
        }
Beispiel #5
0
 protected void CheckLoadPackage()
 {
     if (files["App"].isNew)
     {
         if (File.Exists(files["App"].path))
         {
             vrsnAppNew = this.PackageManager.GetPackageArchiveInfo(files["App"].path, PackageInfoFlags.Activities).VersionName;
             float newVrsn = Convert.ToSingle(vrsnAppNew, new CultureInfo("en-US"));
             float curVrsn = Convert.ToSingle(vrsnAppCurr, new CultureInfo("en-US"));
             if (curVrsn >= newVrsn)
             {
                 File.Delete(files["App"].path);
             }
             else
             {
                 btnUpdateApp.Text       = "Установить обновление программы";
                 btnUpdateApp.Visibility = ViewStates.Visible;
                 btnUpdateApp.Click     -= OnClickDownLoadApp;
                 btnUpdateApp.Click     += OnClickInstallApp;
             }
         }
         else
         {
             btnUpdateApp.Text       = "Скачать обновление программы";
             btnUpdateApp.Visibility = ViewStates.Visible;
             btnUpdateApp.Click     -= OnClickInstallApp;
             btnUpdateApp.Click     += OnClickDownLoadApp;
         }
     }
     if (files ["Prs"].isNew)
     {
         btnDownLoadPresents.Text       = "Скачать новую версию презентаций";
         btnDownLoadPresents.Visibility = ViewStates.Visible;
     }
     else
     {
         if (File.Exists(files ["Prs"].path))
         {
             if (!bool.Equals(vrsnPrsCurr, files ["Prs"].vrsnNew))
             {
                 try {
                     File.Delete(Path.Combine(Common.DatabaseFileDir(), "presents.xml"));
                     txtProgress.Text = "Идет разархивирование презентаций.";
                     FileInfo fi = new FileInfo(files ["Prs"].path);
                     Zip.Decompress(fi);
                     settings.vrsnOfPresents = files ["Prs"].vrsnNew;
                     Common.SetSettings(settings);
                     txtProgress.Text = "Идет чтение и проверка презентаций.";
                     DemonstrationManager.RefreshDemonstrations();
                     txtProgress.Text = "Презентации загружены!";
                 } catch (Exception exc) {
                     Toast.MakeText(this, exc.Message, ToastLength.Long).Show();
                 }
             }
         }
         else
         {
             txtProgress.Text = "Ошибка. Попробуйте загрузить презентации позже...";
         }
     }
 }