Exemplo n.º 1
0
 public static void UploadLuYin(string path)
 {
     try
     {
         string url = "";
         jsonFile1.FileID = ResID;
         if (JsEvent.parameter != null && JsEvent.parameter.zimu != null && JsEvent.parameter.zimu != "")
         {
             jsonFile1.FileID = ResID + JsEvent.parameter.wordIndex;
         }
         jsonFile1.UserName      = thearID;
         jsonFile1.ResourceStyle = 101;
         string        JsonFile = JsEvent.EnSerialize <JsonFile>(jsonFile1);
         byte[]        bt       = client.UploadFile(UploadUrl + "?JsonFile=" + JsonFile, path);
         string        temp     = System.Text.Encoding.UTF8.GetString(bt);
         List <string> ls       = temp.Split(',').ToList();
         if (ls != null && ls.Count == 8)
         {
             List <string> ls2 = ls[6].Split(',').ToList();
             url = ls2[0].Replace("\"FilePath\":\"", "").Replace("\"}", "");
             string strGUID = System.Guid.NewGuid().ToString(); //直接返回字符串类型
             url += "?ran=" + strGUID;
             if (JsEvent.cbId != "-1")
             {
                 mesage msag = new mesage();
                 msag.code = 0;
                 msag.msg  = "";
                 msag.data = new data();
                 msag.data.recordFileUrl = url;
                 string res = JsEvent.EnSerialize <mesage>(msag);
                 bool   s   = JsEvent.wb.Enabled;
                 JsEvent.wb.ExecuteScriptAsync("sClassJSBridge.handleMessage('" + JsEvent.cbId + "','" + res + "');");
             }
             else
             {
                 JsEvent.wb.ExecuteScriptAsync("cpGetLuyinPath('" + url + "');");
             }
         }
         else
         {
             if (JsEvent.cbId != "-1")
             {
                 JsEvent.wb.ExecuteScriptAsync("sClassJSBridge.handleMessage('" + JsEvent.cbId + "','" + "上传失败" + "');");
             }
             else
             {
                 JsEvent.wb.ExecuteScriptAsync("cpGetLuyinPath('上传失败');");
             }
         }
     }
     catch (Exception ex)
     {
         new Helper().InsertErrorMsg(ex.StackTrace, ex.Message);
         throw;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 接收安卓文件
 /// </summary>
 /// <param name="clientSocket"></param>
 /// <param name="msg"></param>
 public static void Create(object clientSocket, string msg)
 {
     //FileStream MyFileStream = null;
     try
     {
         new Helper().InsertErrorMsg(msg, "收到安卓文件");
         Socket client = clientSocket as Socket;
         msg = Regex.Split(msg, "0X11:")[1];
         string[] fileinfo = Regex.Split(msg, "&");//文件地址&
         string   pp       = "Page" + "\\" + fileinfo[0];
         string   fullPath = Path.Combine(Environment.CurrentDirectory, pp);
         //string filename = System.IO.Path.GetFileName(fullPath);
         FileInfo fileInfo = new FileInfo(fullPath);
         if (File.Exists(fullPath) && !fullPath.ToLower().Contains(".json") && fileInfo.Length != 0)
         {
             Message message = new Message()
             {
                 cbId = "sendFileStatus_n", data = fileinfo[0], Status = true
             };
             string strmessag = JsEvent.EnSerialize <Message>(message);
             //Thread createThread = new Thread(getJson);
             //createThread.Start(strmessag);
             getJson(strmessag);
             return;
         }
         else
         {
             Message message = new Message()
             {
                 cbId = "sendFileStatus_n", data = fileinfo[0], Status = false
             };
             string strmessag = JsEvent.EnSerialize <Message>(message);
             //Thread createThread = new Thread(getJson);
             //createThread.Start(strmessag);
             getJson(strmessag);
         }
         long bagSize = Convert.ToInt64(fileinfo[1]);
         TransferFiles.ReceiveData(client, bagSize, fullPath);
         IsTime = true;
     }
     catch (Exception ex)
     {
         new Helper().InsertErrorMsg(ex.Message + "||" + ex.StackTrace, "create收文件异常");
         return;
     }
     //关闭文件流
     //MyFileStream.Close();
     //关闭套接字
     //client.Close();
 }
Exemplo n.º 3
0
        public static void SendMsg(string s)
        {
            Message nam = JsEvent.DecodeJson <Message>(s);

            try
            {
                string re = EnSerialize <LocalFunMsg>(GetLocalFunMsg(nam.data));
                JsEvent.wb.ExecuteScriptAsync("sClassJSBridge.handleMessage('" + nam.cbId + "'," + re + ");");
            }
            catch (Exception ex)
            {
                LocalFunMsg fas = GetLocalFunMsg("", 1, false, ex.Message);
                JsEvent.wb.ExecuteScriptAsync("sClassJSBridge.handleMessage('" + nam.cbId + "'," + fas + ");");
            }
        }
Exemplo n.º 4
0
 public static void Message(object clientSocket, string msg)
 {
     try
     {
         new Helper().InsertErrorMsg(msg, "收到返回消息");
         Socket client = clientSocket as Socket;
         msg = Regex.Split(msg, "0X12:")[1];
         long   bagSize = Convert.ToInt64(msg);
         byte[] data    = TransferFiles.ReceiveMsg(client, bagSize);
         string datamsg = Encoding.UTF8.GetString(data, 0, data.Length);
         JsEvent.SendMsg(datamsg);
     }
     catch (Exception ex)
     {
     }
 }
Exemplo n.º 5
0
        private int callback(IntPtr usrdata, string record_id, int type, byte[] message, int size)
        {
            if (stop == "is")
            {
                return(0);
            }
            int score = 0;

            if (type == AIENGINE_MESSAGE_TYPE_JSON)
            {
                IndexForm aiEngine = (IndexForm)GCHandle.FromIntPtr(usrdata).Target;
                aiEngine.result = Encoding.UTF8.GetString(message);
                string  mess  = Encoding.UTF8.GetString(message);
                message messg = JsEvent.DecodeJson <message>(mess);
                if (messg.result != null)
                {
                    score = int.Parse(messg.result.overall);
                }
            }
            try
            {
                if (JsEvent.parameter != null && JsEvent.parameter.zimu != null && JsEvent.parameter.zimu != "")
                {
                    if (JsEvent.cbId != "-1")
                    {
                        mesage msag = new mesage();
                        msag.code       = 0;
                        msag.msg        = "";
                        msag.data       = new data();
                        msag.data.score = score;
                        string res = JsEvent.EnSerialize <mesage>(msag);
                        JsEvent.wb.ExecuteScriptAsync("sClassJSBridge.handleMessage('" + JsEvent.cbId + "','" + res + "');");
                    }
                    else
                    {
                        JsEvent.wb.ExecuteScriptAsync("cpgetScore('" + score + "');");
                    }
                }
            }
            catch (Exception ee)
            {
                new Helper().InsertErrorMsg("窗体关闭" + ee.StackTrace, ee.Message);
                throw;
            }
            return(0);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 结束录音
        /// </summary>
        /// <param name="recordURL">录音存放主文件夹地址</param>
        /// <param name="thearID">教师ID</param>
        /// <param name="ResID">资源文件ID</param>
        public string RecordEnd(string recordURL, string thearID, string ResID, string UploadUrl)
        {
            //Stop();
            //string URL = System.Configuration.ConfigurationManager.AppSettings["ResouseServer"];
            string   URL = UploadUrl;
            DateTime dt  = DateTime.Now;
            //System.Environment.CurrentDirectory
            string path = (recordURL == string.Empty ? "D:" : recordURL) + "\\Record\\" + thearID.Replace("-", "");// + "\\" + dt.Year + "\\" + dt.Month;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            //string fileName = dt.ToFileTime().ToString();

            mciSendString("stop movie", "", 0, 0); //停止录音
            //string path1 = path + "\\" + ResID.Replace("-", "") + ".wav";
            string path2 = path + "\\" + ResID.Replace("-", "") + ".mp3";

            if (JsEvent.parameter != null && JsEvent.parameter.zimu != null && JsEvent.parameter.zimu != "")
            {
                //path1 = path + "\\" + ResID.Replace("-", "") + JsEvent.parameter.wordIndex + ".wav";
                path2 = path + "\\" + ResID.Replace("-", "") + JsEvent.parameter.wordIndex + ".mp3";
            }
            int a = mciSendString("save movie " + path2, "", 0, 0); //保存mp3给前端

            //mciSendString("save movie " + path1, "", 0, 0); //保存wav测评
            mciSendString("close movie", "", 0, 0);                                          //mciSendString("close movie", "", 0, 0);
            if (a == 0)
            {
                try
                {
                    //上传文件
                    //return path + "\\" + fileName + ".mp3";
                    string    url    = "";
                    WebClient client = new WebClient();
                    //JsEvent je = new JsEvent(null, null);
                    JsonFile jsonFile1 = new JsonFile();
                    jsonFile1.FileID = ResID;
                    if (JsEvent.parameter != null && JsEvent.parameter.zimu != null && JsEvent.parameter.zimu != "")
                    {
                        jsonFile1.FileID = ResID + JsEvent.parameter.wordIndex;
                    }
                    jsonFile1.UserName      = thearID;
                    jsonFile1.ResourceStyle = 101;
                    string        JsonFile = JsEvent.EnSerialize <JsonFile>(jsonFile1);
                    byte[]        bt       = client.UploadFile(URL + "?JsonFile=" + JsonFile, path2);
                    string        temp     = System.Text.Encoding.UTF8.GetString(bt);
                    List <string> ls       = temp.Split(',').ToList();
                    if (ls != null && ls.Count == 8)
                    {
                        List <string> ls2 = ls[6].Split(',').ToList();
                        url = ls2[0].Replace("\"FilePath\":\"", "").Replace("\"}", "");
                        return(url);
                    }
                    else
                    {
                        //return "false上传错误1" + path;
                        return("");
                    }
                }
                catch (Exception ex)
                {
                    //return "false上传错误2" + ex.Message;
                    return("");
                }
            }
            else
            {
                //return "false保存失败" + path;
                return("");
            }
        }