Beispiel #1
0
 public static void AddMessage(VoiceMessage message)
 {
     #if !DEBUG
     var serviceClient = new AlexusService.AlexusVoiceServiceClient();
     serviceClient.AddMessage;
     #endif
     #if DEBUG
     MessageAddingCore.AddMessage(message);
     #endif
 }
Beispiel #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="message"></param>
 public static void AddMessage(VoiceMessage message)
 {
     #if !DEBUG
     MessageAddingCore.AddMessage(message);
     message.Data = null;
     var serviceClient = new AlexusService.AlexusVoiceServiceClient("BasicHttpBinding_IAlexusVoiceService");
     serviceClient.AddMessage(message);
     #endif
     #if DEBUG
     MessageAddingCore.AddMessage(message);
     #endif
 }
        public void AddMessage(VoiceMessage message)
        {
            //MessageAddingCore.AddMessage(message);
            message.Id = DbDataAccessor.CreateDefaultInstance<VoiceMessageDAO>().Insert(message);

            //TODO: Add recipients
            foreach (MessageRecipient mr in message.Recipients)
            {
                mr.MessageId = message.Id;
                DbDataAccessor.CreateDefaultInstance<MessageRecipientDAO>().Insert(mr);
            }

            SendNotification(message);
        }
Beispiel #4
0
        public static void AddMessage(VoiceMessage message)
        {
            CloudStorageAccount storageAccount =
                CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["VoiceBlobStorage"].ConnectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            CloudBlobContainer container = blobClient.GetContainerReference("voices");
            // Create the container if it doesn't already exist.
            container.CreateIfNotExists();
            var blobName = string.Format("{0}.mp3", Guid.NewGuid());
            CloudBlockBlob blob = container.GetBlockBlobReference(blobName);
            using (var memoryStream = new MemoryStream(message.Data))
            {
                blob.UploadFromStream(memoryStream);
            }

            message.URL = blob.Uri.AbsoluteUri;
        }
Beispiel #5
0
        private void sendBtn_Click(object sender, EventArgs e)
        {
            if (_recorder == null || _recorder.State != Recorder.RecordingState.Stopped)
                return;

            if (_users == null || _users.Count == 0)
                return;

            List<MessageRecipient> _resip = new List<MessageRecipient>();
            foreach (User u in _users )
            {
                MessageRecipient mr = new MessageRecipient()
                {
                    UserId = u.Id,
                };

                _resip.Add(mr);
            }

            var message = new VoiceMessage()
                {
                    SenderId = ExecutionContext.UserId,
                    CreatingDate = DateTime.Now,
                    Recipients = _resip
                };

            if (_recorder.State == Recorder.RecordingState.Stopped)
            {
                //maxLen is in ms (1000 = 1 second)
                string outfile = "-b 32 --resample 22.05 -m m \"" + _recorder.TempWavFileName + "\" \"" + _recorder.TempWavFileName.Replace(".wav", ".mp3") + "\"";
                System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
                psi.FileName = "\"" + "encoder\\lame.exe" + "\"";
                psi.Arguments = outfile;
                //psi.WorkingDirectory=pworkingDir;
                psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
                System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);

                p.WaitForExit();

                message.Data = File.ReadAllBytes(_recorder.TempWavFileName.Replace(".wav", ".mp3"));
            }

            ServiceCore.AddMessage(message);

            this.ParentForm.GoBack();
        }
        private static void SendNotification(VoiceMessage message)
        {
            foreach (var messageRecipient in message.Recipients)
            {

                try
                {
                    // Get the URI that the Microsoft Push Notification Service returns to the push client when creating a notification channel.
                    // Normally, a web service would listen for URIs coming from the web client and maintain a list of URIs to send
                    // notifications out to.

                    var user =
                        DbDataAccessor.CreateDefaultInstance<UserDAO>().Select(messageRecipient.UserId);
                    if (user != null && !string.IsNullOrWhiteSpace(user.DeviceURL))
                    {
                        HttpWebRequest sendNotificationRequest = (HttpWebRequest) WebRequest.Create(user.DeviceURL);

                        // Create an HTTPWebRequest that posts the toast notification to the Microsoft Push Notification Service.
                        // HTTP POST is the only method allowed to send the notification.
                        sendNotificationRequest.Method = "POST";

                        // The optional custom header X-MessageID uniquely identifies a notification message.
                        // If it is present, the same value is returned in the notification response. It must be a string that contains a UUID.
                        // sendNotificationRequest.Headers.Add("X-MessageID", "<UUID>");

                        // Create the toast message.
                        string toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                              "<wp:Notification xmlns:wp=\"WPNotification\">" +
                                              "<wp:Toast>" +
                                              "<wp:Text1>Hello</wp:Text1>" +
                                              "<wp:Text2>" + message.URL + "</wp:Text2>" +

                                              "</wp:Toast> " +
                                              "</wp:Notification>";
                        ;

                        // Set the notification payload to send.
                        byte[] notificationMessage = Encoding.Default.GetBytes(toastMessage);

                        // Set the web request content length.
                        sendNotificationRequest.ContentLength = notificationMessage.Length;
                        sendNotificationRequest.ContentType = "text/xml";
                        sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");
                        sendNotificationRequest.Headers.Add("X-NotificationClass", "2");

                        using (Stream requestStream = sendNotificationRequest.GetRequestStream())
                        {
                            requestStream.Write(notificationMessage, 0, notificationMessage.Length);
                        }

                        // Send the notification and get the response.
                        HttpWebResponse response = (HttpWebResponse) sendNotificationRequest.GetResponse();
                        string notificationStatus = response.Headers["X-NotificationStatus"];
                        string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
                        string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];

                        // Display the response from the Microsoft Push Notification Service.
                        // Normally, error handling code would be here. In the real world, because data connections are not always available,
                        // notifications may need to be throttled back if the device cannot be reached.
                        Console.WriteLine(notificationStatus + " | " + deviceConnectionStatus + " | " +
                                          notificationChannelStatus);
                    }
                }
                catch
                    (Exception
                        ex)
                {
                    Console.WriteLine("Exception caught sending update: " + ex.ToString());
                }
            }
        }