示例#1
0
        public static void TestUri(CustomerConfig configData, String server, String key)
        {
            String requestUriStr = "https://" + server +
                                   "/app2/messagemanager/getnextmessagebymerchantid/" +
                                   key +
                                   "/winapp/";
            HttpWebRequest request = (HttpWebRequest)
                                     WebRequest.Create(requestUriStr);

            try
            {
                request.Timeout = configData.Timeout_mSec; // 10 seconds
                // execute the request
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    MessageBox.Show("Url Validated (200)");
                }
                else
                {
                    MessageBox.Show("Incorrect URL: " + response.StatusDescription);
                }
                response.Close();
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("Incorrect URL: " + ex.Message);
            }
        }
示例#2
0
        public Form1()
        {
            InitializeComponent();
            //load printers
            PrintDocument prtdoc            = new PrintDocument();
            string        strDefaultPrinter = prtdoc.PrinterSettings.PrinterName;

            foreach (String strPrinter in PrinterSettings.InstalledPrinters)
            {
                comboBox1.Items.Add(strPrinter);
                if (strPrinter == strDefaultPrinter)
                {
                    comboBox1.SelectedIndex = comboBox1.Items.IndexOf(strPrinter);
                }
            }

            configData = Helper.LoadConfigData();

            //server
            txtServer.Text = configData.Server;
            if (comboBox1.Items.IndexOf(configData.Printer) > -1)
            {
                comboBox1.SelectedIndex = comboBox1.Items.IndexOf(configData.Printer);
            }

            txtKey.Text = configData.Key;
        }
示例#3
0
        public void Start()
        {
            configData = Helper.LoadConfigData();

            // Configure the system tray icon.
            appIcon.Icon = redIco;
            appIcon.Text = "Splick·It";

            TimerCallback timerDelegate = new TimerCallback(GetOrder);

            timer = new System.Threading.Timer(timerDelegate, null, 0, configData.Timeperiod_mSec);

            // Place the menu items in the menu.
            sysTrayMenu.MenuItems.Add(settings);
            sysTrayMenu.MenuItems.Add(exitApp);
            appIcon.ContextMenu = sysTrayMenu;

            // Show the system tray icon.
            appIcon.Visible = true;

            // Attach event handlers.
            exitApp.Click  += new EventHandler(ExitApp);
            settings.Click += new EventHandler(settingsClicked);


            if (configData.Key == "")
            {
                settingsClicked(this, null);
            }

            frm.Show();
        }
示例#4
0
        private void settingsClicked(object sender, System.EventArgs e)
        {
            // load the last saved settings
            configData = Helper.LoadConfigData();
            DialogResult dlgResult = frmSettings.ShowDialog();

            // user may have changed settings, load updates.
            configData = Helper.LoadConfigData();
            GetOrder(null);
        }
示例#5
0
        public static void SaveConfigData(CustomerConfig configData)
        {
            //save ini
            string  appPath = Path.GetDirectoryName(Application.CommonAppDataPath);
            IniFile file    = new IniFile(appPath + "/app.ini");

            file.IniWriteValue("Settings", "Key", configData.Key);

            file.IniWriteValue("Settings", "Server", configData.Server);
            file.IniWriteValue("Settings", "Printer", configData.Printer);
        }
示例#6
0
        public static CustomerConfig LoadConfigData()
        {
            CustomerConfig configData = new CustomerConfig();
            //load config file
            string appPath = Path.GetDirectoryName(Application.CommonAppDataPath);

            IniFile file = new IniFile(appPath + "/app.ini");

            configData.Key = file.IniReadValue("Settings", "Key");

            //server
            configData.Server = file.IniReadValue("Settings", "Server").ToLower();

            //printer
            configData.Printer = file.IniReadValue("Settings", "Printer");

            Int32   timeperiod_sec = 0;
            String  strTimePeriod  = ConfigurationManager.AppSettings.Get("Timeperiod_Sec");
            Boolean gotTimeperiod  = Int32.TryParse(strTimePeriod, out timeperiod_sec);

            if (!gotTimeperiod || timeperiod_sec < 1)
            {
                configData.Timeperiod_mSec = 30000; // 30 seconds
                configData.Timeout_mSec    = 10000; // 10 secs
            }
            else
            {
                configData.Timeperiod_mSec = timeperiod_sec * 1000;
                configData.Timeout_mSec    = configData.Timeperiod_mSec / 2;
            }

            if (configData.Timeout_mSec > 10000)
            {
                configData.Timeout_mSec = 10000;
            }

            return(configData);
        }
示例#7
0
        public static bool GetOrders(CustomerConfig configData, out bool hasOrder, out string retVal)
        {
            bool linkActive = false;

            retVal   = "OK";
            hasOrder = false;
            string resp = String.Empty;

            resp = String.Empty;
            //EventLog.WriteEntry("SplickIt Remote Printing", "HTTP Request");
            // prepare the web page we will be asking for
            String requestUriStr = "https://" + configData.Server +
                                   "/app2/messagemanager/getnextmessagebymerchantid/" +
                                   configData.Key +
                                   "/winapp/";
            HttpWebRequest request = (HttpWebRequest)
                                     WebRequest.Create(requestUriStr);

            try
            {
                request.Timeout = configData.Timeout_mSec; // 10 seconds
                // execute the request
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    // Get the stream associated with the response.
                    Stream receiveStream = response.GetResponseStream();

                    // Pipes the stream to a higher level stream reader with the required encoding format.
                    StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
                    resp     = HttpUtility.UrlDecode(readStream.ReadToEnd());
                    hasOrder = resp.Contains("<order_id>");
                    if (hasOrder)
                    {
                        order ord = new order();
                        // Read a purchase order.
                        XmlSerializer serializer = new XmlSerializer(typeof(order));

                        XmlReaderSettings settings = new XmlReaderSettings();
                        settings.ConformanceLevel = ConformanceLevel.Fragment;
                        settings.IgnoreWhitespace = true;
                        settings.IgnoreComments   = true;

                        XmlReader xmlReader = XmlReader.Create(new StringReader(resp), settings);
                        xmlReader.Read();

                        ord = (order)serializer.Deserialize(xmlReader);
                        RawPrinterHelper.SendStringToPrinter(configData.Printer, ord.order_details);
                        retVal = ord.order_details;
                    }
                    else
                    {
                        retVal = "NO Order";
                    }
                    readStream.Close();
                    linkActive = true;
                }
                else
                {
                    //error
                    retVal     = "Error:" + response.StatusDescription;
                    linkActive = false;
                }
                response.Close();
            }
            catch (System.Net.WebException ex)
            {
                retVal     = "Error:" + ex.Message;
                linkActive = false;
            }

            return(linkActive);
        }