示例#1
0
        public ActionResult <string> Post()
        {
            try
            {
                using (StreamReader reader = new StreamReader(HttpContext.Request.Body, Encoding.UTF8))
                {
                    string message = reader.ReadToEnd();

                    string meg = "This message recive from Edge module webapi message is : " + message;

                    Console.WriteLine();
                    Console.WriteLine(meg);

                    Task.Run(() =>
                    {
                        IoTEdge.UpLoadMessage(message);
                    }).Wait();

                    return(Ok(message));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine("ex message: " + ex.ToString());
                return(BadRequest(ex));
            }
        }
示例#2
0
        public ActionResult <string> Get(string message)
        {
            string meg = "This message recive from Edge module webapi message is : " + message;

            Console.WriteLine();
            Console.WriteLine(meg);

            //try
            //{
            //    Console.WriteLine();
            //    string localPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            //    string localFileName = "QuickStart_" + Guid.NewGuid().ToString() + ".txt";
            //    string sourceFile = Path.Combine(localPath, localFileName);
            //    // Write text to the file.
            //    System.IO.File.WriteAllText(sourceFile, "Hello, World!");

            //    Console.WriteLine("Temp file = {0}", sourceFile);
            //    Console.WriteLine("WriteAllText successed");
            //    Console.WriteLine();
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine("ex message: " + ex.ToString());
            //    Console.WriteLine();
            //}

            try
            {
                Task.Run(() =>
                {
                    IoTEdge.UpLoadMessage(message);
                    //SocketClientCore.StartClient();
                }).Wait();

                return(Ok(message));
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine("ex message: " + ex.ToString());
                return(BadRequest(ex));
            }
        }