public override async System.Threading.Tasks.Task<DataAccessLayer.SOAResult> DownloadLocalAsync(User user, string deviceLanguage)
        {
            Console.WriteLine("__________________________________ START ___________________________________________________");
            DataAccessLayer.SOAResult result = DataAccessLayer.SOAResult.FALSE;
            try
                {
                // In this progress we increase the progress status, too
                // Main step: Kunden Data
                DataAccessLayer.PerformanceWatch stopWatch = new DataAccessLayer.PerformanceWatch();
                stopWatch.Start();
                ResetProgressStatus();

                ProgressStatusWish = 1;
                DataAccessLayer.DAL_Kunde dal_Kunde = new DataAccessLayer.DAL_Kunde();

                using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                    result = await dal_Kunde.InsertKundeAsync(this, user,true); 
                }
//                result = await dal_Kunde.InsertKundeAsync(this,  user,true);
                ProgressStatus = 1;
                stopWatch.Stop();
                stopWatch.PrintConsole ("InsertKundeAsync");



                // Then the related data
                // 1. Ansprechpartner

                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 2;
                    List<Ansprechpartner> ansprechpartnern = await Ansprechpartner.GetAnsprechpartnernAsync(this.ID, deviceLanguage, user);
                    ProgressStatus += 2;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("GetAnsprechpartnernAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 1;
                    DataAccessLayer.DAL_Ansprechpartner dal_ansprechpartner = new DataAccessLayer.DAL_Ansprechpartner();
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                    result =  await System.Threading.Tasks.Task.Run(() =>dal_ansprechpartner.InsertAnsprechpartnernAsync(ansprechpartnern,user,true));
                    }
                    ProgressStatus += 1;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("InsertAnsprechpartnernAsync");
                    ansprechpartnern = null;
                }

                // 2. PersonUmsatz for Charts
                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 3;
                    List<BusinessLayer.PersonUmsatz> PersonUmsatzList =  await GetPersonTimeUmsatzAsync ("36",   user);
                    ProgressStatus += 3;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("GetPersonTimeUmsatzAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 2;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                    result =  await System.Threading.Tasks.Task.Run(() =>dal_Kunde.InsertPersonUmsatzAsync(PersonUmsatzList ,this, user, true));
                    }
                    ProgressStatus += 2;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("InsertPersonUmsatzAsync");
                    PersonUmsatzList = null;
                    stopWatch.PrintConsole ("Finished InsertPersonUmsatzAsync");
                }

                // 3. Tasks and related data
                // I. Tasks
                DataAccessLayer.DAL_Task dal_task = new DataAccessLayer.DAL_Task();
                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 11;
                    Console.WriteLine("Start dal_task.GetTasksAsync");
                    List<Task> tasks = await dal_task.GetTasksAsync(this.ID,  user);
                    ProgressStatus += 11;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("GetTasksAsync");
                    stopWatch.Start();
                    stopWatch.PrintConsole ("GetTasksAsync2");
                    ProgressStatusWish += 32;
                    stopWatch.PrintConsole ("GetTasksAsync3");

                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                                           result =  await System.Threading.Tasks.Task.Run(() =>dal_task.InsertTasksAsync(tasks, user, true));
                    }
                    stopWatch.PrintConsole ("GetTasksAsync4");

                    //result = await dal_task.InsertTasksAsync(tasks, user, true);
                    ProgressStatus += 32;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("InsertTasksAsync");
                    tasks = null;

                }

                // II. TaskArt
                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 2;
                    List<TaskArt> taskArts = await DataAccessLayer.DAL_Task.GetTaskArtsAsync(user);
                    ProgressStatus += 2;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("GetTaskArtsAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 1;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                    result =  await System.Threading.Tasks.Task.Run(() =>dal_task.InsertTaskArtsAsync(taskArts, user, true));
                    }
                    ProgressStatus += 1;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("InsertTaskArtsAsync");
                    taskArts = null;
                }

                // III. TaskTyp
                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 3;
                    List<TaskTyp> taskTyps = await DataAccessLayer.DAL_Task.GetTaskTypsAsync(user);
                    ProgressStatus += 3;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("GetTaskTypsAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 1;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                                           result =  await System.Threading.Tasks.Task.Run(() =>dal_task.InsertTaskTypsAsync(taskTyps, user, true));
                    }
                    ProgressStatus += 1;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("InsertTaskTypsAsync");
                }

                // IV. Mitarbeiter
                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 2;
                    List<Mitarbeiter> mitarbeitern = await DataAccessLayer.DAL_Task.GetTaskMitarbeiternAsync(user);
                    ProgressStatus += 2;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("GetTaskMitarbeiternAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 1;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                    result =  await System.Threading.Tasks.Task.Run(() =>dal_task.InsertMitarbeiternAsync(mitarbeitern, user, true));
                    }
                    ProgressStatus += 1;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("InsertMitarbeiternAsync");
                }

                // V. Abteilung
                if (result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 2;
                    List<Abteilung> abteilungen = await DataAccessLayer.DAL_Task.GetTaskAbteilungenAsync(user);
                    ProgressStatus += 2;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("GetTaskAbteilungenAsync");
                    stopWatch.Start();
                    ProgressStatusWish += 1;
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                    result =  await System.Threading.Tasks.Task.Run(() => dal_task.InsertAbteilungenAsync(abteilungen, user, true));
                    }
                    ProgressStatus += 1;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("InsertAbteilungenAsync");
                }

                // VI. Angebote
                DataAccessLayer.DAL_Angebot dal_angebot = new DataAccessLayer.DAL_Angebot();
                DataAccessLayer.DAL_Position dal_position = new DataAccessLayer.DAL_Position();
                if(result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 7;
                    List<Angebot> angebote = await dal_angebot.GetAngeboteAsync(ID, deviceLanguage, user);
                    ProgressStatus += 7;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("GetAngeboteAsync");
                    stopWatch.Start();
                    foreach (var angebot in angebote)
                    {
                        List<Position> positionen = await dal_position.GetPositionenAsync(angebot.ID, angebot.Waehrung, deviceLanguage, user);
                        result = await System.Threading.Tasks.Task.Run(() => dal_position.InsertPositionenAsync(positionen, user, true));
                    }
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("AngebotGetPositionenAsyncInsertPositionenAsync");
                    ProgressStatusWish += 11;
                    stopWatch.Start();
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                    result =  await System.Threading.Tasks.Task.Run(() => dal_angebot.InsertAngeboteAsync(angebote, user, true));
                    }
                    ProgressStatus += 11;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("InsertAngeboteAsync");

                }

                // VI. Auftraege
                DataAccessLayer.DAL_Auftrag dal_auftrag = new DataAccessLayer.DAL_Auftrag();

                if(result == DataAccessLayer.SOAResult.TRUE)
                {
                    stopWatch.Start();
                    ProgressStatusWish += 7;
                    List<Auftrag> auftraege = await dal_auftrag.GetAuftraegeAsync(ID, deviceLanguage, user);
                    ProgressStatus += 7;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("GetAuftraegeAsync");
                    stopWatch.Start();
                    foreach (var auftrag in auftraege)
                    {

                        List<Position> positionen = await dal_position.GetPositionenAsync(auftrag.ID, auftrag.Waehrung, deviceLanguage, user);
                        result = await System.Threading.Tasks.Task.Run(() => dal_position.InsertPositionenAsync(positionen, user, true));
                    }
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("AuftragGetPositionenAsyncInsertPositionenAsync");
                    ProgressStatusWish += 6;
                    stopWatch.Start();
                    using (await DataAccessLayer.SQLiteUtilities.Mutex.LockAsync ().ConfigureAwait (false)) { 
                                           result =  await System.Threading.Tasks.Task.Run(() => dal_auftrag.InsertAuftraegeAsync(auftraege, user, true));
                    }
                    ProgressStatus += 6;
                    stopWatch.Stop();
                    stopWatch.PrintConsole ("InsertAuftraegeAsync");
                    Console.WriteLine("__________________________________ END ___________________________________________________");

                }
            }
            catch (Exception ex)
            {
                DataAccessLayer.ExceptionWriter.WriteLogFile(ex);
            }

            return result;

        }
Example #2
0
		async private void  ListItemClickAsync ( AdapterView.ItemClickEventArgs args)
		{
			ProgressDialog progressDialog = null;

			try
			{
				// Run the progressbar
                progressDialog = ProgressDialog.Show(this, "Apollo",Resources.GetString(Resource.String.Loading), false);
				progressDialog.SetProgressStyle(ProgressDialogStyle.Spinner);
				DataAccessLayer.PerformanceWatch stopWatch = new DataAccessLayer.PerformanceWatch();
				stopWatch.Start();

				Android.Views.InputMethods.InputMethodManager imm = (Android.Views.InputMethods.InputMethodManager)GetSystemService(Context.InputMethodService);
				imm.HideSoftInputFromWindow(_edSearch.WindowToken, 0);


				_list.ChoiceMode = ChoiceMode.Single;

//				if (selectedRow != null)
//					selectedRow.SetBackgroundResource(Android.Resource.Color.Transparent);
//
				_list.SetItemChecked (args.Position ,true);
//
//				if (selectedRow != null) {
//					selectedRow.SetBackgroundResource(Android.Resource.Color.Transparent);
//				}
//				selectedRow = args.View;
				//args.View.SetBackgroundResource(Android.Resource.Color.HoloOrangeDark);

				await _mainUIManager.ListViewClickAsync (args.Position);			

				// This could happen to fast, so show the progress dialog for a second
				stopWatch.Stop();
				if (stopWatch.ElapsedMilliseconds < 500)
					System.Threading.Thread.Sleep (500);

			}
			catch(Exception ex)
			{
                DataAccessLayer.ExceptionWriter.WriteLogFile(ex);
            }
			finally
			{
				// Hide the progressbar
				if (progressDialog != null)
					progressDialog.Dismiss ();
			}

		}