Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlSerializer Memory Leak Fix #255

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,10 @@ artifacts

# Test
testrunner
scripts/output.txt
scripts/output.txt
/.vs
/.vs
/.vs/slnx.sqlite
/src/.vs/config
/src/.vs/config
/src/.vs/config/applicationhost.config
14 changes: 14 additions & 0 deletions samples/CompositeConsole/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<appSettings>
<add key="SecurityToken" value=""/>
<add key="ConsumerKey" value=""/>
<add key="ConsumerSecret" value=""/>
<add key="Username" value=""/>
<add key="Password" value=""/>
<add key="IsSandboxUser" value="true"/>
</appSettings>
</configuration>
66 changes: 66 additions & 0 deletions samples/CompositeConsole/CompositeConsole.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{95CF1FA1-98E8-411C-89BF-DB7D086F27CE}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>CompositeConsole</RootNamespace>
<AssemblyName>CompositeConsole</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExtensionMethods.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\CommonLibrariesForNET\CommonLibrariesForNET.csproj">
<Project>{688BC3A2-29C2-48F7-BC28-7A81ABF5C3D3}</Project>
<Name>CommonLibrariesForNET</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\ForceToolkitForNET\ForceToolkitForNET.csproj">
<Project>{1CC985BC-27F3-4F1D-8946-F4DDB084B58F}</Project>
<Name>ForceToolkitForNET</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
34 changes: 34 additions & 0 deletions samples/CompositeConsole/CompositeConsole.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompositeConsole", "CompositeConsole.csproj", "{95CF1FA1-98E8-411C-89BF-DB7D086F27CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ForceToolkitForNET", "..\..\src\ForceToolkitForNET\ForceToolkitForNET.csproj", "{1CC985BC-27F3-4F1D-8946-F4DDB084B58F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonLibrariesForNET", "..\..\src\CommonLibrariesForNET\CommonLibrariesForNET.csproj", "{688BC3A2-29C2-48F7-BC28-7A81ABF5C3D3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{95CF1FA1-98E8-411C-89BF-DB7D086F27CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95CF1FA1-98E8-411C-89BF-DB7D086F27CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95CF1FA1-98E8-411C-89BF-DB7D086F27CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95CF1FA1-98E8-411C-89BF-DB7D086F27CE}.Release|Any CPU.Build.0 = Release|Any CPU
{1CC985BC-27F3-4F1D-8946-F4DDB084B58F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1CC985BC-27F3-4F1D-8946-F4DDB084B58F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1CC985BC-27F3-4F1D-8946-F4DDB084B58F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1CC985BC-27F3-4F1D-8946-F4DDB084B58F}.Release|Any CPU.Build.0 = Release|Any CPU
{688BC3A2-29C2-48F7-BC28-7A81ABF5C3D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{688BC3A2-29C2-48F7-BC28-7A81ABF5C3D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{688BC3A2-29C2-48F7-BC28-7A81ABF5C3D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{688BC3A2-29C2-48F7-BC28-7A81ABF5C3D3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions samples/CompositeConsole/ExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompositeConsole
{
public static class ExtensionMethods
{
public static IEnumerable<List<T>> Partition<T>(this IList<T> source, Int32 size)
{
for (int i = 0; i < (source.Count / size) + (source.Count % size > 0 ? 1 : 0); i++)
yield return new List<T>(source.Skip(size * i).Take(size));
}
}
}
160 changes: 160 additions & 0 deletions samples/CompositeConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Salesforce.Common;
using Salesforce.Force;

namespace CompositeConsole
{
class Program
{
private static readonly string SecurityToken = ConfigurationManager.AppSettings["SecurityToken"];
private static readonly string ConsumerKey = ConfigurationManager.AppSettings["ConsumerKey"];
private static readonly string ConsumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"];
private static readonly string Username = ConfigurationManager.AppSettings["Username"];
private static readonly string Password = ConfigurationManager.AppSettings["Password"] + SecurityToken;
private static readonly string IsSandboxUser = ConfigurationManager.AppSettings["IsSandboxUser"];

public static void Main()
{
try
{
var task = RunSample();
task.Wait();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);

var innerException = e.InnerException;
while (innerException != null)
{
Console.WriteLine(innerException.Message);
Console.WriteLine(innerException.StackTrace);

innerException = innerException.InnerException;
}
}

Console.WriteLine("\nPress enter to close...");
Console.ReadLine();
}

private static async Task RunSample()
{
var auth = new AuthenticationClient();

// Authenticate with Salesforce
Console.WriteLine("Authenticating with Salesforce");
var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase)
? "https://test.salesforce.com/services/oauth2/token"
: "https://login.salesforce.com/services/oauth2/token";

await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url);
Console.WriteLine("Connected to Salesforce");

// Get a bulk client
var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);

//Create some Accounts using the SOobject Tree
var sObjectTreeRecords = new
{
records = new[]
{
new
{
attributes = new {type = "Account", referenceId = "ref1"},
name = "SampleAccount1",
phone = "1111111111",
website = "nicode.org",
numberOfEmployees = "1",
industry = "Software"
},
new
{
attributes = new {type = "Account", referenceId = "ref2"},
name = "SampleAccount2",
phone = "22222222222",
website = "nicode.org",
numberOfEmployees = "2",
industry = "Software"
},
new
{
attributes = new {type = "Account", referenceId = "ref3"},
name = "SampleAccount1",
phone = "3333333333",
website = "nicode.org",
numberOfEmployees = "3",
industry = "Software"
},
new
{
attributes = new {type = "Account", referenceId = "ref4"},
name = "SampleAccount4",
phone = "4444444444",
website = "nicode.org",
numberOfEmployees = "4",
industry = "Software"
},
}
};

var results = (await client.SObjectTreeSave("Account", sObjectTreeRecords)).results;

//Record the AccountIds to a List
var newAccountIds = new List<string>();
foreach (var successResponseObjectTreeResult in results)
{
Console.WriteLine(successResponseObjectTreeResult.referenceId + " : " + successResponseObjectTreeResult.id);
newAccountIds.Add(successResponseObjectTreeResult.id);
}


//Using the partition extension method to split into partitions of 25 (requirement for batch request)
foreach (var newAccountIdPartition in newAccountIds.Partition(25))
{
//Update the industry of each Account
var updateObject = new
{
batchRequests = newAccountIdPartition
.Select(id => new
{
method = "PATCH",
url = "v34.0/sobjects/Account/" + id,
richInput = new { Industry = "Engineering" }
})
.ToArray()
};
var unused = (await client.BatchSave(updateObject)).results;
}

//Verifying industry changed
var accounts = (await client.QueryAsync<Account>("SELECT Id, Industry FROM Account WHERE website = 'nicode.org'")).Records;
foreach (var account in accounts)
{
Console.WriteLine(account.Id + " : " + account.Industry);
}

foreach (var accountPartition in accounts.Partition(25))
{
var deleteObjects = new
{
batchRequests = accountPartition
.Select(account => new { method = "DELETE", url = "v34.0/sobjects/Account/" + account.Id })
.ToArray()
};
var unused = (await client.BatchSave(deleteObjects)).results;
}
}
public class Account
{
public string Id { get; set; }
public string Industry { get; set; }
}
}
}
36 changes: 36 additions & 0 deletions samples/CompositeConsole/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("CompositeConsole")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CompositeConsole")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[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("95cf1fa1-98e8-411c-89bf-db7d086f27ce")]

// 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")]
4 changes: 4 additions & 0 deletions src/ChatterToolkitForNET/ChatterToolkitForNET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<SchemaVersion>2.0</SchemaVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
7 changes: 7 additions & 0 deletions src/CommonLibrariesForNET/CommonLibrariesForNET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<SchemaVersion>2.0</SchemaVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -63,6 +67,8 @@
<Compile Include="Models\Json\ErrorResponse.cs" />
<Compile Include="Models\Json\ErrorResponses.cs" />
<Compile Include="Models\Json\QueryResult.cs" />
<Compile Include="Models\Json\SuccessResponseBatchSave.cs" />
<Compile Include="Models\Json\SuccessResponseSObjectTree.cs" />
<Compile Include="Models\Json\SuccessResponse.cs" />
<Compile Include="Models\Json\UserInfo.cs" />
<Compile Include="Models\Xml\BatchInfoResult.cs" />
Expand All @@ -82,6 +88,7 @@
<Compile Include="JsonHttpClient.cs" />
<Compile Include="Attributes\UpdateableAttribute.cs" />
<Compile Include="XmlHttpClient.cs" />
<Compile Include="XmlSerializerCache.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config">
Expand Down
Loading