コード例 #1
0
        public async Task <bool> SendGenericFileToServer(string serverUrl, string filePath, string name,
                                                         ServerSendFileCallback callback = null)
        {
            bool   result  = true;
            string message = null;

            try {
                ServerRequest serverRequest = new ServerRequest();

                if (request == null)
                {
                    RequestBuilder requestBuilder = new RequestBuilder();
                    request = requestBuilder
                              .SetDevice_id(App.config.GetDeviceId())
                              .SetDevice_tokenFirebase(App.firebaseInstanceId.Token)
                              .Build();
                }

                string responseString = await serverRequest.SendFileToServerAsync(serverUrl,
                                                                                  filePath, name, request);

                Response response = ServerResponse.ParsingJsonResponse(responseString);
                if (!response.Error)
                {
                    Debug.WriteLine(string.Format("File {0} inviato con successo", filePath));

                    //elimino la richiesta appena eseguita
                    request = null;
                    result  = true;
                }
                else
                {
                    result  = false;
                    message = string.Format("Il server ha restituito un errore durante l'invio del file {0}. Messaggio : {1}",
                                            name, response.Message);
                    Debug.WriteLine(message);
                }
            }
            catch (Exception e) {
                result = false;
                Debug.WriteLine(e.Message);
                Debug.WriteLine(e.StackTrace);
                Debug.WriteLine(e.InnerException);
                Debug.WriteLine(string.Format("Non e' stato possibile l'invio del file {0}.", name));
            }

            callback?.Invoke(result, message);

            return(result);
        }
コード例 #2
0
        private async Task <bool> SendFileAudioToServerAndDelete(string filePath, string name, ServerSendFileCallback callback = null)
        {
            RequestBuilder requestBuilder = new RequestBuilder();

            requestBuilder
            .SetDevice_id(App.config.GetDeviceId())
            .SetDevice_tokenFirebase(App.firebaseInstanceId.Token);
            if (timerSpanToRecord != null)
            {
                requestBuilder.SetLength(timerSpanToRecord.ToString());
            }
            _serverSendFile.request = requestBuilder.Build();

            bool result =
                await _serverSendFile.SendGenericFileToServer(ServerConfig.Instance.server_url_send_audio, filePath, name, callback);

            result = result && await StorageUtility.DeleteFileLocalStorage(filePath);


            return(result);
        }