private void Upload(List <SampleCode> codes)
 {
     try
     {
         using (ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient(_ip, _port))
         {
             if (client.Ping())
             {
                 //using (var trans = client.CreatePipeline())
                 //{
                 //    for (int i = 0; i < codes.Count; i++)
                 //    {
                 //        String value = Newtonsoft.Json.JsonConvert.SerializeObject(codes[i]);
                 //        trans.QueueCommand(r => r.AddItemToList(_Channel, value));
                 //    }
                 //    trans.Flush();
                 //}
                 for (int i = 0; i < codes.Count; i++)
                 {
                     HNCAPI.Data.HncMessage <SampleCode> msg = new HncMessage <SampleCode>();
                     msg.Header = "SampleData";
                     msg.Body   = codes[i];
                     String message = Newtonsoft.Json.JsonConvert.SerializeObject(msg);
                     client.PublishMessage(_Channel, message);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("publish Upload:" + ex.Message);
     }
 }
Beispiel #2
0
        public void Read()
        {
            System.IO.StreamReader reader = null;
            try
            {
                if (System.IO.File.Exists(_FileName) == false)
                {
                    return;
                }
                if (!IsTextFile())
                {
                    return;
                }
                String MacSN = _mac.MachineSN;
                if (String.IsNullOrEmpty(MacSN))
                {
                    return;
                }
                reader = new System.IO.StreamReader(_FileName);
                ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient("127.0.0.1", 6379);
                if (client.Ping() == false)
                {
                    return;
                }
                client.Db = _mac.LocalDB;
                using (var trans = client.CreatePipeline())
                {
                    if (client.Exists("GCODE:" + _GCodeFile) == 1)
                    {
                        trans.QueueCommand(r => r.Remove("GCODE:" + _GCodeFile));
                        trans.Flush();
                    }
                    while (!reader.EndOfStream)
                    {
                        String GCodetext = reader.ReadLine();
                        trans.QueueCommand(r => r.AddItemToList("GCODE:" + _GCodeFile, GCodetext));
                    }
                    trans.Flush();
                }

                // reader.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("GCodeSender" + e.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }