Beispiel #1
0
        public static RestClient GetUrl(string endpoint)
        {
            ReadConfig    readConfig  = new ReadConfig();
            List <Config> _configList = readConfig.GetAllConfigs();
            string        endurl      = _configList[0].server_url + endpoint;
            RestClient    url         =
                new RestClient(endurl);

            return(url);
        }
Beispiel #2
0
        public static RestRequest GetRequestBody(string method)
        {
            ReadConfig    readConfig = new ReadConfig();
            List <Config> _config    = readConfig.GetAllConfigs();

            if (_config[0].session_data != "")
            {
                ReadSession readSession  = new ReadSession();
                Session     _sessionData = readSession.GetSession();
                string      token        = _sessionData.token;
                if (method == "post")
                {
                    var request = new RestRequest(Method.POST);
                    request.AddHeader("Content-Type", "application/json");
                    if (token != null)
                    {
                        request.AddHeader("Authorization", "Bearer " + token);
                    }
                    return(request);
                }
                else
                {
                    var request = new RestRequest(Method.GET);
                    request.AddHeader("Content-Type", "application/json");
                    if (token != null)
                    {
                        request.AddHeader("Authorization", "Bearer " + token);
                    }
                    return(request);
                }
            }
            else
            {
                if (method == "post")
                {
                    var request = new RestRequest(Method.POST);
                    request.AddHeader("Content-Type", "application/json");
                    return(request);
                }
                else
                {
                    var request = new RestRequest(Method.GET);
                    request.AddHeader("Content-Type", "application/json");
                    return(request);
                }
            }
        }
        public async Task <bool> CetakTicket(string printerName, List <Ticket> data)
        {
            List <int> ticket_ids = new List <int>();

            ConfigList = readConfig.GetAllConfigs();
            foreach (Ticket ticket in data)
            {
                ticket_ids.Add(ticket.id);
            }
            await SendPrintingStatus(ticket_ids, ConfigList[0].api_key, ConfigList[0].server_url, "printing");

            foreach (Ticket printer in data)
            {
                StringBuilder label = new StringBuilder();
                label.AppendLine("N");
                label.AppendLine("ZT");
                label.AppendLine("D10");
                label.AppendLine("Q680,B24");
                label.AppendLine("q440");
                label.AppendLine("b30,300,P,380,800,x2,y11,l100,r100,f0,s5,\"" + printer.barcode + "\"");
                label.AppendLine("A70,430,0,1,2,2,N,\"" + printer.barcode + "\"");
                label.AppendLine("A30,470,0,1,1,1,N,\"" + printer.line1 + "\"");
                label.AppendLine("A30,490,0,1,1,1,N,\"" + printer.line2 + "\"");
                label.AppendLine("A30,510,0,1,1,1,N,\"" + printer.line3 + "\"");
                label.AppendLine("A30,530,0,1,1,1,N,\"" + printer.line4 + " \"");
                label.AppendLine("A30,550,0,1,1,1,N,\"" + printer.line5 + " \"");
                label.AppendLine("A30,570,0,1,1,1,N,\"" + printer.line6 + " \"");
                label.AppendLine("A100,620,0,1,1,1,N,\"Ceria Tiada Habisnya!\"");
                label.AppendLine("ZT");
                label.AppendLine("P1");
                if (SendStringToPrinter(printerName, label.ToString(), "RAW") == true)
                {
                    await UpdateStatus(printer.id, ConfigList[0].api_key, ConfigList[0].server_url, "printed");
                }
                else
                {
                    await UpdateStatus(printer.id, ConfigList[0].api_key, ConfigList[0].server_url, "draft");
                }
            }
            return(true);
        }
        public Session GetSession()
        {
            SecurityModule.EncDec dec = new SecurityModule.EncDec();
            readConfig = new ReadConfig();
            ConfigList = readConfig.GetAllConfigs();

            string session_data = ConfigList[0].session_data;

            session_data = dec.Decrypt(session_data);

            string[] arr     = session_data.Split("|".ToCharArray());
            Session  session = new Session
            {
                user_id       = arr[0].Replace("\r\n", string.Empty),
                user_name     = arr[1].Replace("\r\n", string.Empty),
                user_login    = arr[2].Replace("\r\n", string.Empty),
                token         = arr[3].Replace("\r\n", string.Empty),
                refresh_token = arr[4].Replace("\r\n", string.Empty),
                token_live    = arr[5].Replace("\r\n", string.Empty)
            };

            return(session);
        }