コード例 #1
0
ファイル: CommService.cs プロジェクト: pravse/CommSample
        public RequestHandle CreateRequest(ServiceRequest instance)
        {
            // process the new request
            RequestHandle reqHandle = commLogic.HandleNewRequest(instance);

            if (null != reqHandle)
            {
                // add it to the store
                instance.Handle = reqHandle;
                requestStore.Add(reqHandle.Id, instance);
            }

            return reqHandle;
        }
コード例 #2
0
ファイル: CommLogic.cs プロジェクト: pravse/CommSample
 public RequestHandle HandleNewRequest(ServiceRequest request)
 {
     Debug.Assert(null != request);
     if (request.Channel == ChannelChoice.EMAIL_EMAIL)
     {
         return twoWayEmail(request);
     }
     else if (request.Channel == ChannelChoice.EMAIL_DOODLE)
     {
         return emailToDoodle(request);
     }
     else if (request.Channel == ChannelChoice.TWILIO)
     {
         return twilioComm(request);
     }
     return null;
 }
コード例 #3
0
ファイル: ServiceRequest.cs プロジェクト: pravse/CommSample
 public void Add(string requestId, ServiceRequest newRequest)
 {
     if ((null != newRequest) && (null != requestId))
     {
         requestDict.Add(requestId, newRequest);
     }
 }
コード例 #4
0
ファイル: CommService.cs プロジェクト: pravse/CommSample
 public ServiceRequest UpdateOrDelete(string id, ServiceRequest instance, string method)
 {
     if ((null != method))
         {
             // implement update as delete + insert
             requestStore.Delete(id);
         }
       if ((null != method) && method.Equals("update") && (null != instance))
         {
             requestStore.Add(id, instance);
             return instance;
         }
       return null;
 }
コード例 #5
0
ファイル: CommLogic.cs プロジェクト: pravse/CommSample
        private RequestHandle twoWayEmail(ServiceRequest request)
        {
            Debug.Assert(null != request);

            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add(QUESTION_KEY, request.Question);
            parameters.Add(EMAIL_FORM_SUFFIX_KEY, "TwoWayEmail");
            return new RequestHandle
            {
                Id = sendEmailMessage(request, parameters),
                Channel = request.Channel,
                Metadata = null
            };
        }
コード例 #6
0
ファイル: CommLogic.cs プロジェクト: pravse/CommSample
        private RequestHandle twilioComm(ServiceRequest request)
        {
            // start a phone call to the request recipient
            twilioClient.MakeCall(request.Recipient, request.Subject, request.Question);

            return null;
        }
コード例 #7
0
ファイル: CommLogic.cs プロジェクト: pravse/CommSample
        private string sendEmailMessage(ServiceRequest request, Dictionary<string, string> parameters)
        {
            // for two-way email, we can generate random IDs
            string requestId = generateNewId();

            // construct a mail message from the service request
            MailMessage newMsg = new MailMessage(
                mailClient.Smtp.Credentials.GetCredential(mailClient.Smtp.Host,
                                                          mailClient.Smtp.Port,
                                                          "SSL").UserName,
                request.Recipient);
            newMsg.Subject = request.Subject + "[id=" + requestId + "]";
            newMsg.Body = constructEmailMsgBody(request, parameters);
            newMsg.IsBodyHtml = true;

            // send the mail message : for now, keep it simple with a synchronous send. Make it async later
            mailClient.Smtp.Send(newMsg);

            return requestId;
        }
コード例 #8
0
ファイル: CommLogic.cs プロジェクト: pravse/CommSample
        private RequestHandle emailToDoodle(ServiceRequest request)
        {
            // set up a Doodle poll
            CreatePollResponse createPollResponse = createDoodlePoll(request);
            string doodlePollUrl;

            if (null == createPollResponse)
            {
                // TODO: handle this: for now, continue with a dummy url
                doodlePollUrl = doodleClient.ConstructUrl("ErrorPollId");
            }
            else
            {
                doodlePollUrl = doodleClient.ConstructUrl(createPollResponse.PollId);
            }

            // send an email message with the link to the poll
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add(DOODLE_LINK_KEY, doodlePollUrl);
            parameters.Add(EMAIL_FORM_SUFFIX_KEY, "EmailToDoodle");
            sendEmailMessage(request, parameters);

            return new RequestHandle { Id = createPollResponse.PollId,
                                       Channel = request.Channel,
                                       Metadata = createPollResponse.PollKey };
        }
コード例 #9
0
ファイル: CommLogic.cs プロジェクト: pravse/CommSample
        /// <summary>
        /// returns an ID for the constructed Doodle poll
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private CreatePollResponse createDoodlePoll(ServiceRequest request)
        {
            PollType newPoll = new PollType(PollTypeType.TEXT, false, "Please answer this!", "2", request.Question);
            newPoll.initiator = new InitiatorType();
            newPoll.initiator.name = "Praveen";
            newPoll.options = new OptionsTypeOption[3];
            newPoll.options[0] = new OptionsTypeOption();
            newPoll.options[0].Value = "Three?";
            newPoll.options[1] = new OptionsTypeOption();
            newPoll.options[1].Value = "Four?";
            newPoll.options[2] = new OptionsTypeOption();
            newPoll.options[2].Value = "Five?";

            CreatePollResponse createPollResponse = doodleClient.CreatePoll(newPoll);

            return createPollResponse; ;
        }
コード例 #10
0
ファイル: CommLogic.cs プロジェクト: pravse/CommSample
        private string constructEmailMsgBody(ServiceRequest request, Dictionary<string, string> parameters)
        {
            string msgBody;
            string emailFormSuffix = parameters[EMAIL_FORM_SUFFIX_KEY];
            Debug.Assert(null != emailFormSuffix);

            string myFormFilename = HostingEnvironment.MapPath(@"/App_Data/EmailForm." + emailFormSuffix + ".htm");
            if (null != myFormFilename)
            {
                // open the file
                msgBody = File.ReadAllText(myFormFilename);
                if (null != msgBody)
                {
                    foreach (var entry in parameters)
                    {
                        // TODO: pravse: yes it is grungy to use the parameters to also pass the form name.
                        msgBody = msgBody.Replace("%%"+entry.Key+"%%", entry.Value);
                    }
                }
            }
            else
            {
                msgBody = request.Question;
            }
            return msgBody;
        }