Skip to content

Commit

Permalink
#4: Resolve tooling issue and unit test project issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tsharp committed Jul 14, 2017
1 parent 28fd005 commit eeae1e9
Show file tree
Hide file tree
Showing 34 changed files with 2,744 additions and 65 deletions.
83 changes: 83 additions & 0 deletions AutoNumber-Old/AutoNumber.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{10E2B428-F093-400A-8F7F-38AA8BCBD434}</ProjectGuid>
<ProjectTypeGuids>{4C25E9B5-9FA6-436c-8E19-B395D2A65FAF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Celedon</RootNamespace>
<AssemblyName>CeledonPartners.AutoNumber</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>AutoNumberStrongKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Crm.Sdk.Proxy, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\CRM 2013 SP1 R1 SDK\SDK\Bin\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\CRM 2013 SP1 R1 SDK\SDK\Bin\Microsoft.Xrm.Sdk.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.XML" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="AutoNumberPluginConfig.cs" />
<Compile Include="CeledonExtensions.cs" />
<Compile Include="CreateAutoNumber.cs" />
<Compile Include="DeleteAutoNumber.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CeledonPlugin.cs" />
<Compile Include="GetNextAutoNumber.cs" />
<Compile Include="RuntimeParameter.cs" />
<Compile Include="ValidateAutoNumber.cs" />
</ItemGroup>
<ItemGroup>
<None Include="AutoNumberStrongKey.snk" />
<None Include="license.md" />
<None Include="readme.md" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
17 changes: 17 additions & 0 deletions AutoNumber-Old/AutoNumberPluginConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Celedon
{
[DataContract]
public class AutoNumberPluginConfig
{
[DataMember]
public string EntityName;

[DataMember]
public string EventName;
}
}
154 changes: 154 additions & 0 deletions AutoNumber-Old/CeledonExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Author: Matt Barnes ([email protected])
/*The MIT License (MIT)
Copyright (c) 2015 Celedon Partners
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

// Collection of useful extension methods

using System;
using System.IO;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace Celedon
{
// Helpful extentions
// Use these and add to these to make our plugins a little shorter/cleaner/leaner
public static class Extensions
{
// Used to get values from context inputparameters and outputparameters, of a specific type rather than handling the Object type in our code.
public static bool TryGetValue<T>(this ParameterCollection parameterCollection, string key, out T value)
{
object valueObj;
if (parameterCollection.TryGetValue(key, out valueObj))
{
try
{
value = (T)valueObj;
return true;
}
catch (InvalidCastException) { } // Key exists, but cast failed. Let this fall through to the default return value.
}

value = default(T);
return false;
}

// NotNull because Plugins attached to custom Actions recieve ALL input parameters, even if they were not included in the original Action context
public static bool TryGetValueNotNull<T>(this ParameterCollection parameterCollection, string key, out T value)
{
object valueObj;
if (parameterCollection.TryGetValue(key, out valueObj))
{
if (valueObj != null)
{
try
{
value = (T)valueObj;
return true;
}
catch (InvalidCastException) { } // Key exists, but cast failed. Let this fall through to the default return value.
}
}

value = default(T);
return false;
}

// NotNull because Plugins attached to custom Actions recieve ALL input parameters, even if they were not included in the original Action context
public static bool ContainsNotNull(this ParameterCollection parameterCollection, string key)
{
return parameterCollection.Contains(key) && parameterCollection[key] != null;
}

// Parse JSON string to object - CRM Online compatible
public static T ParseJSON<T>(this string jsonString, bool useSimpleDictionaryFormat = true)
{
try
{
DataContractJsonSerializer JsonDeserializer = new DataContractJsonSerializer(typeof(T));
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)))
{
return (T)JsonDeserializer.ReadObject(stream);
}
}
catch
{
throw new InvalidDataContractException("JSON string is invalid, or could not be serialized to the specified type.");
}
}

// Try Parse JSON string to object - CRM Online compatible
public static bool TryParseJSON<T>(this string jsonString, out T obj, bool useSimpleDictionaryFormat = true)
{
try
{
obj = jsonString.ParseJSON<T>(useSimpleDictionaryFormat);
return true;
}
catch
{
obj = default(T);
return false;
}
}

// Convert object to JSON string - CRM Online compatible
public static string ToJSON(this object obj, bool useSimpleDictionaryFormat = true)
{
DataContractJsonSerializer JsonSerializer = new DataContractJsonSerializer(obj.GetType());
using (MemoryStream stream = new MemoryStream())
{
JsonSerializer.WriteObject(stream, obj);
return Encoding.UTF8.GetString(stream.ToArray());
}
}

// A slightly easier way to retreive all columns
public static Entity Retrieve(this IOrganizationService service, string entityName, Guid entityId, bool allColumns)
{
return service.Retrieve(entityName, entityId, new ColumnSet(allColumns));
}

// Easily convert Guid to EntityReference
public static EntityReference ToEntityReference(this Guid id, string entityType)
{
return new EntityReference(entityType, id);
}

// Easily convert integer to OptionSetValue
public static OptionSetValue ToOptionSetValue(this int value)
{
return new OptionSetValue(value);
}

// This is how the OOB GetService method should have been...
public static T GetService<T>(this IServiceProvider serviceProvider)
{
return (T)serviceProvider.GetService(typeof(T));
}
}
}
Loading

0 comments on commit eeae1e9

Please sign in to comment.