From 6e3213d64ed893424ee993203314c57eb973430e Mon Sep 17 00:00:00 2001 From: Jim Daly Date: Tue, 27 Mar 2018 12:44:23 -0700 Subject: [PATCH] Adding first example --- .gitattributes | 63 ++++++++++++ common-data-service/C#/App.config | 24 +++++ .../CRUD-Dynamic-Entity.sln | 25 +++++ .../CRUD-Dynamic-Entity.csproj | 95 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 +++++++ .../CRUD-Dynamic-Entity/SampleMethods.cs | 16 ++++ .../CRUD-Dynamic-Entity/SampleProgram.cs | 86 +++++++++++++++++ common-data-service/C#/packages.config | 8 ++ 8 files changed, 353 insertions(+) create mode 100644 .gitattributes create mode 100644 common-data-service/C#/App.config create mode 100644 common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity.sln create mode 100644 common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity.csproj create mode 100644 common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/Properties/AssemblyInfo.cs create mode 100644 common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/SampleMethods.cs create mode 100644 common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/SampleProgram.cs create mode 100644 common-data-service/C#/packages.config diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..1ff0c423 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/common-data-service/C#/App.config b/common-data-service/C#/App.config new file mode 100644 index 00000000..e53d8c78 --- /dev/null +++ b/common-data-service/C#/App.config @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity.sln b/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity.sln new file mode 100644 index 00000000..a43c0c00 --- /dev/null +++ b/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CRUD-Dynamic-Entity", "CRUD-Dynamic-Entity\CRUD-Dynamic-Entity.csproj", "{06E79C5F-3024-400F-80D5-A1A493831CFE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {06E79C5F-3024-400F-80D5-A1A493831CFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06E79C5F-3024-400F-80D5-A1A493831CFE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06E79C5F-3024-400F-80D5-A1A493831CFE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06E79C5F-3024-400F-80D5-A1A493831CFE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0EF236BE-4A0E-4D8C-9949-44FC32A87F06} + EndGlobalSection +EndGlobal diff --git a/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity.csproj b/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity.csproj new file mode 100644 index 00000000..71fd69d6 --- /dev/null +++ b/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity.csproj @@ -0,0 +1,95 @@ + + + + + Debug + AnyCPU + {06E79C5F-3024-400F-80D5-A1A493831CFE} + Exe + PowerApps.Samples + CRUD-Dynamic-Entity + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.0.5\lib\net452\Microsoft.Crm.Sdk.Proxy.dll + + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.22.302111727\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + + ..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.22.302111727\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll + + + ..\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.0.5\lib\net452\Microsoft.Xrm.Sdk.dll + + + ..\packages\Microsoft.CrmSdk.Deployment.9.0.0.5\lib\net452\Microsoft.Xrm.Sdk.Deployment.dll + + + ..\packages\Microsoft.CrmSdk.Workflow.9.0.0.5\lib\net452\Microsoft.Xrm.Sdk.Workflow.dll + + + ..\packages\Microsoft.CrmSdk.XrmTooling.CoreAssembly.9.0.0.7\lib\net452\Microsoft.Xrm.Tooling.Connector.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + App.config + + + packages.config + + + + \ No newline at end of file diff --git a/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/Properties/AssemblyInfo.cs b/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..d8cbd992 --- /dev/null +++ b/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CRUD-Dynamic-Entity")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CRUD-Dynamic-Entity")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("06e79c5f-3024-400f-80d5-a1a493831cfe")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/SampleMethods.cs b/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/SampleMethods.cs new file mode 100644 index 00000000..ae518a51 --- /dev/null +++ b/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/SampleMethods.cs @@ -0,0 +1,16 @@ +using Microsoft.Xrm.Sdk; +using Microsoft.Xrm.Sdk.Messages; +using System; + +namespace PowerApps.Samples +{ + partial class SampleProgram + { + + public static Guid CreateEntity(IOrganizationService service, Entity entity) { + CreateRequest req = new CreateRequest() { Target = entity }; + CreateResponse resp = (CreateResponse)service.Execute(req); + return resp.id; + } + } +} diff --git a/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/SampleProgram.cs b/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/SampleProgram.cs new file mode 100644 index 00000000..5101c7ec --- /dev/null +++ b/common-data-service/C#/CRUD-Dynamic-Entity/CRUD-Dynamic-Entity/SampleProgram.cs @@ -0,0 +1,86 @@ +using Microsoft.Xrm.Sdk; +using Microsoft.Xrm.Tooling.Connector; +using System; +using System.Configuration; +using System.ServiceModel; + +namespace PowerApps.Samples +{ + partial class SampleProgram + { + static void Main(string[] args) + { + try { + CrmServiceClient csc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["Connect"].ConnectionString); + IOrganizationService service = csc.OrganizationServiceProxy; + + //Add code here + ////////////////////////////////////////////// + Entity account = new Entity("account"); + account["name"] = "Test Account"; + + //User service methods directly: + // Guid accountid = service.Create(account); + + //Use method defined in SampleMethods.cs + Guid accountid = CreateEntity(service, account); + + ////////////////////////////////////////////// + + } + catch (FaultException ex) + { + Console.WriteLine("The application terminated with an error."); + Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp); + Console.WriteLine("Code: {0}", ex.Detail.ErrorCode); + Console.WriteLine("Message: {0}", ex.Detail.Message); + Console.WriteLine("Plugin Trace: {0}", ex.Detail.TraceText); + Console.WriteLine("Inner Fault: {0}", + null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); + } + catch (TimeoutException ex) + { + Console.WriteLine("The application terminated with an error."); + Console.WriteLine("Message: {0}", ex.Message); + Console.WriteLine("Stack Trace: {0}", ex.StackTrace); + Console.WriteLine("Inner Fault: {0}", + null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message); + } + catch (Exception ex) + { + Console.WriteLine("The application terminated with an error."); + Console.WriteLine(ex.Message); + + // Display the details of the inner exception. + if (ex.InnerException != null) + { + Console.WriteLine(ex.InnerException.Message); + + FaultException fe = ex.InnerException + as FaultException; + if (fe != null) + { + Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp); + Console.WriteLine("Code: {0}", fe.Detail.ErrorCode); + Console.WriteLine("Message: {0}", fe.Detail.Message); + Console.WriteLine("Plugin Trace: {0}", fe.Detail.TraceText); + Console.WriteLine("Inner Fault: {0}", + null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault"); + } + } + } + // Additional exceptions to catch: SecurityTokenValidationException, ExpiredSecurityTokenException, + // SecurityAccessDeniedException, MessageSecurityException, and SecurityNegotiationException. + + finally + { + + Console.WriteLine("Press to exit."); + Console.ReadLine(); + } + + + + } + } +} diff --git a/common-data-service/C#/packages.config b/common-data-service/C#/packages.config new file mode 100644 index 00000000..65b0e66a --- /dev/null +++ b/common-data-service/C#/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file