public async void SendTallyStatusToServer(object param) { TallyConnectedResquestModel tallyConnectedResquestModel = new TallyConnectedResquestModel(GlobalSettings.UserName, enumTallyConnectedStatus.nc); ApiResponseWrapper <TallyConnectedResponseModel> res = await ApiManager.getInstance().SendTallyConnected(tallyConnectedResquestModel); if (!res.IsSuccessful) { MessageBox.Show(res.Message, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } else { MessageBox.Show(MessageConstants.SentTallyStatusSuccess, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } }
public async Task <ApiResponseWrapper <TallyConnectedResponseModel> > SendTallyConnected(TallyConnectedResquestModel tallyConnectedResquestModel) { ApiResponseWrapper <TallyConnectedResponseModel> res = new ApiResponseWrapper <TallyConnectedResponseModel>(); try { HttpClient client = new HttpClient(); //specify to use TLS 1.2 as default connection System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; var values = new Dictionary <string, string> { { "login_id", tallyConnectedResquestModel.UserName }, { "status", tallyConnectedResquestModel.Status.ToString() } }; var content = new FormUrlEncodedContent(values); var response = await client.PostAsync(ApiConstants.TallyStatusApiUrl, content); string result = response.Content.ReadAsStringAsync().Result; response.Dispose(); res = new ApiResponseWrapper <TallyConnectedResponseModel>(true, JsonConvert.DeserializeObject <TallyConnectedResponseModel>(result)); } catch (Exception ex) { res = new ApiResponseWrapper <TallyConnectedResponseModel>(false, null, ex.Message); } return(res); }
public async void StartServices() { if (!timer.IsEnabled) { timer.Start(); } this.IsStartEnable = false; this.IsStopEnable = true; this.LogStr += "Checking for Tally connection. \n"; AddEscapeSequence(); ApiResponseWrapper <string> res = await GetTallyConnected(); if (!res.IsSuccessful) { this.LogStr += "Tally is not connected. Please start Tally and start the services again... \n"; AddEscapeSequence(); TallyConnectedResquestModel tallyConnectedResquestModel = new TallyConnectedResquestModel(GlobalSettings.UserName, enumTallyConnectedStatus.nc); ApiResponseWrapper <TallyConnectedResponseModel> res1 = await ApiManager.getInstance().SendTallyConnected(tallyConnectedResquestModel); if (!res1.IsSuccessful) { this.LogStr += "Something went wrong : \n" + res.Message; AddEscapeSequence(); } else { this.LogStr += "Sent Tally status successfully to the server. \n"; AddEscapeSequence(); } } else { AddEscapeSequence(); this.LogStr += "Tally is connected. \n"; AddEscapeSequence(); this.LogStr += "Sending Tally connected confirmation to server. \n"; AddEscapeSequence(); TallyConnectedResquestModel tallyConnectedResquestModel = new TallyConnectedResquestModel(GlobalSettings.UserName, enumTallyConnectedStatus.c); ApiResponseWrapper <TallyConnectedResponseModel> res1 = await ApiManager.getInstance().SendTallyConnected(tallyConnectedResquestModel); if (!res1.IsSuccessful) { this.LogStr += "Something went wrong : \n" + res.Message; AddEscapeSequence(); } else { this.LogStr += "Sent Tally status successfully to the server. \n"; AddEscapeSequence(); this.LogStr += "Checking for Tally connected companies. \n"; AddEscapeSequence(); ApiResponseWrapper <string> res2 = await GetTallyConnected(); if (res2.IsSuccessful) { this.LogStr += "Tally connected companies: \n" + res2.Data; AddEscapeSequence(); this.LogStr += "Sending Tally connected companies to the server. \n"; AddEscapeSequence(); ENVELOPE CompanyListXmlObj = XmlHelper.Deserialize <ENVELOPE>(res2.Data); string CompanyListCSV = (CompanyListXmlObj.COMPANYNAME_LIST.COMPANYNAME.ToCsv(x => x, typeof(CsvTrimBare <string>))); TallyConnectedCompaniesResquestModel tallyConnectedCompaniesResquestModel = new TallyConnectedCompaniesResquestModel(GlobalSettings.UserName, CompanyListCSV); ApiResponseWrapper <TallyConnectedCompaniesResponseModel> res3 = await ApiManager.getInstance().SendTallyConnectedCompanies(tallyConnectedCompaniesResquestModel); if (!res3.IsSuccessful) { this.LogStr += "Something went wrong : \n" + res3.Message; AddEscapeSequence(); } else { this.LogStr += "Sent connected companies successfully to the server. \n"; AddEscapeSequence(); if (CompanyListXmlObj.COMPANYNAME_LIST.COMPANYNAME.Count > 0) { foreach (var COMPANYNAME in CompanyListXmlObj.COMPANYNAME_LIST.COMPANYNAME) { //===============================DayBook Summary======================================= this.LogStr += "Getting TallyDayBookInformation for " + COMPANYNAME + " company. \n"; AddEscapeSequence(); ApiResponseWrapper <string> res4 = await GetTallyRaportsInformation(ApiConstants.TallyReportName_DayBook, COMPANYNAME); //ApiResponseWrapper<string> res4 = await GetTallyDayBookInformation(COMPANYNAME); if (!res4.IsSuccessful) { this.LogStr += "Something went wrong : \n" + res4.Message; AddEscapeSequence(); } else { this.LogStr += COMPANYNAME + " TallyDayBookInformation: \n" + res4.Data; AddEscapeSequence(); this.LogStr += "Sending " + COMPANYNAME + " TallyDayBookInformation to the server. \n"; AddEscapeSequence(); //TallyDayBookInfoResquestModel tallyDayBookInfoResquestModel = new TallyDayBookInfoResquestModel(enumXMLType.DayBook, GlobalSettings.UserName, "ITLION", res4.Data); TallyDayBookInfoResquestModel tallyDayBookInfoResquestModel = new TallyDayBookInfoResquestModel(enumXMLType.daybook, GlobalSettings.UserName, COMPANYNAME, res4.Data); ApiResponseWrapper <TallyDayBookInfoResponseModel> res5 = await ApiManager.getInstance().SendTallyDayBookInformation(tallyDayBookInfoResquestModel); if (!res5.IsSuccessful) { this.LogStr += "Something went wrong : \n" + res5.Message; AddEscapeSequence(); } else { this.LogStr += "Sent " + COMPANYNAME + " TallyDayBookInformation successfully to the server. \n"; AddEscapeSequence(); } } //===============================Stock Summary======================================= this.LogStr += "Getting TallyStockCategorySummary Information for " + COMPANYNAME + " company. \n"; AddEscapeSequence(); ApiResponseWrapper <string> res6 = await GetTallyRaportsInformation(ApiConstants.TallyReportName_Stock, COMPANYNAME); if (!res6.IsSuccessful) { this.LogStr += "Something went wrong : \n" + res6.Message; AddEscapeSequence(); } else { this.LogStr += COMPANYNAME + " TallyStockCategorySummary Information \n" + res6.Data; AddEscapeSequence(); this.LogStr += "Sending " + COMPANYNAME + " TallyStockCategorySummary Information to the server. \n"; AddEscapeSequence(); //TallyDayBookInfoResquestModel tallyDayBookInfoResquestModel = new TallyDayBookInfoResquestModel(enumXMLType.DayBook, GlobalSettings.UserName, "ITLION", res4.Data); TallyDayBookInfoResquestModel tallyDayBookInfoResquestModel = new TallyDayBookInfoResquestModel(enumXMLType.stock, GlobalSettings.UserName, COMPANYNAME, res6.Data); ApiResponseWrapper <TallyDayBookInfoResponseModel> res7 = await ApiManager.getInstance().SendTallyDayBookInformation(tallyDayBookInfoResquestModel); if (!res7.IsSuccessful) { this.LogStr += "Something went wrong : \n" + res7.Message; AddEscapeSequence(); } else { this.LogStr += "Sent " + COMPANYNAME + " TallyStockCategorySummary Information successfully to the server. \n"; AddEscapeSequence(); } } } } else { this.LogStr += "Can not Send TallyDayBookInformation to the server due to unavailability of connected companies from Tally.\n"; AddEscapeSequence(); } } } } } this.LastRunOnStr = "Services Last excuted on: " + DateTime.Now.ToString(); }