Skip to content

Commit

Permalink
Signficant updates/refactoring/merging to get tests to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
wadewegner committed Jul 29, 2016
2 parents 5bec98e + bff77d8 commit 76c2c62
Show file tree
Hide file tree
Showing 76 changed files with 2,600 additions and 219 deletions.
155 changes: 152 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Force.com Toolkit for .NET [![Build status](https://ci.appveyor.com/api/projects/status/43y1npcb2q0u7aca)](https://ci.appveyor.com/project/WadeWegner/force-com-toolkit-for-net)

The Force.com Toolkit for .NET provide an easy way for .NET developers to interact with the Force.com & Chatter REST APIs using native libraries.
The Force.com Toolkit for .NET provide an easy way for .NET developers to interact with the Force.com, Force.com Bulk & Chatter REST APIs using native libraries.

These toolkits are built using the [Async/Await pattern](http://msdn.microsoft.com/en-us/library/hh191443.aspx) for asynchronous development and .NET [portable class libraries](http://msdn.microsoft.com/en-us/library/gg597391.aspx), making it easy to target multiple Microsoft platforms, including .NET 4.5, Windows Phone 8, Windows 8/8.1, and iOS/Android using Xamarin and Mono.NET.

Expand All @@ -17,7 +17,7 @@ Install-Package DeveloperForce.Force
Install-Package DeveloperForce.Chatter
```

## Samples
## Samples

The toolkit includes the following sample applications.

Expand All @@ -33,6 +33,18 @@ You can find this sample here: https://github.com/developerforce/Force.com-Toolk

This sample shows how to write a console application that leverages the async/await paradigm of .NET 4.5 and uses the toolkit to log in to and communicate with a Salesforce organization. Useful for quick POC applications and scheduled jobs.

### Simple Bulk Console Application

You can find this sample here: https://github.com/developerforce/Force.com-Toolkit-for-NET/tree/master/samples/SimpleBulkConsole

This sample shows how to write a console application to create, update and delete multiple records using the bulk functionality in the toolkit.

### Advanced Bulk Console Application

You can find this sample here: https://github.com/developerforce/Force.com-Toolkit-for-NET/tree/master/samples/AdvancedBulkConsole

This sample shows how to use the methods on the ```BulkForceClient``` to control bulk jobs step by step. It gives an example of a polling method that you could change to implement your own custom polling.

## Operations

Currently the following operations are supported.
Expand Down Expand Up @@ -74,7 +86,7 @@ await auth.WebServerAsync("YOURCONSUMERKEY", "YOURCONSUMERSECRET", "YOURCALLBACK

You can see a demonstration of this in the following sample application: https://github.com/developerforce/Force.com-Toolkit-for-NET/tree/master/samples/WebServerOAuthFlow

#### Creating the ForceClient
#### Creating the ForceClient or BulkForceClient

After this completes successfully you will receive a valid Access Token and Instance URL. The Instance URL returned identifies the web service URL you'll use to call the Force.com REST APIs, passing in the Access Token. Additionally, the authentication client will return the API version number, which is used to construct a valid HTTP request.

Expand All @@ -86,6 +98,7 @@ var accessToken = auth.AccessToken;
var apiVersion = auth.ApiVersion;
var client = new ForceClient(instanceUrl, accessToken, apiVersion);
var bulkClient = new BulkForceClient(instanceUrl, accessToken, apiVersion);
```
### Sample Code
Expand Down Expand Up @@ -164,6 +177,142 @@ foreach (var account in accounts.records)
}
```
### Bulk Sample Code
Below are some simple examples that show how to use the ```BulkForceClient```
**NOTE:** The following features are currently not supported
* CSV data type requests / responses
* Zipped attachment uploads
* Serial bulk jobs
* Query type bulk jobs
#### Create
You can create multiple records at once with the Bulk client:
```
public class Account
{
public string Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
...
var accountsBatch1 = new SObjectList<Account>
{
new Account {Name = "TestStAccount1"},
new Account {Name = "TestStAccount2"}
};
var accountsBatch2 = new SObjectList<Account>
{
new Account {Name = "TestStAccount3"},
new Account {Name = "TestStAccount4"}
};
var accountsBatch3 = new SObjectList<Account>
{
new Account {Name = "TestStAccount5"},
new Account {Name = "TestStAccount6"}
};
var accountsBatchList = new List<SObjectList<Account>>
{
accountsBatch1,
accountsBatch2,
accountsBatch3
};
var results = await bulkClient.RunJobAndPollAsync("Account",
Bulk.OperationType.Insert, accountsBatchList);
```
The above code will create 6 accounts in 3 batches. Each batch can hold upto 10,000 records and you can use multiple batches for Insert and all of the operations below.
For more details on the Salesforce Bulk API, see [the documentation](https://resources.docs.salesforce.com/196/latest/en-us/sfdc/pdf/api_asynch.pdf "Salesforce Bulk API Docs").
You can also create objects dynamically using the inbuilt SObject class:
```
var accountsBatch1 = new SObjectList<SObject>
{
new SObject
{
{"Name" = "TestDyAccount1"}
},
new SObject
{
{"Name" = "TestDyAccount2"}
}
};
var accountsBatchList = new List<SObjectList<SObject>>
{
accountsBatch1
};
var results = await bulkClient.RunJobAndPollAsync("Account",
Bulk.OperationType.Insert, accountsBatchList);
```
#### Update
Updating multiple records follows the same pattern as above, just change the ```Bulk.OperationType``` to ```Bulk.OperationType.Update```
```
var accountsBatch1 = new SObjectList<SObject>
{
new SObject
{
{"Id" = "YOUR_RECORD_ID"},
{"Name" = "TestDyAccount1Renamed"}
},
new SObject
{
{"Id" = "YOUR_RECORD_ID"},
{"Name" = "TestDyAccount2Renamed"}
}
};
var accountsBatchList = new List<SObjectList<SObject>>
{
accountsBatch1
};
var results = await bulkClient.RunJobAndPollAsync("Account",
Bulk.OperationType.Update, accountsBatchList);
```
#### Delete
As above, you can delete multiple records with ```Bulk.OperationType.Delete```
```
var accountsBatch1 = new SObjectList<SObject>
{
new SObject
{
{"Id" = "YOUR_RECORD_ID"}
},
new SObject
{
{"Id" = "YOUR_RECORD_ID"}
}
};
var accountsBatchList = new List<SObjectList<SObject>>
{
accountsBatch1
};
var results = await bulkClient.RunJobAndPollAsync("Account",
Bulk.OperationType.Delete, accountsBatchList);
```
## Contributing to the Repository ###
If you find any issues or opportunities for improving this respository, fix them! Feel free to contribute to this project by [forking](http://help.github.com/fork-a-repo/) this repository and make changes to the content. Once you've made your changes, share them back with the community by sending a pull request. Please see [How to send pull requests](http://help.github.com/send-pull-requests/) for more information about contributing to Github projects.
Expand Down
69 changes: 69 additions & 0 deletions samples/AdvancedBulkConsole/AdvancedBulkConsole.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" 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>{039891F9-ABE6-4F96-AE25-A2A4FB3007D8}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AdvancedBulkConsole</RootNamespace>
<AssemblyName>AdvancedBulkConsole</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</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" />
<!-- 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>
6 changes: 6 additions & 0 deletions samples/AdvancedBulkConsole/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Loading

0 comments on commit 76c2c62

Please sign in to comment.