Esempio n. 1
0
        public async Task <ChatSentResponse> SendChatFileAsync(string token, int eventID, int type, string message, IEnumerable <string> filePaths, int chat, int belongingTo)
        {
            if (string.IsNullOrEmpty(message))
            {
                message = DateTime.Now.ToShortDateString();
            }

            string apiUrl = App.Context.ServerAddress + string.Format(Constants.AppAPI.SendChatAPI, token, eventID, type, message, 0, string.Empty);

            List <byte[]> data      = new List <byte[]>();
            List <string> fileNames = new List <string>();

            foreach (var path in filePaths)
            {
                data.Add(System.IO.File.ReadAllBytes(path));
                fileNames.Add(System.IO.Path.GetFileName(path));
            }

            var apiResponse = await NetWorkUtility.SendFile(apiUrl, data, fileNames);

            if (apiResponse.Length > 25)
            {
                try
                {
                    var result = JsonConvert.DeserializeObject <ChatSentResponse>(apiResponse);
                    return(result);
                }
                catch (Exception ex)
                {
                    //mvxLog.Error(ex.ToString());
                    //mvxLog.Error(ex.StackTrace);
                }
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// "api/send-chat?api_token={0}&surveyID={1}&&type={2}&content={3}&file=&belongingTo={4}"
        /// </summary>
        /// <param name="token"></param>
        /// <param name="eventID"></param>
        /// <param name="type"></param>
        /// <param name="message"></param>
        /// <param name="chat"></param>
        /// <param name="belongingTo"></param>
        /// <returns></returns>
        public async Task <ChatSentResponse> SendChatFileAsync(string token, int eventID, int type, string message, byte[] data, int chat, int belongingTo, string fileName)
        {
            string apiUrl      = App.Context.ServerAddress + string.Format(Constants.AppAPI.SendChatAPI, token, eventID, type, message, 0, string.Empty);
            var    apiResponse = await NetWorkUtility.SendFile(apiUrl, new List <byte[]>() { data }, new List <string>() { string.Empty });

            if (apiResponse.Length > 25)
            {
                try
                {
                    var result = JsonConvert.DeserializeObject <ChatSentResponse>(apiResponse);
                    return(result);
                }
                catch (Exception ex)
                {
                    //mvxLog.Error(ex.ToString());
                    //mvxLog.Error(ex.StackTrace);
                }
            }
            return(null);
        }