private void CheckIfThereisAnewMessageFromApi(ConnectToApi connectToApi) { EncrypConnection encryp = new EncrypConnection(); string crypFinalPass = encryp.Encrypt(); //// get message from preferences GrudMessageFromPreferemces grudMessage = new GrudMessageFromPreferemces(); int lastMessageId = grudMessage.GetMessageFromPreferencesInPhone().MessageID; //realno !!!!!!!!!!!!! string messageUrl = ConnectToApi.urlAPI + "api/msg/"; ///testovo // string messageUrl = ConnectToApi.wtf + "api/msg/"; string finalUrl = messageUrl + crypFinalPass + "/" + lastMessageId; var messageFromApiAsJsonString = connectToApi.FetchApiDataAsync(finalUrl); // check api response if (messageFromApiAsJsonString != null) { Message newMessage = new Message(); newMessage = connectToApi.GetMessageFromApi(messageFromApiAsJsonString); if (newMessage.MessageID > lastMessageId) { grudMessage.SaveMessageInPhone(newMessage); // SaveMessageInPhone(newMessage); int messagesCount = newMessage.Messages.Count; if (messagesCount > 0) { SentNotificationWithoutSubscribe(newMessage); } } } }
private void UpdateCustomers(List <Customer> mCustomers, ISharedPreferences pref) { ConnectToApi connectToApi = new ConnectToApi(); bool connection = connectToApi.CheckConnectionOfVikSite(); if (connection == true) { EncrypConnection encryp = new EncrypConnection(); string crypFinalPass = encryp.Encrypt(); //// get from preferences GrudMessageFromPreferemces grudMessage = new GrudMessageFromPreferemces(); int lastMessageId = grudMessage.GetMessageFromPreferencesInPhone().MessageID; //realno !!!!!!!!!!!!!! string messageUrl = ConnectToApi.urlAPI + "api/msg/"; ///teest // string messageUrl = "http://192.168.2.222/VIKWebApi/api/msg/"; string finalUrl = messageUrl + crypFinalPass + "/" + lastMessageId; var messageFromApiAsJsonString = connectToApi.FetchApiDataAsync(finalUrl); if (messageFromApiAsJsonString != null) { Message newMessage = new Message(); newMessage = connectToApi.GetMessageFromApi(messageFromApiAsJsonString); if (newMessage.MessageID > lastMessageId) { grudMessage.SaveMessageInPhone(newMessage); int messagesCount = newMessage.Messages.Count; if (messagesCount > 0) { SentNotificationWithoutSubscribe(newMessage); // myNotification.SentNotificationWithoutSubscribe(newMessage); } } } int testNullResponse = 0; foreach (var item in mCustomers) { mTempFetchCollection.Add(item); } foreach (var customer in mCustomers) { bool isReceiveNotifyNewInvoiceCheck = false; bool isReceiveNotifyInvoiceOverdueCheck = false; bool isReciveNotifyReadingCheck = false; isReceiveNotifyNewInvoiceCheck = customer.NotifyNewInvoice; isReceiveNotifyInvoiceOverdueCheck = customer.NotifyInvoiceOverdue; isReciveNotifyReadingCheck = customer.NotifyReading; string billNumber = customer.Nomer.ToString(); string egn = customer.EGN.ToString(); string realUrl = "http://192.168.2.222/VIKWebApi/" + "api/abonats/" + crypFinalPass + "/" + billNumber + "/" + egn + "/" + ConnectToApi.updateByButtonRefresh + "/" + isReceiveNotifyNewInvoiceCheck + "/" + isReceiveNotifyInvoiceOverdueCheck + "/" + isReciveNotifyReadingCheck + "/"; mTempFetchCollection.Remove(customer); // if(isAnyNotifycationCheck == true) // { //CREATE test URL string url = "http://192.168.2.222/VIKWebApi/"; /// !!!!!!!!!!!!!!!!!!!!!!!! //string realUrl = ConnectToApi.urlAPI + "api/abonats/" + crypFinalPass + "/" // + billNumber + "/" + egn + "/" + ConnectToApi.updateByButtonRefresh + "/"; // // + isReceiveNotifyNewInvoiceToday + "/" + isReceiveNotifyInvoiceOverdueToday + "/" + isReciveNotifyReadingToday + "/"; // var jsonResponse = connectToApi.FetchApiDataAsync(realUrl); string jsonResponse = string.Empty; if (testNullResponse >= 1) { jsonResponse = null; } else { jsonResponse = connectToApi.FetchApiDataAsync(realUrl); } //check the api if (jsonResponse == null) { RunOnUiThread(() => RefreshProgressDialogAndToastWhenNoConnectioToApi()); // mAllUpdateCustomerFromApi.AddRange(mTempFetchCollection); mAllUpdateCustomerFromApi.Add(customer); // return; } // check in vikSite is there a customer with this billNumber (is billNumber correct) else if (jsonResponse == "[]") { RefreshProgressDialogAndToastWhenInputIsNotValid(); mAllUpdateCustomerFromApi.Add(customer); // return; } // check is billNumber correct and get and save customer in phone else if (jsonResponse != null) { // var jsonArray = JArray.Parse(jsonResponse); // Customer newCustomer = connectToApi.GetCustomerFromApi(jsonResponse); Customer updateCutomerButNoNotify = connectToApi.GetCustomerFromApi(jsonResponse); if (updateCutomerButNoNotify != null && updateCutomerButNoNotify.IsExisting == true) // (newCustomer != null && newCustomer.IsExisting == true) { updateCutomerButNoNotify.NotifyNewInvoice = customer.NotifyNewInvoice; updateCutomerButNoNotify.NotifyInvoiceOverdue = customer.NotifyInvoiceOverdue; updateCutomerButNoNotify.NotifyReading = customer.NotifyReading; mAllUpdateCustomerFromApi.Add(updateCutomerButNoNotify); ////////////updateCutomerButNoNotify testNullResponse++; //mTempFetchCollection.Remove(customer); // SaveUpdatesInPhone(pref, mDate.Text.ToString(), mHour.Text.ToString()); } else { RunOnUiThread(() => { RefreshProgressDialogAndToastWhenNoConnectioToApi(); }); return; } } // } } #region setting the updating date string updateHour; string updateDate; GetUpdateDateAndHour(out updateHour, out updateDate); #endregion RunOnUiThread(() => { GetFinalUpdateDateHour(); }); SelectWhichCustomersTobeNotified(countНotifyReadingustomers, countНotifyInvoiceOverdueCustomers, countNewНotifyNewInvoiceCustomers, mAllUpdateCustomerFromApi); //mCustomerFromApiToNotifyToday SaveUpdatesInPhone(pref, mDate.Text.ToString(), mHour.Text.ToString()); //MyNotification myNotification = new MyNotification(this); //myNotification.SentNotificationForOverdue(mCountНotifyInvoiceOverdueCustomers); SentNoficationForNewInovoice(countNewНotifyNewInvoiceCustomers); SentNotificationForOverdue(countНotifyInvoiceOverdueCustomers); SentNotificationForReading(countНotifyReadingustomers); var intent = new Intent(this, typeof(MainActivity)); StartActivity(intent); } else { Looper.Prepare(); RunOnUiThread(() => RefreshProgresDialogAndToastWhenThereIsNoConnection()); return; } }