Exemplo n.º 1
0
        private async void InitiateImageUpload(string filePath, string fileName)
        {
            if (chatRoom == null) //This code will be executed only in case of new conversation
            {
                CreateChatRoom(LinphoneManager.Instance.Core.InterpretURL(NewChatSipAddress.Text));
            }
            if (chatRoom != null)
            {
                ProgressPopup.Visibility = Visibility.Visible;
                MessageBox.Visibility    = Visibility.Collapsed;
                //CancelUpload.Visibility = Visibility.Visible;
                Task.Run(() => {
                    FileInfo fileInfo;
                    try {
                        fileInfo        = new FileInfo(filePath);
                        ChatMessage msg = chatRoom.CreateFileTransferMessage("application", "octet-stream", fileName, (int)fileInfo.Length, filePath);
                        msg.AppData     = fileName;
                        chatRoom.SendMessage(msg, this);
                    } catch (Exception e) {
                    }
                });
            }
            else
            {
                ProgressPopup.Visibility = Visibility.Collapsed;
                MessageBox.Visibility    = Visibility.Visible;
                var messageDialog = new MessageDialog(ResourceLoader.GetForCurrentView().GetString("ChatRoomCreationError"), ResourceLoader.GetForCurrentView().GetString("GenericError"));
                await messageDialog.ShowAsync();

                //CancelUpload.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 2
0
        private async void InitiateImageUpload(string filePath, string fileName, string fileType)
        {
            if (chatRoom == null) //This code will be executed only in case of new conversation
            {
                CreateChatRoom(LinphoneManager.Instance.Core.InterpretUrl(NewChatSipAddress.Text));
            }
            if (chatRoom != null)
            {
                ProgressPopup.Visibility = Visibility.Visible;
                MessageBox.Visibility    = Visibility.Collapsed;
                //CancelUpload.Visibility = Visibility.Visible;
                Task.Run(() => {
                    FileInfo fileInfo;
                    try {
                        fileInfo                       = new FileInfo(filePath);
                        Content content                = LinphoneManager.Instance.Core.CreateContent();
                        content.Type                   = "image";
                        content.Subtype                = fileType;
                        content.Name                   = fileName + "." + fileType;
                        content.Size                   = (int)fileInfo.Length;
                        ChatMessage msg                = chatRoom.CreateFileTransferMessage(content);
                        msg.Appdata                    = fileName;
                        msg.FileTransferFilepath       = filePath;
                        msg.Listener.OnMsgStateChanged = MessageStateChanged;
                        chatRoom.SendChatMessage(msg);
                    } catch (Exception e) {
                        Debug.WriteLine("Cannot upload image: " + e);
                    }
                });
            }
            else
            {
                ProgressPopup.Visibility = Visibility.Collapsed;
                MessageBox.Visibility    = Visibility.Visible;
                var messageDialog = new MessageDialog(ResourceLoader.GetForCurrentView().GetString("ChatRoomCreationError"), ResourceLoader.GetForCurrentView().GetString("GenericError"));
                await messageDialog.ShowAsync();

                //CancelUpload.Visibility = Visibility.Collapsed;
            }
        }