Skip to content

Merge #13

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

Open
wants to merge 163 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
1227d19
Debut Model Generation
PeteGuy Apr 1, 2022
df1ae20
Debut dictionnaire traduction AttributeTypeCode à string
PeteGuy Apr 1, 2022
fae3e3d
AttributeTypeTranslator
PeteGuy Apr 1, 2022
ad797f1
Ajouts model manager CLI, avec erreur non corrigé dans le def manager…
PeteGuy Apr 5, 2022
d914707
Modifications ModelManager, ajout DefinitionClasses at every coreProj…
PeteGuy Apr 13, 2022
22d1ac2
trucs
PeteGuy Apr 19, 2022
ed11853
ofzen
PeteGuy Apr 20, 2022
28161a7
Corrections TableSourceFileGenerator
Apr 20, 2022
aebbf07
added stuff
PeteGuy Apr 21, 2022
6644d12
Merge from CGO to master
Apr 21, 2022
253d367
Merge branch 'master' of github.com:PeteGuy/XrmFramework
PeteGuy Apr 21, 2022
0ede1b2
Correction Unit tests
Apr 21, 2022
03d4703
Ajout .table dans xrmFramework.definitions et suppression des classes…
PeteGuy Apr 22, 2022
7a7ed1e
Merge branch 'master' of github.com:PeteGuy/XrmFramework
PeteGuy Apr 22, 2022
da4c037
removed unused columns from base table files and modified tablesource…
PeteGuy Apr 22, 2022
524f1bb
Correction partie isLocked mainForm (DefinitionManager)
PeteGuy Apr 22, 2022
dd5589e
GenerateTableFilesFromLocalCode + Modifs DefinitionsManager
PeteGuy Apr 25, 2022
a5ad49b
Merge branch 'master' into merge_cgoconseils
cgoconseils Apr 25, 2022
a5ed6ae
Merge pull request #2 from cgoconseils/merge_cgoconseils
cgoconseils Apr 25, 2022
bed9c2a
Cleanup DefinitionManager and TableSourceFileGenerator
PeteGuy Apr 25, 2022
c91ecf1
Ajout Tests
PeteGuy Apr 27, 2022
c90071b
Merge branch 'master' of https://github.com/cgoconseils/XrmFramework …
PeteGuy Apr 27, 2022
21e9d47
Merge branch 'cgoconseils-master'
PeteGuy Apr 27, 2022
a37fcff
Ajout formulaire plugin, ajout equivalent definition manager pour xrm…
PeteGuy May 10, 2022
3b88474
Modifications PluginControl et ajout TableHandler
PeteGuy May 13, 2022
4eb39aa
Développement outil xrmtoolbox
PeteGuy May 24, 2022
b363427
début génération models
PeteGuy May 25, 2022
67fb817
modifications/résolutions de problèmes gestion de models
PeteGuy Jun 7, 2022
79ec825
modifs pour prendre en compte non création de currentProject
PeteGuy Jun 13, 2022
7213372
Create QuickStart.md
PeteGuy Jun 15, 2022
0023a09
Update QuickStart.md
PeteGuy Jun 15, 2022
d1d8020
Update QuickStart.md
PeteGuy Jun 15, 2022
488f7cc
Add files via upload
PeteGuy Jun 15, 2022
1e1b507
Update QuickStart.md
PeteGuy Jun 15, 2022
fbfb3ac
Add files via upload
PeteGuy Jun 15, 2022
3781a97
Update QuickStart.md
PeteGuy Jun 15, 2022
386962c
Add files via upload
PeteGuy Jun 15, 2022
5277630
Add files via upload
PeteGuy Jun 15, 2022
8d6f638
Update QuickStart.md
PeteGuy Jun 15, 2022
bf5cebf
ajouts
PeteGuy Jun 16, 2022
6510a9a
Merge branch 'master' of github.com:PeteGuy/XrmFramework
PeteGuy Jun 16, 2022
9d25afb
Add files via upload
PeteGuy Jun 17, 2022
e03f710
Add files via upload
PeteGuy Jun 17, 2022
0dcd8da
Delete AddTablesButton.PNG
PeteGuy Jun 17, 2022
dcd003e
Add files via upload
PeteGuy Jun 17, 2022
01706fe
Update QuickStart.md
PeteGuy Jun 17, 2022
9b06897
Add files via upload
PeteGuy Jun 17, 2022
dd3aadb
Update QuickStart.md
PeteGuy Jun 17, 2022
7e479b4
Add files via upload
PeteGuy Jun 17, 2022
6f38c3a
Update QuickStart.md
PeteGuy Jun 17, 2022
00e516e
Update QuickStart.md
PeteGuy Jun 17, 2022
aa2214e
Update QuickStart.md
PeteGuy Jun 17, 2022
aa58252
Create PreReleaseUpdate.md
PeteGuy Jun 17, 2022
c96277c
Update PreReleaseUpdate.md
PeteGuy Jun 17, 2022
6671e38
Update PreReleaseUpdate.md
PeteGuy Jun 17, 2022
2ec6192
Update PreReleaseUpdate.md
PeteGuy Jun 17, 2022
efb3708
Update PreReleaseUpdate.md
PeteGuy Jun 20, 2022
ab80db0
Update PreReleaseUpdate.md
PeteGuy Jun 20, 2022
f23b774
Modifications generation tables, to only generate selected attributes
PeteGuy Jun 20, 2022
1a4ad0e
Merge branch 'master' of github.com:PeteGuy/XrmFramework
PeteGuy Jun 20, 2022
3e0ac05
Adjustement XrmTool
PeteGuy Jun 20, 2022
7cc7cbe
Create MigrationDefinitions.md
PeteGuy Jun 21, 2022
4e1c507
Update MigrationDefinitions.md
PeteGuy Jun 21, 2022
c900441
Update MigrationDefinitions.md
PeteGuy Jun 21, 2022
7a8f34b
Add files via upload
PeteGuy Jun 21, 2022
3875c87
Update MigrationDefinitions.md
PeteGuy Jun 21, 2022
444ac10
Update MigrationDefinitions.md
PeteGuy Jun 21, 2022
fceaf5b
Update MigrationDefinitions.md
PeteGuy Jun 21, 2022
8c28a24
Added ILMerge to use one DLL for XrmToolBoxPlugin
PeteGuy Jun 21, 2022
25af69f
Merge branch 'master' of github.com:PeteGuy/XrmFramework
PeteGuy Jun 21, 2022
f98a9b6
Create Binding Models
PeteGuy Jun 22, 2022
3874f9d
Rename Binding Models to Binding Models.md
PeteGuy Jun 22, 2022
5b95a41
Update Binding Models.md
PeteGuy Jun 22, 2022
ee29413
Update Binding Models.md
PeteGuy Jun 22, 2022
bf7e8c8
Update Binding Models.md
PeteGuy Jun 22, 2022
6224cf4
Update Binding Models.md
PeteGuy Jun 22, 2022
047a6d7
Update Binding Models.md
PeteGuy Jun 22, 2022
f87efcd
Update Binding Models.md
PeteGuy Jun 22, 2022
e9c5874
Update Binding Models.md
PeteGuy Jun 22, 2022
b7071d0
Update Binding Models.md
PeteGuy Jun 22, 2022
8d8eee6
Update Binding Models.md
PeteGuy Jun 22, 2022
aede936
Update Binding Models.md
PeteGuy Jun 22, 2022
64eb168
Update Binding Models.md
PeteGuy Jun 22, 2022
576b34f
Update Binding Models.md
PeteGuy Jun 22, 2022
b44f4e9
Update Binding Models.md
PeteGuy Jul 18, 2022
3960934
Update Binding Models.md
PeteGuy Jul 18, 2022
0f97e43
Update Binding Models.md
PeteGuy Jul 18, 2022
93c255f
Update Binding Models.md
PeteGuy Jul 18, 2022
703e02e
Update Binding Models.md
PeteGuy Jul 18, 2022
ce60788
Update Binding Models.md
PeteGuy Jul 18, 2022
1ede93b
Update Binding Models.md
PeteGuy Jul 18, 2022
4ce93ee
Update Binding Models.md
PeteGuy Jul 18, 2022
d2dde5f
Update Binding Models.md
PeteGuy Jul 19, 2022
dde7f67
Update Binding Models.md
PeteGuy Jul 19, 2022
29fd1ff
Update Binding Models.md
PeteGuy Jul 19, 2022
160c8a0
Update Binding Models.md
PeteGuy Jul 19, 2022
979d05f
Update Binding Models.md
PeteGuy Jul 19, 2022
4686528
Update Binding Models.md
PeteGuy Jul 19, 2022
9855171
Update Binding Models.md
PeteGuy Jul 19, 2022
235e050
Update Binding Models.md
PeteGuy Jul 19, 2022
6c612c7
Update Binding Models.md
PeteGuy Jul 19, 2022
a55b703
Update Binding Models.md
PeteGuy Jul 19, 2022
2256ba9
Update Binding Models.md
PeteGuy Jul 19, 2022
99999b3
Update Binding Models.md
PeteGuy Jul 19, 2022
396dde4
Update Binding Models.md
PeteGuy Jul 19, 2022
3478f76
Update Binding Models.md
PeteGuy Jul 19, 2022
4558dc5
Update Binding Models.md
PeteGuy Jul 19, 2022
719e88f
Update Binding Models.md
PeteGuy Jul 19, 2022
cfec143
Update Binding Models.md
PeteGuy Jul 19, 2022
e566ef5
Update Binding Models.md
PeteGuy Jul 19, 2022
cb466f5
Update Binding Models.md
PeteGuy Jul 19, 2022
5dd8134
Update Binding Models.md
PeteGuy Jul 19, 2022
dca5eca
Update Binding Models.md
PeteGuy Jul 19, 2022
4c28703
Update Binding Models.md
PeteGuy Jul 19, 2022
896c32f
Update Binding Models.md
PeteGuy Jul 19, 2022
dfb9097
Update Binding Models.md
PeteGuy Jul 19, 2022
0d906af
Update Binding Models.md
PeteGuy Jul 19, 2022
c2b34d9
Update Binding Models.md
PeteGuy Jul 19, 2022
ff263e0
Update Binding Models.md
PeteGuy Jul 19, 2022
6b2b11e
Update Binding Models.md
PeteGuy Jul 19, 2022
da95bc6
Update Binding Models.md
PeteGuy Jul 19, 2022
fdd3e95
Update Binding Models.md
PeteGuy Jul 20, 2022
28bae7a
Update Binding Models.md
PeteGuy Jul 20, 2022
7f1cf60
Update Binding Models.md
PeteGuy Jul 20, 2022
07ec599
Update Binding Models.md
PeteGuy Jul 20, 2022
83998a5
Update Binding Models.md
PeteGuy Jul 20, 2022
bf1b260
Update Binding Models.md
PeteGuy Jul 20, 2022
46170c6
Update Binding Models.md
PeteGuy Jul 20, 2022
52c383b
Update Binding Models.md
PeteGuy Jul 20, 2022
0c3b868
Update Binding Models.md
PeteGuy Jul 20, 2022
c94a03c
Update Binding Models.md
PeteGuy Jul 20, 2022
660337f
Update Binding Models.md
PeteGuy Jul 20, 2022
1723d68
Update Binding Models.md
PeteGuy Jul 20, 2022
bd458b5
Update Binding Models.md
PeteGuy Jul 20, 2022
fc055a9
Update Binding Models.md
PeteGuy Jul 20, 2022
a07d363
Update Binding Models.md
PeteGuy Jul 20, 2022
9249099
Update Binding Models.md
PeteGuy Jul 20, 2022
097f103
Update Binding Models.md
PeteGuy Jul 20, 2022
f669219
Update Binding Models.md
PeteGuy Jul 20, 2022
399c498
Update Binding Models.md
PeteGuy Jul 20, 2022
68b0855
Update Binding Models.md
PeteGuy Jul 20, 2022
bbba9c5
Update Binding Models.md
PeteGuy Jul 20, 2022
59521de
Update Binding Models.md
PeteGuy Jul 20, 2022
abb54ab
Update Binding Models.md
PeteGuy Jul 20, 2022
97a1ca9
Update Binding Models.md
PeteGuy Jul 20, 2022
0dff6fc
Update Binding Models.md
PeteGuy Jul 20, 2022
33740ec
Update Binding Models.md
PeteGuy Jul 20, 2022
4ededd1
Update Binding Models.md
PeteGuy Jul 20, 2022
4e69b0d
Update Binding Models.md
PeteGuy Jul 20, 2022
45de949
Update Binding Models.md
PeteGuy Jul 20, 2022
cbf0854
Update Binding Models.md
PeteGuy Jul 20, 2022
233c491
Update Binding Models.md
PeteGuy Jul 20, 2022
3e74faa
Update Binding Models.md
PeteGuy Jul 20, 2022
f6ba588
Update Binding Models.md
PeteGuy Jul 20, 2022
7354281
Update Binding Models.md
PeteGuy Jul 20, 2022
9284c09
Update Binding Models.md
PeteGuy Jul 20, 2022
cee37d2
Update Binding Models.md
PeteGuy Jul 20, 2022
87d12be
Update Binding Models.md
PeteGuy Jul 20, 2022
0630fdc
Update Binding Models.md
PeteGuy Jul 20, 2022
00506ab
Update Binding Models.md
PeteGuy Jul 20, 2022
5406c7e
Update Binding Models.md
PeteGuy Jul 22, 2022
c6f4091
Update Binding Models.md
PeteGuy Jul 22, 2022
1d9dd07
Update Binding Models.md
PeteGuy Jul 25, 2022
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
311 changes: 311 additions & 0 deletions docs/Binding Models.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
## Binding Models

- [Introduction](#introduction)
- [Creating a BindingModel](#creating-a-binding-model)
- [Retrieving the CRM data](#retrieving-the-crm-data)
- [Updating the CRM data](#updating-the-crm-data)
- [Json serialization](#json-serialization)
- [Types to use for CRM data](#types-to-use-for-crm-data)
- [Connecting to other BindingModels](#connecting-to-other-bindingmodels)
- [Structuring the data](#structuring-the-data)


## Introduction
There are three classes related to a a table from a CRM at various levels of abstraction.
- Entity, stores the data corresponding to a table record from the CRM.
- EntityDefinition, lists the various components of a table. Each table can have one per project.
- BindingModel, strongly typed representation of a table record. There can be as many binding models as there are needs for one table in one project.



## Creating a Binding Model
First, you need a Definition corresponding to your table. You need to retrieve it from the CRM. You can see how by following [this](https://github.com/cgoconseils/XrmFramework#readme) tutorial

Then create a new class in your project, it needs to inherit either IBindingModel or BindingModelBase the difference between the two is explained in [this](#updating-the-crm-data) part.
You can add a property for each column you want to use in your project.
To do so, use the CrmMapping attribute and the corresponding TableDefinition. The type of the property has to make sense for the column you want to retrieve. For example, a property corresponding to the name column of a table will have to be of type string. The various types to use are detailed in [this](#types-to-use-for-crm-data) section.

```CS

[CrmEntity(AccountDefinition.EntityName)] //Specifies the table to which the model maps
public class AccountModel : IBindingModel // Can be replaced with BindingModelBase
{
public Guid Id { get; set; } // Corresponds to the unique identifier of the record

[CrmMapping(AccountDefinition.Columns.Name)] // Specifies the column to which the property maps
public string Name { get; set; }

}
```




## Retrieving the CRM data
In order to retrieve table records as BindingModel, the framework uses custom AdminOrganizationService functions :
```cs
query = BindingModelHelper.GetRetrieveAllQuery<AccountModel>();
AdminOrganizationService.RetrieveAll<BindingModel>(query); // Returns all records corresponding to the table present on the CRM as BindingModels.

AdminOrganizationService.GetById<AccountModel>(ID); // Returns the table record corresponding to the ID as a BindingModel

```

If you want to retrieve the data corresponding to a lookup property in the form of a model, you should use the FollowLink option for the CrmMapping Attribute.
```cs
[CrmMapping(ContactDefinition.Columns.FirstLeadId, FollowLink = true)]
public LeadModel FirstLead {get;set;}
```





## Updating the CRM data

In order to update the data using a BindingModel you can use the Upsert function. However, to avoid any chance of overwriting CRM data, we recommend the following steps :
Make it so that your BindingModel inherits BindingModelBase and then call the OnPropertyChanged function inside of the set function of any property you wish to be able to update on the CRM. Then create the difference between the CRM record and the local record by using the GetDiffGeneric function. Then use the Upsert function on the result.

```cs
var existingAccount = service.getById<AccountModel>(accountID);
var newAccountModel = new AccountModel {Name = "Titi"};
var diffAccount = newAccountModel.GetDiffGeneric(existingAccount);
if(diffAccount.InitializedProperties.Any())
{
service.Upsert(diffAccount);
}
```

Another way to control the way a CRM record is updated is to create a custom Upsert behavior. For example, if your model contains a custom property that connects to a list of other BindingModels, you can add the upsert of these model in your custom behavior. An UpsertBehavior is a class that implements the IBehavior interface.

```cs
public class MyUpsertBehavior : IBehavior<MyModel>
{
public void ApplyBehavior(IOrganizationService service, MyModel model)
{
// Put your custom logic here
}

}
```


```cs
[CrmEntity(MyDefinition.EntityName)]
[UpsertBehavior(typeof(MyUpsertBehavior))]
public class MyModel : BindingModelBase

```

## JSon Serialization
Any BindingModel instance can be serialized by using the JsonProperty and JsonObject attributes :
```cs

[JsonObject(MemberSerialization.OptIn)]
[CrmEntity(BaseDefinition.EntityName)]
public class BaseModel : IBindingModel

//////////////////////////////////////////////////////////////////////////
[JsonProperty("name")]
[CrmMapping(BaseDefinition.Columns.Name)]
public string Name {get;set;}
```

If a property is of a complex type such as another BindingModel, you can use a custom type converter.
```cs
[JsonConverter(typeof(MyCustomConverter))]
```



## Types to use for CRM data

| CRM column type | C# equivalents |
| ----------- | ----------- |
| Boolean | System.Boolean |
| | System.Int32 |
| | System.String |
| Integer | System.Int32 |
| DateTime | System.DateTime |
| Decimal | System.Decimal |
| Double | System.Double |
| Lookup | To be explained further |
| Memo | System.String |
| PickList | System.Int32 |
| PickList | Corresponding OptionSetEnum |
| State | Corresponding OptionSetEnum |
| State | System.Int32 |
| Status | Corresponding OptionSetEnum |
| Status | System.Int32 |
| String | System.String |
| UniqueIdentifier | System.Guid |
| BigInt | System.Int64 |
| EntityName | System.String |


Lookup et oneToManyRelationShip


## Connecting to other BindingModels
An Entity attribute of type Lookup can be used to retrieve :
- the data corresponding to the ID of the corresponding Entity record,
```cs
[CrmMapping(AccountDefinition.Columns.PrimaryContactId)]
public Guid PrimaryContactIdentifier {get;set;}
```
- the EntityReference instance of the corresponding Entity record,
```cs
[CrmMapping(AccountDefinition.Columns.PrimaryContactId)]
public EntityReference PrimaryContactReference {get;set;}
```
- the data of a particular attribute of the corresponding Entity record by using the CrmLookup attribute
```cs
[CrmMapping(AccountDefinition.Columns.PrimaryContactId)]
[CrmLookup(ContactDefinition.EntityName,ContactDefinition.Columns.Name)]
public string PrimaryContactName {get;set;} // Corresponds to the name of the record corresponding to the primary contact of the account record
```
- the data of a collection of attributes through the BindingModel instance of the corresponding Entity record
```cs
[CrmMapping(AccountDefinition.Columns.PrimaryContactId)]
public ContactModel PrimaryContact {get;set;}

// [CrmEntity(ContactDefinition.EntityName)]
// public ContactModel : IBindingModel
// {
// [CrmMapping(ContactDefinition.Columns.Name)]
// public string Name {get;set;}
// }

```

You can also have a list of BindingModel instances by using a OneToMany relationship of the table.

```cs
[ChildRelationship(AccountDefinition.OneToManyRelationShip.contact_customer_accounts)]
public ICollection<ContactModel> SubContacts {get;} = new List<ContactModel>();

```

## Structuring the data
You can regroup several table columns together under one property by using the ExtendBindingModel attribute. You can do so by creating a second model for the same table, in this model, map the attributes you want to see grouped together. Then for your first model, add a property with the second BindingModel and use the ExtendBindingModel attribute.


<table>
<tr>
<th>Code</th>
<th>Corresponding data structure</th>
</tr>
<tr>
<td>

```cs
[JsonObject(MemberSerialization.OptIn)]
[CrmEntity(AccountDefinition.EntityName)]
public class AccountModel : IBindingModel
{
[JsonProperty("id")]
public Guid Id {get;set;}

[CrmMapping(AccountEntity.Columns.PrimaryContactId)]
public EntityReference PrimaryContactRef {get;set;}

[JsonProperty("name")]
[CrmMapping(AccountEntity.Columns.Name)]
public string Name {get;set;}

[JsonProperty("Address1Line")]
[CrmMapping(AccountEntity.Columns.Address1_Line1)]
public string AddressLine1 {get;set;}

[JsonProperty("Address1City")]
[CrmMapping(AccountEntity.Columns.Address1_City)]
public string AddressLine1 {get;set;}

}
```







</td>
<td>

```json
{
"id": "0f8fad5b-d9cb-469f-a165-70867728950e",
"name": "mary",
"Address1City": "San York",
"Address1Line": "23 Rupert Street"
}
```

</td>
</tr>

<tr>
<td>

```cs
[JsonObject(MemberSerialization.OptIn)]
[CrmEntity(AccountDefinition.EntityName)]
public class AccountModel : IBindingModel
{
[JsonProperty("id")]
public Guid Id {get;set;}

[CrmMapping(AccountEntity.Columns.PrimaryContactId)]
public EntityReference PrimaryContactRef {get;set;}

[JsonProperty("name")]
[CrmMapping(AccountEntity.Columns.Name)]
public string Name {get;set;}

[JsonProperty("Address")]
[ExtendBindingModel]
public AccountAddressModel Address {get;set;}
}

// Second BindingModel
[JsonObject(MemberSerialization.OptIn)]
[CrmEntity(AccountDefinition.EntityName)]
public class AccountAddressModel : IBindingModel

{
[JsonProperty("id")]
public Guid Id {get;set;}

///// Properties to be grouped
[JsonProperty("Line")]
[CrmMapping(AccountEntity.Columns.Address1_Line1)]
public string AddressLine1 {get;set;}

[JsonProperty("City")]
[CrmMapping(AccountEntity.Columns.Address1_City)]
public string AddressLine1 {get;set;}
///////
}
```

</td>
<td>

```json
{
"id": "0f8fad5b-d9cb-469f-a165-70867728950e",
"name": "mary",
"Address" :
{
"City": "San York",
"Line": "23 Rupert Street"
}
}
```

</td>
</tr>
</table>


26 changes: 26 additions & 0 deletions docs/MigrationDefinitions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Migrate definitions from the old definition system to the new table system

This document explains how to setup a project that uses the old Definition system of the framework (using DefinitionManager inside of a VS instance), so that it can use the new latest version of the framework.



- Clone the XrmFramework project in the folder of your choice.
- Open a powershell window and set the working directory to the one where the executable is located
- launch the executable with the following arguments : path to the dll for the core project of the project you want to migrate and the path to the folder were you want your tables to be saved.

![CoreProject](images/MigrationCoreProject.PNG)


![MigrationCommand](images/MigrationCmd.PNG)


- You should now have one .table file in your destination folder for each definitions
- you can now delete the definition .cs files from your project (or save them out of your project)

- Now you should update your project to the latest version of the framework (you can do so by following [this tutorial](PreReleaseUpdate.md))
-
- You can now launch the project manager tool on XrmToolBox and select your project
- You should see the tables that were just generated in the UI, just like a regular project.
- For each of these tables, press the "Refresh attributes" button, the details should update and you should now see the full table with your selected attributes ticked on and your custom names.
- now if you rebuild your old project, you should have the exact same definition classes generated in your project.

Loading