private void RegisterDownload(string uri, string localUri) { //string fileName = System.IO.Path.GetFileName(localUri); string search = "/pub/"; uri = uri.Substring(uri.IndexOf(search) + search.Length).Trim('/'); try { //registrazione download Uri nHost = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl); if (Reachability.IsHostReachable("http://" + nHost.Host)) { var data = _context.DeviceInfo(); data.Add("file", uri); Notification notif = new Notification(); if (!notif.RegisterDownload(data)) { Log.Error("Registrazione download", "Eerrore registrazione download"); } Log.Info(this.Title, "Fine download"); } } catch (Exception value) { Console.WriteLine(value); } }
private void Login() { Uri host = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl); if (!Reachability.IsHostReachable("http://" + host.Host)) { var alert = new AlertDialog.Builder(Activity); alert.SetTitle(GetString(Resource.String.gen_error)); alert.SetMessage(GetString(Resource.String.gen_serverNotReachable)); alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null); alert.Show().SetDivider(); } if (_txtUser.Text == "" || _txtPasswd.Text == "") { return; } _txtUser.ClearFocus(); _txtPasswd.ClearFocus(); var inputManager = Activity.GetSystemService(Context.InputMethodService) as InputMethodManager; inputManager.HideSoftInputFromWindow(_txtUser.WindowToken, HideSoftInputFlags.None); LoginResult result = DownloadManager.CheckUser(_txtUser.Text, _txtPasswd.Text); if (result.Success) { Intent myIntent = new Intent(Activity, typeof(DownloadFragment)); myIntent.PutExtra("action", "refresh"); Activity.SetResult(Result.Ok, myIntent); //Activity.Finish(); DataManager.Get <IPreferencesManager>().Preferences.DownloadUsername = _txtUser.Text; DataManager.Get <IPreferencesManager>().Preferences.DownloadPassword = _txtPasswd.Text; DataManager.Get <IPreferencesManager>().Save(); Activity.Finish(); if (LoginSuccess != null) { LoginSuccess(); } } else { if (result.Message != null && result.Message != "") { _lblResult.Text = result.Message; } else { _lblResult.Text = Activity.GetString(Resource.String.set_loginFailed); } } }
private void SendReset() { string url = DataManager.Get <ISettingsManager>().Settings.DownloadUrl; Uri host = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl); if (!Reachability.IsHostReachable("http://" + host.Host)) { var alert = new AlertDialog.Builder(Activity); alert.SetTitle(GetString(Resource.String.gen_error)); alert.SetMessage(GetString(Resource.String.gen_serverNotReachable)); alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null); alert.Show().SetDivider(); } url += "services/edicola_services.php?action=resetPassword&mail=" + _txtMail.Text + "&app=" + DataManager.Get <ISettingsManager>().Settings.AppId; try { XDocument xDoc = XDocument.Load(url); var result = xDoc.Element("root").Element("result"); if (XMLUtils.GetBoolValue(result.Attribute("success"))) { _lblResult.Text = GetString(Resource.String.set_mailPasswd); } else { switch (XMLUtils.GetIntValue(result.Attribute("code"))) { case 1: _lblResult.Text = GetString(Resource.String.log_mail_invalid); break; case 2: _lblResult.Text = GetString(Resource.String.set_mailProblem); break; default: break; } } } catch (Exception ex) { Log.Info("resetPassword", ex.Message); _lblResult.Text = GetString(Resource.String.gen_tryLater); } }
private void CheckUpdates() { Uri host = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl); if (!Reachability.IsHostReachable("http://" + host.Host)) { return; } var info = new DirectoryInfo(DataManager.Get <ISettingsManager>().Settings.DocPath); var dir = _CurrentDir.FullName.Replace(info.FullName, "").Trim('/'); ThreadPool.QueueUserWorkItem(delegate { var downloads = DownloadManager.GetDocuments(dir); //var updates = downloads.Where(d => d.Stato == DownloadStato.Update); _downloads = downloads.ToList(); if (Activity == null) { return; } Activity.RunOnUiThread(() => { try { EdicolaGridAdapter adapter = (EdicolaGridAdapter)_EdicolaGridView.Adapter; adapter.CheckUpdates(_downloads); } catch (Exception ex) { Log.Error("", ex.Message); } }); }); }
private void Register() { //string username = txtUsername.Text; string password = _txtPasswd.Text; string mail = _txtUser.Text; if (!Regex.Match(mail, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$").Success) { _lblResult.Text = GetString(Resource.String.log_mail_invalid); return; } if (password.Length < 5) { _lblResult.Text = GetString(Resource.String.log_passwd_short); return; } Uri host = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl); if (!Reachability.IsHostReachable("http://" + host.Host)) { var alert = new AlertDialog.Builder(Activity); alert.SetTitle(GetString(Resource.String.gen_error)); alert.SetMessage(GetString(Resource.String.gen_serverNotReachable)); alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null); alert.Show().SetDivider(); } var result = Notification.RegisterUser(mail, password); if (result["success"].ToLower() == "true") { DataManager.Get <IPreferencesManager>().Preferences.DownloadUsername = mail; DataManager.Get <IPreferencesManager>().Preferences.DownloadPassword = password; DataManager.Get <IPreferencesManager>().Save(); Intent myIntent = new Intent(Activity, typeof(DownloadFragment)); myIntent.PutExtra("action", "refresh"); Activity.SetResult(Result.Ok, myIntent); var alert = new AlertDialog.Builder(Activity); alert.SetMessage(GetString(Resource.String.log_account_created)); alert.SetPositiveButton("Ok", delegate { Activity.Finish(); }); alert.Show(); } else { int resId = Resources.GetIdentifier(result["errorKey"], "string", Activity.PackageName); if (resId == 0) { _lblResult.Text = result["errorKey"]; } else { _lblResult.Text = GetString(resId); } } }
private bool CheckBeforeConnect() { Uri host = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl); if (!Reachability.IsHostReachable("http://" + host.Host)) { if (Activity == null) { return(false); } Activity.RunOnUiThread(() => { StopUpdating(); var alert = new AlertDialog.Builder(Activity); alert.SetTitle(GetString(Resource.String.gen_error)); alert.SetMessage(GetString(Resource.String.gen_serverNotReachable)); alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null); alert.Show().SetDivider(); }); return(false); } //se siamo nella cartella principale controllo la compatibilità con la versione dell'app var verResult = DownloadManager.CheckAppVersion(2); if (!verResult.Success) { Activity.RunOnUiThread(() => { StopUpdating(); var alert = new AlertDialog.Builder(Activity); alert.SetCancelable(false); alert.SetTitle(GetString(Resource.String.gen_error)); alert.SetMessage(GetString(Resource.String.gen_appVersion)); alert.SetPositiveButton(GetString(Resource.String.gen_downApp), delegate { var callIntent = new Intent(Intent.ActionView); Android.Net.Uri uri = Android.Net.Uri.Parse(verResult.Link); callIntent.SetData(uri); this.StartActivity(callIntent); //va all'edicola var home = Activity as HomeScreen; home.GoTo(0); }); alert.SetNegativeButton(GetString(Resource.String.gen_cancel), delegate { //va all'edicola var home = Activity as HomeScreen; home.GoTo(0); }); alert.Show().SetDivider(); }); this.IsUpdating = false; return(false); } //controllo utente disattivato var result = DownloadManager.CheckUser(); if (!result.Success) { if (result.ErrBloccante) { Activity.RunOnUiThread(() => { StopUpdating(); var alert = new AlertDialog.Builder(Activity); alert.SetTitle(GetString(Resource.String.gen_error)); alert.SetMessage(result.Message); alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null); alert.Show().SetDivider(); var adapter = new DownloadGridAdapter(Activity, new List <Object>()); _GridView.Adapter = adapter; StopUpdating(); }); this.IsUpdating = false; return(false); } } return(true); }
private void ShowResetDialog() { var builder = new AlertDialog.Builder(Activity); builder.SetTitle(GetString(Resource.String.set_reset)); builder.SetView(Activity.LayoutInflater.Inflate(Resource.Layout.ResetPasswordDialog, null)); builder.SetPositiveButton(GetString(Resource.String.gen_send), (EventHandler <DialogClickEventArgs>)null); builder.SetNegativeButton(GetString(Resource.String.gen_cancel), (EventHandler <DialogClickEventArgs>)null); builder.SetCancelable(true); var dialog = builder.Create(); dialog.Show(); dialog.SetDivider(); EditText txtMail = dialog.FindViewById <EditText>(Resource.Id.txtMail); TextView lblSuccess = dialog.FindViewById <TextView>(Resource.Id.lblSuccess); ProgressBar prgLogin = dialog.FindViewById <ProgressBar>(Resource.Id.prgLogin); txtMail.Background.Colorize(DataManager.Get <ISettingsManager>().Settings.ButtonColor); //se è edicola con password nascondo il campo username //pulsante login var btnSend = dialog.GetButton((int)DialogButtonType.Positive); if (btnSend == null) { return; } btnSend.Click += (sender, e) => { Activity.RunOnUiThread(() => { lblSuccess.Text = ""; prgLogin.Visibility = ViewStates.Visible; lblSuccess.Visibility = ViewStates.Gone; }); string url = DataManager.Get <ISettingsManager>().Settings.DownloadUrl; if (!Reachability.IsHostReachable("http://" + new Uri(url).Host)) { var alert = new AlertDialog.Builder(Activity); alert.SetTitle(GetString(Resource.String.gen_error)); alert.SetMessage(GetString(Resource.String.gen_serverNotReachable)); alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null); alert.Show().SetDivider(); return; } url += "services/edicola_services.php?action=resetPassword&mail=" + txtMail.Text + "&app=" + DataManager.Get <ISettingsManager>().Settings.AppId; try { XDocument xDoc = XDocument.Load(url); var result = xDoc.Element("root").Element("result"); if (XMLUtils.GetBoolValue(result.Attribute("success"))) { var alert = new AlertDialog.Builder(Activity); alert.SetTitle(GetString(Resource.String.set_reset)); alert.SetMessage(GetString(Resource.String.set_mailPasswd)); alert.SetPositiveButton("Ok", delegate { dialog.Dismiss(); }); alert.Show().SetDivider(); } else { switch (XMLUtils.GetIntValue(result.Attribute("code"))) { case 1: lblSuccess.Text = GetString(Resource.String.set_mailNotValid); break; case 2: lblSuccess.Text = GetString(Resource.String.set_mailProblem); break; default: break; } lblSuccess.Visibility = ViewStates.Visible; prgLogin.Visibility = ViewStates.Gone; } } catch (Exception ex) { Log.Info("resetPassword", ex.Message); lblSuccess.Text = GetString(Resource.String.gen_serverNotReachable); } }; }
private void ShowLoginDialog() { var builder = new AlertDialog.Builder(Activity); builder.SetTitle(_DownCategory.Title); builder.SetView(Activity.LayoutInflater.Inflate(Resource.Layout.LoginDialog, null)); builder.SetPositiveButton("Login", (EventHandler <DialogClickEventArgs>)null); builder.SetNegativeButton(GetString(Resource.String.gen_cancel), (EventHandler <DialogClickEventArgs>)null); builder.SetCancelable(true); var dialog = builder.Create(); dialog.Show(); dialog.SetDivider(); EditText txtUser = dialog.FindViewById <EditText>(Resource.Id.txtUser); //new EditText(Activity); EditText txtPasswd = dialog.FindViewById <EditText>(Resource.Id.txtPasswd); //new EditText(Activity); TextView lblSuccess = dialog.FindViewById <TextView>(Resource.Id.lblSuccess); ProgressBar prgLogin = dialog.FindViewById <ProgressBar>(Resource.Id.prgLogin); txtUser.Background.Colorize(DataManager.Get <ISettingsManager>().Settings.ButtonColor); txtPasswd.Background.Colorize(DataManager.Get <ISettingsManager>().Settings.ButtonColor); //se è edicola con password nasconto il campo username if (!DataManager.Get <ISettingsManager>().Settings.DownloadUtenti) { txtUser.Visibility = ViewStates.Gone; } //pulsante login var btnLogin = dialog.GetButton((int)DialogButtonType.Positive); if (btnLogin == null) { return; } btnLogin.Click += (sender, e) => { Activity.RunOnUiThread(() => { lblSuccess.Text = ""; prgLogin.Visibility = ViewStates.Visible; lblSuccess.Visibility = ViewStates.Gone; }); Uri host = new Uri(DataManager.Get <ISettingsManager>().Settings.DownloadUrl); if (!Reachability.IsHostReachable("http://" + host.Host)) { var alert = new AlertDialog.Builder(Activity); alert.SetTitle(GetString(Resource.String.gen_error)); alert.SetMessage(GetString(Resource.String.gen_serverNotReachable)); alert.SetPositiveButton("Ok", (EventHandler <DialogClickEventArgs>)null); alert.Show().SetDivider(); return; } var result = DownloadManager.CheckUser(txtUser.Text, txtPasswd.Text); if (result.Success) { DataManager.Get <IPreferencesManager>().Preferences.DownloadUsername = txtUser.Text; DataManager.Get <IPreferencesManager>().Preferences.DownloadPassword = txtPasswd.Text; DataManager.Get <IPreferencesManager>().Save(); if (DataManager.Get <ISettingsManager>().Settings.DownloadUtenti) { _DownUser.Summary = txtUser.Text; } else if (DataManager.Get <ISettingsManager>().Settings.DownloadPassword) { _DownUser.Summary = GetString(Resource.String.set_logged); } //registro il device Notification notif = new Notification(); string pushId = Activity.DevicePushId(); var data = Activity.BaseContext.DeviceInfo(); data.Add("deviceToken", Activity.DevicePushId()); notif.RegisterDevice(data); if ((Preference)this.FindPreference("DownLogout") == null) { _DownCategory.AddPreference(_DownLogout); } if ((Preference)this.FindPreference("DownReset") != null) { _DownCategory.RemovePreference(_DownReset); } dialog.Dismiss(); } else { if (result.Message != null && result.Message != "") { _DownUser.Summary = result.Message; } else { _DownUser.Summary = GetString(Resource.String.set_notLogged); } Activity.RunOnUiThread(() => { if (result.Message != null && result.Message != "") { lblSuccess.Text = result.Message; } else { lblSuccess.Text = GetString(Resource.String.set_loginFailed); } lblSuccess.Visibility = ViewStates.Visible; prgLogin.Visibility = ViewStates.Gone; }); DataManager.Get <IPreferencesManager>().Preferences.DownloadUsername = ""; DataManager.Get <IPreferencesManager>().Preferences.DownloadPassword = ""; DataManager.Get <IPreferencesManager>().Save(); if ((Preference)this.FindPreference("DownLogout") != null) { _DownCategory.RemovePreference(_DownLogout); } if (DataManager.Get <ISettingsManager>().Settings.PasswordReset&& (Preference)this.FindPreference("DownReset") == null) { _DownCategory.AddPreference(_DownReset); } } }; }