public MainWindow()
        {
            // Set the product info header, used to update the HTTP User-Agent for requests to Tethr.
            var type = typeof(MainWindow);

            TethrSession.SetProductInfoHeaderValue(type.Namespace, type.Assembly.GetName().Version.ToString());

            InitializeComponent();
            CallMetaData.ItemsSource = CallMetaDataItems;

            ApiUserName.Text = Properties.Settings.Default.ApiUser;
            UrlEndPoint.Text = Properties.Settings.Default.Uri;

            var fields = Properties.Settings.Default.MetaDataFields;

            if (!string.IsNullOrEmpty(fields))
            {
                foreach (var s in fields.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    CallMetaDataItems.Add(new MetaDataItem {
                        Key = s
                    });
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            // Setup Common Logger with default settings
            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter();

            // Set the product info header, used to update the HTTP User-Agent for requests to Tethr.
            var programType = typeof(Program);

            TethrSession.SetProductInfoHeaderValue(programType.Namespace, programType.Assembly.GetName().Version.ToString());

            // Get the connection string so that we can initialize a Tethr session
            var connectionStringSettings = ConfigurationManager.ConnectionStrings["Tethr"];

            if (connectionStringSettings == null)
            {
                throw new InvalidOperationException(
                          $"Could not find a connection string for Tethr. Please add a connection string in the <ConnectionStrings> section of the application's configuration file. For example: <add name=\"Tethr\" connectionString=\"uri=https://YourCompanyNameHere.Audio.Tethr.io/;ApiUser=YourUserNameHere;Password=YourPasswordHere\" />");
            }

            // Initialize new options from the connection string
            var sessionOptions = TethrSessionOptions.InitializeFromConnectionString(connectionStringSettings.ConnectionString);

            // Create a Tethr Session and store it for use when we make our API calls.
            _tethrSession = new TethrSession(sessionOptions);             // {DefaultProxy = new WebProxy("http://127.0.0.1:8888", false) };

            // Send the file, and then await the result.
            var fileName = args.Length < 1 ? "SampleRecording.json" : args[0] ?? "";

            Console.WriteLine("Reading : " + fileName);

            var result = Task.Run(() => SendFile(fileName)).GetAwaiter().GetResult();

            Console.WriteLine("Sent recording:");
            Console.WriteLine("\tSession id       : {0}", result.SessionId);
            Console.WriteLine("\tCall Start Time  : {0} (Local Time)", result.StartTime.ToLocalTime().ToLongTimeString());
            Console.WriteLine("\tTethr call id is : {0}", result.CallId);

            // Complete.
            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }
        private void RefreshCallStateClick(object sender, RoutedEventArgs e)
        {
            var sessionId = this.SessionId.TextValueOrNull();

            if (sessionId != null)
            {
                var hostUri     = new Uri(this.UrlEndPoint.Text);
                var apiUser     = ApiUserName.Text;
                var apiPassword = ApiPassword.SecurePassword;
                var status      = Task.Run(async() =>
                {
                    try
                    {
                        // Because we are doing this in a UI, and that the setting can change from run to run
                        // we are creating a new session per request.  However, it is normaly recommended that session
                        // be a singleton instanse per processes
                        using (var session = new TethrSession(hostUri, apiUser, apiPassword))
                        {
                            var archiveRecorder = new TethrArchivedRecording(session);
                            return(await archiveRecorder.GetRecordingStatusAsync(sessionId));
                        }
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message, "Error sending call", MessageBoxButton.OK, MessageBoxImage.Error);
                        return(null);
                    }
                }).GetAwaiter().GetResult();

                if (status != null)
                {
                    CallId.Text = status.CallId;
                }

                CallState.Text = status?.Status.ToString() ?? "CALL NOT FOUND";
            }
        }
        private void StartUploadClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                var audioFilePath = this.AudioFileName.Text;
                if (!File.Exists(audioFilePath))
                {
                    MessageBox.Show("Audio file not found.", "Error preping to send call", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                var audioExt  = Path.GetExtension(audioFilePath).ToLowerInvariant();
                var audioType = (string)null;
                switch (audioExt)
                {
                case ".wav":
                    audioType = "audio/x-wav";
                    break;

                case ".mp3":
                    audioType = "audio/mp3";
                    break;

                case ".ogg":
                    // TODO: we only support OPUS in Ogg, really should open the file and make sure it's OPUS.
                    audioType = "audio/ogg";
                    break;

                default:
                    MessageBox.Show(audioExt + " is not a supported audio file.", "Error preping to send call", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                var settings = CreateRecordingInfo();

                this.UploadBtn.IsEnabled       = false;
                this.UploadProgress.Visibility = Visibility.Visible;
                var hostUri     = new Uri(this.UrlEndPoint.Text);
                var apiUser     = ApiUserName.Text;
                var apiPassword = ApiPassword.SecurePassword;

                Task.Run(async() =>
                {
                    try
                    {
                        // Because we are doing this in a UI, and that the setting can change from run to run
                        // we are creating a new session per request.  However, it is normaly recommended that session
                        // be a singleton instanse per processes
                        using (var session = new TethrSession(hostUri, apiUser, apiPassword))
                        {
                            var archiveRecorder = new TethrArchivedRecording(session);
                            using (var audioStream = File.OpenRead(audioFilePath))
                            {
                                var result = await archiveRecorder.SendRecordingAsync(settings, audioStream, audioType);
                                this.Dispatcher.Invoke(() => { this.CallId.Text = result.CallId; });
                                MessageBox.Show($"Call Upload Successful.\r\n\r\nCall ID : {result.CallId}", "Call Uploaded", MessageBoxButton.OK, MessageBoxImage.Information);
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message, "Error sending call", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    finally
                    {
                        this.Dispatcher.Invoke(() =>
                        {
                            this.UploadBtn.IsEnabled       = true;
                            this.UploadProgress.Visibility = Visibility.Collapsed;
                        });
                    }
                });
            }
            catch (Exception exception)
            {
                this.UploadBtn.IsEnabled       = true;
                this.UploadProgress.Visibility = Visibility.Collapsed;
                MessageBox.Show(exception.Message, "Error preping to send call", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }