/// <summary> /// /// </summary> /// <param name="menu"></param> /// <param name="entry"></param> /// <param name="option"></param> /// <param name="o"></param> /// <returns></returns> static bool TestListenerCreate(MenuList menu, CMenu entry, char option, object o) { string fileToUse = Input("File to use", LISTENER_TEST_FILE, out bool isdef); if (string.IsNullOrEmpty(fileToUse)) { return(true); } FileInfo fi = new FileInfo(fileToUse); if (!fi.Exists || YesNo($"A test file called {fileToUse} already exists, do you want to override it ?")) { var json = new CJson <CListenerRequest>(fileToUse); CListenerRequest req = json.ReadSettings(out bool except); string ip = Input("POI IP", (null != req ? req.IP : CStream.Localhost()), out isdef); if (null == ip) { return(true); } int port; string sport = Input("POI Port", (null != req ? req.Port.ToString() : "2018"), out isdef); if (null == sport) { return(true); } try { port = int.Parse(sport); } catch (Exception) { return(true); } string saleid = Input($"Sale ID", (null != req ? req.SaleID : "SaleID"), out isdef); if (null == saleid) { return(true); } string poiid = Input($"POI ID", (null != req ? req.POIID : "POIID"), out isdef); if (null == poiid) { return(true); } string service = Input($"Retailer service to call", (null != req ? req.Service : MessageCategoryEnumeration.Login.ToString()), out isdef); if (null == service) { return(true); } bool isLogin = (0 == string.Compare(MessageCategoryEnumeration.Login.ToString(), service, true)); bool isPay = (0 == string.Compare(MessageCategoryEnumeration.Payment.ToString(), service, true)); /* * bool autologin = false; * if (!isLogin) * { * autologin = YesNo("Autologin"); * } */ double amount = 0D; PaymentTypeEnumeration pt = PaymentTypeEnumeration.Normal; if (isPay) { if (!YesNo("Normal Payment (otherwise it will be a Refund)")) { pt = PaymentTypeEnumeration.Refund; } try { amount = double.Parse(Input("Amount", "1", out isdef)); } catch (Exception) { amount = 0D; } } string dts = (isLogin ? "LoginRequest.SaleSoftware.ManufacturerID" : null); string value = null; if (null != dts) { try { value = req.ElementsToSend[dts].Value.ToString(); } catch (Exception) { } } dts = Input("Data to send", dts, out isdef); if (null != dts) { value = Input($"Value for {dts}", value, out isdef); } string dtr = (isLogin ? "LoginResponse.POISystemData.POISoftware.ManufacturerID" : null); //if (0 != req.ElementsToSend.Count) // foreach (KeyValuePair<string, CListenerDataElement> k in req.ElementsToReturn) // { // dtr = k.Key; // break; // } dtr = Input("Data to return", dtr, out isdef); var toSend = new CListenerDataElements(); if (null != dts) { toSend.Add(dts, new CListenerDataElement() { Value = value }); } var toReturn = new CListenerDataElements(); if (null != dtr) { toReturn.Add(dtr, new CListenerDataElement()); } var request = new CListenerRequest() { Amount = (isPay ? amount : 0D), PaymentType = (isPay ? pt.ToString() : null), ElementsToSend = toSend, ElementsToReturn = toReturn, IP = ip, Port = port, Service = service, POIID = poiid, SaleID = saleid }; json.WriteSettings(request); Console.WriteLine(); Console.WriteLine(request.ToString()); } return(true); }