using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using System.Activities;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
namespace SendPolicyAttachment
{
public class EmailPolicyAttachment : CodeActivity
{
[Input("contact")]
[ReferenceTarget("contact")]
public InArgument<EntityReference> customer { get; set; }
[Input("quoteNo")]
public InArgument<string> quoteNo { get; set; }
protected override void Execute(CodeActivityContext context)
{
ITracingService _traceservice = context.GetExtension<ITracingService>();
//Create the context
IWorkflowContext _context = context.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory _servicefactory = context.GetExtension<IOrganizationServiceFactory>();
IOrganizationService _service = _servicefactory.CreateOrganizationService(_context.UserId);
try
{
Guid recordId = _context.PrimaryEntityId;
EntityReference contactId = customer.Get<EntityReference>(context);
Guid contId = contactId.Id;
_traceservice.Trace(contId.ToString());
string quote = quoteNo.Get<string>(context);
_traceservice.Trace(quote);
string strurl = String.Format("{api URL}");
_traceservice.Trace(strurl);
WebRequest requestobj = WebRequest.Create(strurl);
requestobj.Method = "GET";
requestobj.ContentType = "application/json";
using (WebResponse response = requestobj.GetResponse())
{
using (var sr = new StreamReader(response.GetResponseStream()))
{
string result = sr.ReadToEnd();
_traceservice.Trace(result);
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message) ;
}
}
}
}