using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Win32;
using OrnekPlugins.CrmSdk;
using System.Collections;
using System.IO;
namespace OrnekPlugins
{
public class Plugins : IPlugin
{
public void Execute(IPluginExecutionContext context)
{
try
{
#region CRMSERVICE
OrnekPlugins.CrmSdk.CrmService crmService = null;
OrnekPlugins.CrmSdk.CrmAuthenticationToken token = new OrnekPlugins.CrmSdk.CrmAuthenticationToken();
token.AuthenticationType = 0;// Active Directory =0
token.OrganizationName = "CRM";
crmService = new OrnekPlugins.CrmSdk.CrmService();
// crmService.PreAuthenticate = true;
crmService.UnsafeAuthenticatedConnectionSharing = true;
crmService.Url = @"http://deneme/MSCrmServices/2007/CrmService.asmx";
crmService.CrmAuthenticationTokenValue = token;
crmService.CrmAuthenticationTokenValue.CallerId = context.UserId;
crmService.UseDefaultCredentials = false;
crmService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
//ICrmService crmService = context.CreateCrmService(context.UserId);
//WhoAmIRequest request = new WhoAmIRequest();
//WhoAmIResponse response = (WhoAmIResponse)crmService.Execute(request);
#endregion
Microsoft.Crm.Sdk.DynamicEntity inputEntity = null;
Guid _inputEntity = Guid.Empty;
#region Kontroller
if (!context.InputParameters.Contains("Target"))
return;
if (string.IsNullOrEmpty(context.MessageName))
return;
if (string.IsNullOrEmpty(context.PrimaryEntityName))
return;
#endregion
#region InputEntityId Alma
if (context.MessageName.ToUpper().Equals("CREATE"))
{
inputEntity = (Microsoft.Crm.Sdk.DynamicEntity)context.InputParameters["Target"];
if (inputEntity != null && inputEntity.Properties.Contains("accountid"))
{
_inputEntity = new Guid(context.OutputParameters.Properties["id"].ToString());
}
}
else if (context.MessageName.ToUpper().Equals("UPDATE"))
{
inputEntity = (Microsoft.Crm.Sdk.DynamicEntity)context.InputParameters["Target"];
if (inputEntity != null)
{
Microsoft.Crm.Sdk.Key input = (Microsoft.Crm.Sdk.Key)inputEntity["accountid"];
if (input != null && input.Value != Guid.Empty)
{
_inputEntity = input.Value;
}
}
}
#endregion
#region FullCode
if (_inputEntity != Guid.Empty)
{
if (crmService != null)
{
switch (context.PrimaryEntityName.ToLower())
{
case "account":
{
/*Bu araya yapılacak işlem yazılacak*/
} break;
default:
break;
}
}
else
{
throw new InvalidPluginExecutionException("An error occurred in the Plugins plug-in.Crm connection is broken");
}
}
#endregion
}
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the Plugins plug-in.", ex);
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException("An error occurred in the Plugins plug-in.", ex);
}
}
}
}
Hiç yorum yok:
Yorum Gönder