// Transfer Daily Report From Master To Iorder , Company Shekofa static void Main(string[] args) { try { Applications.UrlApiLogin = "******"; Console.WriteLine("API Address Login :{0} \n", Applications.UrlApiLogin); Applications.UrlApiSendDailyReport = "http://iordertest.shekofats.com/api/site/insertVisitorDailyReport"; Console.WriteLine("API Address Send Daily Report :{0} \n", Applications.UrlApiSendDailyReport); Applications.AuthenticationApi = "{\"Username\":\"3081.1\",\"Password\":\"123456\" , \"hardwareSerial\" : \"1\"}"; Console.WriteLine("Authntication :{0} \n", Applications.AuthenticationApi); Int32 ResultLoginToAPI = 0; String PHPSESSIONID = ""; var client = new RestClient(Applications.UrlApiLogin); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddParameter("Data", Applications.AuthenticationApi); IRestResponse response = client.Execute(request); String json = response.Content; JObject jsonObject = JObject.Parse(json); ResultLoginToAPI = (int)jsonObject["MessageNumber"]; Console.WriteLine(jsonObject["MessageContent"] + "(" + ResultLoginToAPI + ")" + "\n"); if (ResultLoginToAPI == 200) { JArray jArrayJson = ((JArray)((JObject)jsonObject["CallBackData"])["login"]); PHPSESSIONID = (String)(JObject.Parse((jArrayJson[0]).ToString()))["SessionString"]; Console.WriteLine(PHPSESSIONID); Uri uri = new Uri(Applications.UrlApiSendDailyReport); client.BaseUrl = uri; Applications.ServerNameSQL = "46.209.203.218,1453"; Applications.UserNameDataBaseSQL = "sa"; Applications.PasswordDataBaseSQL = "110110A@"; Applications.DataBaseSQL = "PTCERP_Dev"; IDataBaseServices dataBaseServices = new DataBaseServices(); Applications.ConnectionString = dataBaseServices.GetParameterSQLConnections(Applications.ServerNameSQL, Applications.DataBaseSQL, Applications.UserNameDataBaseSQL, Applications.PasswordDataBaseSQL, "10"); try { bool tt = dataBaseServices.CheckConnectionSQL(Applications.ConnectionString); if (tt == true) { Console.WriteLine("Successfull connect to server \n"); int CountRow = 0; CountRow = dataBaseServices.CountRowTableVisitorSailTarget(Applications.ConnectionString, "select count(ReportData) from ##tblVisitorSailTarget where isSend = 0 "); Console.WriteLine("Number Of Row With IsSend 0 :{0} \n", CountRow); if (CountRow == 0) { Environment.Exit(0); } int CountUpdate = 0; //Dictionary<String, Int32> DataBasesName = new Dictionary<string, int>(); while (CountRow > CountUpdate) { var ShowDataBasesQuery = "select top 10 VisitorCode,ReportData from ##tblVisitorSailTarget where IsSend = 0 "; //DataBasesName.Clear(); foreach (var item in dataBaseServices.LoadDatabases(Applications.ConnectionString, ShowDataBasesQuery)) { //Console.WriteLine("VisitorCode:"+ item.Value); ShowDataBasesQuery = ""; request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddHeader("Cookie", "64559f88fd9f45bb95f624a1e0a74310=edcb5c1d0e346d42bc122b6bee6ac0ca3238c2cda%3A4%3A%7Bi%3A0%3Bs%3A4%3A%227149%22%3Bi%3A1%3Bs%3A6%3A%223081.1%22%3Bi%3A2%3Bi%3A14400%3Bi%3A3%3Ba%3A0%3A%7B%7D%7D;" + PHPSESSIONID + ";appLanguage=fa"); try { JToken.Parse(item.Value); } catch (Exception ee) { if (++CountUpdate > CountRow) { break; } else { continue; } } //request.AddParameter("Data", JToken.Parse(item.Value.Replace("\"VisitorCode\":\"4969\"", "\"VisitorCode\":\"4320\""))); request.AddParameter("Data", JToken.Parse(item.Value)); response = client.Execute(request); if (response.IsSuccessful && response.Content == "") { Console.WriteLine("Responseeeee" + response); ShowDataBasesQuery = "update ##tblVisitorSailTarget set issend = 1 where VisitorCode =" + item.Key; CountUpdate++; dataBaseServices.UpdateVisitorIsSend(Applications.ConnectionString, ShowDataBasesQuery); ShowDataBasesQuery = ""; } Console.WriteLine("Response VisitorCode {0} :{1} ", item.Key, response.Content); } } System.Environment.Exit(1); } } catch (Exception e) { Console.WriteLine("Connections Failed : {0} ", e.Message); } } else { Console.WriteLine("Could Not Connect To API Server : {0} ", Applications.UrlApiLogin); return; } //JObject tt = (JObject)jsonObject["CallBackData"]; //String tt = jsonObject["login"].ToString(); //JArray a = JArray.Parse((String)tt["login"]); //Console.WriteLine((String)(JObject.Parse((jArrayJson[0]).ToString()))["SessionString"]); } catch (Exception) { throw; } //Console.WriteLine("Enter ServerName DataBase SQL : "); //Applications.ServerNameSQL = Console.ReadLine(); //Console.WriteLine("Enter UserName DataBase SQL :"); //Applications.UserNameDataBaseSQL = Console.ReadLine(); //Console.WriteLine("Enter Password DataBase SQL :"); //Applications.PasswordDataBaseSQL = Console.ReadLine(); //IDataBaseServices dataBaseServices = new DataBaseServices(); //Applications.ConnectionString = dataBaseServices.GetParameterSQLConnections(Applications.ServerNameSQL, "", Applications.UserNameDataBaseSQL, Applications.PasswordDataBaseSQL, "10"); //try //{ // bool tt = dataBaseServices.CheckConnectionSQL(Applications.ConnectionString); // Console.WriteLine(tt.ToString()); // if (tt == true) // { // Console.WriteLine("SuccessFull Connect To DB "); // String ShowDataBasesQuery = "select name from sys.databases where name not in ('master' , 'tempdb' , 'model' , 'msdb')"; // List<String> DataBasesName = new List<string>(); // DataBasesName.AddRange(dataBaseServices.LoadDatabases(Applications.ConnectionString, ShowDataBasesQuery)); // foreach (var item in DataBasesName) // { // Console.WriteLine(item); // } // Console.WriteLine("Copy DataBase Name And Paste: "); // Applications.DataBaseSQL = Console.ReadLine(); // if (DataBasesName.Contains(Applications.DataBaseSQL) == false) // { // Console.WriteLine("DataBase Name Incorrect"); // } // } //} //catch (Exception e) //{ // Console.WriteLine("Connections Failed : {0} ", e.Message); //} // Constrouctor : //TestClass obj1 = new TestClass(); //Console.WriteLine("Number is : " + obj1.Num + "\nName is :" + obj1.Name); }