コード例 #1
0
ファイル: Program.cs プロジェクト: hydr/PlacetelDialer
        public static void CheckSettings()
        {
            while (string.IsNullOrEmpty(_dialerConfig.ApiKey))
            {
                Console.Write("Please enter the Placetel API Key:");
                var enteredKey = Console.ReadLine();

                //Test the key
                var testClient = new PlacetelApiClient.PlacetelClient(enteredKey);
                var success = testClient.Test();
                if (success)
                    _dialerConfig.ApiKey = enteredKey;
                else
                    Console.WriteLine("The key was not tested successfully!");
            }

            SaveConfig();

            while (string.IsNullOrEmpty(_dialerConfig.SipUser))
            {
                var testClient = new PlacetelApiClient.PlacetelClient(_dialerConfig.ApiKey);
                var sipUsers = testClient.GetVoipUsers();

                Console.WriteLine("Select a telephone line:");
                for (var i = 0; i < sipUsers.Count; i++)
                {
                    var s = sipUsers[i];
                    Console.WriteLine("{0:000}: {1} ({2})", i+1, s.Name, s.Uid);
                }

                var enteredId = Console.ReadLine();
                int id;
                if (!int.TryParse(enteredId, out id) || sipUsers.ElementAtOrDefault(id-1) == null)
                {
                    Console.WriteLine("You must enter the ID of the line!");
                    continue;
                }
                var sipUser = sipUsers.ElementAt(id - 1);
                _dialerConfig.SipUser = sipUser.Uid;
            }

            SaveConfig();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: hydr/PlacetelDialer
        static void Main(string[] args)
        {
            //If the program is executed with admin rights, we register the protocol handler
            var principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
            bool isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);

            if (isAdmin)
            {
                var r = new RegisterProtocolHandler();
                r.Register();
                return;
            }

            Init();
            CheckSettings();

            string phoneNumber = null;
            if (args.Length > 0)
                phoneNumber = args[0];

            if (phoneNumber == null)
            {
                Console.Write("Please enter the phone number: ");
                phoneNumber = Console.ReadLine();
                Console.WriteLine();
            }

            if (phoneNumber == null)
                throw new ArgumentException("No phone number entered");

            if (phoneNumber.Length > 50)
                throw new ArgumentException("Phone number is too long");

            Console.WriteLine("Sent phone number '{0}'", phoneNumber);

            phoneNumber = Regex.Replace(phoneNumber, @"\+", "00"); //Placetel can't handel the + in the beginning
            phoneNumber = Regex.Replace(phoneNumber, @"[^0-9]", ""); //Strip all non number characters from the number.

            Console.WriteLine("Dialing the phone number '{0}'", phoneNumber);

            //Make the call
            var client = new PlacetelApiClient.PlacetelClient(_dialerConfig.ApiKey);
            client.InitiateCall(_dialerConfig.SipUser, phoneNumber);

            System.Threading.Thread.Sleep(3000);
        }