Exemple #1
0
		private async void onayButton_Click(object sender, RoutedEventArgs e)
		{
			using (var client = new HttpClient())
			{
				client.BaseAddress = new Uri("http://mobileservice.migros.com.tr/");
				client.DefaultRequestHeaders.Accept.Clear();
				client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

				try
				{
					var req = new Request();

					/*PhoneControl'den farklı olarak PasswordBox'a girilen karakterler req objesinin
					password değişkenine atanmıştır.*/
					req.requestHeader = new RequestHeader() { userName = "******", password = passwordTextBox.Password, serviceName = "sifreKontrol" };
					req.requestBody = new Sifre.SifreRequestBody() { sifre = "ABCD1234" };
                    passwordTextBox.Password = "";
					var response = await client.PostAsJsonAsync("droppointpavoapi/api/genericmethod", req);

					if (response.IsSuccessStatusCode)
					{
						string data = await response.Content.ReadAsStringAsync();

						var results = JsonConvert.DeserializeObject<dynamic>(data);
						string apiResultCode = results.responseHeader.resultCode;						

						if (apiResultCode == "BASARILI")
						{

							this.Content = new Result();
						}

						else
						{
							MessageBox.Show("Hatalı Şifre!");
                            
                            
						}
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.ToString());
				}
			}	
		}
Exemple #2
0
		// Web API'ye yapılan Post() çağrısına verilen cevap
		public Response Post(Request value)
		{
			try
			{
				clientAddress = System.Web.HttpContext.Current.Request.UserHostAddress;
			}
			catch
			{
				clientAddress = "";
			}

			// Gelen requestin değerleri üzerinden kontrol
			if (value.requestHeader.userName == "Migros" && value.requestHeader.password == "Migros2015")
			{
				return IstekIsle(value);
			}
			else
			{
				return new Response() { responseHeader = new ResponseHeader() { status = "-1", resultCode = "ERR01", resultMessage = "AUTHENTICATION ERROR" }, responseBody = new ResponseBody() };
			}
		}
Exemple #3
0
		private Response IstekIsle(Request istek)
		{
			Response cevap = new Response();

			switch (istek.requestHeader.serviceName)
			{
				case "sifreKontrol":

					cevap.responseHeader = new ResponseHeader() { status = "1", resultCode = "BASARILI", resultMessage = "" };

					// Web API'nin muhtemel olarak döndüreceği değişkenler
                    Sifre.SifreResponseBody basicData = new Sifre.SifreResponseBody() { kapakNo = 57, kilit = 1, icSicaklik = 6, disSicaklik = 27, hedefIcSicaklik = 4, islemciSicaklik = 23, kapi = 0, doluluk = 0, 
                    gerilim = 0, akim = 0};
					List<Sifre.SifreResponseBody> tempData = new List<Sifre.SifreResponseBody>();
					tempData.Add(basicData);
					cevap.responseBody = new ResponseBody() { kapakListesi = tempData };					

					break;

				case "cihazDurum":

					List<Sifre.SifreResponseBody> kapakData = new List<Sifre.SifreResponseBody>();

					// Burada yoruma alınan satırlar kontrol amaçlıdır. Aşağıdaki try catch blokları
					//yoruma alınıp bu satırlar yorumdan çıkarılırsa uygulama seri port bağlantıları
					//olmadan çalışmaktadır. 

                    /*byte[] tempBoxAddresses = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
                    ushort[] writeData = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 , 110 ,120};

                    for (short i = 0; i < tempBoxAddresses.Length; i++)
                    {
                        Sifre.SifreResponseBody incomingData = new Sifre.SifreResponseBody() { kapakNo = tempBoxAddresses[i], intFanSt = writeData[0], extFanSt = writeData[1], kilit = writeData[2], lightSt = writeData[3], icSicaklik = writeData[4], disSicaklik = writeData[5], hedefIcSicaklik = writeData[6], islemciSicaklik = writeData[7], kapi = writeData[8], doluluk = writeData[9], gerilim = writeData[10], akim = writeData[11] };
                        kapakData.Add(incomingData);	
                    }*/

                    try
					{
						using( port = new SerialPort("COM2", 57600, Parity.None, 8, StopBits.One) )
						{
							if (!port.IsOpen)
							{
								port.Open();
								if (port.IsOpen)
								{
									//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
									port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);

									byte[] tempBoxAddresses = { 56, 57, 58, 61, 5, 6, 7, 8, 9, 10, 11, 12 };

									for (short i = 0; i < tempBoxAddresses.Length; i++)
									{
										byte[] getCommandFromAddresses = prepareGetPacket(tempBoxAddresses[i]);
                                        byteList.Clear();
										getCommand(getCommandFromAddresses);

										System.Threading.Thread.Sleep(100);

										using (TextWriter tw = new StreamWriter("ErrorInformation.txt", true))
										{
											tw.WriteLine();
											tw.Write("Bytes Read from Port: ");
											for (int j = 0; j < byteList.Count; j++)
											{
												tw.Write(byteList[j] + ", ");
											}

											tw.WriteLine();
											tw.WriteLine();
										}

										ushort[] writeData = new ushort[14];
										writeData = parseList(byteList);

										// Eğer okunan değerlerde bir hata varsa
										if (writeData.SequenceEqual(errorBytes) || writeData.SequenceEqual(bccError) || writeData.SequenceEqual(ackError) || writeData.SequenceEqual(brokenDataError) ||
										writeData.SequenceEqual(dataSizeError) || writeData.SequenceEqual(STXError) || writeData.SequenceEqual(serverAddressError) || writeData.SequenceEqual(packetTypeError))
										{
											Console.WriteLine("Error Bytes returned! BROKEN DATA!!!");
										}
										else
										{
                                            //Sifre.SifreResponseBody incomingData = new Sifre.SifreResponseBody() { boxAddress = tempBoxAddresses[i], intFanSt = writeData[0], extFanSt = writeData[1], lockSt = writeData[2], lightSt = writeData[3], intTemp = writeData[4], extTemp = writeData[5], hedefIcSicaklik = writeData[6], cpuTemp = writeData[7], kapi = writeData[8], presenceSt = writeData[9], gerilim = writeData[12], akim = writeData[13] };	
                                            Sifre.SifreResponseBody incomingData = new Sifre.SifreResponseBody() { kapakNo = i, kilit = writeData[2], icSicaklik = writeData[4], disSicaklik = writeData[5], hedefIcSicaklik = writeData[6], islemciSicaklik = writeData[7], kapi = writeData[8], doluluk = writeData[9], gerilim = writeData[12], akim = writeData[13] };	
											kapakData.Add(incomingData);
										}

									}

									//port.Close();
									//port.Dispose();
								}

								else
								{
									cevap.responseHeader = new ResponseHeader() { status = "-1", resultCode = "PORT ERROR", resultMessage = "" };
								}
							}	
						}						
					}
					catch (Exception ex)
					{
						//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
						using (TextWriter tw = new StreamWriter("GeneralErrors.txt", true))
						{
							tw.WriteLine();
							tw.Write(ex.ToString());							
							tw.WriteLine();
						}
						cevap.responseHeader = new ResponseHeader() { status = "-1", resultCode = "PORT ERROR: " + ex.ToString(), resultMessage = "" };
					}

					if(kapakData.Count==12) // Burada if'in içine daha mantıklı kontroller yazılabilir
					{
						cevap.responseHeader = new ResponseHeader() { status = "1", resultCode = "BASARILI", resultMessage = "" };	
						cevap.responseBody = new ResponseBody() { kapakListesi = kapakData };
					}
					else
					{
						cevap.responseHeader = new ResponseHeader() { status = "-1", resultCode = "BASARISIZ", resultMessage = "DOLAP BİLGİSİ OKUMA HATASI" };
                        cevap.responseBody = new ResponseBody() { kapakListesi = kapakData };
						//ERROR. Kontrol edilmeli
					}				

					break;
				default:
					break;
			}
			return cevap;
		}