示例#1
0
 public void OnBind()
 {
     if (service != null)
     {
         service.ResetUpdateInterval();
         network.SetBackgroundService(service);
     }
 }
示例#2
0
		public void DoWork ()
		{
			db = new DataBaseWrapper (Resources);
			network = new AsyncNetwork ();
			network.SetBackgroundService (this);
			user = db.Table<User>().FirstOrDefault ();
			var connectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService);

			if (user != null && user.user != null) {
				var t = new Thread (async () => {
					while (true) {
						Setting.Frequency f = db.Table<Setting>().FirstOrDefault().Synchronisation;
						if (f != Setting.Frequency.wlan || connectivityManager.GetNetworkInfo(ConnectivityType.Wifi).GetState() == NetworkInfo.State.Connected) {
							while(!await network.UpdateEvents (db, user)) {
								await network.Authenticate(db, user);
							}
						}

						// Wifi connection gets normal updates, other networks get 4 times worse update time.
						if (connectivityManager.GetNetworkInfo(ConnectivityType.Wifi).GetState() == NetworkInfo.State.Connected)
						{
							connectivityMode = 1;
						} else {
							connectivityMode = 4;
						}

						switch(f) {
						case Setting.Frequency.often:
							Mode = 1;
							break;
						case Setting.Frequency.normal:
							Mode = 2;
							break;
						case Setting.Frequency.rare:
							Mode = 4;
							break;
						case Setting.Frequency.wlan:
							Mode = 2;
							break;
						}

						Thread.Sleep (UpdateInterval * Mode* connectivityMode);

						if (UpdateInterval < 12000) {
							UpdateInterval += 1000;
						} else if (UpdateInterval < 30000) {
							UpdateInterval += 2000;
						} else {
							UpdateInterval = 120000;
						}
					}
				}
				);
				t.Start ();
			} else {
				StopSelf ();
			}
		}
示例#3
0
 public void OnBind()
 {
     if (service != null)
     {
         service.ResetUpdateInterval();
         service.ActiveConversation = conversation;
         service.ChatActivity       = this;
         network.SetBackgroundService(service);
         service.CancelNotify(conversation);
     }
 }
示例#4
0
        public void DoWork()
        {
            db      = new DataBaseWrapper(Resources);
            network = new AsyncNetwork();
            network.SetBackgroundService(this);
            user = db.Table <User>().FirstOrDefault();
            var connectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService);

            if (user != null && user.user != null)
            {
                var t = new Thread(async() => {
                    while (true)
                    {
                        Setting.Frequency f = db.Table <Setting>().FirstOrDefault().Synchronisation;
                        if (f != Setting.Frequency.wlan || connectivityManager.GetNetworkInfo(ConnectivityType.Wifi).GetState() == NetworkInfo.State.Connected)
                        {
                            while (!await network.UpdateEvents(db, user))
                            {
                                await network.Authenticate(db, user);
                            }
                        }

                        // Wifi connection gets normal updates, other networks get 4 times worse update time.
                        if (connectivityManager.GetNetworkInfo(ConnectivityType.Wifi).GetState() == NetworkInfo.State.Connected)
                        {
                            connectivityMode = 1;
                        }
                        else
                        {
                            connectivityMode = 4;
                        }

                        switch (f)
                        {
                        case Setting.Frequency.often:
                            Mode = 1;
                            break;

                        case Setting.Frequency.normal:
                            Mode = 2;
                            break;

                        case Setting.Frequency.rare:
                            Mode = 4;
                            break;

                        case Setting.Frequency.wlan:
                            Mode = 2;
                            break;
                        }

                        Thread.Sleep(UpdateInterval * Mode * connectivityMode);

                        if (UpdateInterval < 12000)
                        {
                            UpdateInterval += 1000;
                        }
                        else if (UpdateInterval < 30000)
                        {
                            UpdateInterval += 2000;
                        }
                        else
                        {
                            UpdateInterval = 60000;
                        }
                    }
                }
                                   );
                t.Start();
            }
            else
            {
                StopSelf();
            }
        }