diff --git a/docs/Binding Models.md b/docs/Binding Models.md new file mode 100644 index 00000000..79d8ed52 --- /dev/null +++ b/docs/Binding Models.md @@ -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(); +AdminOrganizationService.RetrieveAll(query); // Returns all records corresponding to the table present on the CRM as BindingModels. + +AdminOrganizationService.GetById(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(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 +{ + 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 SubContacts {get;} = new List(); + +``` + +## 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. + + + + + + + + + + + + + + + + +
CodeCorresponding data structure
+ +```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;} + + } +``` + + + + + + + + + +```json +{ + "id": "0f8fad5b-d9cb-469f-a165-70867728950e", + "name": "mary", + "Address1City": "San York", + "Address1Line": "23 Rupert Street" +} +``` + +
+ + ```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;} + /////// + } +``` + + + +```json +{ + "id": "0f8fad5b-d9cb-469f-a165-70867728950e", + "name": "mary", + "Address" : + { + "City": "San York", + "Line": "23 Rupert Street" + } +} +``` + +
+ + diff --git a/docs/MigrationDefinitions.md b/docs/MigrationDefinitions.md new file mode 100644 index 00000000..72e33166 --- /dev/null +++ b/docs/MigrationDefinitions.md @@ -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. + diff --git a/docs/PreReleaseUpdate.md b/docs/PreReleaseUpdate.md new file mode 100644 index 00000000..532303b0 --- /dev/null +++ b/docs/PreReleaseUpdate.md @@ -0,0 +1,85 @@ +# How to update a regular project to the prerelease version. + +- Delete the DefinitionManager +- ### Deploy and Deploy.Webresources : + - go in the Nugget package manager, tick PreRelease on, update the Nugget packages to the latest recent preRelease version. + +- ### Core project : + - delete the XrmFramework.Coreproject package + - update the XrmFramework package to the latest preRelease version + - add the latest preRelease version of the XrmFramework.Analyzers package + - copy the text 1) in the csproj +- ### Plugins project : + - update the XrmFramework package to the latest preRelease version. + - copy the text 1) in the csproj + - copy the text 2) in the csproj, replace the "PROJECTCORE" part by the name of your Core project, ex : TestProjet.Core + +- ### Remote debugger : (to be completed) + - unload the project + **OR** + - keep the current version of the remote debugger package + + + + + + + + + + + + + + + + + + + +Texts to be pasted : +1) +```XML + + true + Generated + + + + + + + + + + + + + + + + + + + +``` + +2) +```XML + + + +``` + +3) +```XML + + + $([System.String]::Copy("%(FileName)").Replace(".","")) + + + + + +``` + diff --git a/docs/QuickStart.md b/docs/QuickStart.md new file mode 100644 index 00000000..dfc8c985 --- /dev/null +++ b/docs/QuickStart.md @@ -0,0 +1,62 @@ +# Quick start + + +## Create a project + +- ### Using the CLI +Open a powershell windows in the folder of your choice. +Enter the following command to download the project templates for visual studio : + + ```PS + dotnet new -i XrmFramework.Templates + ``` + + Now create a project using the following command : + + ```PS +PS C:\Temp> dotnet new xrmSolution -n {solutionName} + ``` + + The templating service will prompt you to accept the execution of a PowerShell initialization script : + +```PS +Processing post-creation actions... +Template is configured to run the following action: +Description: Finalize XrmFramework solution initialization +Manual instructions: Initialisation XrmFramework +Actual command: powershell -File initXrm.ps1 +Do you want to run this action (Y|N)? +``` + +You need to accept this execution to be sure to have the solution configured correctly. + +- ### Using the ProjectManagerTool + +Open the tool + +![Tool](https://github.com/PeteGuy/XrmFramework/blob/master/docs/images/ToolPic.PNG) + +Click the button to create a project. + + +![CreateProj](https://github.com/PeteGuy/XrmFramework/blob/master/docs/images/CreateProjTool.PNG) + Choose a folder and name your project. + + ![ProjectCreationForm](https://github.com/PeteGuy/XrmFramework/blob/master/docs/images/ProjectCreationForm.PNG) + + After creating a project, in order to use the new version of the framework, you need to follow the PreRelease update documentation. + + + ### Add tables to your project + + To do this open the xrmTool and select your project. + + ![Project choice](https://github.com/PeteGuy/XrmFramework/blob/master/docs/images/AddTablesButton2.PNG) + + Use the attribute panel to select the columns you want to add to your project. You can also rename the attributes by clicking on the corresponding column. + + ![Attributes Panel](https://github.com/PeteGuy/XrmFramework/blob/master/docs/images/AttributesPanel.PNG) + + Next save the tables. You will now be able to use the definition classes in your project. + + diff --git a/docs/images/AddTablesButton.PNG b/docs/images/AddTablesButton.PNG new file mode 100644 index 00000000..a6b97f8a Binary files /dev/null and b/docs/images/AddTablesButton.PNG differ diff --git a/docs/images/AddTablesButton2.PNG b/docs/images/AddTablesButton2.PNG new file mode 100644 index 00000000..a6b97f8a Binary files /dev/null and b/docs/images/AddTablesButton2.PNG differ diff --git a/docs/images/AttributesPanel.PNG b/docs/images/AttributesPanel.PNG new file mode 100644 index 00000000..a8cb7806 Binary files /dev/null and b/docs/images/AttributesPanel.PNG differ diff --git a/docs/images/ChooseProject.PNG b/docs/images/ChooseProject.PNG new file mode 100644 index 00000000..31a37a2e Binary files /dev/null and b/docs/images/ChooseProject.PNG differ diff --git a/docs/images/CreateProjTool.PNG b/docs/images/CreateProjTool.PNG new file mode 100644 index 00000000..b7aeaace Binary files /dev/null and b/docs/images/CreateProjTool.PNG differ diff --git a/docs/images/MigrationCmd.PNG b/docs/images/MigrationCmd.PNG new file mode 100644 index 00000000..0e9076f0 Binary files /dev/null and b/docs/images/MigrationCmd.PNG differ diff --git a/docs/images/MigrationCoreProject.PNG b/docs/images/MigrationCoreProject.PNG new file mode 100644 index 00000000..c8f347c8 Binary files /dev/null and b/docs/images/MigrationCoreProject.PNG differ diff --git a/docs/images/ProjectCreationForm.PNG b/docs/images/ProjectCreationForm.PNG new file mode 100644 index 00000000..f001e638 Binary files /dev/null and b/docs/images/ProjectCreationForm.PNG differ diff --git a/docs/images/ToolPic.PNG b/docs/images/ToolPic.PNG new file mode 100644 index 00000000..3b427196 Binary files /dev/null and b/docs/images/ToolPic.PNG differ diff --git a/src/GenerateTableFilesFromLocalCode/GenerateTableFilesFromLocalCode.csproj b/src/GenerateTableFilesFromLocalCode/GenerateTableFilesFromLocalCode.csproj new file mode 100644 index 00000000..f30657d4 --- /dev/null +++ b/src/GenerateTableFilesFromLocalCode/GenerateTableFilesFromLocalCode.csproj @@ -0,0 +1,18 @@ + + + + Exe + $(XrmFramework_FullFramework_TFM) + + + + + + + + + + + + + diff --git a/src/GenerateTableFilesFromLocalCode/Program.cs b/src/GenerateTableFilesFromLocalCode/Program.cs new file mode 100644 index 00000000..c40dfc81 --- /dev/null +++ b/src/GenerateTableFilesFromLocalCode/Program.cs @@ -0,0 +1,281 @@ +using Microsoft.Xrm.Sdk; +using System; +using XrmFramework.Core; +using System.Reflection; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; + +namespace GenerateTableFilesFromLocalCode +{ + internal class Program + { + static TableCollection tables = new TableCollection(); + EntityCollection entities; + static void Main(string[] args) + { + if(args.Length != 2) + { + Console.WriteLine(); + Console.WriteLine("Number of argument too low, the command must be entered the following way : "); + Console.WriteLine(); + Console.WriteLine("GenerateTableFilesFromLocalCode \"path\\to\\dll\" \"path\\to\\.tableDirectory\""); + Console.WriteLine(); + Console.ReadKey(); + + return; + } + string userInput = ""; + Assembly assembly = null; + string definitionDirectory; + try + { + assembly = Assembly.UnsafeLoadFrom(args[0]); + } + catch + { + Console.WriteLine(); + Console.WriteLine($"Error argument \"{args[0]}\" is invalid, no assembly could be loaded from it, reminder : it should be a path to a .dll file."); + Console.WriteLine(); + Console.ReadKey(); + return; + } + + if(!Directory.Exists(args[1])) + { + Console.WriteLine(); + Console.WriteLine($"Error argument \"{args[1]}\" is invalid, reminder : it should be the path to the directory in which you want to save your .table files"); + Console.WriteLine(); + Console.ReadKey(); + + return; + + } + + + definitionDirectory = args[1]; + var codedTables = GetCodedTables(assembly); + + + //tables.AddRange(GetCodedTables(assembly)); + //GetCoded entityDefinitions + string txt; + foreach (var table in codedTables) + { + txt = JsonConvert.SerializeObject(table, new JsonSerializerSettings() + { + Formatting = Formatting.Indented, + }); + + var fileInfo = new FileInfo($"{definitionDirectory}/{table.Name}.table"); + File.WriteAllText(fileInfo.FullName,txt); + Console.WriteLine(table.Name); + } + + + } + + public static IEnumerable GetCodedTables(Assembly definitionAssembly) + { + var entityDefinitionAttributeType = definitionAssembly.GetType("XrmFramework.EntityDefinitionAttribute"); + var definitionTypes = definitionAssembly.GetTypes().Where(t => t.GetCustomAttributes(entityDefinitionAttributeType, false).Any()); + var relationshipAttributeType = definitionAssembly.GetType("XrmFramework.RelationshipAttribute"); + var definitionManagerIgnoreAttributeType = definitionAssembly.GetType("XrmFramework.Definitions.Internal.DefinitionManagerIgnoreAttribute"); + if(definitionManagerIgnoreAttributeType == null) + { + definitionManagerIgnoreAttributeType = definitionAssembly.GetType("Model.DefinitionManagerIgnoreAttribute"); + + } + + var tableList = new List
(); + Console.WriteLine($"F{definitionTypes.Count()} definitions were found."); + + foreach (var t in definitionTypes) + { + Console.WriteLine($"Adding {t.Name} to tables."); + if (t.GetCustomAttributes(definitionManagerIgnoreAttributeType).Any()) + { + continue; + } + + var table = new Table + { + Name = t.Name.Replace("Definition","") + , + LogicalName = t.GetField("EntityName").GetValue(null) as string + , + CollectionName = t.GetField("EntityCollectionName")?.GetValue(null) as string + , + Selected = true + }; + + + + foreach (var field in t.GetNestedType("Columns").GetFields()) + { + table.Columns.Add(new Column + { + LogicalName = field.GetValue(null) as string + , + Name = field.Name + , + Selected = true + + }); + + + + } + + foreach (var field in t.GetFields()) + { + if (field.Name == "EntityName" || field.Name == "EntityCollectionName") + { + continue; + } + + var typeName = field.FieldType.Name; + + //definition.AdditionalInfoCollection.Add(new AttributeDefinition + //{ + // Type = typeName + // , + // Name = field.Name + // , + // LogicalName = field.Name + // , + // Value = field.GetValue(null).ToString() + // , + // IsSelected = true + //}); + } + + foreach (var nestedType in t.GetNestedTypes()) + { + if (nestedType.Name == "Columns") + { + continue; + } + + //var classDefinition = new ClassDefinition + //{ + // LogicalName = nestedType.Name + // , + // Name = nestedType.Name + // , + // IsEnum = nestedType.IsEnum + //}; + + //if (nestedType.IsEnum) + //{ + // var names = Enum.GetNames(nestedType); + // var values = Enum.GetValues(nestedType); + // + // for (var i = 0; i < names.Length; i++) + // { + // classDefinition.Attributes.Add(new AttributeDefinition + // { + // LogicalName = Name = names[i] + // , + // Name = names[i] + // , + // Value = (int)values.GetValue(i) + // , + // IsSelected = true + // }); + // } + //} + //else + //{ + // foreach (var field in nestedType.GetFields()) + // { + // + // if (nestedType.Name == "ManyToOneRelationships" || nestedType.Name == "OneToManyRelationships" || nestedType.Name == "ManyToManyRelationships") + // { + // dynamic relationshipAttribute = field.GetCustomAttribute(relationshipAttributeType); + // + // classDefinition.Attributes.Add(new RelationshipAttributeDefinition + // { + // LogicalName = field.GetValue(null).ToString() + // , + // Name = field.Name + // , + // Type = field.FieldType.Name + // , + // Value = field.GetValue(null).ToString() + // , + // IsSelected = true + // , + // NavigationPropertyName = relationshipAttribute?.NavigationPropertyName + // , + // Role = relationshipAttribute?.Role.ToString() ?? "Referenced" + // , + // TargetEntityName = relationshipAttribute?.TargetEntityName + // }); + // } + // else + // { + // classDefinition.Attributes.Add(new AttributeDefinition + // { + // LogicalName = field.GetValue(null).ToString() + // , + // Name = field.Name + // , + // Type = field.FieldType.Name + // , + // Value = field.GetValue(null).ToString() + // , + // IsSelected = true + // }); + // } + // } + //} + + //definition.AdditionalClassesCollection.Add(classDefinition); + } + + tables.Add(table); + } + + return tables; + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } +} diff --git a/src/Tests/XrmFramework.Plugin.tests/Extensions.Test.cs b/src/Tests/XrmFramework.Plugin.tests/Extensions.Test.cs new file mode 100644 index 00000000..e268430c --- /dev/null +++ b/src/Tests/XrmFramework.Plugin.tests/Extensions.Test.cs @@ -0,0 +1,266 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.Xrm.Sdk; +using Microsoft.Xrm.Sdk.Query; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XrmFramework; + +namespace XrmFramework.Plugin.tests +{ + public enum TestEnum + { + Option1, + [System.ComponentModel.Description("Description for option 2")] + Option2, + Option3, + [ExternalValue("option 4")] + Option4, + + } + + [TestClass] + public class Extensions + { + + + [TestMethod] + public void CollectionExtension() + { + List testCollection = new List(); + for (int i = 0; i < 10000; i++) + { + testCollection.Add(i); + } + int counter = 0; + foreach (List testList in testCollection.SplitList()) + { + Assert.AreEqual(1000, testList.Count); + for (int i = 0; i < testList.Count; i++) + { + Assert.AreEqual(counter * 1000 + i, testList[i]); + } + + counter++; + } + + } + + + [TestMethod] + public void DecimalExtensions() + { + + + decimal? testD = 10.2m; + decimal? testD2 = null; + + + + Money testM2 = new Money(testD.Value); + Assert.AreEqual(testD.ToMoney(), testM2); + + Assert.IsNull(testD2.ToMoney()); + } + + [TestMethod] + public void EntityExtensions() + { + var testEntity = new Entity(); + + OptionSetValue optionSetValue = new OptionSetValue((int)TestEnum.Option3); + List testEnumList = new List(); + testEnumList.Add(TestEnum.Option1); + testEnumList.Add(TestEnum.Option2); + testEnumList.Add(TestEnum.Option3); + + testEntity.Attributes["a1"] = 50; + testEntity.Attributes["a2"] = null; + testEntity.Attributes["optionSetValue"] = optionSetValue; + testEntity.Attributes["optionSetValues"] = testEnumList; + + Assert.IsNull(testEntity.GetAttributeValue("nonExistentValue")); + Assert.AreEqual(50, testEntity.GetAttributeValue("a1")); + Assert.IsNull(testEntity.GetAttributeValue("a2")); + Assert.AreEqual(TestEnum.Option3, testEntity.GetOptionSetValue("optionSetValue")); + + var enumValues = testEntity.GetAttributeValue>("optionSetValues"); + for (int i = 0; i < enumValues.Count; i++) + { + Assert.AreEqual(testEnumList[i], enumValues[i]); + } + testEnumList.Clear(); + var testEnumList2 = new List(); + testEnumList2.Add(TestEnum.Option4); + testEnumList2.Add(TestEnum.Option4); + testEnumList2.Add(TestEnum.Option4); + + //testEnumList.Add(TestEnum.Option4); + //testEnumList.Add(TestEnum.Option4); + //testEnumList.Add(TestEnum.Option4); + + for (int i = 0; i < enumValues.Count; i++) + { + Assert.AreNotEqual((int)testEnumList2[i], (int)enumValues[i]); + } + testEntity.SetOptionSetValues("optionSetValues", testEnumList2); + for (int i = 0; i < enumValues.Count; i++) + { + Assert.AreEqual((int)testEnumList2[i], (int)enumValues[i]); + } + testEntity.SetOptionSetValue("optionSetValue", TestEnum.Option1); + Assert.AreEqual(TestEnum.Option1, testEntity.GetOptionSetValue("optionSetValue")); + + + var eList = new List(); + eList.Add(new Entity("e1", Guid.NewGuid())); + eList.Add(new Entity("e2", Guid.NewGuid())); + eList.Add(new Entity("e3", Guid.NewGuid())); + eList.Add(new Entity("e4", Guid.NewGuid())); + + var testCollection = new EntityCollection(eList); + testCollection.EmptyIds(); + for (int i = 0; i < 4; i++) + { + Assert.AreEqual(Guid.Empty, testCollection[i].Id); + } + + var testPreimage = new Entity(); + testEntity.CopyField(testPreimage, "a1", "a3"); + Assert.AreEqual(testPreimage.Attributes["a3"], testEntity.Attributes["a1"]); + + //testEntity.MergeWith(testPreimage); + testPreimage.MergeWith(testEntity); + + foreach (var key in testEntity.Attributes.Keys) + { + Assert.AreEqual(testEntity.Attributes[key], testPreimage.Attributes[key]); + } + var testE1 = new Entity(); + var testE2 = new Entity(); + + testE1.Attributes["a1"] = 1; + testE1.Attributes["a2"] = 2; + testE2.Attributes["a3"] = 3; + testE2.Attributes["a4"] = 4; + var testE3 = testE1.Merge(testE2); + + foreach (var key in testE1.Attributes.Keys) + { + Assert.IsTrue(testE3.Contains(key)); + } + foreach (var key in testE2.Attributes.Keys) + { + Assert.IsTrue(testE3.Contains(key)); + } + + + + + + } + + [TestMethod] + public void EntityReferenceExtensions() + { + EntityReference nullE = null; + Assert.IsNull(nullE.ToEntity()); + + var testE = new EntityReference(); + testE.LogicalName = "test"; + testE.Id = Guid.NewGuid(); + testE.KeyAttributes["1"] = "a1"; + testE.KeyAttributes["2"] = "a2"; + testE.KeyAttributes["3"] = "a3"; + + var testEE = testE.ToEntity(); + Assert.AreEqual(testEE.Id, testE.Id); + Assert.AreEqual(testEE.LogicalName, testE.LogicalName); + foreach (var key in testE.KeyAttributes.Keys) + { + Assert.AreEqual(testE.KeyAttributes[key], testEE.KeyAttributes[key]); + } + } + + [TestMethod] + public void EnumExtensions() + { + Assert.AreEqual(TestEnum.Option2, (1).ToEnum()); + Assert.AreEqual("Description for option 2", TestEnum.Option2.GetDescription()); + Assert.AreEqual(TestEnum.Option2, TestEnum.Option2.GetDescription().ParseDescription()); + Assert.AreEqual(TestEnum.Option3, TestEnum.Option3.ToString().ToEnum()); + Assert.AreEqual("option 4", TestEnum.Option4.GetExternalValue()); + Assert.AreEqual(TestEnum.Option4, TestEnum.Option4.GetExternalValue().ParseExternalValue()); + Assert.AreEqual(3, TestEnum.Option4.ToInt()); + Assert.AreEqual(new OptionSetValue(3), TestEnum.Option4.ToOptionSetValue()); + + var oc = new OptionSetValueCollection(); + oc.Add(new OptionSetValue(1)); + oc.Add(new OptionSetValue(2)); + oc.Add(new OptionSetValue(3)); + + var el = new List(); + el.Add(TestEnum.Option2); + el.Add(TestEnum.Option3); + el.Add(TestEnum.Option4); + + var elo = el.ToOptionSetValueCollection(); + for (int i = 0; i < elo.Count; i++) + { + Assert.AreEqual(oc.ElementAt(i), elo[i]); + } + var oce = oc.ToEnumCollection(typeof(TestEnum)); + for (int i = 0; i < oce.Count; i++) + { + Assert.AreEqual(el[i], oce.ElementAt(i)); + } + } + + [TestMethod] + public void GuidExtensions() + { + var testGuid = Guid.NewGuid(); + var testEntityRef = testGuid.ToEntityReference("testEntityRefName"); + Assert.AreEqual(testGuid, testEntityRef.Id); + Assert.AreEqual("testEntityRefName", testEntityRef.LogicalName); + } + + [TestMethod] + public void QueryExpressionExtensions() + { + var qTest = new QueryExpression(); + var conditionExpression = new ConditionExpression("attribute", ConditionOperator.ChildOf); + qTest.Criteria.Conditions.Add(conditionExpression); + qTest.Criteria.Conditions.Add(new ConditionExpression("nfzl", ConditionOperator.ContainValues)); + Assert.AreEqual(conditionExpression, qTest.GetRootFilterExpression().Conditions.First()); + //qTest.Criteria.GetConditionValue<>("attribute"); + //Tester GetConditionValue, je sais pas encore comment faire + + } + + [TestMethod] + public void StringExtensions() + { + var testString = "testString"; + var testGuid = "0f8fad5b-d9cb-469f-a165-70867728950e"; + var testStringTrimmed = testString.TrimIfTooLong(4); + var guid = new Guid(testGuid); + string testVoidString = ""; + String testNullString = null; + var testE1 = testGuid.ToEntityReference("logical name"); + var testE2 = testGuid.ToEntityReference("logical name 2", "value"); + Assert.AreEqual(guid, testGuid.ToGuid()); + Assert.ThrowsException(()=>testVoidString.ShouldNotBeNull()); + Assert.ThrowsException(() => testNullString.ShouldNotBeNull()); + Assert.AreEqual(guid, testE1.Id); + Assert.AreEqual("logical name", testE1.LogicalName); + Assert.AreEqual(testGuid, testE2.KeyAttributes["value"]); + Assert.AreEqual(testString, testString.ToRelationship().SchemaName); + Assert.AreEqual("test", testStringTrimmed); + Assert.AreEqual(4,testStringTrimmed.Length); + + } + } +} diff --git a/src/Tests/XrmFramework.Plugin.tests/XrmFramework.Plugin.tests.csproj b/src/Tests/XrmFramework.Plugin.tests/XrmFramework.Plugin.tests.csproj new file mode 100644 index 00000000..67cbcbf6 --- /dev/null +++ b/src/Tests/XrmFramework.Plugin.tests/XrmFramework.Plugin.tests.csproj @@ -0,0 +1,28 @@ + + + + net462;netcoreapp3.1 + + false + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/src/XrmFramework.Analyzers/Generators/ModelSourceFileGenerator.cs b/src/XrmFramework.Analyzers/Generators/ModelSourceFileGenerator.cs new file mode 100644 index 00000000..19b05993 --- /dev/null +++ b/src/XrmFramework.Analyzers/Generators/ModelSourceFileGenerator.cs @@ -0,0 +1,339 @@ +using Microsoft.CodeAnalysis; +using Microsoft.EntityFrameworkCore.Internal; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; +using XrmFramework.Core; + +namespace XrmFramework.Analyzers.Generators +{ + [Generator] + public class ModelSourceFileGenerator : IIncrementalGenerator + { + public void Initialize(IncrementalGeneratorInitializationContext context) + { + + //return; + //var tableFiles = context.AdditionalTextsProvider.Where(a => a.Path.EndsWith(".table")); + var files = + context.AdditionalTextsProvider + .Where(a => a.Path.EndsWith(".model") || a.Path.EndsWith(".table")); + + // read their contents and save their name + var namesAndContents = + files.Select((text, cancellationToken) => (name: Path.GetFileName(text.Path), content: text.GetText(cancellationToken)!.ToString())) + .Collect(); + + var compilationAndModels = context.CompilationProvider.Combine(namesAndContents); + + context.RegisterSourceOutput(compilationAndModels, (productionContext, compilationModels) => + { + var modelValues = compilationModels.Right; + + var coreProjectName = compilationModels.Left.AssemblyName; + + List models = new List(); + TableCollection tables = new TableCollection(); + Table GlobalEnums = null; + try + { + foreach (var tuple in modelValues) + { + if(tuple.name.Contains(".model")) + { + var model = JsonConvert.DeserializeObject(tuple.content); + //model.Name = tuple.name; + models.Add(model); + } + else if(tuple.name.Contains(".table")) + { + if(tuple.name == "OptionSet.table") + { + GlobalEnums = JsonConvert.DeserializeObject
(tuple.content); + } + else + { + var table = JsonConvert.DeserializeObject
(tuple.content); + tables.Add(table); + } + } + + } + + WriteModelFiles(productionContext, models,tables,GlobalEnums); + } + catch (Exception e) + { + productionContext.AddSource("Exception.txt", $"/*\r\n{e}\r\n*/"); + } + }); + } + + private void WriteModelFiles(SourceProductionContext productionContext, List models,TableCollection tables, Table globalEnums) + { + if(globalEnums == null) + { + throw new Exception("global enums is null for some reason"); + } + foreach(var model in models) + { + var table = tables.FirstOrDefault(t => t.LogicalName == model.TableLogicalName); + if(table == null) + { + productionContext.AddSource($"{model.Name}.model.cs", $"// This is an empty test file {model.Name}, there are {globalEnums.Enums.Count} global enums, there are {tables.Count} tables "); + + } + else + { + // Create start of class + var sb = new IndentedStringBuilder(); + var correspondingTable = tables.FirstOrDefault(t => t.LogicalName == model.TableLogicalName); + if (correspondingTable == null) + { + throw new Exception("The table corresponding to this model was not found, its logical name is : " + model.TableLogicalName); + } + sb.AppendLine(""); + sb.AppendLine("using System;"); + sb.AppendLine("using System.CodeDom.Compiler;"); + sb.AppendLine("using System.ComponentModel.DataAnnotations;"); + sb.AppendLine("using System.Diagnostics.CodeAnalysis;"); + sb.AppendLine("using System.Collections.Generic;"); + sb.AppendLine("using XrmFramework;"); + sb.AppendLine("using Newtonsoft.Json;"); + sb.AppendLine("using XrmFramework.BindingModel;"); + sb.AppendLine("using XrmFramework.Definitions;"); + foreach(var otherModel in models) + { + //if(otherModel.Name != model.Name) + //{ + // if(!string.IsNullOrEmpty(otherModel.ModelNamespace)) + // { + // sb.AppendLine("using " + otherModel.ModelNamespace + ";"); + // + // } + //} + } + //sb.AppendLine($"using {CoreProjectName};"); + sb.AppendLine(); + if (model.ModelNamespace != null && model.ModelNamespace != "") + { + sb.AppendLine($"namespace {model.ModelNamespace}"); + + } + else + { + sb.AppendLine($"namespace ProjectModels"); + + } + sb.AppendLine("{"); + + using (sb.Indent()) + { + // Class declaration + sb.AppendLine("[GeneratedCode(\"XrmFramework\", \"2.0\")]"); + sb.AppendLine("[ExcludeFromCodeCoverage]"); + sb.AppendLine($"[CrmEntity({correspondingTable.Name}Definition.EntityName)]"); + sb.AppendLine("[JsonObject(MemberSerialization.OptIn)]"); + + + + + sb.AppendLine($"public partial class {model.Name} : BindingModelBase"); + + + sb.AppendLine("{"); + // Properties + using (sb.Indent()) + { + //sb.AppendLine(); + //sb.AppendLine($"[CrmMapping({correspondingTable.Name}Definition.Columns.Id)]"); + //sb.AppendLine("public Guid Id { get; set; }"); + sb.AppendLine(); + foreach (var prop in model.Properties) + { + + var correspondingColumn = correspondingTable.Columns.FirstOrDefault(c => c.LogicalName == prop.LogicalName); + if(!correspondingColumn.Selected) + { + continue; + } + { + if (correspondingColumn != null) + { //This property is a column + sb.Append($"[CrmMapping({correspondingTable.Name}Definition.Columns.{correspondingColumn.Name}");//)]"); + if (prop.IsValidForUpdate) + { + sb.Append(")]"); + + } + else + { + sb.Append(",IsValidForUpdate = false)]"); + } + if (correspondingColumn.Type == AttributeTypeCode.Lookup) + { + //Get the corresponding relationship info in the table + var correspondingRelation = correspondingTable.ManyToOneRelationships.FirstOrDefault(r => r.LookupFieldName == prop.LogicalName); + if (correspondingRelation == null) + { + throw new Exception("No corresponding relationship found in table for " + prop.Name); + } + else + { + sb.AppendLine(); + sb.Append($"[CrmLookup("); + var referencedTable = tables.FirstOrDefault(t => t.LogicalName == correspondingRelation.EntityName); + if (referencedTable != null) + { + sb.Append($"{referencedTable.Name}Definition.EntityName,"); + var referencedColumn = referencedTable.Columns.FirstOrDefault(c => c.LogicalName == correspondingRelation.LookupFieldName); + if (referencedColumn != null) + { + sb.Append($"{referencedTable.Name}Definition.Columns.{referencedColumn.Name})]"); + } + else + { + sb.Append($"\"{correspondingRelation.LookupFieldName}\")]"); + + } + } + else + { + sb.AppendLine($"\"{correspondingRelation.EntityName}\",\"{correspondingRelation.LookupFieldName}\")]"); + } + } + } + } + else + { + //This property is a OneToMany relation + var correspondingRelation = correspondingTable.OneToManyRelationships.FirstOrDefault(r => r.Name == prop.LogicalName); + if (correspondingRelation == null) + { + throw new Exception("Error, no corresponding OneToMany relation found for this property : " + prop.Name); + } + sb.AppendLine($"[ChildRelationship({correspondingTable.Name}Definition.OneToManyRelationships.{correspondingRelation.NavigationPropertyName})]"); + } + + if (prop.JsonPropertyName != null) + { + sb.AppendLine(); + sb.AppendLine($"[JsonProperty(\"{prop.JsonPropertyName}\")]"); + } + + // Add other possible attributes + + + if (!prop.IsValidForUpdate) + { + // Write regular declaration + if (correspondingColumn != null) + { + sb.AppendLine(String.Format("public {0} {1} {{get; set;}}", prop.TypeFullName, prop.Name)); + } + else + { + sb.AppendLine($"public List<{prop.TypeFullName}> {prop.Name} {{get;set;}} = new List<{prop.TypeFullName}>();"); + } + } + else + { + + // Write property declaration with call to OnPropertyChanged() + if (correspondingColumn != null) + { + string tmp = @$" + public {prop.TypeFullName} {prop.Name} + {{ + get {{return _{prop.Name};}} + set + {{ + if(value == _{prop.Name}) + return; + _{prop.Name} = value; + OnPropertyChanged(); + }} + }} + "; + //Console.WriteLine(tmp); + sb.AppendLine(tmp); + } + else + { + string tmp2 = @$" + public List<{prop.TypeFullName}> {prop.Name} + {{ + get {{return _{prop.Name};}} + set + {{ + if(value == _{prop.Name}) + return; + _{prop.Name} = value; + OnPropertyChanged(); + }} + }}= new List<{prop.TypeFullName}>(); + "; + sb.AppendLine(tmp2); + // "{" + + // " get { return _{1};}\n" + + // " set\n" + + // " {\n" + + // " if(value == _{1})\n" + + // " {\n" + + // " return;\n" + + // " }\n" + + // " _{1} = value;\n" + + // " OnPropertyChanged();\n" + + // " }\n" + + // "} = new List<{0}>();\n", prop.TypeFullName, prop.Name)); + } + + } + + sb.AppendLine(); + } + } + + + + + sb.AppendLine("#region Fields"); + + foreach (var prop in model.Properties.Where(p => p.IsValidForUpdate)) + { + //Add the corresponding field + var correspondingColumn = correspondingTable.Columns.FirstOrDefault(c => c.LogicalName == prop.LogicalName); + if (correspondingColumn != null) + { + sb.AppendLine(String.Format("private {0} _{1};", prop.TypeFullName, prop.Name)); + + } + else + { + sb.AppendLine(String.Format("private List<{0}> _{1};", prop.TypeFullName, prop.Name)); + } + } + sb.AppendLine("#endregion"); + + + + + + + } + sb.AppendLine("}"); + + } + + sb.AppendLine("}"); + productionContext.AddSource($"{model.Name}.model.cs", sb.ToString()); + + + } + + } + + } + } +} diff --git a/src/XrmFramework.Analyzers/Generators/TableSourceFileGenerator.cs b/src/XrmFramework.Analyzers/Generators/TableSourceFileGenerator.cs index ea6de7a1..e08b55fe 100644 --- a/src/XrmFramework.Analyzers/Generators/TableSourceFileGenerator.cs +++ b/src/XrmFramework.Analyzers/Generators/TableSourceFileGenerator.cs @@ -93,6 +93,10 @@ private void WriteTables(SourceProductionContext productionContext, TableCollect { foreach (var col in table.Columns) { + if(!col.Selected) + { + continue; + } var enumDefinition = scopedEnums.FirstOrDefault(e => e.LogicalName == col.EnumName); AddColumnSummary(sb, col, enumDefinition); @@ -185,7 +189,6 @@ private void WriteTables(SourceProductionContext productionContext, TableCollect sb.AppendLine("}"); - //if(table.Enums.Any(e=>table.Columns.Any()) if (table.Keys != null && table.Keys.Any()) { @@ -201,188 +204,7 @@ private void WriteTables(SourceProductionContext productionContext, TableCollect } sb.AppendLine("}"); } - /* - if (table.ManyToOneRelationships.Any()) - { - sb.AppendLine("public static class ManyToOneRelationships"); - sb.AppendLine("{"); - using (sb.Indent()) - { - foreach (var relationship in table.ManyToOneRelationships) - { - sb.Append("[Relationship("); - var targetTable = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - if (targetTable != null) - { - sb.Append($"{targetTable.Name}Definition.EntityName"); - } - else - { - sb.Append($"\"{relationship.EntityName}\""); - } - - sb.Append($", EntityRole.{relationship.Role}, \"{relationship.NavigationPropertyName}\", "); - - if (relationship.Role == EntityRole.Referencing) - { - //var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - - - //var re = tb?.OneToManyRelationships.FirstOrDefault(r => r.Name == relationship.Name); - var rc = table.Columns.FirstOrDefault(col => col.LogicalName == relationship.LookupFieldName); - - if (rc != null) - { - sb.Append($"{table.Name}Definition.Columns.{rc.Name}"); - } - else - { - sb.Append($"\"{relationship.LookupFieldName}\""); - } - } - else - { - var rc = table.Columns.FirstOrDefault(col => col.LogicalName == relationship.LookupFieldName); - - //var r = tb?.OneToManyRelationships.FirstOrDefault(r => r.Name == relationship.Name); - - - if (rc != null) - { - sb.Append($"{table.Name}Definition.Columns.{rc.Name}"); - } - else - { - sb.Append($"\"{relationship.LookupFieldName}\""); - } - } - - sb.AppendLine(")]"); - sb.AppendLine($"public const string {relationship.Name} = \"{relationship.Name}\";"); - } - - - } - sb.AppendLine("}"); - } - - if (table.ManyToManyRelationships.Any()) - { - sb.AppendLine("public static class ManyToManyRelationships"); - sb.AppendLine("{"); - using (sb.Indent()) - { - foreach (var relationship in table.ManyToManyRelationships) - { - sb.Append("[Relationship("); - var targetTable = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - if (targetTable != null) - { - sb.Append($"{targetTable.Name}Definition.EntityName"); - } - else - { - sb.Append($"\"{relationship.EntityName}\""); - } - - sb.Append($", EntityRole.{relationship.Role}, \"{relationship.NavigationPropertyName}\", "); - - if (relationship.Role == EntityRole.Referencing) - { - var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - var rc = tb?.Columns.FirstOrDefault(col => col.LogicalName == relationship.LookupFieldName); - - if (rc != null && tb != null) - { - sb.Append($"{tb.Name}Definition.Columns.{rc.Name}"); - } - else - { - sb.Append($"\"{relationship.LookupFieldName}\""); - } - } - else - { - var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - - var rc = tb?.Columns.FirstOrDefault(col => col.LogicalName == relationship.LookupFieldName); - - if (rc != null && tb != null) - { - sb.Append($"{tb.Name}Definition.Columns.{rc.Name}"); - } - else - { - sb.Append($"\"{relationship.LookupFieldName}\""); - } - } - - sb.AppendLine(")]"); - sb.AppendLine($"public const string {relationship.Name} = \"{relationship.Name}\";"); - } - } - sb.AppendLine("}"); - } - - if (table.OneToManyRelationships.Any()) - { - sb.AppendLine("public static class OneToManyRelationships"); - sb.AppendLine("{"); - using (sb.Indent()) - { - foreach (var relationship in table.OneToManyRelationships) - { - sb.Append("[Relationship("); - var targetTable = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - - if (targetTable != null) - { - sb.Append($"{targetTable.Name}Definition.EntityName"); - } - else - { - sb.Append($"\"{relationship.EntityName}\""); - } - - sb.Append($", EntityRole.{relationship.Role}, \"{relationship.NavigationPropertyName}\", "); - - if (relationship.Role == EntityRole.Referencing) - { - var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - var rc = tb?.Columns.FirstOrDefault(col => col.LogicalName == relationship.LookupFieldName); - - if (rc != null && tb != null) - { - sb.Append($"{tb.Name}Definition.Columns.{rc.Name}"); - } - else - { - sb.Append($"\"{relationship.LookupFieldName}\""); - } - } - else - { - var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - - var rc = tb?.Columns.FirstOrDefault(col => col.LogicalName == relationship.LookupFieldName); - - if (rc != null && tb != null) - { - sb.Append($"{tb.Name}Definition.Columns.{rc.Name}"); - } - else - { - sb.Append($"\"{relationship.LookupFieldName}\""); - } - } - - sb.AppendLine(")]"); - sb.AppendLine($"public const string {relationship.Name} = \"{relationship.Name}\";"); - } - } - sb.AppendLine("}"); - } - */ + AddRelations(sb, tables, table, table.ManyToOneRelationships,"ManyToOneRelationships"); AddRelations(sb, tables, table, table.ManyToManyRelationships, "ManyToManyRelationships"); AddRelations(sb, tables, table, table.OneToManyRelationships, "OneToManyRelationships"); @@ -397,7 +219,7 @@ private void WriteTables(SourceProductionContext productionContext, TableCollect { foreach (var ose in table.Enums) { - if (ose.IsGlobal && tables.All(t => t.Columns.All(c => c.EnumName != ose.LogicalName))) + if (ose.IsGlobal && tables.All(t => t.Columns.All(c => c.EnumName != ose.LogicalName || (c.EnumName == ose.LogicalName && !c.Selected)))) { continue; } @@ -412,7 +234,7 @@ private void WriteTables(SourceProductionContext productionContext, TableCollect var referencedColumn = table.Columns.FirstOrDefault(col => col.EnumName == ose.LogicalName); - if (referencedColumn == null) + if (referencedColumn == null || !referencedColumn.Selected) { continue; } @@ -536,13 +358,9 @@ private void AddRelations(IndentedStringBuilder sb,TableCollection tables,Table { if (relationship.Role == EntityRole.Referencing) { - //var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - - - //var re = tb?.OneToManyRelationships.FirstOrDefault(r => r.Name == relationship.Name); var rc = table.Columns.FirstOrDefault(col => col.LogicalName == relationship.LookupFieldName); - if (rc != null) + if (rc != null && rc.Selected) { sb.Append($"{table.Name}Definition.Columns.{rc.Name}"); } @@ -555,7 +373,6 @@ private void AddRelations(IndentedStringBuilder sb,TableCollection tables,Table { var rc = table.Columns.FirstOrDefault(col => col.LogicalName == relationship.LookupFieldName); - //var r = tb?.OneToManyRelationships.FirstOrDefault(r => r.Name == relationship.Name); if (rc != null) @@ -578,7 +395,7 @@ private void AddRelations(IndentedStringBuilder sb,TableCollection tables,Table var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); var rc = tb?.Columns.FirstOrDefault(col => col.LogicalName == relationship.LookupFieldName); - if (rc != null && tb != null) + if ((rc != null && rc.Selected) && tb != null) { sb.Append($"{tb.Name}Definition.Columns.{rc.Name}"); } @@ -593,7 +410,7 @@ private void AddRelations(IndentedStringBuilder sb,TableCollection tables,Table var rc = tb?.Columns.FirstOrDefault(col => col.LogicalName == relationship.LookupFieldName); - if (rc != null && tb != null) + if ((rc != null && rc.Selected) && tb != null) { sb.Append($"{tb.Name}Definition.Columns.{rc.Name}"); } diff --git a/src/XrmFramework.Core/Column.cs b/src/XrmFramework.Core/Column.cs index 2ba3fc41..deeb66d0 100644 --- a/src/XrmFramework.Core/Column.cs +++ b/src/XrmFramework.Core/Column.cs @@ -40,7 +40,7 @@ public class Column public string EnumName { get; set; } - [JsonIgnore] + [JsonProperty("Select")] public bool Selected { get; set; } } } diff --git a/src/XrmFramework.Core/ColumnCollection.cs b/src/XrmFramework.Core/ColumnCollection.cs index 4a7445af..a80fb75f 100644 --- a/src/XrmFramework.Core/ColumnCollection.cs +++ b/src/XrmFramework.Core/ColumnCollection.cs @@ -20,15 +20,16 @@ public void Add(Column? item) if (item.Selected || item.IsLocked) { existingColumn.Name = item.Name; - existingColumn.Selected = true; + existingColumn.Selected = item.Selected; } else if (existingColumn.Selected || existingColumn.IsLocked) { item.Name = existingColumn.Name; - item.Selected = true; + item.Selected = existingColumn.Selected; - Columns[item.LogicalName] = item; } + Columns[item.LogicalName] = item; + } else { diff --git a/src/XrmFramework.DefinitionManager/Definitions/AbstractDefinition.cs b/src/XrmFramework.DefinitionManager/Definitions/AbstractDefinition.cs index ab4609d2..e0b2e246 100644 --- a/src/XrmFramework.DefinitionManager/Definitions/AbstractDefinition.cs +++ b/src/XrmFramework.DefinitionManager/Definitions/AbstractDefinition.cs @@ -171,7 +171,14 @@ internal void Merge(AbstractDefinition definition) throw new Exception("Only similar types can be merged."); } - IsSelected = true; + if (definition.IsSelected) + { + IsSelected = true; + } + else if (IsSelected) + { + definition.IsSelected = true; + } foreach (var column in this.GetType().GetProperties().Where(p => p.GetCustomAttributes(typeof(MergeableAttribute), false).Any())) { diff --git a/src/XrmFramework.DefinitionManager/Definitions/EntityDefinition.cs b/src/XrmFramework.DefinitionManager/Definitions/EntityDefinition.cs index 2394ed7d..a0119369 100644 --- a/src/XrmFramework.DefinitionManager/Definitions/EntityDefinition.cs +++ b/src/XrmFramework.DefinitionManager/Definitions/EntityDefinition.cs @@ -79,6 +79,7 @@ protected override void MergeInternal(AbstractDefinition definition) LogicalCollectionName = def.LogicalCollectionName; IsLoaded = definition.IsLoaded; + IsSelected = definition.IsSelected; _attributes.AddRange(def.AttributesCollection.Definitions); diff --git a/src/XrmFramework.DefinitionManager/MainForm.Designer.cs b/src/XrmFramework.DefinitionManager/MainForm.Designer.cs index a39c50e3..2d748ab8 100644 --- a/src/XrmFramework.DefinitionManager/MainForm.Designer.cs +++ b/src/XrmFramework.DefinitionManager/MainForm.Designer.cs @@ -35,6 +35,7 @@ private void InitializeComponent() this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.generateDefinitionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.getEntitiesFromCRMToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.entityListView = new XrmFramework.DefinitionManager.EntityListViewControl(); this.splitContainer2 = new System.Windows.Forms.SplitContainer(); @@ -67,26 +68,28 @@ private void InitializeComponent() this.statusStrip1.ImageScalingSize = new System.Drawing.Size(32, 32); this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripStatusLabel1}); - this.statusStrip1.Location = new System.Drawing.Point(0, 529); + this.statusStrip1.Location = new System.Drawing.Point(0, 656); this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(1209, 22); + this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 19, 0); + this.statusStrip1.Size = new System.Drawing.Size(1612, 22); this.statusStrip1.TabIndex = 0; this.statusStrip1.Text = "statusStrip1"; // // toolStripStatusLabel1 // this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; - this.toolStripStatusLabel1.Size = new System.Drawing.Size(0, 17); + this.toolStripStatusLabel1.Size = new System.Drawing.Size(0, 16); // // menuStrip1 // this.menuStrip1.ImageScalingSize = new System.Drawing.Size(32, 32); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.generateDefinitionsToolStripMenuItem}); + this.generateDefinitionsToolStripMenuItem, + this.getEntitiesFromCRMToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Padding = new System.Windows.Forms.Padding(3, 1, 0, 1); - this.menuStrip1.Size = new System.Drawing.Size(1209, 24); + this.menuStrip1.Padding = new System.Windows.Forms.Padding(4, 1, 0, 1); + this.menuStrip1.Size = new System.Drawing.Size(1612, 30); this.menuStrip1.TabIndex = 1; this.menuStrip1.Text = "menuStrip1"; // @@ -94,14 +97,22 @@ private void InitializeComponent() // this.generateDefinitionsToolStripMenuItem.Enabled = false; this.generateDefinitionsToolStripMenuItem.Name = "generateDefinitionsToolStripMenuItem"; - this.generateDefinitionsToolStripMenuItem.Size = new System.Drawing.Size(126, 22); + this.generateDefinitionsToolStripMenuItem.Size = new System.Drawing.Size(159, 28); this.generateDefinitionsToolStripMenuItem.Text = "Generate Definitions"; this.generateDefinitionsToolStripMenuItem.Click += new System.EventHandler(this.generateDefinitionsToolStripMenuItem_Click); // + // getEntitiesFromCRMToolStripMenuItem + // + this.getEntitiesFromCRMToolStripMenuItem.Name = "getEntitiesFromCRMToolStripMenuItem"; + this.getEntitiesFromCRMToolStripMenuItem.Size = new System.Drawing.Size(171, 28); + this.getEntitiesFromCRMToolStripMenuItem.Text = "Get Entities From CRM"; + this.getEntitiesFromCRMToolStripMenuItem.Click += new System.EventHandler(this.getEntitiesFromCRMToolStripMenuItem_Click); + // // splitContainer1 // this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer1.Location = new System.Drawing.Point(0, 24); + this.splitContainer1.Location = new System.Drawing.Point(0, 30); + this.splitContainer1.Margin = new System.Windows.Forms.Padding(4); this.splitContainer1.Name = "splitContainer1"; // // splitContainer1.Panel1 @@ -113,8 +124,9 @@ private void InitializeComponent() // this.splitContainer1.Panel2.Controls.Add(this.splitContainer2); this.splitContainer1.Panel2MinSize = 600; - this.splitContainer1.Size = new System.Drawing.Size(1209, 505); - this.splitContainer1.SplitterDistance = 305; + this.splitContainer1.Size = new System.Drawing.Size(1612, 626); + this.splitContainer1.SplitterDistance = 406; + this.splitContainer1.SplitterWidth = 5; this.splitContainer1.TabIndex = 3; // // entityListView @@ -124,7 +136,7 @@ private void InitializeComponent() this.entityListView.Location = new System.Drawing.Point(0, 0); this.entityListView.Margin = new System.Windows.Forms.Padding(0); this.entityListView.Name = "entityListView"; - this.entityListView.Size = new System.Drawing.Size(305, 505); + this.entityListView.Size = new System.Drawing.Size(406, 626); this.entityListView.TabIndex = 2; // // splitContainer2 @@ -145,8 +157,9 @@ private void InitializeComponent() this.splitContainer2.Panel2.Controls.Add(this.enumListView); this.splitContainer2.Panel2Collapsed = true; this.splitContainer2.Panel2MinSize = 100; - this.splitContainer2.Size = new System.Drawing.Size(900, 505); + this.splitContainer2.Size = new System.Drawing.Size(1201, 626); this.splitContainer2.SplitterDistance = 100; + this.splitContainer2.SplitterWidth = 5; this.splitContainer2.TabIndex = 4; // // attributeListView @@ -156,7 +169,7 @@ private void InitializeComponent() this.attributeListView.Location = new System.Drawing.Point(0, 0); this.attributeListView.Margin = new System.Windows.Forms.Padding(0); this.attributeListView.Name = "attributeListView"; - this.attributeListView.Size = new System.Drawing.Size(900, 505); + this.attributeListView.Size = new System.Drawing.Size(1201, 626); this.attributeListView.TabIndex = 2; // // enumListView @@ -165,7 +178,7 @@ private void InitializeComponent() this.enumListView.Location = new System.Drawing.Point(0, 0); this.enumListView.Margin = new System.Windows.Forms.Padding(0); this.enumListView.Name = "enumListView"; - this.enumListView.Size = new System.Drawing.Size(112, 37); + this.enumListView.Size = new System.Drawing.Size(150, 46); this.enumListView.TabIndex = 4; // // picklistNameHeader @@ -188,23 +201,24 @@ private void InitializeComponent() this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem1}); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(176, 26); + this.contextMenuStrip1.Size = new System.Drawing.Size(205, 28); // // toolStripMenuItem1 // this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(175, 22); + this.toolStripMenuItem1.Size = new System.Drawing.Size(204, 24); this.toolStripMenuItem1.Text = "Copy LogicalName"; // // MainForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1209, 551); + this.ClientSize = new System.Drawing.Size(1612, 678); this.Controls.Add(this.splitContainer1); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; + this.Margin = new System.Windows.Forms.Padding(4); this.Name = "MainForm"; this.Text = "Definition Manager"; this.Load += new System.EventHandler(this.DefinitionManager_Load); @@ -246,6 +260,7 @@ private void InitializeComponent() private System.Windows.Forms.ColumnHeader picklistValueHeader; private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem getEntitiesFromCRMToolStripMenuItem; } } diff --git a/src/XrmFramework.DefinitionManager/MainForm.cs b/src/XrmFramework.DefinitionManager/MainForm.cs index b0f62399..7e81e214 100644 --- a/src/XrmFramework.DefinitionManager/MainForm.cs +++ b/src/XrmFramework.DefinitionManager/MainForm.cs @@ -56,18 +56,23 @@ public MainForm(Type iServiceType, string coreProjectName) - //_selectedTables = LoadLocalTables(); _selectedTables = new TableCollection(); _localTables = LoadLocalTables(); - _localTables.AddRange(GetTablesFromFormerDefinitionCode()); - //_selectedTables.AddRange(GetTablesFromFormerDefinitionCode()); + + foreach(var table in _localTables) { var localEntity = TableToBaseEntityDefinition(table); _entityCollection.Add(localEntity); + _tables.Add(table); } - //MessageBox.Show($"There are currently {_selectedTables.Count} tables selected in this project."); + + + this.generateDefinitionsToolStripMenuItem.Enabled = true; + this.entityListView.Enabled = true; + this.attributeListView.Enabled = true; + } void attributeListView_SelectionChanged(object sender, CustomListViewControl.SelectionChangedEventArgs e) @@ -95,11 +100,12 @@ void RetrieveEntitiesSucceeded(object result) _entityCollection.AddRange(entities.Item1); _tables.AddRange(entities.Item2); MessageBox.Show($"There are {_localTables.Count} local tables"); - //MergeLocalTablesWithCrmData(_localTables); _enums.AddRange(entities.Item3); this.generateDefinitionsToolStripMenuItem.Enabled = true; + this.entityListView.Enabled = true; this.attributeListView.Enabled = true; + } void ConnectionSucceeded(object service) @@ -113,20 +119,6 @@ private void DefinitionManager_Load(object sender, EventArgs e) List localCodedDefinitions = new List(); _entityCollection.AttachListView(this.entityListView); - //var entities = GetCodedEntities().ToList(); - //_tables.AddRange(entities); - - // - //localCodedDefinitions = GetCodedEntityDefinitions(); - - var localTables = LoadLocalTables(); - foreach(var table in localTables) - { - localCodedDefinitions.Add(TableToBaseEntityDefinition(table)); - } - //_entityCollection.AddRange(localCodedDefinitions); - - DataAccessManager.Instance.Connect(ConnectionSucceeded); } private void InitEnumDefinitions() @@ -199,31 +191,19 @@ private void InitEnumDefinitions() private Type GetExternalType(string name) => _iServiceType.Assembly.GetType(name); - //private IEnumerable
GetCodedEntities() - //{ - // var entityFiles = Directory.EnumerateFiles(".", "*.table", SearchOption.AllDirectories); - - // foreach (var entityFile in entityFiles) - // { - // var fileContent = File.ReadAllText(entityFile); - - // var entity = JsonConvert.DeserializeObject
(fileContent); - // entity.Selected = true; - // entity.Columns.ForEach(a => a.Selected = true); - - // yield return entity; - // } - //} + private IEnumerable GetCodedEntityDefinitions() { + var definitionList = new List(); + return definitionList; //Console.WriteLine(_tables.Count); var entityDefinitionAttributeType = GetExternalType("XrmFramework.EntityDefinitionAttribute"); var definitionTypes = _iServiceType.Assembly.GetTypes().Where(t => t.GetCustomAttributes(entityDefinitionAttributeType, false).Any()); var relationshipAttributeType = GetExternalType("XrmFramework.RelationshipAttribute"); var definitionManagerIgnoreAttributeType = GetExternalType("XrmFramework.Definitions.Internal.DefinitionManagerIgnoreAttribute"); - var definitionList = new List(); + foreach (var t in definitionTypes) { @@ -377,17 +357,16 @@ private IEnumerable GetCodedEntityDefinitions() private void generateDefinitionsToolStripMenuItem_Click(object sender, EventArgs e) { - //GenerateDefinitionCodeFromJson(); - // Add new selected tables + foreach(var item in _entityCollection.SelectedDefinitions) { - if(!_selectedTables.Any(t=>t.LogicalName == item.LogicalName)) + if (!_selectedTables.Any(t => t.LogicalName == item.LogicalName)) { var table = _tables.FirstOrDefault(t => t.LogicalName == item.LogicalName); table.Selected = true; foreach (var a in item.AttributesCollection.SelectedDefinitions) { - table.Columns.FirstOrDefault(c => c.LogicalName == a.LogicalName).Selected = true; + table.Columns.FirstOrDefault(c => c.LogicalName == a.LogicalName).Selected = a.IsSelected; } _selectedTables.Add(table); @@ -399,19 +378,19 @@ private void generateDefinitionsToolStripMenuItem_Click(object sender, EventArgs _selectedTables.Remove(tableToRemove); var table = _tables.FirstOrDefault(t => t.LogicalName == item.LogicalName); - if(table == null) + if (table == null) { throw new Exception($"Table named {item.LogicalName} does not exist in the list _tables, _tables.Count is {_tables.Count}"); } table.Selected = true; foreach (var a in item.AttributesCollection.SelectedDefinitions) - { - table.Columns.FirstOrDefault(c => c.LogicalName == a.LogicalName).Selected = true; - } + table.Columns.FirstOrDefault(c => c.LogicalName == a.LogicalName).Selected = a.IsSelected; - _selectedTables.Add(table); + _selectedTables.Add(table); } + + } var nameOfTablesToDelete = new List(); @@ -429,285 +408,7 @@ private void generateDefinitionsToolStripMenuItem_Click(object sender, EventArgs _selectedTables.Remove(_selectedTables.FirstOrDefault(t => t.LogicalName == name)); } - foreach (var item in this._entityCollection.SelectedDefinitions) - { - var sb = new IndentedStringBuilder(); - - //var entity = _tables.FirstOrDefault(e => e.LogicalName == item.LogicalName); - //var selectedAttributes = item.AttributesCollection.SelectedDefinitions; - - //entity.Columns.RemoveAll(a => selectedAttributes.All(s => s.LogicalName != a.LogicalName)); - - //var enumsToKeep = entity.Columns.Where(a => !string.IsNullOrEmpty(a.EnumName)) - // .Select(en => en.EnumName).Distinct().ToList(); - - //entity.Enums.RemoveAll(en => !enumsToKeep.Contains(en.LogicalName)); - - //var entityTxt = JsonConvert.SerializeObject(entity, Formatting.Indented, new JsonSerializerSettings - //{ - // DefaultValueHandling = DefaultValueHandling.Ignore - //}); - - /* - sb.AppendLine(""); - sb.AppendLine("using System;"); - sb.AppendLine("using System.CodeDom.Compiler;"); - sb.AppendLine("using System.ComponentModel.DataAnnotations;"); - sb.AppendLine("using System.Diagnostics.CodeAnalysis;"); - sb.AppendLine("using XrmFramework;"); - sb.AppendLine(); - sb.AppendLine($"namespace {CoreProjectName}"); - sb.AppendLine("{"); - - using (sb.Indent()) - { - - sb.AppendLine("[GeneratedCode(\"XrmFramework\", \"2.0\")]"); - sb.AppendLine("[EntityDefinition]"); - sb.AppendLine("[ExcludeFromCodeCoverage]"); - - - sb.AppendLine($"public static class {item.Name}"); - sb.AppendLine("{"); - - using (sb.Indent()) - { - - sb.AppendLine($"public const string EntityName = \"{item.LogicalName}\";"); - sb.AppendLine($"public const string EntityCollectionName = \"{item.LogicalCollectionName}\";"); - - foreach (var t in item.AdditionalInfoCollection.Definitions) - { - sb.AppendLine(); - sb.AppendLine( - $"public const {t.Type} {t.Name} = {(t.Type == "String" ? "\"" + (string)t.Value + "\"" : t.Value)};"); - } - - sb.AppendLine(); - sb.AppendLine("[SuppressMessage(\"Microsoft.Design\", \"CA1034:NestedTypesShouldNotBeVisible\")]"); - sb.AppendLine("public static class Columns"); - sb.AppendLine("{"); - - using (sb.Indent()) - { - - foreach (var attr in item.AttributesCollection.SelectedDefinitions) - { - AddAttributeSummary(sb, attr); - if (!string.IsNullOrEmpty(attr.Type)) - { - sb.AppendLine($"[AttributeMetadata(AttributeTypeCode.{attr.Type})]"); - } - - if (attr.Enum != null) - { - sb.AppendLine($"[OptionSet(typeof({attr.Enum.Name}))]"); - } - - if (attr.IsPrimaryIdAttribute) - { - sb.AppendLine("[PrimaryAttribute(PrimaryAttributeType.Id)]"); - } - - if (attr.IsPrimaryNameAttribute) - { - sb.AppendLine("[PrimaryAttribute(PrimaryAttributeType.Name)]"); - } - - if (attr.IsPrimaryImageAttribute) - { - sb.AppendLine("[PrimaryAttribute(PrimaryAttributeType.Image)]"); - } - - if (attr.StringMaxLength.HasValue) - { - sb.AppendLine($"[StringLength({attr.StringMaxLength.Value})]"); - } - - if (attr.MinRange.HasValue && attr.MaxRange.HasValue) - { - sb.AppendLine($"[Range({attr.MinRange.Value}, {attr.MaxRange.Value})]"); - } - - foreach (var keyName in attr.KeyNames) - { - sb.AppendLine($"[AlternateKey(AlternateKeyNames.{keyName})]"); - } - - if (attr.DateTimeBehavior != null) - { - var behavior = string.Empty; - if (attr.DateTimeBehavior == Microsoft.Xrm.Sdk.Metadata.DateTimeBehavior.DateOnly) - { - behavior = "DateOnly"; - } - else if (attr.DateTimeBehavior == - Microsoft.Xrm.Sdk.Metadata.DateTimeBehavior.TimeZoneIndependent) - { - behavior = "TimeZoneIndependent"; - } - else if (attr.DateTimeBehavior == - Microsoft.Xrm.Sdk.Metadata.DateTimeBehavior.UserLocal) - { - behavior = "UserLocal"; - } - - sb.AppendLine($"[DateTimeBehavior(DateTimeBehavior.{behavior})]"); - } - - foreach (var relationship in attr.Relationships) - { - if (this._entityCollection.SelectedDefinitions.Any(d => - d.LogicalName == relationship.ReferencedEntity)) - { - var eC = this._entityCollection[relationship.ReferencedEntity]; - sb.AppendLine(string.Format( - "[CrmLookup({0}.EntityName, {0}.Columns.{1}, RelationshipName = ManyToOneRelationships.{2})]", - eC.Name, eC.AttributesCollection[relationship.ReferencedAttribute].Name, - relationship.SchemaName)); - } - else if (relationship.ReferencedEntity != "owner") - { - sb.AppendLine( - $"[CrmLookup(\"{relationship.ReferencedEntity}\", \"{relationship.ReferencedAttribute}\", RelationshipName = \"{relationship.SchemaName}\")]"); - } - else if (relationship.ReferencedEntity == "owner") - { - sb.AppendLine( - $"[CrmLookup(\"{relationship.ReferencedEntity}\", \"{relationship.ReferencedAttribute}\", RelationshipName = \"{relationship.SchemaName}\")]"); - } - } - - sb.AppendLine($"public const string {attr.Name} = \"{attr.LogicalName}\";\r\n"); - } - } - - sb.AppendLine("}"); - - - foreach (var def in item.AdditionalClassesCollection.Definitions) - { - sb.AppendLine(); - if (def.IsEnum) - { - sb.AppendLine($"public enum {def.Name}"); - } - else - { - sb.AppendLine("[SuppressMessage(\"Microsoft.Design\", \"CA1034:NestedTypesShouldNotBeVisible\")]"); - sb.AppendLine($"public static class {def.Name}"); - } - - sb.AppendLine("{"); - - using (sb.Indent()) - { - if (def.IsEnum) - { - foreach (var attr in def.Attributes.Definitions.OrderBy(a => a.Value)) - { - sb.AppendLine($"{attr.Name} = {attr.Value},"); - } - } - else - { - foreach (var attr in def.Attributes.Definitions.OrderBy(a => a.Name)) - { - if (attr.Type == "String") - { - if (attr is RelationshipAttributeDefinition rAttr) - { - sb.Append("[Relationship("); - if (this._entityCollection.SelectedDefinitions.Any(d => - d.LogicalName == rAttr.TargetEntityName)) - { - sb.Append($"{_entityCollection[rAttr.TargetEntityName].Name}.EntityName"); - } - else - { - sb.Append($"\"{rAttr.TargetEntityName}\""); - } - - sb.Append($", EntityRole.{rAttr.Role}, \"{rAttr.NavigationPropertyName}\", "); - - if (rAttr.Role == "Referencing") - { - var ec = _entityCollection.Definitions.FirstOrDefault(d => - d.LogicalName == item.LogicalName); - var att = ec?.AttributesCollection.SelectedDefinitions - .FirstOrDefault( - d => - d.LogicalName == rAttr.LookupFieldName); - - if (att != null) - { - sb.Append($"{ec.Name}.Columns.{att.Name}"); - } - else - { - sb.Append($"\"{rAttr.LookupFieldName}\""); - } - } - else - { - var ec = _entityCollection.SelectedDefinitions.FirstOrDefault(d => - d.LogicalName == rAttr.TargetEntityName); - var att = ec?.AttributesCollection.SelectedDefinitions - .FirstOrDefault( - d => - d.LogicalName == rAttr.LookupFieldName); - - if (att != null) - { - sb.Append($"{ec.Name}.Columns.{att.Name}"); - } - else - { - sb.Append($"\"{rAttr.LookupFieldName}\""); - } - } - - sb.AppendLine(")]"); - } - - sb.AppendLine($"public const string {attr.Name} = \"{attr.Value}\";"); - } - else - { - sb.AppendLine($"public const int {attr.Name} = {attr.Value};"); - } - } - } - } - - sb.AppendLine("}"); - } - } - - sb.AppendLine("}"); - } - - sb.AppendLine("}"); - - var fileInfo = new FileInfo($"../../../../../{CoreProjectName}/Definitions/{item.Name}.cs"); - - - */ - - - //var definitionFolder = new DirectoryInfo($"../../../../../{CoreProjectName}/Definitions"); - //if (definitionFolder.Exists == false) - //{ - // definitionFolder.Create(); - //} - // - ////File.WriteAllText(fileInfo.FullName, sb.ToString()); - // - //var fileInfo2 = new FileInfo($"../../../../../{CoreProjectName}/Definitions/{item.Name.Replace("Definition", string.Empty)}.table"); - - //File.WriteAllText(fileInfo2.FullName, entityTxt); - } @@ -731,88 +432,10 @@ private void generateDefinitionsToolStripMenuItem_Click(object sender, EventArgs File.WriteAllText(fileInfoOptionSets.FullName, optionSetsTxt); - /* - var fc = new IndentedStringBuilder(); - fc.AppendLine("using System.ComponentModel;"); - fc.AppendLine("using XrmFramework;"); - fc.AppendLine(); - fc.AppendLine($"namespace {CoreProjectName}"); - fc.AppendLine("{"); - - using (fc.Indent()) - { - foreach (var def in EnumDefinitionCollection.Instance.SelectedDefinitions) - { - fc.AppendLine(); - if (def.IsGlobal) - { - fc.AppendLine($"[OptionSetDefinition(\"{def.LogicalName}\")]"); - } - else - { - var attribute = def.ReferencedBy.First(); - - if (!_entityCollection.SelectedDefinitions.Any(s => s.LogicalName == attribute.ParentEntity.LogicalName)) - { - continue; - } - - fc.AppendLine(string.Format("[OptionSetDefinition({0}.EntityName, {0}.Columns.{1})]", - attribute.ParentEntity.Name, attribute.Name)); - } - - fc.AppendLine($"public enum {def.Name}"); - fc.AppendLine("{"); - - using (fc.Indent()) - { - - if (def.HasNullValue) - { - fc.AppendLine("Null = 0,"); - } - - foreach (var val in def.Values.Definitions) - { - fc.AppendLine($"[Description(\"{val.DisplayName}\")]"); - - if (!string.IsNullOrEmpty(val.ExternalValue)) - { - fc.AppendLine($"[ExternalValue(\"{val.ExternalValue}\")]"); - } - - fc.AppendLine($"{val.Name} = {val.LogicalName},"); - } - } - - fc.AppendLine("}"); - } - } - - fc.AppendLine("}"); - File.WriteAllText($"../../../../../{CoreProjectName}/Definitions/OptionSetDefinitions.cs", fc.ToString()); - */ + foreach(var table in _selectedTables) { - //MessageBox.Show(table.Name); - - table.Columns.RemoveNonSelectedColumns(); - - - // To be deleted - //table.isLocked = true; - //foreach (var column in table.Columns) - //{ - // column.IsLocked = true; - //} - //foreach(var en in table.Enums) - //{ - // en.IsLocked = true; - //} - - - var serializedTable = JsonConvert.SerializeObject(table, Formatting.Indented, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore @@ -820,12 +443,6 @@ private void generateDefinitionsToolStripMenuItem_Click(object sender, EventArgs JObject test = JObject.Parse(serializedTable); - //MessageBox.Show(test["LogName"].ToString()); - //MessageBox.Show(test.ToString()); - - - - var fileInfo = new FileInfo($"../../../../../{CoreProjectName}/Definitions/{table.Name}.table"); var definitionFolderForEnums = new DirectoryInfo($"../../../../../{CoreProjectName}/Definitions"); @@ -852,26 +469,7 @@ private void generateDefinitionsToolStripMenuItem_Click(object sender, EventArgs globalOptionSets.Enums.AddRange(_enums.Where(en => globalEnums.Contains(en.LogicalName) && en.IsGlobal)); - //if (globalSelectedEnums.Any()) - //{ - // - // string serializedEnums; - // serializedEnums = JsonConvert.SerializeObject(globalSelectedEnums, Formatting.Indented, new JsonSerializerSettings - // { - // DefaultValueHandling = DefaultValueHandling.Ignore - // }); - // - // var enumFileInfo = new FileInfo($"../../../../../{CoreProjectName}/Definitions/OptionSet.table"); - // - // var definitionFolder = new DirectoryInfo($"../../../../../{CoreProjectName}/Definitions"); - // if (definitionFolder.Exists == false) - // { - // definitionFolder.Create(); - // } - // - // - // File.WriteAllText(enumFileInfo.FullName, serializedEnums); - //} + var serializedGlobalEnums = JsonConvert.SerializeObject(globalOptionSets, Formatting.Indented, new JsonSerializerSettings { @@ -887,27 +485,7 @@ private void generateDefinitionsToolStripMenuItem_Click(object sender, EventArgs } - File.WriteAllText(enumFileInfo.FullName, serializedGlobalEnums); - - string serializedEnums; - serializedEnums = JsonConvert.SerializeObject(globalSelectedEnums, Formatting.Indented, new JsonSerializerSettings - { - DefaultValueHandling = DefaultValueHandling.Ignore - }); - - var enumFileInfo = new FileInfo($"../../../../../{CoreProjectName}/Definitions/OptionSet.table"); - - var definitionFolder = new DirectoryInfo($"../../../../../{CoreProjectName}/Definitions"); - if (definitionFolder.Exists == false) - { - definitionFolder.Create(); - } - - - File.WriteAllText(enumFileInfo.FullName, serializedEnums); - } - - + File.WriteAllText(enumFileInfo.FullName, serializedGlobalEnums); MessageBox.Show(@"Definition files generation succeeded"); } @@ -1005,757 +583,8 @@ public object GetCustomList(Type type) } - // Is now deprecated - private void GenerateDefinitionCodeFromJson() - { - TableCollection tables = new TableCollection(); - List globalEnums = new List(); - List referencedSelectedOptionSet = new List(); - // - //MessageBox.Show($"../../../../../{CoreProjectName}/Definitions"); - FileInfo fileInfo; - String text; - Table currentTable; - foreach (string fileName in Directory.GetFiles($"../../../../../{CoreProjectName}/Definitions", "*.table")) - { - if(!fileName.Contains("OptionSet.table")) - { - //MessageBox.Show(fileName); - fileInfo = new FileInfo(fileName); - text = File.ReadAllText(fileInfo.FullName); - JObject jTable = JObject.Parse(text); - - - currentTable = jTable.ToObject
(); - /*currentTable = JsonConvert.DeserializeObject
(text,new JsonSerializerSettings - { - DefaultValueHandling = DefaultValueHandling.Ignore - });*/ - - if (jTable["Cols"].Any()) - { - Column currentColumn; - foreach (var jColumn in jTable["Cols"]) - { - currentColumn = jColumn.ToObject(); - currentTable.Columns.Add(currentColumn); - } - } - tables.Add(currentTable); - } - else - { - fileInfo = new FileInfo(fileName); - text = File.ReadAllText(fileInfo.FullName); - globalEnums = JsonConvert.DeserializeObject>(text, new JsonSerializerSettings - { - DefaultValueHandling = DefaultValueHandling.Ignore - }); - //MessageBox.Show($"There are {globalEnums.Count} enums"); - } - - } - - - - - foreach (var table in tables) - { - var sb = new IndentedStringBuilder(); - - sb.AppendLine(""); - sb.AppendLine("using System;"); - sb.AppendLine("using System.CodeDom.Compiler;"); - sb.AppendLine("using System.ComponentModel.DataAnnotations;"); - sb.AppendLine("using System.Diagnostics.CodeAnalysis;"); - sb.AppendLine("using System.ComponentModel;"); - sb.AppendLine("using XrmFramework;"); - sb.AppendLine(); - sb.AppendLine($"namespace {CoreProjectName}"); - sb.AppendLine("{"); - - using (sb.Indent()) - { - - sb.AppendLine("[GeneratedCode(\"XrmFramework\", \"2.0\")]"); - sb.AppendLine("[EntityDefinition]"); - sb.AppendLine("[ExcludeFromCodeCoverage]"); - - - sb.AppendLine($"public static partial class {table.Name}Definition"); - sb.AppendLine("{"); - - using (sb.Indent()) - { - - sb.AppendLine($"public const string EntityName = \"{table.LogicalName}\";"); - sb.AppendLine($"public const string EntityCollectionName = \"{table.CollectionName}\";"); - - // foreach (var t in item.AdditionalInfoCollection.Definitions) - // { - // sb.AppendLine(); - // sb.AppendLine( - // $"public const {t.Type} {t.Name} = {(t.Type == "String" ? "\"" + (string)t.Value + "\"" : t.Value)};"); - // } - - sb.AppendLine(); - sb.AppendLine("[SuppressMessage(\"Microsoft.Design\", \"CA1034:NestedTypesShouldNotBeVisible\")]"); - sb.AppendLine("public static class Columns"); - sb.AppendLine("{"); - - using (sb.Indent()) - { - - foreach (var col in table.Columns) - { - - AddColumnSummary(sb, col); - if (col.Type != null) - { - - sb.AppendLine($"[AttributeMetadata(AttributeTypeCode.{col.Type.ToString()})]"); - if (col.Type == AttributeTypeCode.Lookup) - { - var relation = table.ManyToOneRelationships.FirstOrDefault(r => r.LookupFieldName == col.LogicalName); - if (relation != null) - { - var tb = tables.FirstOrDefault(t => t.LogicalName == relation.EntityName); - //var eC = this._entityCollection[relationship.ReferencedEntity]; - var rcol = tb?.Columns.FirstOrDefault(c => c.PrimaryType == PrimaryType.Id); - - if (tb != null) - { - sb.Append($"[CrmLookup({tb.Name}Definition.EntityName,"); - if (rcol != null) - { - sb.Append($"{tb.Name}Definition.Columns.{rcol.Name},"); - } - else - { - throw new Exception("No primaryType was found for the referenced table"); - sb.Append($"{relation.LookupFieldName},"); - } - - } - else - { - sb.Append($"[CrmLookup(\"{relation.EntityName}\","); - sb.Append($"\"{relation.LookupFieldName}\","); - - } - sb.AppendLine($"RelationshipName = ManyToOneRelationships.{relation.Name})]"); - - - } - else - { - MessageBox.Show("The corresponding relationShip is null ??"); - } - - - - - } - - - - } - - - - if (col.PrimaryType == PrimaryType.Id) - { - sb.AppendLine("[PrimaryAttribute(PrimaryAttributeType.Id)]"); - } - if (col.EnumName != null && col.EnumName != "") - { - foreach(var e in table.Enums) - { - if(e.LogicalName == col.EnumName) - { - - sb.AppendLine($"[OptionSet(typeof({e.Name}))]"); - break; - } - } - - - } - - if (col.PrimaryType == PrimaryType.Name) - { - sb.AppendLine("[PrimaryAttribute(PrimaryAttributeType.Name)]"); - } - - if (col.PrimaryType == PrimaryType.Image) - { - sb.AppendLine("[PrimaryAttribute(PrimaryAttributeType.Image)]"); - } - if (col.StringLength.HasValue) - { - sb.AppendLine($"[StringLength({col.StringLength.Value})]"); - } - - if (col.MinRange.HasValue && col.MaxRange.HasValue) - { - sb.AppendLine($"[Range({col.MinRange.Value}, {col.MaxRange.Value})]"); - } - - if(table.Keys != null) - { - foreach (var key in table.Keys) - { - if (key.FieldNames.FirstOrDefault(n => n == col.LogicalName) != null) - { - // Write a corresonding line - sb.AppendLine($"[AlternateKey(AlternateKeyNames.{key.Name})]"); - } - } - } - - - if (col.DateTimeBehavior != null) - { - var behavior = string.Empty; - if (col.DateTimeBehavior == DateTimeBehavior.DateOnly) - { - behavior = "DateOnly"; - } - else if (col.DateTimeBehavior == - DateTimeBehavior.TimeZoneIndependent) - { - behavior = "TimeZoneIndependent"; - } - else if (col.DateTimeBehavior == - DateTimeBehavior.UserLocal) - { - behavior = "UserLocal"; - } - - sb.AppendLine($"[DateTimeBehavior(DateTimeBehavior.{behavior})]"); - } - - sb.AppendLine($"public const string {col.Name} = \"{col.LogicalName}\";\r\n"); - } - - - - - - - - } - - sb.AppendLine("}"); - - //if(table.Enums.Any(e=>table.Columns.Any()) - - if (table.Keys != null && table.Keys.Any()) - { - sb.AppendLine("[SuppressMessage(\"Microsoft.Design\", \"CA1034:NestedTypesShouldNotBeVisible\")]"); - sb.AppendLine("public static class AlternateKeyNames"); - sb.AppendLine("{"); - using (sb.Indent()) - { - foreach (var key in table.Keys) - { - sb.AppendLine($"public const string {key.Name} = \"{key.LogicalName}\";\r\n"); - } - } - sb.AppendLine("}"); - } - - if (table.ManyToOneRelationships.Any()) - { - sb.AppendLine("public static class ManyToOneRelationships"); - sb.AppendLine("{"); - using (sb.Indent()) - { - foreach (var relationship in table.ManyToOneRelationships) - { - sb.Append("[Relationship("); - var targetTable = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - if (targetTable != null) - { - sb.Append($"{targetTable.Name}Definition.EntityName"); - } - else - { - sb.Append($"\"{relationship.EntityName}\""); - } - - sb.Append($", EntityRole.{relationship.Role}, \"{relationship.NavigationPropertyName}\", "); - - if (relationship.Role == EntityRole.Referencing) - { - var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - - - //var re = tb?.OneToManyRelationships.FirstOrDefault(r => r.Name == relationship.Name); - var rc = table.Columns.FirstOrDefault(c => c.LogicalName == relationship.LookupFieldName); - - if (rc != null) - { - sb.Append($"{table.Name}Definition.Columns.{rc.Name}"); - } - else - { - sb.Append($"\"{relationship.LookupFieldName}\""); - } - } - else - { - var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - var rc = table.Columns.FirstOrDefault(c => c.LogicalName == relationship.LookupFieldName); - - //var r = tb?.OneToManyRelationships.FirstOrDefault(r => r.Name == relationship.Name); - - - if (rc != null) - { - sb.Append($"{table.Name}Definition.Columns.{rc.Name}"); - } - else - { - sb.Append($"\"{relationship.LookupFieldName}\""); - } - } - - sb.AppendLine(")]"); - sb.AppendLine($"public const string {relationship.Name} = \"{relationship.Name}\";"); - } - - - } - sb.AppendLine("}"); - } - - - if (table.ManyToManyRelationships.Any()) - { - sb.AppendLine("public static class ManyToManyRelationships"); - sb.AppendLine("{"); - using (sb.Indent()) - { - foreach (var relationship in table.ManyToManyRelationships) - { - sb.Append("[Relationship("); - var targetTable = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - if (targetTable != null) - { - sb.Append($"{targetTable.Name}Definition.EntityName"); - } - else - { - sb.Append($"\"{relationship.EntityName}\""); - } - - sb.Append($", EntityRole.{relationship.Role}, \"{relationship.NavigationPropertyName}\", "); - - if (relationship.Role == EntityRole.Referencing) - { - var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - var rc = tb?.Columns.FirstOrDefault(c => c.LogicalName == relationship.LookupFieldName); - - - //var re = tb?.ManyToManyRelationships.FirstOrDefault(r => r.Name == relationship.Name); - - - if (rc != null) - { - sb.Append($"{tb.Name}Definition.Columns.{rc.Name}"); - } - else - { - sb.Append($"\"{relationship.LookupFieldName}\""); - } - } - else - { - var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - - var rc = tb?.Columns.FirstOrDefault(c => c.LogicalName == relationship.LookupFieldName); - - - if (rc != null) - { - sb.Append($"{tb.Name}Definition.Columns.{rc.Name}"); - } - else - { - sb.Append($"\"{relationship.LookupFieldName}\""); - } - } - - sb.AppendLine(")]"); - sb.AppendLine($"public const string {relationship.Name} = \"{relationship.Name}\";"); - } - } - sb.AppendLine("}"); - } - if (table.OneToManyRelationships.Any()) - { - sb.AppendLine("public static class OneToManyRelationships"); - sb.AppendLine("{"); - using (sb.Indent()) - { - foreach (var relationship in table.OneToManyRelationships) - { - sb.Append("[Relationship("); - var targetTable = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - if (targetTable != null) - { - sb.Append($"{targetTable.Name}Definition.EntityName"); - } - else - { - sb.Append($"\"{relationship.EntityName}\""); - } - - sb.Append($", EntityRole.{relationship.Role}, \"{relationship.NavigationPropertyName}\", "); - - if (relationship.Role == EntityRole.Referencing) - { - var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - var rc = tb?.Columns.FirstOrDefault(c => c.LogicalName == relationship.LookupFieldName); - - - //var re = tb?.ManyToOneRelationships.FirstOrDefault(r => r.Name == relationship.Name); - - - if (rc != null) - { - sb.Append($"{tb.Name}Definition.Columns.{rc.Name}"); - } - else - { - sb.Append($"\"{relationship.LookupFieldName}\""); - } - } - else - { - var tb = tables.FirstOrDefault(t => t.LogicalName == relationship.EntityName); - - //var re = tb?.ManyToOneRelationships.FirstOrDefault(r => r.Name == relationship.Name); - var rc = tb?.Columns.FirstOrDefault(c => c.LogicalName == relationship.LookupFieldName); - - - if (rc != null) - { - sb.Append($"{tb.Name}Definition.Columns.{rc.Name}"); - } - else - { - sb.Append($"\"{relationship.LookupFieldName}\""); - } - } - - sb.AppendLine(")]"); - sb.AppendLine($"public const string {relationship.Name} = \"{relationship.Name}\";"); - } - } - sb.AppendLine("}"); - } - - if(table.Enums.Any()) - { - foreach (var ose in table.Enums) - { - sb.AppendLine(); - if (ose.IsGlobal) - { - continue; - } - else - { - var referencedColumns = table.Columns.Where(c => c.EnumName == ose.LogicalName); - //var attribute = def.ReferencedBy.First(); - - if (!referencedColumns.Any()) - { - continue; - } - foreach(var col in referencedColumns) - { - sb.AppendLine(string.Format("[OptionSetDefinition({0}Definition.EntityName, {0}Definition.Columns.{1})]", - table.Name, col.Name)); - } - - } - - sb.AppendLine($"public enum {ose.Name}"); - sb.AppendLine("{"); - - using (sb.Indent()) - { - - if (ose.HasNullValue) - { - sb.AppendLine("Null = 0,"); - } - - foreach (var val in ose.Values) - { - sb.AppendLine($"[Description(\"{val.Name}\")]"); - - if (!string.IsNullOrEmpty(val.ExternalValue)) - { - sb.AppendLine($"[ExternalValue(\"{val.ExternalValue}\")]"); - } - - sb.AppendLine($"{val.Name} = {val.Value},"); - } - } - - sb.AppendLine("}"); - } - - } - - - } - - sb.AppendLine("}"); - } - - sb.AppendLine("}"); - - - - var classFileInfo = new FileInfo($"../../../../../{CoreProjectName}/Definitions/{table.Name}.table.cs"); - - var definitionFolder = new DirectoryInfo($"../../../../../{CoreProjectName}/Definitions"); - if (definitionFolder.Exists == false) - { - definitionFolder.Create(); - } - - File.WriteAllText(classFileInfo.FullName, sb.ToString()); - - - - - - - } - - var fc = new IndentedStringBuilder(); - fc.AppendLine("using System.ComponentModel;"); - fc.AppendLine("using XrmFramework;"); - fc.AppendLine(); - fc.AppendLine($"namespace {CoreProjectName}"); - fc.AppendLine("{"); - - using (fc.Indent()) - { - foreach (var ose in globalEnums) - { - fc.AppendLine(); - if (ose.IsGlobal) - { - fc.AppendLine($"[OptionSetDefinition(\"{ose.LogicalName}\")]"); - } - else - { - continue; - } - - fc.AppendLine($"public enum {ose.Name}"); - fc.AppendLine("{"); - - using (fc.Indent()) - { - - if (ose.HasNullValue) - { - fc.AppendLine("Null = 0,"); - } - - foreach (var val in ose.Values) - { - fc.AppendLine($"[Description(\"{val.Name}\")]"); - - if (!string.IsNullOrEmpty(val.ExternalValue)) - { - fc.AppendLine($"[ExternalValue(\"{val.ExternalValue}\")]"); - } - - fc.AppendLine($"{val.Name} = {val.Value},"); - } - } - - fc.AppendLine("}"); - } - } - fc.AppendLine("}"); - - - var optionSetFileInfo = new FileInfo($"../../../../../{CoreProjectName}/Definitions/OptionSet.table.cs"); - - File.WriteAllText(optionSetFileInfo.FullName, fc.ToString()); - MessageBox.Show("Finished writing option set"); - - - - - - - - //MessageBox.Show(sb.ToString()); - } - - public List
GetTablesFromFormerDefinitionCode() - { - MessageBox.Show("Going to try to get coded entity defs"); - - List
localTables = new List
(); - //MessageBox.Show("Getting "); - // Get entity definitions - var definitionsToBeConverted = GetCodedEntityDefinitions(); - Table table; - Column column; - Relation relation; - - foreach(var entity in definitionsToBeConverted) - { - table = new Table() - { - LogicalName = entity.LogicalName, - CollectionName = entity.LogicalCollectionName, - Name = entity.Name.Replace("Definition",""), - Selected = true, - - - }; - - - foreach (var def in entity.AdditionalClassesCollection.Definitions) - { - if (def.IsEnum) - { - - } - - } - - - // Assign columns - foreach (var attr in entity.AttributesCollection.Definitions) - { - column = new Column() - { - LogicalName = attr.LogicalName, - Name = attr.Name, - - - Selected = true, - //Delete this line after generation of base tables - //IsLocked = true, - - }; - - - table.Columns.Add(column); - /* - // Assign Primary type - if(attr.IsPrimaryIdAttribute) - { - column.PrimaryType = PrimaryType.Id; - } - else if(attr.IsPrimaryImageAttribute) - { - column.PrimaryType = PrimaryType.Image; - } - else if(attr.IsPrimaryNameAttribute) - { - column.PrimaryType = PrimaryType.Name; - } - else - { - column.PrimaryType = PrimaryType.None; - } - - // Assign AttributeTypeCode Type - if(!string.IsNullOrEmpty(attr.Type)) - { - column.Type = (AttributeTypeCode)Enum.Parse(typeof(AttributeTypeCode), attr.Type); - } - //Assign Capabilities - if(attr.IsValidForAdvancedFind) - { - column.Capabilities |= AttributeCapabilities.AdvancedFind; - } - if (attr.IsValidForCreate) - { - column.Capabilities |= AttributeCapabilities.Create; - } - if (attr.IsValidForRead) - { - column.Capabilities |= AttributeCapabilities.Read; - } - if (attr.IsValidForUpdate) - { - column.Capabilities |= AttributeCapabilities.Update; - } - // Assign Labels ? - - // Assign StringLength - column.StringLength = attr.StringMaxLength; - // Assign MinRange - column.MinRange = attr.MinRange; - // Assign MaxRange - column.MaxRange = attr.MaxRange; - // DateTimeBehavior - column.DateTimeBehavior = attr.DateTimeBehavior; - //IsMultiSelect ? - - //EnumName - column.EnumName = attr.EnumName; - //Selected - column.Selected = true; - if(attr.Relationships != null && attr.Relationships.Any()) - { - column.Type = AttributeTypeCode.Lookup; - } - - // Assign keys - if(attr.KeyNames != null && attr.KeyNames.Any()) - { - foreach(var keyAttr in attr.KeyNames) - { - var correspondingkey = table.Keys.FirstOrDefault(k => k.Name == keyAttr); - if (correspondingkey != null) - { - correspondingkey.FieldNames.Add(attr.LogicalName); - } - } - }*/ - } - - - - - - // Assign Enums - - // Assign selected - table.Selected = true; - - localTables.Add(table); - } - - - // Penser aussi à checker pour récupérer les enums globaux s'il y en a; ou juste a les mettre en tant qu'enum selectionné - - - - return localTables; - } - - - - + private EntityDefinition TableToBaseEntityDefinition(Table table) { var entityDefinition = new EntityDefinition() @@ -1773,8 +602,7 @@ private EntityDefinition TableToBaseEntityDefinition(Table table) DisplayName = col.Name, LogicalName = col.LogicalName, Name = col.Name, - IsSelected=true, - + IsSelected=col.Selected, }; entityDefinition.Add(attributeDefinition); @@ -1798,12 +626,11 @@ private Table EntityDefinitionToBaseTable(EntityDefinition entity) foreach (var attr in entity.AttributesCollection.Definitions) { - column = new Column() { LogicalName = attr.LogicalName, Name = attr.Name, - + Selected = attr.IsSelected, }; // Assign Primary type @@ -1905,10 +732,7 @@ public TableCollection LoadLocalTables() var currentTable = jTable.ToObject
(); - /*currentTable = JsonConvert.DeserializeObject
(text,new JsonSerializerSettings - { - DefaultValueHandling = DefaultValueHandling.Ignore - });*/ + if (jTable["Cols"].Any()) { @@ -1923,15 +747,7 @@ public TableCollection LoadLocalTables() } else { - /* - fileInfo = new FileInfo(fileName); - text = File.ReadAllText(fileInfo.FullName); - globalEnums = JsonConvert.DeserializeObject>(text, new JsonSerializerSettings - { - DefaultValueHandling = DefaultValueHandling.Ignore - }); - MessageBox.Show($"There are {globalEnums.Count} enums"); - */ + } } @@ -1942,116 +758,21 @@ public TableCollection LoadLocalTables() return tables; } + private void getEntitiesFromCRMToolStripMenuItem_Click(object sender, EventArgs e) + { + this.generateDefinitionsToolStripMenuItem.Enabled = false; + this.entityListView.Enabled = false; + this.attributeListView.Enabled = false; + this.getEntitiesFromCRMToolStripMenuItem.Enabled = false; + DataAccessManager.Instance.Connect(ConnectionSucceeded); + + } - //public void MergeLocalTablesWithCrmData(TableCollection localTables) - // - // // Merge with TableCollection - // foreach (Table table in localTables) - // { - // var correspondingTable = _tables.FirstOrDefault(t => t.LogicalName == table.LogicalName); - // if (correspondingTable != null) - // { - // correspondingTable.Name = table.Name; - // correspondingTable.Selected = true; - // foreach(var col in table.Columns) - // { - // var correspondingCol = correspondingTable.Columns.FirstOrDefault(c => c.LogicalName == col.LogicalName); - // if(correspondingCol != null) - // { - // correspondingCol.Name = col.Name; - // correspondingCol.Selected = true; - // } - // } - // } - // - // var correspondingEntity = _entityCollection[table.LogicalName]; - // correspondingEntity.IsSelected = true; - // //MessageBox.Show("Has just tried to set IsSelected to true"); - // - // if(correspondingEntity != null) - // { - // _entityCollection[table.LogicalName].IsSelected = true; - // //MessageBox.Show("Has just tried to set IsSelected to true"); - // - // correspondingEntity.Name = table.Name+"Definition ocajociaz"; - // foreach( var col in table.Columns) - // { - // var correspondingAttribute = correspondingEntity.AttributesCollection[col.LogicalName]; - // if(correspondingAttribute != null) - // { - // correspondingAttribute.IsSelected = true; - // correspondingAttribute.Name = col.Name + "ovnhzeo"; - // } - // } - // } - // - // } - // - // - // - // - // + } } -/*var fc = new IndentedStringBuilder(); - fc.AppendLine("using System.ComponentModel;"); - fc.AppendLine("using XrmFramework;"); - fc.AppendLine(); - fc.AppendLine($"namespace {CoreProjectName}"); - fc.AppendLine("{"); - - using (fc.Indent()) - { - foreach (var ose in enums) - { - fc.AppendLine(); - if (ose.IsGlobal) - { - fc.AppendLine($"[OptionSetDefinition(\"{ose.LogicalName}\")]"); - } - else - { - var attribute = ose.ReferencedBy.First(); - - if (!_entityCollection.SelectedDefinitions.Any(s => s.LogicalName == attribute.ParentEntity.LogicalName)) - { - continue; - } - - fc.AppendLine(string.Format("[OptionSetDefinition({0}.EntityName, {0}.Columns.{1})]", - attribute.ParentEntity.Name, attribute.Name)); - } - - fc.AppendLine($"public enum {ose.Name}"); - fc.AppendLine("{"); - - using (fc.Indent()) - { - - if (ose.HasNullValue) - { - fc.AppendLine("Null = 0,"); - } - - foreach (var val in ose.Values) - { - fc.AppendLine($"[Description(\"{val.Name}\")]"); - - if (!string.IsNullOrEmpty(val.ExternalValue)) - { - fc.AppendLine($"[ExternalValue(\"{val.ExternalValue}\")]"); - } - - fc.AppendLine($"{val.Name} = {val.Value},"); - } - } - - fc.AppendLine("}"); - } - } - fc.AppendLine("}");*/ diff --git a/src/XrmFramework.DefinitionManager/Managers/DataAccessManager.cs b/src/XrmFramework.DefinitionManager/Managers/DataAccessManager.cs index 4fed7a70..c214b719 100644 --- a/src/XrmFramework.DefinitionManager/Managers/DataAccessManager.cs +++ b/src/XrmFramework.DefinitionManager/Managers/DataAccessManager.cs @@ -223,6 +223,7 @@ object DoRetrieveEntities(object arg) } } + var lookupFields = new Dictionary>(); if (entity.ManyToOneRelationships.Any()) { @@ -273,6 +274,7 @@ object DoRetrieveEntities(object arg) } } + // bar 2 entities.Add(entityDefinition); newEntities.Add(newEntity); @@ -560,6 +562,8 @@ object DoRetrieveEntities(object arg) object DoRetrieveAttributes(object item) { + var list = new List(); + return list; var i = item as EntityDefinition; SendStepChange(string.Format("Retrieving '{0}' attributes...", i.LogicalName)); @@ -573,7 +577,7 @@ object DoRetrieveAttributes(object item) var response = (RetrieveEntityResponse)_service.Execute(request); - var list = new List(); + foreach (AttributeMetadata attributeMetadata in response.EntityMetadata.Attributes.OrderBy(a => a.LogicalName)) { diff --git a/src/XrmFramework.ModelManager/ModelManager.cs b/src/XrmFramework.ModelManager/ModelManager.cs index f453b00d..fe3a2060 100644 --- a/src/XrmFramework.ModelManager/ModelManager.cs +++ b/src/XrmFramework.ModelManager/ModelManager.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Windows; using XrmFramework.Core; namespace XrmFramework.ModelManager @@ -110,7 +111,7 @@ public static void TestBindingModelGeneration(string CoreProjectName) var hasCorrespondingTable = false; foreach (var table in tables) { - if (table.LogicalName == model.tableLogicalName) ; + if (table.LogicalName == model.TableLogicalName) ; { hasCorrespondingTable |= true; } @@ -127,10 +128,10 @@ public static void TestBindingModelGeneration(string CoreProjectName) { // Create start of class var sb = new IndentedStringBuilder(); - var correspondingTable = tables.FirstOrDefault(t => t.LogicalName == model.tableLogicalName); + var correspondingTable = tables.FirstOrDefault(t => t.LogicalName == model.TableLogicalName); if(correspondingTable == null) { - throw new Exception("The table corresponding to this model was not found, its logical name is : " + model.tableLogicalName); + throw new Exception("The table corresponding to this model was not found, its logical name is : " + model.TableLogicalName); } sb.AppendLine(""); sb.AppendLine("using System;"); @@ -185,7 +186,7 @@ public static void TestBindingModelGeneration(string CoreProjectName) if (correspondingColumn != null) { //This property is a column sb.Append($"[CrmMapping({correspondingTable.Name}Definition.Columns.{correspondingColumn.Name}");//)]"); - if(prop.isValidForUpdate) + if(prop.IsValidForUpdate) { sb.Append(")]"); @@ -238,15 +239,15 @@ public static void TestBindingModelGeneration(string CoreProjectName) sb.AppendLine($"[ChildRelationship({correspondingTable.Name}Definition.OneToManyRelationships.{correspondingRelation.NavigationPropertyName})]"); } - if (prop.jsonName != null) + if (prop.JsonPropertyName != null) { - sb.AppendLine($"[JsonProperty(\"{prop.jsonName}\")]"); + sb.AppendLine($"[JsonProperty(\"{prop.JsonPropertyName}\")]"); } // Add other possible attributes - if (!prop.isValidForUpdate) + if (!prop.IsValidForUpdate) { // Write regular declaration if (correspondingColumn != null) @@ -321,7 +322,7 @@ public List<{prop.TypeFullName}> {prop.Name} sb.AppendLine("#region Fields"); - foreach (var prop in model.Properties.Where(p => p.isValidForUpdate)) + foreach (var prop in model.Properties.Where(p => p.IsValidForUpdate)) { //Add the corresponding field var correspondingColumn = correspondingTable.Columns.FirstOrDefault(c => c.LogicalName == prop.LogicalName); @@ -377,10 +378,10 @@ private static void GetFilesFromFolder(String folderPath, string extension, List private static Model CreateModelFromTable(Table table) { Model model = new Model(); - model.tableLogicalName = table.LogicalName; + model.TableLogicalName = table.LogicalName; // Temporaire model.Name = table.Name; // A modifier - model.Properties = new List(); + //model.Properties = new List(); //foreach (var col in table.Columns) //{ // var prop = new ModelProperty(); @@ -425,7 +426,7 @@ public static void AddModelProperty(Model model, Table table, string propertyLog } } - prop.isValidForUpdate = true; + prop.IsValidForUpdate = true; model.Properties.Add(prop); } @@ -437,22 +438,22 @@ public static void AddModelProperty(Model model, Table table, string propertyLog prop.LogicalName = rel.Name; prop.Name = rel.Name; - prop.isValidForUpdate = true; + prop.IsValidForUpdate = true; model.Properties.Add(prop); } } - public static void SetPropertyJsonName(Model model, string propertyLogicalName, string jsonName) + public static void SetPropertyJsonPropertyName(Model model, string propertyLogicalName, string JsonPropertyName) { var prop = model.Properties.FirstOrDefault(p => p.LogicalName == propertyLogicalName); - prop.Name = jsonName; + prop.Name = JsonPropertyName; } public static void ToggleOnPropertyChanged(Model model, string propertyLogicalName) { var prop = model.Properties.FirstOrDefault(p => p.LogicalName == propertyLogicalName); - prop.isValidForUpdate = !prop.isValidForUpdate; + prop.IsValidForUpdate = !prop.IsValidForUpdate; } public static void SelectPropertyType(Model model, ModelProperty property, AttributeTypeCode type) @@ -467,8 +468,8 @@ public static List GetPossiblePropertyTypes(Model model, ModelProperty p OptionSetEnum SecondEnum; var possibleTypes = new List(); - - var table = Tables.FirstOrDefault(t => t.LogicalName == model.tableLogicalName); + + var table = Tables.FirstOrDefault(t => t.LogicalName == model.TableLogicalName); if (table == null) { return possibleTypes; @@ -488,7 +489,7 @@ public static List GetPossiblePropertyTypes(Model model, ModelProperty p foreach (var possibleModel in Models) { - if (possibleModel.tableLogicalName == relation.EntityName) + if (possibleModel.TableLogicalName == relation.EntityName) { possibleTypes.Add($"{CoreProjectName}.{possibleModel.ModelNamespace}.{possibleModel.Name}"); @@ -534,8 +535,8 @@ public static List GetPossiblePropertyTypes(Model model, ModelProperty p break; case AttributeTypeCode.Lookup: //Get the corresponding relation, find the corresponding model if it exists - - + + var re = table.ManyToOneRelationships.FirstOrDefault(r => r.LookupFieldName == column.LogicalName); if (re == null) { @@ -543,8 +544,9 @@ public static List GetPossiblePropertyTypes(Model model, ModelProperty p } foreach(var possibleModel in Models) { - if(possibleModel.tableLogicalName == re.EntityName) + if(possibleModel.TableLogicalName == re.EntityName) { + possibleTypes.Add($"{CoreProjectName}.{possibleModel.ModelNamespace}.{possibleModel.Name}"); } @@ -980,7 +982,7 @@ public static void CLI_AddProperty(Model model) // Choose relation or column property string userInput; int intInput; - var table = Tables.FirstOrDefault(t => t.LogicalName == model.tableLogicalName); + var table = Tables.FirstOrDefault(t => t.LogicalName == model.TableLogicalName); ModelProperty newProperty = new ModelProperty(); if(table == null) { @@ -1027,29 +1029,29 @@ public static void CLI_AddProperty(Model model) newProperty.Name = userInput; - Console.WriteLine("Enter p to set isValidForUpdate to true, enter anything else to not"); + Console.WriteLine("Enter p to set IsValidForUpdate to true, enter anything else to not"); if (Console.ReadLine() == "p") { - newProperty.isValidForUpdate = true; + newProperty.IsValidForUpdate = true; //Check if any other common crm mapping is true - var similarMapping = model.Properties.FirstOrDefault(p => p.LogicalName == newProperty.LogicalName && p.isValidForUpdate); + var similarMapping = model.Properties.FirstOrDefault(p => p.LogicalName == newProperty.LogicalName && p.IsValidForUpdate); if(similarMapping != null) { //Choose the right one do { - Console.WriteLine($"Another property named {similarMapping.Name} connected to the same crm property already has isValidForUpdate set to true, do you want to switch it to false in order to set it to true for your property {newProperty.Name} ? (y/n)"); + Console.WriteLine($"Another property named {similarMapping.Name} connected to the same crm property already has IsValidForUpdate set to true, do you want to switch it to false in order to set it to true for your property {newProperty.Name} ? (y/n)"); userInput = Console.ReadLine(); } while(userInput != "y" && userInput != "n"); if(userInput == "y") { - similarMapping.isValidForUpdate = false; - newProperty.isValidForUpdate = true; + similarMapping.IsValidForUpdate = false; + newProperty.IsValidForUpdate = true; } else { - newProperty.isValidForUpdate = false; + newProperty.IsValidForUpdate = false; } @@ -1057,17 +1059,17 @@ public static void CLI_AddProperty(Model model) } else { - newProperty.isValidForUpdate = false; + newProperty.IsValidForUpdate = false; } Console.WriteLine("If you want this property to be serialized, enter a name, otherwise press enter"); userInput = Console.ReadLine(); - var samejsonProperty = model.Properties.FirstOrDefault(p=>p.jsonName == userInput); + var samejsonProperty = model.Properties.FirstOrDefault(p=>p.JsonPropertyName == userInput); if (userInput != "" && samejsonProperty != null) { - newProperty.jsonName = userInput; + newProperty.JsonPropertyName = userInput; } var possibleTypes = GetPossiblePropertyTypes(model, newProperty); @@ -1140,18 +1142,18 @@ public static void CLI_AddProperty(Model model) Console.WriteLine("Enter p to use onPropertyChanged (only works if model.isBindingModelBase is true), enter anything to not"); if (Console.ReadLine() == "p") { - newProperty.isValidForUpdate = true; + newProperty.IsValidForUpdate = true; } else { - newProperty.isValidForUpdate = false; + newProperty.IsValidForUpdate = false; } Console.WriteLine("If you want this property to be serialized, enter a name, otherwise press enter"); userInput = Console.ReadLine(); if (userInput != "") { - newProperty.jsonName = userInput; + newProperty.JsonPropertyName = userInput; } var possibleTypes = GetPossiblePropertyTypes(model, newProperty); @@ -1206,7 +1208,7 @@ public static void CLI_EditProperty(Model model) { Console.WriteLine("a : modify Name"); Console.WriteLine("b : toggle use onPropertyChanged"); - Console.WriteLine("c : modify jsonName"); + Console.WriteLine("c : modify JsonPropertyName"); Console.WriteLine("d : modify type name"); Console.WriteLine("e : exit"); userInput = Console.ReadLine(); @@ -1230,31 +1232,31 @@ public static void CLI_EditProperty(Model model) Console.WriteLine("Enter u to use onPropertyChanged, anything else to not"); if(userInput == "u") { - property.isValidForUpdate = true; + property.IsValidForUpdate = true; } else { - property.isValidForUpdate = false; + property.IsValidForUpdate = false; } } else if(userInput=="c") { - // Modify JsonName + // Modify JsonPropertyName ModelProperty sameProperty; do { Console.WriteLine("Enter the new name for your property"); userInput = Console.ReadLine(); - sameProperty = model.Properties.FirstOrDefault(p => p.jsonName == userInput); + sameProperty = model.Properties.FirstOrDefault(p => p.JsonPropertyName == userInput); } while (sameProperty != null); if(userInput != "") { - property.jsonName = userInput; + property.JsonPropertyName = userInput; } else { - property.jsonName = null; + property.JsonPropertyName = null; } diff --git a/src/XrmFramework.XrmToolbox.Plugin/DataHandlers/ModelHandler.cs b/src/XrmFramework.XrmToolbox.Plugin/DataHandlers/ModelHandler.cs new file mode 100644 index 00000000..b61452c2 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/DataHandlers/ModelHandler.cs @@ -0,0 +1,481 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using XrmFramework.Core; +using XrmFramework.XrmToolbox.Forms; +using Model = XrmFramework.Core.Model; + + +namespace XrmFramework.XrmToolbox.DataHandlers + +{ + public static class ModelHandler + { + public static Dictionary ModelAndPath = new Dictionary(); + public static List PreexistingModelPaths = new List(); + public static XrmFrameworkPluginControl PluginControl; + public static string PathToRegisterModel; + private static SortedSet existingNamespaces = new SortedSet(); + public static void LoadModelsFromProject(string projectPath) + { + foreach (var fileName in Directory.GetFiles($"{projectPath}", "*.model", SearchOption.AllDirectories)) + { + PreexistingModelPaths.Add(fileName); + + //MessageBox.Show(fileName); + var fileInfo = new FileInfo(fileName); + var text = File.ReadAllText(fileInfo.FullName); + var model = JsonConvert.DeserializeObject(text); + + var splitFilename = fileName.Split('\\').ToList(); + splitFilename.RemoveAt(splitFilename.Count - 1); + var path = RemoveCurrentProjectPathFromModelPath(string.Join("\\", splitFilename), projectPath); + //var rootPath = projectPath; + //var splitRootPath = rootPath.Split('\\').ToList(); + //splitRootPath.Remove(splitRootPath.ElementAt(splitRootPath.Count - 1)); + //rootPath = String.Join("\\", splitRootPath); + ModelAndPath[model.Name] = new ModelData(model,path); + if(!string.IsNullOrEmpty(model.ModelNamespace)) + { + existingNamespaces.Add(model.ModelNamespace); + } + + + + } + + + } + + public static void AddModel() + { + var createModelForm = new CreateModelForm(); + createModelForm.PluginControl = PluginControl; + TableCollection tables = new TableCollection(); + foreach(var key in TableHandler.TableAndPath.Keys) + { + tables.Add(TableHandler.TableAndPath[key].table); + } + createModelForm.SetTableBindingSource(tables); + createModelForm.SetExistingNamespaces(existingNamespaces.ToList()); + createModelForm.FormClosing += (s, e) =>{ + if(!createModelForm.CreateModel) + { + return; + } + // Create the model + var model = new XrmFramework.Core.Model() + { + TableLogicalName = createModelForm.tableLogicalName, + ModelNamespace = createModelForm.modelNamespace, + Name = createModelForm.modelName, + }; + var table = TableHandler.TableAndPath[model.TableLogicalName].table; + var idCol = table.Columns.FirstOrDefault(c => c.PrimaryType == PrimaryType.Id); + if (idCol == null) + { + throw new Exception("Error, table id corresponding to model was not found"); + } + var idProperty = new ModelProperty(); + idProperty.Name = "Id"; + idProperty.LogicalName = idCol.LogicalName; + idProperty.TypeFullName = "Guid"; + + var nameCol = table.Columns.FirstOrDefault(c=>c.PrimaryType == PrimaryType.Name); + //idProperty.JsonPropertyName = + var nameProperty = new ModelProperty(); + + if (nameCol == null) + { + throw new Exception("Error, table name corresponding to model was not found"); + } + nameProperty.Name = "Name"; + nameProperty.LogicalName = nameCol.LogicalName; + nameProperty.TypeFullName = "string"; + model.Properties.Add(nameProperty); + model.Properties.Add(idProperty); + + // Create the path to register it + ModelAndPath[model.Name] = new ModelData(model, ModelHandler.RemoveCurrentProjectPathFromModelPath(ModelHandler.PathToRegisterModel, PluginControl.CurrentProject.FolderPath)); + existingNamespaces.Add(model.ModelNamespace); + PluginControl.RefreshModelsDisplay(); + + }; + createModelForm.ShowDialog(); + } + public static string RemoveCurrentProjectPathFromModelPath(string path, string projectPath) + { + var splitPath = path.Split('\\'); + var rootPath = projectPath; + var splitRootPath = rootPath.Split('\\').ToList(); + splitRootPath.Remove(splitRootPath.ElementAt(splitRootPath.Count - 1)); + rootPath = String.Join("\\", splitRootPath); + return path.Replace(rootPath.Trim('\\'), ""); + } + + public static void SaveModels() + { + if(string.IsNullOrEmpty(PathToRegisterModel)) + { + + return; + } + if (!Directory.Exists(ModelHandler.PathToRegisterModel)) + { + Directory.CreateDirectory(ModelHandler.PathToRegisterModel); + } + + foreach (var key in ModelHandler.ModelAndPath.Keys) + { + var path = ModelHandler.ModelAndPath[key].path; + var model = ModelHandler.ModelAndPath[key].model; + var splitPath = PluginControl.CurrentProject.FolderPath.Split('\\').ToList(); + //var rootPath = mySettings.RootFolders.FirstOrDefault(r => r.OrganizationName == mySettings.CurrentOrganizationName).FolderPath; + //var splitRootPath = rootPath.Split('\\').ToList(); + splitPath.Remove(splitPath.ElementAt(splitPath.Count - 1)); + + var splitTablePath = path.Split('\\').ToList(); + //splitTablePath = + + //var project = mySettings.RootFolders.FirstOrDefault(r => r.FolderPath == CurrentProject); + if (PluginControl.CurrentProject == null) + { + MessageBox.Show("Could not save model"); + return; + } + + var projectPath = String.Join("\\", splitPath); + var txt = JsonConvert.SerializeObject(model, Formatting.Indented, new JsonSerializerSettings + { + DefaultValueHandling = DefaultValueHandling.Ignore + }); + //MessageBox.Show(projectPath); + //MessageBox.Show(registrationPath); + + + var finalPath = projectPath + path + "\\" + $"{model.Name}.model"; + //CheckForDuplicateTableFile(finalPath, table); + var fileInfo = new FileInfo(finalPath); + File.WriteAllText(fileInfo.FullName, txt); + } + } + + public static List GetPossiblePropertyTypes(XrmFramework.Core.Model model, string columnLogicalName) + { + OptionSetEnum FirstEnum; + OptionSetEnum SecondEnum; + var possibleTypes = new List(); + + // Get the corresponding tabke + var table = TableHandler.TableAndPath[model.TableLogicalName].table; + if (table == null) + { + return possibleTypes; + } + var column = table.Columns.FirstOrDefault(c => c.LogicalName == columnLogicalName); + Relation relation; + if (column == null) + { + relation = table.OneToManyRelationships.FirstOrDefault(r => r.Name == columnLogicalName); + if (relation == null) + { + return possibleTypes; + } + else + { + var possibleModelAdded = false; + // Find a corresponding model and return + foreach(var key in ModelAndPath.Keys) + { + var possibleModel = ModelAndPath[key].model; + if(possibleModel.TableLogicalName == relation.EntityName) + { + //possibleTypes.Add($"{CoreProjectName}.{possibleModel.ModelNamespace}.{possibleModel.Name}"); + //Todo : Find a way to use the full typename of the model + possibleTypes.Add(possibleModel.ModelNamespace+"."+possibleModel.Name); + possibleModelAdded = true; + + + } + } + if(!possibleModelAdded) + { + // Find corresponding table, and get its name + // Find corresponding table, and get its name + if (!TableHandler.TableAndPath.ContainsKey(relation.EntityName)) + { + MessageBox.Show($"can't find table {relation.EntityName}"); + } + else + { + var correspondingTable = TableHandler.TableAndPath[relation.EntityName].table; + possibleTypes.Add(correspondingTable.Name + "Model"); + } + } + //foreach (var possibleModel in Models) + //{ + // if (possibleModel.TableLogicalName == relation.EntityName) + // { + // + // } + //} + + possibleTypes.Add("System.Guid"); + possibleTypes.Add("Microsoft.Xrm.Sdk.EntityReference"); + + return possibleTypes; + + } + } + + switch (column.Type) + { + + case AttributeTypeCode.Boolean: + possibleTypes.Add("System.Boolean"); + possibleTypes.Add("System.Int32"); + possibleTypes.Add("System.String"); + + break; + case AttributeTypeCode.Customer: + throw new Exception("The type Customer is not currently handled by the model manager"); + //possibleTypes.Add($"{CoreProjectName}.{model.}.{}"); + possibleTypes.Add("System.Guid"); + possibleTypes.Add("Microsoft.Xrm.Sdk.EntityReference"); + + break; + case AttributeTypeCode.Integer: + possibleTypes.Add("System.Int32"); + break; + case AttributeTypeCode.DateTime: + possibleTypes.Add("System.DateTime"); + possibleTypes.Add("System.String"); + break; + case AttributeTypeCode.Decimal: + possibleTypes.Add("System.Decimal"); + break; + case AttributeTypeCode.Double: + possibleTypes.Add("System.Double"); + break; + case AttributeTypeCode.Lookup: + //Get the corresponding relation, find the corresponding model if it exists + + + var re = table.ManyToOneRelationships.FirstOrDefault(r => r.LookupFieldName == column.LogicalName); + if (re == null) + { + throw new Exception(); + } + var possibleModelAdded = false; + foreach(var key in ModelAndPath.Keys) + { + var possibleModel = ModelAndPath[key].model; + //TODO : find a way to use the typefullname + if(possibleModel.TableLogicalName == re.EntityName) + { + possibleTypes.Add(possibleModel.ModelNamespace + "." + possibleModel.Name); + possibleModelAdded = true; + } + + + } + if(!possibleModelAdded) + { + // Find corresponding table, and get its name + if (!TableHandler.TableAndPath.ContainsKey(re.EntityName)) + { + MessageBox.Show($"can't find table {re.EntityName}"); + } + else + { + var correspondingTable = TableHandler.TableAndPath[re.EntityName].table; + possibleTypes.Add(correspondingTable.Name + "Model"); + } + + } + //foreach (var possibleModel in Models) + //{ + // if (possibleModel.TableLogicalName == re.EntityName) + // { + // possibleTypes.Add($"{CoreProjectName}.{possibleModel.ModelNamespace}.{possibleModel.Name}"); + // + // } + //} + + possibleTypes.Add("System.Guid"); + possibleTypes.Add("Microsoft.Xrm.Sdk.EntityReference"); + break; + case AttributeTypeCode.Memo: + possibleTypes.Add("System.String"); + break; + case AttributeTypeCode.Money: + possibleTypes.Add("System.Decimal"); + break; + case AttributeTypeCode.Owner: + possibleTypes.Add("System.Guid"); + possibleTypes.Add("Microsoft.Xrm.Sdk.EntityReference"); + //possibleTypes.Add("ModelType à déterminer"); + break; + case AttributeTypeCode.PartyList: // Est ce que c'est les one to many relationships ? parce que si oui ça pose problème avec la manière dont j'ai écrit mon code de génération + //possibleTypes.Add("System.Collections.Generic.List"); + //possibleTypes.Add("System.Collections.Generic.List"); + //possibleTypes.Add("System.Collections.Generic.List"); + throw new Exception("The type PartyList is not currently handled in the Model Manager"); + + break; + case AttributeTypeCode.Picklist: + //possibleTypes.Add("Truc.Enum à déterminer"); + // Get the corresponding enum + FirstEnum = table.Enums.FirstOrDefault(e => e.LogicalName == column.EnumName); + if (FirstEnum == null) + { + SecondEnum = TableHandler.globalEnumsTable.Enums.FirstOrDefault(e => e.LogicalName == column.EnumName); + //SecondEnum = GlobalEnums.FirstOrDefault(e => e.LogicalName == column.EnumName); + if (SecondEnum != null) + { + // TODO : Find a way to get the namespace + //possibleTypes.Add($"{CoreProjectName}.{SecondEnum.Name}"); + possibleTypes.Add($"{SecondEnum.Name}"); + } + else + { + throw new Exception("No corresponding enumeration found for property : " + column.Name); + } + } + else + { + // TODO : Find a way to get the namespace + //possibleTypes.Add($"{CoreProjectName}.{FirstEnum.Name}"); + possibleTypes.Add($"{FirstEnum.Name}"); + + } + + possibleTypes.Add("System.Int32"); + break; + case AttributeTypeCode.State: + + FirstEnum = table.Enums.FirstOrDefault(e => e.LogicalName == column.EnumName); + if (FirstEnum == null) + { + SecondEnum = TableHandler.globalEnumsTable.Enums.FirstOrDefault(e => e.LogicalName == column.EnumName); + //SecondEnum = GlobalEnums.FirstOrDefault(e => e.LogicalName == column.EnumName); + if (SecondEnum != null) + { + // TODO : Find a way to get the namespace + + possibleTypes.Add($"{SecondEnum.Name}"); + } + else + { + throw new Exception("No corresponding enumeration found for property : " + column.Name); + } + } + else + { + // TODO : Find a way to get the namespace + + possibleTypes.Add($"{FirstEnum.Name}"); + } + + possibleTypes.Add("System.Int32"); + break; + case AttributeTypeCode.Status: + FirstEnum = table.Enums.FirstOrDefault(e => e.LogicalName == column.EnumName); + if (FirstEnum == null) + { + SecondEnum = TableHandler.globalEnumsTable.Enums.FirstOrDefault(e => e.LogicalName == column.EnumName); + //SecondEnum = GlobalEnums.FirstOrDefault(e => e.LogicalName == column.EnumName); + if (SecondEnum != null) + { + // TODO : Find a way to get the namespace + possibleTypes.Add($"{SecondEnum.Name}"); + } + else + { + throw new Exception("No corresponding enumeration found for property : " + column.Name); + } + } + else + { + // TODO : Find a way to get the namespace + possibleTypes.Add($"{FirstEnum.Name}"); + } + possibleTypes.Add("System.Int32"); + break; + case AttributeTypeCode.String: + possibleTypes.Add("System.String"); + break; + case AttributeTypeCode.Uniqueidentifier: + possibleTypes.Add("System.Guid"); + break; + case AttributeTypeCode.CalendarRules: + throw new Exception("The type CalendarRules is not currently handled in the Model Manager"); + break; + case AttributeTypeCode.Virtual: + throw new Exception("The type Virtual is not currently handled in the Model Manager"); + break; + case AttributeTypeCode.BigInt: + possibleTypes.Add("System.Int64"); + break; + case AttributeTypeCode.ManagedProperty: + throw new Exception("The type ManagedProperty is not currently handled in the Model Manager"); + break; + case AttributeTypeCode.EntityName: + possibleTypes.Add("System.String"); + break; + } + + return possibleTypes; + } + + public static bool IsPropertyNameUsed(string name,XrmFramework.Core.Model model) + { + foreach(var prop in model.Properties) + { + if(prop.Name == name) + { + return true; + } + } + + return false; + } + public static bool IsModelNameUsed(string name) + { + if(ModelAndPath.ContainsKey(name)) + { + return true; + } + return false; + } + + public static bool IsJsonPropertyNameUsed(string name, Core.Model model) + { + foreach (var prop in model.Properties) + { + if (prop.JsonPropertyName == name) + { + return true; + } + } + + return false; + } + } + + public class ModelData + { + public XrmFramework.Core.Model model; + public String path; + public ModelData(XrmFramework.Core.Model model, string path) + { + this.model = model; + this.path = path; + } + } +} diff --git a/src/XrmFramework.XrmToolbox.Plugin/DataHandlers/TableHandler.cs b/src/XrmFramework.XrmToolbox.Plugin/DataHandlers/TableHandler.cs new file mode 100644 index 00000000..60a92d69 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/DataHandlers/TableHandler.cs @@ -0,0 +1,747 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using XrmFramework.Core; +using System.Windows.Forms; +using XrmToolBox.Extensibility; +using Microsoft.Xrm.Sdk.Messages; +using Microsoft.Xrm.Sdk.Metadata; + +namespace XrmFramework.XrmToolbox.DataHandlers +{ + public static class TableHandler + { + public static string CurrentTable = null; + public static string PathToRegisterTables = ""; + //private DataTable TableContent = new DataTable(); + //private TableCollection ProjectTables = new TableCollection(); + public static Dictionary TableAndPath = new Dictionary(); + public static Table globalEnumsTable = null; + public static List PublisherPrefixes { get; } = new(); + public static TableCollection BasicTables = new TableCollection(); + public static List PreexistingTablePaths = new List(); + public static string CurrentEnum = null; + public static XrmFrameworkPluginControl PluginControl; + + + public static void LoadTablesFromProject(string projectPath) + { + foreach (var fileName in Directory.GetFiles($"{projectPath}", "*.table", SearchOption.AllDirectories)) + { + PreexistingTablePaths.Add(fileName); + if (fileName.Contains("OptionSet")) + { + //MessageBox.Show(fileName); + var fileInfo = new FileInfo(fileName); + var text = File.ReadAllText(fileInfo.FullName); + var table = JsonConvert.DeserializeObject
(text); + globalEnumsTable = table; + } + else + { + //MessageBox.Show(fileName); + var fileInfo = new FileInfo(fileName); + var text = File.ReadAllText(fileInfo.FullName); + var table = JsonConvert.DeserializeObject
(text); + var splitFilename = fileName.Split('\\').ToList(); + splitFilename.RemoveAt(splitFilename.Count - 1); + var rootPath = projectPath; + var splitRootPath = rootPath.Split('\\').ToList(); + splitRootPath.Remove(splitRootPath.ElementAt(splitRootPath.Count - 1)); + rootPath = String.Join("\\", splitRootPath); + //var path = RemoveCurrentProjectPathFromTablePath(string.Join("\\", splitFilename), projectPath); + var path = RemoveCurrentProjectPathFromTablePath(string.Join("\\",splitFilename), projectPath); + + //MessageBox.Show(fileName); + //foreach(var txt in splitFilename) + //{ + // MessageBox.Show(txt); + //} + //MessageBox.Show(string.Join("\\", splitFilename)); + //MessageBox.Show(projectPath); + //MessageBox.Show(path); + TableAndPath[table.LogicalName] = new TableData(table, path); + } + + + + } + + if(globalEnumsTable == null) + { + globalEnumsTable = new Table() + { + Name = "OptionSet", + LogicalName = "globalEnums" + }; + } + + + } + + public static string RemoveCurrentProjectPathFromTablePath(string path, string projectPath) + { + + var splitPath = projectPath.Split('\\').ToList(); + splitPath.RemoveAt(splitPath.Count - 1); + var rootPath = string.Join("\\", splitPath); + //var splitRootPath = rootPath.Split('\\').ToList(); + //splitRootPath.Remove(splitRootPath.ElementAt(splitRootPath.Count - 1)); + //rootPath = String.Join("\\", splitRootPath); + return path.Replace(rootPath.Trim('\\'), ""); + } + public static void ModifyEnumName(string previousText, OptionSetEnum en, string text) + { + var newForm = new TryOtherNameForm(text); + newForm.FormClosing += (o, e) => + { + //If the user has chosen to modify (he clicked the modify button) send ou object ? + if (!newForm.ModifyName || newForm.Name == previousText) + { + //MessageBox.Show("did not modify name"); + return; + } + // Check if a table is already using this name + + if (IsEnumNameUsed(en, newForm.Name)) + { + // If already used, don't modify table name and notify user + MessageBox.Show("This name is already in use"); + return; + } + else + { + // If not, then modify the name + //MessageBox.Show("You modified this Name"); + var finalName = RemovePrefix(newForm.Name).StrongFormat(); + en.Name = finalName; + + } + }; + + newForm.ShowDialog(); + } + + private static bool IsEnumNameUsed(OptionSetEnum en, string name) + { + if(TableHandler.globalEnumsTable == null) + { + return false; + } + // Is enum name used in a global enum + if (TableHandler.globalEnumsTable.Enums.Any(e => e.Name == name && e.LogicalName != en.LogicalName)) + { + return true; + } + // Is enum name used in a table enum + else + { + foreach (var key in TableHandler.TableAndPath.Keys) + { + var currentTable = TableHandler.TableAndPath[key].table; + if (currentTable.Enums.Any(e => e.Name == name && e.LogicalName != en.LogicalName)) + { + return true; + } + } + } + + return false; + + } + + public static string RemovePrefix(string name) + { + foreach (var prefix in PublisherPrefixes) + { + if (!string.IsNullOrEmpty(prefix) && name.StartsWith(prefix)) + { + name = name.Substring(prefix.Length + 1); + } + } + name = name.Substring(0, 1).ToUpperInvariant() + name.Substring(1); + return name; + } + + public static void ProcessBasicTableRequest(EntityMetadata[] response) + { + BasicTables.Clear(); + foreach (var entity in response) + { + + if (entity.DisplayName.UserLocalizedLabel != null) + { + BasicTables.Add(new Table() + { + LogicalName = entity.LogicalName, + //Name = RemovePrefix(entity.SchemaName).FormatText(), + + Name = entity.DisplayName.UserLocalizedLabel.Label.StrongFormat(), + + }); + } + else + { + BasicTables.Add(new Table() + { + LogicalName = entity.LogicalName, + Name = RemovePrefix(entity.SchemaName).FormatText(), + + //Name = entity.DisplayName.UserLocalizedLabel.Label.StrongFormat(), + + }); + } + + } + + } + + public static void ModifyEnumeValueName(OptionSetEnumValue enumValue, OptionSetEnum en, string text) + { + var newForm = new TryOtherNameForm(text); + newForm.FormClosing += (o, e) => + { + //If the user has chosen to modify (he clicked the modify button) send ou object ? + if (!newForm.ModifyName || newForm.Name == enumValue.Name) + { + //MessageBox.Show("did not modify name"); + return; + } + // Check if a table is already using this name + + if (en.Values.Any(v => v.Name == newForm.Name && v.Value != enumValue.Value)) + { + // If already used, don't modify table name and notify user + MessageBox.Show("This name is already in use"); + return; + } + else + { + // If not, then modify the name + //MessageBox.Show("You modified this Name"); + var finalName = RemovePrefix(newForm.Name).StrongFormat(); + enumValue.Name = finalName; + } + }; + + newForm.ShowDialog(); + } + public static void ModifyTableName(string previousText, Table table, string text) + { + var newForm = new TryOtherNameForm(text); + newForm.FormClosing += (o, e) => + { + //If the user has chosen to modify (he clicked the modify button) send ou object ? + if (!newForm.ModifyName || newForm.Name == previousText) + { + //MessageBox.Show("did not modify name"); + return; + } + // Check if a table is already using this name + + if (IsTableNameUsed(table, newForm.Name)) + { + // If already used, don't modify table name and notify user + MessageBox.Show("This name is already in use"); + return; + } + else + { + // If not, then modify the name + //MessageBox.Show("You modified this Name"); + var finalName = RemovePrefix(newForm.Name).StrongFormat(); + table.Name = finalName; + } + }; + + newForm.ShowDialog(); + + + } + public static void ProcessEntityResponse(Table table, EntityMetadata entity) + { + + if (entity.Keys != null && entity.Keys.Any()) + { + + foreach (var key in entity.Keys) + { + + var newKey = new Key + { + LogicalName = key.LogicalName, + Name = key.DisplayName.UserLocalizedLabel.Label.FormatText() + + }; + newKey.FieldNames.AddRange(key.KeyAttributes); + + + if (!table.Keys.Any(k => k.LogicalName == newKey.LogicalName)) + { + table.Keys.Add(newKey); + + } + } + } + table.OneToManyRelationships.Clear(); + if (entity.OneToManyRelationships.Any()) + { + + foreach (var relationship in entity.OneToManyRelationships) + { + + + table.OneToManyRelationships.Add(new Relation + { + Name = relationship.SchemaName, + Role = EntityRole.Referenced, + EntityName = relationship.ReferencingEntity, + NavigationPropertyName = relationship.ReferencedEntityNavigationPropertyName, + LookupFieldName = relationship.ReferencingAttribute + }); + } + } + table.ManyToManyRelationships.Clear(); + if (entity.ManyToManyRelationships.Any()) + { + + foreach (var relationship in entity.ManyToManyRelationships) + { + + table.ManyToManyRelationships.Add(new Relation + { + Name = relationship.SchemaName, + Role = EntityRole.Referencing, + EntityName = relationship.Entity1LogicalName == table.LogicalName ? relationship.Entity2LogicalName : relationship.Entity1LogicalName, + NavigationPropertyName = relationship.IntersectEntityName, + LookupFieldName = relationship.Entity1LogicalName == table.LogicalName ? relationship.Entity2IntersectAttribute : relationship.Entity1IntersectAttribute + }); + } + } + table.ManyToOneRelationships.Clear(); + if (entity.ManyToOneRelationships.Any()) + { + foreach (var relationship in entity.ManyToOneRelationships) + { + table.ManyToOneRelationships.Add(new Relation + { + Name = relationship.SchemaName, + Role = EntityRole.Referencing, + NavigationPropertyName = relationship.ReferencingEntityNavigationPropertyName, + EntityName = relationship.ReferencedEntity, + LookupFieldName = relationship.ReferencingAttribute + }); + } + } + + foreach (var attributeMetadata in entity.Attributes.OrderBy(a => a.LogicalName)) + { + if (!attributeMetadata.IsValidForCreate.Value && !attributeMetadata.IsValidForRead.Value && !attributeMetadata.IsValidForUpdate.Value) + { + continue; + } + if (attributeMetadata.AttributeType.Value == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.EntityName || !string.IsNullOrEmpty(attributeMetadata.AttributeOf)) + { + continue; + } + + string attributeEnumName = null; + + if (attributeMetadata.AttributeType.Value == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Picklist || attributeMetadata.AttributeType.Value == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.State || attributeMetadata.AttributeType.Value == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Status || attributeMetadata.AttributeType.Value == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Virtual && attributeMetadata is MultiSelectPicklistAttributeMetadata) + { + var meta = ((EnumAttributeMetadata)attributeMetadata).OptionSet; + + var enumLogicalName = meta.IsGlobal.Value ? meta.Name : entity.LogicalName + "|" + attributeMetadata.LogicalName; + + attributeEnumName = enumLogicalName; + + + var newEnum = new OptionSetEnum + { + LogicalName = enumLogicalName, + IsGlobal = meta.IsGlobal.Value, + HasNullValue = attributeMetadata.AttributeType.Value == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Picklist && + meta.Options.All(option => option.Value.GetValueOrDefault() != 0), + }; + + if (attributeMetadata.AttributeType.Value == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.State) + { + + newEnum.Name = table.Name.Replace("Definition", "") + "State"; + } + else if (attributeMetadata.AttributeType.Value == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Status) + { + newEnum.Name = table.Name.Replace("Definition", "") + "Status"; + } + else + { + newEnum.Name = meta.DisplayName.UserLocalizedLabel?.Label.FormatText(); + } + + if (string.IsNullOrEmpty(newEnum.Name)) + { + continue; + } + + foreach (var option in meta.Options) + { + if (option.Label.UserLocalizedLabel == null) + { + continue; + } + + var optionValue = new OptionSetEnumValue + { + Name = option.Label.UserLocalizedLabel.Label.FormatText(), + Value = option.Value.Value, + ExternalValue = option.ExternalValue + }; + + foreach (var displayNameLocalizedLabel in option.Label.LocalizedLabels) + { + optionValue.Labels.Add(new XrmFramework.Core.LocalizedLabel + { + Label = displayNameLocalizedLabel.Label, + LangId = displayNameLocalizedLabel.LanguageCode + }); + } + + newEnum.Values.Add(optionValue); + + } + + if (!newEnum.IsGlobal) + { + var sameEnum = table.Enums.FirstOrDefault(e => e.LogicalName == newEnum.LogicalName); + if (sameEnum != null) + { + newEnum.Name = sameEnum.Name; + table.Enums.Remove(sameEnum); + table.Enums.Add(newEnum); + } + else + { + while (IsEnumNameUsed(newEnum, newEnum.Name)) + { + ModifyEnumName(newEnum.Name, newEnum, newEnum.Name); + } + + + table.Enums.Add(newEnum); + + } + //table.Enums.Add(newEnum); + } + else if (TableHandler.globalEnumsTable == null) + { + if(TableHandler.globalEnumsTable.Enums.All(e => e.LogicalName != newEnum.LogicalName)) + { + var sameEnum = TableHandler.globalEnumsTable.Enums.FirstOrDefault(e => e.LogicalName == newEnum.LogicalName); + if (sameEnum != null) + { + newEnum.Name = sameEnum.Name; + TableHandler.globalEnumsTable.Enums.Remove(sameEnum); + TableHandler.globalEnumsTable.Enums.Add(newEnum); + } + else + { + while (IsEnumNameUsed(newEnum, newEnum.Name)) + { + ModifyEnumName(newEnum.Name, newEnum, newEnum.Name); + } + TableHandler.globalEnumsTable.Enums.Add(newEnum); + + } + } + + } + + + } + + var name = RemovePrefix(attributeMetadata.SchemaName); + + if (attributeMetadata.LogicalName == entity.PrimaryIdAttribute) + { + name = "Id"; + } + + int? maxLength = null; + double? minRangeDouble = null, maxRangeDouble = null; + + switch (attributeMetadata.AttributeType.Value) + { + case Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.String: + maxLength = ((StringAttributeMetadata)attributeMetadata).MaxLength; + break; + case Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Memo: + maxLength = ((MemoAttributeMetadata)attributeMetadata).MaxLength; + break; + case Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Money: + var m = (MoneyAttributeMetadata)attributeMetadata; + minRangeDouble = m.MinValue; + maxRangeDouble = m.MaxValue; + break; + case Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Integer: + var mi = (IntegerAttributeMetadata)attributeMetadata; + minRangeDouble = mi.MinValue; + maxRangeDouble = mi.MaxValue; + break; + case Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Double: + var md = (DoubleAttributeMetadata)attributeMetadata; + minRangeDouble = md.MinValue; + maxRangeDouble = md.MaxValue; + break; + case Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Decimal: + var mde = (DecimalAttributeMetadata)attributeMetadata; + minRangeDouble = (double?)mde.MinValue; + maxRangeDouble = (double?)mde.MaxValue; + break; + } + + + var attribute = new Column + { + LogicalName = attributeMetadata.LogicalName, + Name = RemovePrefix(name).FormatText(), + Type = (XrmFramework.AttributeTypeCode)(int)(attributeMetadata.AttributeType.Value == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Virtual && attributeMetadata is MultiSelectPicklistAttributeMetadata + ? Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Picklist : attributeMetadata.AttributeType.Value), + IsMultiSelect = attributeMetadata.AttributeType.Value == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Virtual && attributeMetadata is MultiSelectPicklistAttributeMetadata, + PrimaryType = attributeMetadata.LogicalName == entity.PrimaryIdAttribute ? + PrimaryType.Id : + attributeMetadata.LogicalName == entity.PrimaryNameAttribute ? + PrimaryType.Name : + attributeMetadata.LogicalName == entity.PrimaryImageAttribute ? PrimaryType.Image : PrimaryType.None, + StringLength = maxLength, + MinRange = minRangeDouble, + MaxRange = maxRangeDouble, + EnumName = attributeEnumName, + Selected = false + }; + + foreach (var displayNameLocalizedLabel in attributeMetadata.DisplayName.LocalizedLabels) + { + attribute.Labels.Add(new XrmFramework.Core.LocalizedLabel + { + Label = displayNameLocalizedLabel.Label, + LangId = displayNameLocalizedLabel.LanguageCode + }); + } + + if (attributeMetadata.IsValidForAdvancedFind.Value) + { + attribute.Capabilities |= AttributeCapabilities.AdvancedFind; + } + + if (attributeMetadata.IsValidForCreate.Value) + { + attribute.Capabilities |= AttributeCapabilities.Create; + } + + if (attributeMetadata.IsValidForRead.Value) + { + attribute.Capabilities |= AttributeCapabilities.Read; + } + + if (attributeMetadata.IsValidForUpdate.Value) + { + attribute.Capabilities |= AttributeCapabilities.Update; + } + + + if (attributeMetadata.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.DateTime) + { + var meta = (DateTimeAttributeMetadata)attributeMetadata; + + attribute.DateTimeBehavior = meta.DateTimeBehavior.ToDateTimeBehavior(); + } + + if (attributeMetadata.LogicalName == "ownerid") + { + + } + + + + + + table.Columns.Add(attribute); + } + + } + public static bool IsTableNameUsed(Table table, string name) + { + if (TableHandler.TableAndPath.Any(t => t.Value.table.Name == name && t.Value.table.LogicalName != table.LogicalName)) + { + return true; + } + return false; + } + + public static void CheckDefaultSelectColumns() + { + Table currentTable; + foreach (var key in TableHandler.TableAndPath.Keys) + { + + currentTable = TableHandler.TableAndPath[key].table; + //Check for key columns + + foreach (var currentKey in currentTable.Keys) + { + foreach (var fieldName in currentKey.FieldNames) + { + var correspondingColumn = currentTable.Columns.FirstOrDefault(c => c.LogicalName == fieldName); + if (correspondingColumn != null) + { + correspondingColumn.Selected = true; + } + } + } + + var idColumn = currentTable.Columns.FirstOrDefault(c => c.PrimaryType == PrimaryType.Id); + var nameColumn = currentTable.Columns.FirstOrDefault(c => c.PrimaryType == PrimaryType.Name); + if (idColumn != null) + { + idColumn.Selected = true; + } + if (nameColumn != null) + { + nameColumn.Selected = true; + } + } + + + + + + + } + + public static void CheckForDuplicateTableFile(string finalPath, Table table) + { + // Check for exisiting file + if (File.Exists(finalPath)) + { + return; + } + + // Iterate through each preexisting tableFile + foreach (var path in TableHandler.PreexistingTablePaths) + { + if(!File.Exists(path)) + { + return; + } + var fileInfo = new FileInfo(path); + var text = File.ReadAllText(fileInfo.FullName); + var deserializedTable = JsonConvert.DeserializeObject
(text); + if (deserializedTable.LogicalName == table.LogicalName) + { + //Delete first file + File.Delete(path); + + } + } + } + + public static void SaveTables() + { + if(string.IsNullOrEmpty(PathToRegisterTables)) + { + return; + } + if (!Directory.Exists(TableHandler.PathToRegisterTables)) + { + Directory.CreateDirectory(TableHandler.PathToRegisterTables); + } + + TableHandler.CheckDefaultSelectColumns(); + + foreach (var key in TableHandler.TableAndPath.Keys) + { + var path = TableHandler.TableAndPath[key].path; + var table = TableHandler.TableAndPath[key].table; + var splitPath = PluginControl.CurrentProject.FolderPath.Split('\\').ToList(); + //var rootPath = mySettings.RootFolders.FirstOrDefault(r => r.OrganizationName == mySettings.CurrentOrganizationName).FolderPath; + //var splitRootPath = rootPath.Split('\\').ToList(); + splitPath.Remove(splitPath.ElementAt(splitPath.Count - 1)); + + var splitTablePath = path.Split('\\').ToList(); + //splitTablePath = + + //var project = mySettings.RootFolders.FirstOrDefault(r => r.FolderPath == CurrentProject); + if (PluginControl.CurrentProject == null) + { + MessageBox.Show("Could not save tables"); + return; + } + + var projectPath = String.Join("\\", splitPath); + var txt = JsonConvert.SerializeObject(table, Formatting.Indented, new JsonSerializerSettings + { + DefaultValueHandling = DefaultValueHandling.Ignore + }); + //MessageBox.Show(projectPath); + //MessageBox.Show(registrationPath); + + + var finalPath = projectPath +path +"\\"+ $"{table.Name}.table"; + CheckForDuplicateTableFile(finalPath, table); + var fileInfo = new FileInfo(finalPath); + File.WriteAllText(fileInfo.FullName, txt); + } + + // Register global enums + + var enumsPath = TableHandler.PathToRegisterTables + $"{TableHandler.globalEnumsTable.Name}.table"; + + var splitEnumPath = enumsPath.Split('\\').ToList(); + //var rootPath = mySettings.RootFolders.FirstOrDefault(r => r.OrganizationName == mySettings.CurrentOrganizationName).FolderPath; + //var splitRootPath = rootPath.Split('\\').ToList(); + splitEnumPath.Remove(splitEnumPath.ElementAt(splitEnumPath.Count - 1)); + splitEnumPath.Remove(splitEnumPath.ElementAt(0)); + splitEnumPath.Remove(splitEnumPath.ElementAt(0)); + + + + var projectE = PluginControl.Settings.RootFolders.FirstOrDefault(r => r.OrganizationName == PluginControl.Settings.CurrentOrganizationName); + if (projectE == null) + { + MessageBox.Show("Could not save enums"); + return; + } + var projectPathE = projectE.FolderPath; + var registrationPathE = String.Join("\\", splitEnumPath); + + var txtE = JsonConvert.SerializeObject(TableHandler.globalEnumsTable, Formatting.Indented, new JsonSerializerSettings + { + DefaultValueHandling = DefaultValueHandling.Ignore + }); + var fileInfoE = new FileInfo(enumsPath); + File.WriteAllText(fileInfoE.FullName, txtE); + } + + + + + + + + } + + public class TableData + { + public Table table; + public String path; + public TableData(Table table, string path) + { + this.table = table; + this.path = path; + } + } +} diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/AddModelPropertyForm.Designer.cs b/src/XrmFramework.XrmToolbox.Plugin/Forms/AddModelPropertyForm.Designer.cs new file mode 100644 index 00000000..ec99a6b0 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/AddModelPropertyForm.Designer.cs @@ -0,0 +1,394 @@ +namespace XrmFramework.XrmToolbox.Forms +{ + partial class AddModelPropertyForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.button1 = new System.Windows.Forms.Button(); + this.TypeComboBox = new System.Windows.Forms.ComboBox(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.PropertyNameTextBox = new System.Windows.Forms.TextBox(); + this.splitContainer2 = new System.Windows.Forms.SplitContainer(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.splitContainer3 = new System.Windows.Forms.SplitContainer(); + this.textBox3 = new System.Windows.Forms.TextBox(); + this.JsonNameTextBox = new System.Windows.Forms.TextBox(); + this.splitContainer4 = new System.Windows.Forms.SplitContainer(); + this.textBox4 = new System.Windows.Forms.TextBox(); + this.ColumnLogicalName = new System.Windows.Forms.TextBox(); + this.splitContainer5 = new System.Windows.Forms.SplitContainer(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.columnBindingSource = new System.Windows.Forms.BindingSource(this.components); + this.checkBox1 = new System.Windows.Forms.CheckBox(); + this.modelPropertyBindingSource = new System.Windows.Forms.BindingSource(this.components); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); + this.splitContainer2.Panel1.SuspendLayout(); + this.splitContainer2.Panel2.SuspendLayout(); + this.splitContainer2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).BeginInit(); + this.splitContainer3.Panel1.SuspendLayout(); + this.splitContainer3.Panel2.SuspendLayout(); + this.splitContainer3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer4)).BeginInit(); + this.splitContainer4.Panel1.SuspendLayout(); + this.splitContainer4.Panel2.SuspendLayout(); + this.splitContainer4.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer5)).BeginInit(); + this.splitContainer5.Panel1.SuspendLayout(); + this.splitContainer5.Panel2.SuspendLayout(); + this.splitContainer5.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.columnBindingSource)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.modelPropertyBindingSource)).BeginInit(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.button1.Location = new System.Drawing.Point(0, 334); + this.button1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(293, 32); + this.button1.TabIndex = 0; + this.button1.Text = "Add property"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // TypeComboBox + // + this.TypeComboBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.TypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.TypeComboBox.FormattingEnabled = true; + this.TypeComboBox.Location = new System.Drawing.Point(0, 0); + this.TypeComboBox.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.TypeComboBox.Name = "TypeComboBox"; + this.TypeComboBox.Size = new System.Drawing.Size(170, 21); + this.TypeComboBox.TabIndex = 1; + // + // textBox1 + // + this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox1.Location = new System.Drawing.Point(0, 0); + this.textBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox1.Name = "textBox1"; + this.textBox1.ReadOnly = true; + this.textBox1.Size = new System.Drawing.Size(96, 20); + this.textBox1.TabIndex = 2; + this.textBox1.Text = "Name"; + // + // splitContainer1 + // + this.splitContainer1.Location = new System.Drawing.Point(0, 37); + this.splitContainer1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.textBox1); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.PropertyNameTextBox); + this.splitContainer1.Size = new System.Drawing.Size(291, 20); + this.splitContainer1.SplitterDistance = 96; + this.splitContainer1.SplitterWidth = 3; + this.splitContainer1.TabIndex = 3; + // + // PropertyNameTextBox + // + this.PropertyNameTextBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.PropertyNameTextBox.Location = new System.Drawing.Point(0, 0); + this.PropertyNameTextBox.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.PropertyNameTextBox.Name = "PropertyNameTextBox"; + this.PropertyNameTextBox.Size = new System.Drawing.Size(192, 20); + this.PropertyNameTextBox.TabIndex = 3; + // + // splitContainer2 + // + this.splitContainer2.Location = new System.Drawing.Point(2, 78); + this.splitContainer2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.splitContainer2.Name = "splitContainer2"; + // + // splitContainer2.Panel1 + // + this.splitContainer2.Panel1.Controls.Add(this.textBox2); + // + // splitContainer2.Panel2 + // + this.splitContainer2.Panel2.Controls.Add(this.TypeComboBox); + this.splitContainer2.Size = new System.Drawing.Size(257, 23); + this.splitContainer2.SplitterDistance = 84; + this.splitContainer2.SplitterWidth = 3; + this.splitContainer2.TabIndex = 4; + // + // textBox2 + // + this.textBox2.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox2.Location = new System.Drawing.Point(0, 0); + this.textBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox2.Name = "textBox2"; + this.textBox2.ReadOnly = true; + this.textBox2.Size = new System.Drawing.Size(84, 20); + this.textBox2.TabIndex = 3; + this.textBox2.Text = "Type"; + // + // splitContainer3 + // + this.splitContainer3.Location = new System.Drawing.Point(2, 120); + this.splitContainer3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.splitContainer3.Name = "splitContainer3"; + // + // splitContainer3.Panel1 + // + this.splitContainer3.Panel1.Controls.Add(this.textBox3); + // + // splitContainer3.Panel2 + // + this.splitContainer3.Panel2.Controls.Add(this.JsonNameTextBox); + this.splitContainer3.Size = new System.Drawing.Size(285, 20); + this.splitContainer3.SplitterDistance = 132; + this.splitContainer3.SplitterWidth = 3; + this.splitContainer3.TabIndex = 5; + // + // textBox3 + // + this.textBox3.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox3.Location = new System.Drawing.Point(0, 0); + this.textBox3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox3.Name = "textBox3"; + this.textBox3.ReadOnly = true; + this.textBox3.Size = new System.Drawing.Size(132, 20); + this.textBox3.TabIndex = 2; + this.textBox3.Text = "Json Property Name"; + // + // JsonNameTextBox + // + this.JsonNameTextBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.JsonNameTextBox.Location = new System.Drawing.Point(0, 0); + this.JsonNameTextBox.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.JsonNameTextBox.Name = "JsonNameTextBox"; + this.JsonNameTextBox.Size = new System.Drawing.Size(150, 20); + this.JsonNameTextBox.TabIndex = 3; + // + // splitContainer4 + // + this.splitContainer4.Dock = System.Windows.Forms.DockStyle.Top; + this.splitContainer4.Location = new System.Drawing.Point(0, 0); + this.splitContainer4.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.splitContainer4.Name = "splitContainer4"; + // + // splitContainer4.Panel1 + // + this.splitContainer4.Panel1.Controls.Add(this.textBox4); + // + // splitContainer4.Panel2 + // + this.splitContainer4.Panel2.Controls.Add(this.ColumnLogicalName); + this.splitContainer4.Size = new System.Drawing.Size(293, 20); + this.splitContainer4.SplitterDistance = 144; + this.splitContainer4.SplitterWidth = 3; + this.splitContainer4.TabIndex = 6; + // + // textBox4 + // + this.textBox4.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox4.Location = new System.Drawing.Point(0, 0); + this.textBox4.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox4.Name = "textBox4"; + this.textBox4.ReadOnly = true; + this.textBox4.Size = new System.Drawing.Size(144, 20); + this.textBox4.TabIndex = 2; + this.textBox4.Text = "Corresponding column Name"; + // + // ColumnLogicalName + // + this.ColumnLogicalName.Dock = System.Windows.Forms.DockStyle.Fill; + this.ColumnLogicalName.Location = new System.Drawing.Point(0, 0); + this.ColumnLogicalName.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.ColumnLogicalName.Name = "ColumnLogicalName"; + this.ColumnLogicalName.ReadOnly = true; + this.ColumnLogicalName.Size = new System.Drawing.Size(146, 20); + this.ColumnLogicalName.TabIndex = 3; + this.ColumnLogicalName.TextChanged += new System.EventHandler(this.ColumnLogicalName_TextChanged); + // + // splitContainer5 + // + this.splitContainer5.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer5.Location = new System.Drawing.Point(0, 0); + this.splitContainer5.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.splitContainer5.Name = "splitContainer5"; + // + // splitContainer5.Panel1 + // + this.splitContainer5.Panel1.Controls.Add(this.dataGridView1); + // + // splitContainer5.Panel2 + // + this.splitContainer5.Panel2.Controls.Add(this.checkBox1); + this.splitContainer5.Panel2.Controls.Add(this.splitContainer4); + this.splitContainer5.Panel2.Controls.Add(this.button1); + this.splitContainer5.Panel2.Controls.Add(this.splitContainer1); + this.splitContainer5.Panel2.Controls.Add(this.splitContainer3); + this.splitContainer5.Panel2.Controls.Add(this.splitContainer2); + this.splitContainer5.Size = new System.Drawing.Size(600, 366); + this.splitContainer5.SplitterDistance = 304; + this.splitContainer5.SplitterWidth = 3; + this.splitContainer5.TabIndex = 7; + // + // dataGridView1 + // + this.dataGridView1.AutoGenerateColumns = false; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.nameDataGridViewTextBoxColumn, + this.Column1}); + this.dataGridView1.DataSource = this.columnBindingSource; + this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView1.Location = new System.Drawing.Point(0, 0); + this.dataGridView1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 51; + this.dataGridView1.RowTemplate.Height = 24; + this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView1.Size = new System.Drawing.Size(304, 366); + this.dataGridView1.TabIndex = 0; + this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick); + // + // nameDataGridViewTextBoxColumn + // + this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name"; + this.nameDataGridViewTextBoxColumn.HeaderText = "Name"; + this.nameDataGridViewTextBoxColumn.MinimumWidth = 6; + this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn"; + this.nameDataGridViewTextBoxColumn.ReadOnly = true; + this.nameDataGridViewTextBoxColumn.Width = 125; + // + // Column1 + // + this.Column1.DataPropertyName = "LogicalName"; + this.Column1.HeaderText = "Logical Name"; + this.Column1.MinimumWidth = 6; + this.Column1.Name = "Column1"; + this.Column1.ReadOnly = true; + this.Column1.Width = 125; + // + // columnBindingSource + // + this.columnBindingSource.DataSource = typeof(XrmFramework.Core.Column); + // + // checkBox1 + // + this.checkBox1.AutoSize = true; + this.checkBox1.Location = new System.Drawing.Point(12, 163); + this.checkBox1.Name = "checkBox1"; + this.checkBox1.Size = new System.Drawing.Size(116, 17); + this.checkBox1.TabIndex = 7; + this.checkBox1.Text = "Is Valid For Update"; + this.checkBox1.UseVisualStyleBackColor = true; + this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); + // + // modelPropertyBindingSource + // + this.modelPropertyBindingSource.DataSource = typeof(XrmFramework.Core.ModelProperty); + // + // AddModelPropertyForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(600, 366); + this.Controls.Add(this.splitContainer5); + this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Name = "AddModelPropertyForm"; + this.Text = "Add model property"; + this.Load += new System.EventHandler(this.AddModelPropertyForm_Load); + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel1.PerformLayout(); + this.splitContainer1.Panel2.ResumeLayout(false); + this.splitContainer1.Panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.splitContainer2.Panel1.ResumeLayout(false); + this.splitContainer2.Panel1.PerformLayout(); + this.splitContainer2.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); + this.splitContainer2.ResumeLayout(false); + this.splitContainer3.Panel1.ResumeLayout(false); + this.splitContainer3.Panel1.PerformLayout(); + this.splitContainer3.Panel2.ResumeLayout(false); + this.splitContainer3.Panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).EndInit(); + this.splitContainer3.ResumeLayout(false); + this.splitContainer4.Panel1.ResumeLayout(false); + this.splitContainer4.Panel1.PerformLayout(); + this.splitContainer4.Panel2.ResumeLayout(false); + this.splitContainer4.Panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer4)).EndInit(); + this.splitContainer4.ResumeLayout(false); + this.splitContainer5.Panel1.ResumeLayout(false); + this.splitContainer5.Panel2.ResumeLayout(false); + this.splitContainer5.Panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer5)).EndInit(); + this.splitContainer5.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.columnBindingSource)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.modelPropertyBindingSource)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.ComboBox TypeComboBox; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.TextBox PropertyNameTextBox; + private System.Windows.Forms.SplitContainer splitContainer2; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.SplitContainer splitContainer3; + private System.Windows.Forms.TextBox textBox3; + private System.Windows.Forms.TextBox JsonNameTextBox; + private System.Windows.Forms.SplitContainer splitContainer4; + private System.Windows.Forms.TextBox textBox4; + private System.Windows.Forms.TextBox ColumnLogicalName; + private System.Windows.Forms.SplitContainer splitContainer5; + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.BindingSource columnBindingSource; + private System.Windows.Forms.BindingSource modelPropertyBindingSource; + private System.Windows.Forms.DataGridViewTextBoxColumn nameDataGridViewTextBoxColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn Column1; + private System.Windows.Forms.CheckBox checkBox1; + } +} \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/AddModelPropertyForm.cs b/src/XrmFramework.XrmToolbox.Plugin/Forms/AddModelPropertyForm.cs new file mode 100644 index 00000000..aec55816 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/AddModelPropertyForm.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using XrmFramework.Core; +using XrmFramework.XrmToolbox.DataHandlers; + +namespace XrmFramework.XrmToolbox.Forms +{ + public partial class AddModelPropertyForm : Form + { + public XrmFramework.Core.Model model; + //public ModelProperty property; + public string typeFullName; + public string JsonPropertyName; + public string propertyName; + public string logicalName; + public bool isValidForUpdate = false; + public bool CreateProperty = false; + + public AddModelPropertyForm() + { + InitializeComponent(); + } + + private void AddModelPropertyForm_Load(object sender, EventArgs e) + { + + } + + private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + //MessageBox.Show(dataGridView1.SelectedRows.Count.ToString()); + if(dataGridView1.SelectedRows.Count > 0) + { + ColumnLogicalName.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString(); + } + } + public void SetPossibleTypes(List possibleTypes) + { + TypeComboBox.Items.Clear(); + TypeComboBox.Items.AddRange(possibleTypes.ToArray()); + TypeComboBox.ResetText(); + } + + public void LoadPossibleColumns() + { + var table = TableHandler.TableAndPath[model.TableLogicalName].table; + var possibleColumn = new List(); + foreach(var column in table.Columns) + { + possibleColumn.Add(column); + //if(!model.Properties.Any(p=>p.LogicalName == column.LogicalName)) + //{ + // possibleColumn.Add(column); + //} + } + dataGridView1.DataSource = possibleColumn; + } + + private void ColumnLogicalName_TextChanged(object sender, EventArgs e) + { + if(!string.IsNullOrEmpty(ColumnLogicalName.Text)) + { + + var typesList = ModelHandler.GetPossiblePropertyTypes(model, ColumnLogicalName.Text); + if(typesList.Count > 0) + { + SetPossibleTypes(typesList); + } + } + } + + private void button1_Click(object sender, EventArgs e) + { + if(string.IsNullOrEmpty(PropertyNameTextBox.Text) || string.IsNullOrEmpty(JsonNameTextBox.Text) ||string.IsNullOrEmpty(TypeComboBox.Text)) + { + MessageBox.Show("Fill all fields to create a property."); + return; + } + //Check the name is not already in use for another property + if(model.Properties.Any(p=>p.Name == PropertyNameTextBox.Text)) + { + MessageBox.Show($"The name {PropertyNameTextBox.Text} is already in use."); + return; + } + if (model.Properties.Any(p => p.JsonPropertyName == JsonNameTextBox.Text)) + { + MessageBox.Show($"The json name {JsonNameTextBox.Text} is already in use."); + return; + + } + typeFullName = TypeComboBox.Text; + propertyName = PropertyNameTextBox.Text; + JsonPropertyName = JsonNameTextBox.Text; + logicalName = ColumnLogicalName.Text; + CreateProperty = true; + Close(); + + } + + private void checkBox1_CheckedChanged(object sender, EventArgs e) + { + if(checkBox1.Checked) + { + MessageBox.Show("For each crm mapping, there can only be one property that is valid for update, any other property linked to the same table column will be set to IsValidForUpdate = false"); + + } + isValidForUpdate = checkBox1.Checked; + } + } +} diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/AddModelPropertyForm.resx b/src/XrmFramework.XrmToolbox.Plugin/Forms/AddModelPropertyForm.resx new file mode 100644 index 00000000..ea4d87a1 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/AddModelPropertyForm.resx @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + 219, 14 + + + True + + + 219, 14 + + + 14, 14 + + + 41 + + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/AddTableForm.Designer.cs b/src/XrmFramework.XrmToolbox.Plugin/Forms/AddTableForm.Designer.cs new file mode 100644 index 00000000..c833915f --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/AddTableForm.Designer.cs @@ -0,0 +1,196 @@ +namespace XrmFramework.XrmToolbox +{ + partial class AddTableForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.Selected = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.button1 = new System.Windows.Forms.Button(); + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.Search = new System.Windows.Forms.TextBox(); + this.SearchBar = new System.Windows.Forms.TextBox(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.logicalNameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.tableBindingSource1 = new System.Windows.Forms.BindingSource(this.components); + this.tableBindingSource = new System.Windows.Forms.BindingSource(this.components); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.tableBindingSource1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.tableBindingSource)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.AllowUserToOrderColumns = true; + this.dataGridView1.AutoGenerateColumns = false; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.nameDataGridViewTextBoxColumn, + this.logicalNameDataGridViewTextBoxColumn, + this.Selected}); + this.dataGridView1.DataSource = this.tableBindingSource1; + this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView1.Location = new System.Drawing.Point(0, 21); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 51; + this.dataGridView1.Size = new System.Drawing.Size(434, 543); + this.dataGridView1.TabIndex = 0; + this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick); + // + // Selected + // + this.Selected.DataPropertyName = "Selected"; + this.Selected.HeaderText = "Selected"; + this.Selected.MinimumWidth = 6; + this.Selected.Name = "Selected"; + this.Selected.Width = 125; + // + // button1 + // + this.button1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.button1.Location = new System.Drawing.Point(0, 564); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(434, 23); + this.button1.TabIndex = 1; + this.button1.Text = "Add Selected Table To Project"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Top; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.Search); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.SearchBar); + this.splitContainer1.Size = new System.Drawing.Size(434, 21); + this.splitContainer1.SplitterDistance = 232; + this.splitContainer1.TabIndex = 2; + // + // Search + // + this.Search.Dock = System.Windows.Forms.DockStyle.Bottom; + this.Search.Location = new System.Drawing.Point(0, 1); + this.Search.Name = "Search"; + this.Search.ReadOnly = true; + this.Search.Size = new System.Drawing.Size(232, 20); + this.Search.TabIndex = 1; + this.Search.Text = "Search"; + this.Search.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + this.Search.TextChanged += new System.EventHandler(this.Search_TextChanged); + // + // SearchBar + // + this.SearchBar.Dock = System.Windows.Forms.DockStyle.Fill; + this.SearchBar.Location = new System.Drawing.Point(0, 0); + this.SearchBar.Name = "SearchBar"; + this.SearchBar.Size = new System.Drawing.Size(198, 20); + this.SearchBar.TabIndex = 0; + this.SearchBar.TextChanged += new System.EventHandler(this.SearchBar_TextChanged); + // + // contextMenuStrip1 + // + this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4); + // + // nameDataGridViewTextBoxColumn + // + this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name"; + this.nameDataGridViewTextBoxColumn.HeaderText = "Name"; + this.nameDataGridViewTextBoxColumn.MinimumWidth = 6; + this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn"; + this.nameDataGridViewTextBoxColumn.ReadOnly = true; + this.nameDataGridViewTextBoxColumn.Width = 125; + // + // logicalNameDataGridViewTextBoxColumn + // + this.logicalNameDataGridViewTextBoxColumn.DataPropertyName = "LogicalName"; + this.logicalNameDataGridViewTextBoxColumn.HeaderText = "LogicalName"; + this.logicalNameDataGridViewTextBoxColumn.MinimumWidth = 6; + this.logicalNameDataGridViewTextBoxColumn.Name = "logicalNameDataGridViewTextBoxColumn"; + this.logicalNameDataGridViewTextBoxColumn.ReadOnly = true; + this.logicalNameDataGridViewTextBoxColumn.Width = 125; + // + // tableBindingSource1 + // + this.tableBindingSource1.DataSource = typeof(XrmFramework.Core.Table); + // + // tableBindingSource + // + this.tableBindingSource.DataSource = typeof(XrmFramework.Core.Table); + // + // AddTableForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(434, 587); + this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.splitContainer1); + this.Controls.Add(this.button1); + this.Name = "AddTableForm"; + this.Text = "Table Selection"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel1.PerformLayout(); + this.splitContainer1.Panel2.ResumeLayout(false); + this.splitContainer1.Panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.tableBindingSource1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.tableBindingSource)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.BindingSource tableBindingSource; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.BindingSource tableBindingSource1; + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.TextBox Search; + private System.Windows.Forms.TextBox SearchBar; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + private System.Windows.Forms.DataGridViewTextBoxColumn nameDataGridViewTextBoxColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn logicalNameDataGridViewTextBoxColumn; + private System.Windows.Forms.DataGridViewCheckBoxColumn Selected; + } +} \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/AddTableForm.cs b/src/XrmFramework.XrmToolbox.Plugin/Forms/AddTableForm.cs new file mode 100644 index 00000000..594ecd41 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/AddTableForm.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using XrmFramework.Core; +using XrmFramework.XrmToolbox.DataHandlers; + +namespace XrmFramework.XrmToolbox +{ + public partial class AddTableForm : Form + { + public List PublisherPrefixes { get; set; } = new(); + public TableCollection BaseTables = new TableCollection(); + public XrmFrameworkPluginControl PluginControl; + + public AddTableForm() + { + InitializeComponent(); + } + + public void RetrieveEntities() + { + PluginControl.RetrieveAllEntities(tableBindingSource1,BaseTables); + //BaseTables.Add(new Table { Name = "fezg", LogicalName = "fzefze" }); + + //tableBindingSource1.DataSource = BaseTables; + + } + + private void button1_Click(object sender, EventArgs e) + { + AddSelectedTablesToPluginControl(); + this.Close(); + } + + private void SearchBar_TextChanged(object sender, EventArgs e) + { + + var search = SearchBar.Text.Split(' '); + + if (search.Length == 1) + { + + var lowerSearch = SearchBar.Text.ToLower(); + + tableBindingSource1.DataSource = TableHandler.BasicTables.Where(t => t.Name.ToLower().Contains(lowerSearch) || t.LogicalName.Contains(lowerSearch)); + //tableBindingSource1.DataSource = Tableh; + + } + else + { + + var tablesToShow = new TableCollection(); + foreach (var searchWord in search) + { + if (searchWord == " " || searchWord == "") + { + continue; + } + var lowerSearch = searchWord.ToLower(); + var correspondingTables = TableHandler.BasicTables.Where(t => t.Name.ToLower().Contains(lowerSearch) || t.LogicalName.Contains(lowerSearch)); + foreach (var table in correspondingTables) + { + tablesToShow.Add(table); + } + + } + tableBindingSource1.DataSource = tablesToShow; + } + + if(SearchBar.Text == "") + { + tableBindingSource1.DataSource = TableHandler.BasicTables; + + } + } + + public void AddSelectedTablesToPluginControl() + { + PluginControl.AddTablesToProject(TableHandler.BasicTables.Where(t => t.Selected).ToList()); + PluginControl.RefreshTreeDisplay(); + + } + private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + + private void Search_TextChanged(object sender, EventArgs e) + { + + } + } +} diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/AddTableForm.resx b/src/XrmFramework.XrmToolbox.Plugin/Forms/AddTableForm.resx new file mode 100644 index 00000000..61126115 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/AddTableForm.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + 175, 17 + + + 339, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/CreateModelForm.Designer.cs b/src/XrmFramework.XrmToolbox.Plugin/Forms/CreateModelForm.Designer.cs new file mode 100644 index 00000000..ad01744f --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/CreateModelForm.Designer.cs @@ -0,0 +1,335 @@ +namespace XrmFramework.XrmToolbox.Forms +{ + partial class CreateModelForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.button2 = new System.Windows.Forms.Button(); + this.splitContainer4 = new System.Windows.Forms.SplitContainer(); + this.textBox5 = new System.Windows.Forms.TextBox(); + this.TableLogicalName = new System.Windows.Forms.TextBox(); + this.TableNameTextBox = new System.Windows.Forms.TextBox(); + this.splitContainer3 = new System.Windows.Forms.SplitContainer(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.ModelNameText = new System.Windows.Forms.TextBox(); + this.splitContainer2 = new System.Windows.Forms.SplitContainer(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.NamespaceComboBox = new System.Windows.Forms.ComboBox(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.logicalNameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.tableBindingSource = new System.Windows.Forms.BindingSource(this.components); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer4)).BeginInit(); + this.splitContainer4.Panel1.SuspendLayout(); + this.splitContainer4.Panel2.SuspendLayout(); + this.splitContainer4.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).BeginInit(); + this.splitContainer3.Panel1.SuspendLayout(); + this.splitContainer3.Panel2.SuspendLayout(); + this.splitContainer3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); + this.splitContainer2.Panel1.SuspendLayout(); + this.splitContainer2.Panel2.SuspendLayout(); + this.splitContainer2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.tableBindingSource)).BeginInit(); + this.SuspendLayout(); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.dataGridView1); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.button2); + this.splitContainer1.Panel2.Controls.Add(this.splitContainer4); + this.splitContainer1.Panel2.Controls.Add(this.splitContainer3); + this.splitContainer1.Panel2.Controls.Add(this.splitContainer2); + this.splitContainer1.Panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.splitContainer1_Panel2_Paint); + this.splitContainer1.Size = new System.Drawing.Size(783, 408); + this.splitContainer1.SplitterDistance = 403; + this.splitContainer1.SplitterWidth = 3; + this.splitContainer1.TabIndex = 0; + // + // dataGridView1 + // + this.dataGridView1.AutoGenerateColumns = false; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.nameDataGridViewTextBoxColumn, + this.logicalNameDataGridViewTextBoxColumn}); + this.dataGridView1.DataSource = this.tableBindingSource; + this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView1.Location = new System.Drawing.Point(0, 0); + this.dataGridView1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.dataGridView1.MultiSelect = false; + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 51; + this.dataGridView1.RowTemplate.Height = 24; + this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView1.Size = new System.Drawing.Size(403, 408); + this.dataGridView1.TabIndex = 0; + this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(406, 369); + this.button2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(102, 29); + this.button2.TabIndex = 5; + this.button2.Text = "Create Model"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // splitContainer4 + // + this.splitContainer4.Location = new System.Drawing.Point(33, 18); + this.splitContainer4.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.splitContainer4.Name = "splitContainer4"; + // + // splitContainer4.Panel1 + // + this.splitContainer4.Panel1.Controls.Add(this.textBox5); + // + // splitContainer4.Panel2 + // + this.splitContainer4.Panel2.Controls.Add(this.TableLogicalName); + this.splitContainer4.Panel2.Controls.Add(this.TableNameTextBox); + this.splitContainer4.Size = new System.Drawing.Size(229, 49); + this.splitContainer4.SplitterDistance = 75; + this.splitContainer4.SplitterWidth = 3; + this.splitContainer4.TabIndex = 4; + // + // textBox5 + // + this.textBox5.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox5.Location = new System.Drawing.Point(0, 0); + this.textBox5.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox5.Name = "textBox5"; + this.textBox5.ReadOnly = true; + this.textBox5.Size = new System.Drawing.Size(75, 20); + this.textBox5.TabIndex = 6; + this.textBox5.Text = "Table"; + // + // TableLogicalName + // + this.TableLogicalName.Dock = System.Windows.Forms.DockStyle.Bottom; + this.TableLogicalName.Location = new System.Drawing.Point(0, 29); + this.TableLogicalName.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.TableLogicalName.Name = "TableLogicalName"; + this.TableLogicalName.ReadOnly = true; + this.TableLogicalName.Size = new System.Drawing.Size(151, 20); + this.TableLogicalName.TabIndex = 5; + this.TableLogicalName.TextChanged += new System.EventHandler(this.textBox3_TextChanged); + // + // TableNameTextBox + // + this.TableNameTextBox.Dock = System.Windows.Forms.DockStyle.Top; + this.TableNameTextBox.Location = new System.Drawing.Point(0, 0); + this.TableNameTextBox.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.TableNameTextBox.Name = "TableNameTextBox"; + this.TableNameTextBox.ReadOnly = true; + this.TableNameTextBox.Size = new System.Drawing.Size(151, 20); + this.TableNameTextBox.TabIndex = 6; + // + // splitContainer3 + // + this.splitContainer3.Location = new System.Drawing.Point(33, 206); + this.splitContainer3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.splitContainer3.Name = "splitContainer3"; + // + // splitContainer3.Panel1 + // + this.splitContainer3.Panel1.Controls.Add(this.textBox2); + // + // splitContainer3.Panel2 + // + this.splitContainer3.Panel2.Controls.Add(this.ModelNameText); + this.splitContainer3.Size = new System.Drawing.Size(318, 21); + this.splitContainer3.SplitterDistance = 107; + this.splitContainer3.SplitterWidth = 3; + this.splitContainer3.TabIndex = 3; + // + // textBox2 + // + this.textBox2.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox2.Location = new System.Drawing.Point(0, 0); + this.textBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox2.Name = "textBox2"; + this.textBox2.ReadOnly = true; + this.textBox2.Size = new System.Drawing.Size(107, 20); + this.textBox2.TabIndex = 1; + this.textBox2.Text = "Name"; + // + // ModelNameText + // + this.ModelNameText.Dock = System.Windows.Forms.DockStyle.Fill; + this.ModelNameText.Location = new System.Drawing.Point(0, 0); + this.ModelNameText.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.ModelNameText.Name = "ModelNameText"; + this.ModelNameText.Size = new System.Drawing.Size(208, 20); + this.ModelNameText.TabIndex = 4; + // + // splitContainer2 + // + this.splitContainer2.Location = new System.Drawing.Point(33, 134); + this.splitContainer2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.splitContainer2.Name = "splitContainer2"; + // + // splitContainer2.Panel1 + // + this.splitContainer2.Panel1.Controls.Add(this.textBox1); + // + // splitContainer2.Panel2 + // + this.splitContainer2.Panel2.Controls.Add(this.NamespaceComboBox); + this.splitContainer2.Size = new System.Drawing.Size(318, 20); + this.splitContainer2.SplitterDistance = 105; + this.splitContainer2.SplitterWidth = 3; + this.splitContainer2.TabIndex = 2; + // + // textBox1 + // + this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox1.Location = new System.Drawing.Point(0, 0); + this.textBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox1.Name = "textBox1"; + this.textBox1.ReadOnly = true; + this.textBox1.Size = new System.Drawing.Size(105, 20); + this.textBox1.TabIndex = 0; + this.textBox1.Text = "Namespace"; + // + // NamespaceComboBox + // + this.NamespaceComboBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.NamespaceComboBox.FormattingEnabled = true; + this.NamespaceComboBox.Location = new System.Drawing.Point(0, 0); + this.NamespaceComboBox.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.NamespaceComboBox.Name = "NamespaceComboBox"; + this.NamespaceComboBox.Size = new System.Drawing.Size(210, 21); + this.NamespaceComboBox.TabIndex = 6; + // + // contextMenuStrip1 + // + this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4); + // + // nameDataGridViewTextBoxColumn + // + this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name"; + this.nameDataGridViewTextBoxColumn.HeaderText = "Name"; + this.nameDataGridViewTextBoxColumn.MinimumWidth = 6; + this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn"; + this.nameDataGridViewTextBoxColumn.ReadOnly = true; + this.nameDataGridViewTextBoxColumn.Width = 125; + // + // logicalNameDataGridViewTextBoxColumn + // + this.logicalNameDataGridViewTextBoxColumn.DataPropertyName = "LogicalName"; + this.logicalNameDataGridViewTextBoxColumn.HeaderText = "LogicalName"; + this.logicalNameDataGridViewTextBoxColumn.MinimumWidth = 6; + this.logicalNameDataGridViewTextBoxColumn.Name = "logicalNameDataGridViewTextBoxColumn"; + this.logicalNameDataGridViewTextBoxColumn.ReadOnly = true; + this.logicalNameDataGridViewTextBoxColumn.Width = 125; + // + // tableBindingSource + // + this.tableBindingSource.DataSource = typeof(XrmFramework.Core.Table); + // + // CreateModelForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(783, 408); + this.Controls.Add(this.splitContainer1); + this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Name = "CreateModelForm"; + this.Text = "Model Creation"; + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.splitContainer4.Panel1.ResumeLayout(false); + this.splitContainer4.Panel1.PerformLayout(); + this.splitContainer4.Panel2.ResumeLayout(false); + this.splitContainer4.Panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer4)).EndInit(); + this.splitContainer4.ResumeLayout(false); + this.splitContainer3.Panel1.ResumeLayout(false); + this.splitContainer3.Panel1.PerformLayout(); + this.splitContainer3.Panel2.ResumeLayout(false); + this.splitContainer3.Panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).EndInit(); + this.splitContainer3.ResumeLayout(false); + this.splitContainer2.Panel1.ResumeLayout(false); + this.splitContainer2.Panel1.PerformLayout(); + this.splitContainer2.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); + this.splitContainer2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.tableBindingSource)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.BindingSource tableBindingSource; + private System.Windows.Forms.SplitContainer splitContainer3; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.TextBox ModelNameText; + private System.Windows.Forms.SplitContainer splitContainer2; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + private System.Windows.Forms.TextBox TableNameTextBox; + private System.Windows.Forms.TextBox TableLogicalName; + private System.Windows.Forms.SplitContainer splitContainer4; + private System.Windows.Forms.TextBox textBox5; + private System.Windows.Forms.DataGridViewTextBoxColumn nameDataGridViewTextBoxColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn logicalNameDataGridViewTextBoxColumn; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.ComboBox NamespaceComboBox; + } +} \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/CreateModelForm.cs b/src/XrmFramework.XrmToolbox.Plugin/Forms/CreateModelForm.cs new file mode 100644 index 00000000..fc58b284 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/CreateModelForm.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using XrmFramework.Core; +using XrmFramework.XrmToolbox.DataHandlers; + +namespace XrmFramework.XrmToolbox.Forms +{ + public partial class CreateModelForm : Form + { + public XrmFrameworkPluginControl PluginControl; + public bool CreateModel = false; + public string modelName; + public string modelNamespace; + public string tableLogicalName; + + public CreateModelForm() + { + InitializeComponent(); + } + + private void textBox3_TextChanged(object sender, EventArgs e) + { + + } + + public void SetTableBindingSource(TableCollection tables) + { + tableBindingSource.DataSource = tables; + } + + private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + if(dataGridView1.SelectedRows.Count > 0) + { + TableNameTextBox.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); + TableLogicalName.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString(); + } + } + + private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e) + { + + } + + private void button2_Click(object sender, EventArgs e) + { + tableLogicalName = TableLogicalName.Text; + modelName = ModelNameText.Text; + modelNamespace = NamespaceComboBox.Text; + if(string.IsNullOrEmpty(tableLogicalName)) + { + MessageBox.Show("Select a table to create a model from."); + return; + } + if (string.IsNullOrEmpty(modelNamespace)) + { + MessageBox.Show("Select a namespace in which to create your model."); + return; + } + if (string.IsNullOrEmpty(modelName)) + { + MessageBox.Show("Give a name to your model"); + return; + } + CreateModel = true; + Close(); + } + + public void SetExistingNamespaces(List namespaces) + { + NamespaceComboBox.Items.AddRange(namespaces.ToArray()); + } + } +} diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/CreateModelForm.resx b/src/XrmFramework.XrmToolbox.Plugin/Forms/CreateModelForm.resx new file mode 100644 index 00000000..28545025 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/CreateModelForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 206, 17 + + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/PickListChoiceForm.Designer.cs b/src/XrmFramework.XrmToolbox.Plugin/Forms/PickListChoiceForm.Designer.cs new file mode 100644 index 00000000..f023afcf --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/PickListChoiceForm.Designer.cs @@ -0,0 +1,119 @@ +namespace XrmFramework.XrmToolbox.Forms +{ + partial class PickListChoiceForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ChoiceComboBox = new System.Windows.Forms.ComboBox(); + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + this.SuspendLayout(); + // + // ChoiceComboBox + // + this.ChoiceComboBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.ChoiceComboBox.FormattingEnabled = true; + this.ChoiceComboBox.Location = new System.Drawing.Point(0, 0); + this.ChoiceComboBox.Margin = new System.Windows.Forms.Padding(2); + this.ChoiceComboBox.Name = "ChoiceComboBox"; + this.ChoiceComboBox.Size = new System.Drawing.Size(314, 21); + this.ChoiceComboBox.TabIndex = 0; + this.ChoiceComboBox.SelectedIndexChanged += new System.EventHandler(this.ChoiceComboBox_SelectedIndexChanged); + // + // splitContainer1 + // + this.splitContainer1.Location = new System.Drawing.Point(28, 67); + this.splitContainer1.Margin = new System.Windows.Forms.Padding(2); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.textBox1); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.ChoiceComboBox); + this.splitContainer1.Size = new System.Drawing.Size(475, 24); + this.splitContainer1.SplitterDistance = 158; + this.splitContainer1.SplitterWidth = 3; + this.splitContainer1.TabIndex = 1; + // + // textBox1 + // + this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox1.Location = new System.Drawing.Point(0, 0); + this.textBox1.Margin = new System.Windows.Forms.Padding(2); + this.textBox1.Name = "textBox1"; + this.textBox1.ReadOnly = true; + this.textBox1.Size = new System.Drawing.Size(158, 20); + this.textBox1.TabIndex = 0; + this.textBox1.Text = "Pick"; + // + // button1 + // + this.button1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.button1.Location = new System.Drawing.Point(0, 188); + this.button1.Margin = new System.Windows.Forms.Padding(2); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(521, 26); + this.button1.TabIndex = 2; + this.button1.Text = "Change value"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // PickListChoiceForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(521, 214); + this.Controls.Add(this.button1); + this.Controls.Add(this.splitContainer1); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "PickListChoiceForm"; + this.Text = "Choice"; + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel1.PerformLayout(); + this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ComboBox ChoiceComboBox; + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Button button1; + } +} \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/PickListChoiceForm.cs b/src/XrmFramework.XrmToolbox.Plugin/Forms/PickListChoiceForm.cs new file mode 100644 index 00000000..c6c1cfea --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/PickListChoiceForm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace XrmFramework.XrmToolbox.Forms +{ + public partial class PickListChoiceForm : Form + { + public string Value = ""; + public bool ChangeValue = false; + + public PickListChoiceForm(bool IsDropDownList) + { + + InitializeComponent(); + //ChoiceComboBox.SelectedValueChanged += ChoiceComboBox_SelectedIndexChanged; + //ChoiceComboBox.DropDownClosed += ChoiceComboBox_SelectedIndexChanged; + + if (IsDropDownList) + { + ChoiceComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + } + else + { + ChoiceComboBox.DropDownStyle = ComboBoxStyle.DropDown; + } + } + + private void ChoiceComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + //MessageBox.Show("Changed value"); + Value = ChoiceComboBox.Text; + + } + + public void SetPossibleChoices(List choices) + { + ChoiceComboBox.Items.AddRange(choices.ToArray()); + } + + private void button1_Click(object sender, EventArgs e) + { + ChangeValue = true; + Close(); + } + } +} diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/PickListChoiceForm.resx b/src/XrmFramework.XrmToolbox.Plugin/Forms/PickListChoiceForm.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/PickListChoiceForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/ProjectCreationForm.Designer.cs b/src/XrmFramework.XrmToolbox.Plugin/Forms/ProjectCreationForm.Designer.cs new file mode 100644 index 00000000..263826bb --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/ProjectCreationForm.Designer.cs @@ -0,0 +1,191 @@ +namespace XrmFramework.XrmToolbox +{ + partial class ProjectCreationForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.button1 = new System.Windows.Forms.Button(); + this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); + this.splitContainer2 = new System.Windows.Forms.SplitContainer(); + this.textBox3 = new System.Windows.Forms.TextBox(); + this.textBox4 = new System.Windows.Forms.TextBox(); + this.button2 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); + this.splitContainer2.Panel1.SuspendLayout(); + this.splitContainer2.Panel2.SuspendLayout(); + this.splitContainer2.SuspendLayout(); + this.SuspendLayout(); + // + // textBox1 + // + this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox1.Location = new System.Drawing.Point(0, 0); + this.textBox1.Margin = new System.Windows.Forms.Padding(2); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(198, 20); + this.textBox1.TabIndex = 0; + // + // textBox2 + // + this.textBox2.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox2.Location = new System.Drawing.Point(0, 0); + this.textBox2.Margin = new System.Windows.Forms.Padding(2); + this.textBox2.Name = "textBox2"; + this.textBox2.ReadOnly = true; + this.textBox2.Size = new System.Drawing.Size(99, 20); + this.textBox2.TabIndex = 1; + this.textBox2.Text = "Project Name"; + // + // splitContainer1 + // + this.splitContainer1.Location = new System.Drawing.Point(73, 109); + this.splitContainer1.Margin = new System.Windows.Forms.Padding(2); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.textBox2); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.textBox1); + this.splitContainer1.Size = new System.Drawing.Size(300, 21); + this.splitContainer1.SplitterDistance = 99; + this.splitContainer1.SplitterWidth = 3; + this.splitContainer1.TabIndex = 2; + // + // button1 + // + this.button1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.button1.Location = new System.Drawing.Point(0, 312); + this.button1.Margin = new System.Windows.Forms.Padding(2); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(600, 54); + this.button1.TabIndex = 3; + this.button1.Text = "Create Project"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // splitContainer2 + // + this.splitContainer2.Location = new System.Drawing.Point(73, 156); + this.splitContainer2.Margin = new System.Windows.Forms.Padding(2); + this.splitContainer2.Name = "splitContainer2"; + // + // splitContainer2.Panel1 + // + this.splitContainer2.Panel1.Controls.Add(this.textBox3); + // + // splitContainer2.Panel2 + // + this.splitContainer2.Panel2.Controls.Add(this.textBox4); + this.splitContainer2.Size = new System.Drawing.Size(300, 21); + this.splitContainer2.SplitterDistance = 99; + this.splitContainer2.SplitterWidth = 3; + this.splitContainer2.TabIndex = 2; + // + // textBox3 + // + this.textBox3.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox3.Location = new System.Drawing.Point(0, 0); + this.textBox3.Margin = new System.Windows.Forms.Padding(2); + this.textBox3.Name = "textBox3"; + this.textBox3.ReadOnly = true; + this.textBox3.Size = new System.Drawing.Size(99, 20); + this.textBox3.TabIndex = 1; + this.textBox3.Text = "Project Path"; + // + // textBox4 + // + this.textBox4.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox4.Location = new System.Drawing.Point(0, 0); + this.textBox4.Margin = new System.Windows.Forms.Padding(2); + this.textBox4.Name = "textBox4"; + this.textBox4.ReadOnly = true; + this.textBox4.Size = new System.Drawing.Size(198, 20); + this.textBox4.TabIndex = 0; + this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(377, 156); + this.button2.Margin = new System.Windows.Forms.Padding(2); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(148, 21); + this.button2.TabIndex = 4; + this.button2.Text = "Set Project Path"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // ProjectCreationForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(600, 366); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.splitContainer2); + this.Controls.Add(this.splitContainer1); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "ProjectCreationForm"; + this.Text = "Project Creation"; + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel1.PerformLayout(); + this.splitContainer1.Panel2.ResumeLayout(false); + this.splitContainer1.Panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.splitContainer2.Panel1.ResumeLayout(false); + this.splitContainer2.Panel1.PerformLayout(); + this.splitContainer2.Panel2.ResumeLayout(false); + this.splitContainer2.Panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); + this.splitContainer2.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1; + private System.Windows.Forms.SplitContainer splitContainer2; + private System.Windows.Forms.TextBox textBox3; + private System.Windows.Forms.TextBox textBox4; + private System.Windows.Forms.Button button2; + } +} \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/ProjectCreationForm.cs b/src/XrmFramework.XrmToolbox.Plugin/Forms/ProjectCreationForm.cs new file mode 100644 index 00000000..9762691d --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/ProjectCreationForm.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Management.Automation; +using System.Management.Automation.Runspaces; +using System.IO; +using System.Threading; +using System.Collections.ObjectModel; +using System.Diagnostics; + +namespace XrmFramework.XrmToolbox +{ + public partial class ProjectCreationForm : Form + { + public string ProjectPath = ""; + public XrmFrameworkPluginControl PluginControl; + + public ProjectCreationForm() + { + InitializeComponent(); + PromptProjectFolderSelection(); + } + + private void button1_Click(object sender, EventArgs e) + { + if(string.IsNullOrEmpty(textBox1.Text)) + { + MessageBox.Show("Enter a valid project name"); + return; + } + if(string.IsNullOrEmpty(ProjectPath)) + { + MessageBox.Show("Select a valid folder to create your project"); + PromptProjectFolderSelection(); + + } + + var projectName = textBox1.Text; + var cmdText = $"/C powershell -command \" dotnet new -i XrmFramework.Templates\""; + var cmdText2 = $"/C powershell -command \"Set-Location {ProjectPath}; dotnet new xrmSolution -n {projectName};\""; + var cmdText3 = $"/C powershell -command \"Set-Location {ProjectPath}" +"\\"+projectName + "; mv gitignore .gitignore;cp Config/connectionStrings.config.sample Config/connectionStrings.config ;rm initXrm.ps1;\""; + //Process process = new Process(); + ProcessStartInfo startInfo = new ProcessStartInfo(); + //startInfo.Arguments = $"new -i XrmFramework.Templates"; + startInfo.Arguments = cmdText; + startInfo.FileName = "cmd.exe"; + startInfo.WorkingDirectory = ProjectPath; + //startInfo.FileName = "dotnet"; + var process = Process.Start(startInfo); + process.WaitForExit(); + + //startInfo.Arguments = $"new -n {projectName}"; + startInfo.FileName = "cmd.exe"; + //startInfo.FileName = "dotnet"; + startInfo.Arguments = cmdText2; + + //startInfo.Verb = "runas"; + var process2 = Process.Start(startInfo); + process2.WaitForExit(); + + startInfo.WorkingDirectory = ProjectPath + "\\" + projectName; + startInfo.Arguments = cmdText3; + var process3 = Process.Start(startInfo); + process3.WaitForExit(); + + // plugin Control add the path to this project and set it as current + PluginControl.SetCurrentProject(ProjectPath + "\\" + projectName); + this.Close(); + //process2.WaitForInputIdle(); + //Run creation commands in powershell opened from the project folder + //System.Diagnostics.Process.Start("CMD.exe", cmdText); + + + + + } + + private void PromptProjectFolderSelection() + { + folderBrowserDialog1.ShowDialog(); + if (Directory.Exists(folderBrowserDialog1.SelectedPath)) + { + ProjectPath = folderBrowserDialog1.SelectedPath; + } + else + { + MessageBox.Show("Selected path is invalid"); + PromptProjectFolderSelection(); + } + + textBox4.Text = ProjectPath; + } + + private void textBox4_TextChanged(object sender, EventArgs e) + { + + } + + private void button2_Click(object sender, EventArgs e) + { + PromptProjectFolderSelection(); + } + } +} diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/ProjectCreationForm.resx b/src/XrmFramework.XrmToolbox.Plugin/Forms/ProjectCreationForm.resx new file mode 100644 index 00000000..69f943da --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/ProjectCreationForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/TryOtherNameForm.Designer.cs b/src/XrmFramework.XrmToolbox.Plugin/Forms/TryOtherNameForm.Designer.cs new file mode 100644 index 00000000..17d68a78 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/TryOtherNameForm.Designer.cs @@ -0,0 +1,109 @@ +namespace XrmFramework.XrmToolbox +{ + partial class TryOtherNameForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // textBox1 + // + this.textBox1.Dock = System.Windows.Forms.DockStyle.Top; + this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 13.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.textBox1.Location = new System.Drawing.Point(0, 0); + this.textBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox1.Name = "textBox1"; + this.textBox1.ReadOnly = true; + this.textBox1.Size = new System.Drawing.Size(602, 28); + this.textBox1.TabIndex = 0; + this.textBox1.Text = "Enter a new name"; + this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // textBox2 + // + this.textBox2.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 16.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.textBox2.Location = new System.Drawing.Point(0, 28); + this.textBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(602, 32); + this.textBox2.TabIndex = 1; + this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged); + // + // button1 + // + this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 13.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.button1.Location = new System.Drawing.Point(338, 234); + this.button1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(255, 31); + this.button1.TabIndex = 2; + this.button1.Text = "Confirm new name"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 13.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.button2.Location = new System.Drawing.Point(9, 234); + this.button2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(255, 31); + this.button2.TabIndex = 3; + this.button2.Text = "Cancel"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // TryOtherNameForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(602, 275); + this.Controls.Add(this.button2); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.button1); + this.Controls.Add(this.textBox1); + this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Name = "TryOtherNameForm"; + this.Text = "Name Change"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + } +} \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/TryOtherNameForm.cs b/src/XrmFramework.XrmToolbox.Plugin/Forms/TryOtherNameForm.cs new file mode 100644 index 00000000..c9189e0c --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/TryOtherNameForm.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace XrmFramework.XrmToolbox +{ + public partial class TryOtherNameForm : Form + { + public XrmFrameworkPluginControl PluginControl; + public string Name; + public bool ModifyName = false; + public TryOtherNameForm(string currentName) + { + InitializeComponent(); + textBox2.Text = currentName; + Name = currentName; + } + + private void textBox2_TextChanged(object sender, EventArgs e) + { + if(!String.IsNullOrEmpty(textBox2.Text)) + { + Name = textBox2.Text; + } + } + + private void button1_Click(object sender, EventArgs e) + { + ModifyName = true; + this.Close(); + } + + private void button2_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/src/XrmFramework.XrmToolbox.Plugin/Forms/TryOtherNameForm.resx b/src/XrmFramework.XrmToolbox.Plugin/Forms/TryOtherNameForm.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Forms/TryOtherNameForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Column.datasource b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Column.datasource new file mode 100644 index 00000000..e36759b0 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Column.datasource @@ -0,0 +1,10 @@ + + + + XrmFramework.Core.Column, XrmFramework.XrmToolbox.Plugin, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.ColumnCollection.datasource b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.ColumnCollection.datasource new file mode 100644 index 00000000..f05073e2 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.ColumnCollection.datasource @@ -0,0 +1,10 @@ + + + + XrmFramework.Core.ColumnCollection, XrmFramework.XrmToolbox.Plugin, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Key.datasource b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Key.datasource new file mode 100644 index 00000000..fc1b8bf0 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Key.datasource @@ -0,0 +1,10 @@ + + + + XrmFramework.Core.Key, XrmFramework.XrmToolbox.Plugin, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Model.datasource b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Model.datasource new file mode 100644 index 00000000..f5c1dcec --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Model.datasource @@ -0,0 +1,10 @@ + + + + XrmFramework.Core.Model, XrmFramework.XrmToolbox.Plugin, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.ModelProperty.datasource b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.ModelProperty.datasource new file mode 100644 index 00000000..de0d7884 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.ModelProperty.datasource @@ -0,0 +1,10 @@ + + + + XrmFramework.Core.ModelProperty, XrmFramework.XrmToolbox.Plugin, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.OptionSetEnum.datasource b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.OptionSetEnum.datasource new file mode 100644 index 00000000..4ecb7e96 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.OptionSetEnum.datasource @@ -0,0 +1,10 @@ + + + + XrmFramework.Core.OptionSetEnum, XrmFramework.XrmToolbox.Plugin, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.OptionSetEnumValue.datasource b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.OptionSetEnumValue.datasource new file mode 100644 index 00000000..25da2312 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.OptionSetEnumValue.datasource @@ -0,0 +1,10 @@ + + + + XrmFramework.Core.OptionSetEnumValue, XrmFramework.XrmToolbox.Plugin, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Relation.datasource b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Relation.datasource new file mode 100644 index 00000000..43af4306 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Relation.datasource @@ -0,0 +1,10 @@ + + + + XrmFramework.Core.Relation, XrmFramework.XrmToolbox.Plugin, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Table.datasource b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Table.datasource new file mode 100644 index 00000000..a7312898 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.Table.datasource @@ -0,0 +1,10 @@ + + + + XrmFramework.Core.Table, XrmFramework.XrmToolbox.Plugin, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.TableCollection.datasource b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.TableCollection.datasource new file mode 100644 index 00000000..36dfb413 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/Properties/DataSources/XrmFramework.Core.TableCollection.datasource @@ -0,0 +1,10 @@ + + + + XrmFramework.Core.TableCollection, XrmFramework.XrmToolbox.Plugin, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/Settings.cs b/src/XrmFramework.XrmToolbox.Plugin/Settings.cs index e41056e8..c64fe2af 100644 --- a/src/XrmFramework.XrmToolbox.Plugin/Settings.cs +++ b/src/XrmFramework.XrmToolbox.Plugin/Settings.cs @@ -1,4 +1,7 @@ -namespace XrmFramework.XrmToolbox +using System; +using System.Collections.Generic; + +namespace XrmFramework.XrmToolbox { /// /// This class can help you to store settings for your plugin @@ -8,8 +11,26 @@ /// public class Settings { + public string LastUsedOrganizationWebappUrl { get; set; } - public string LastUsedOrganizationName { get; set; } + public string CurrentOrganizationName { get; set; } + + public List RootFolders { get; set; } = new List(); + } + [Serializable] + public class Project + { + public Project() + { + + } + public Project(string orgName, string folderPath) + { + OrganizationName = orgName; + FolderPath = folderPath; + } + public string OrganizationName { get; set; } + public string FolderPath { get;set; } } } \ No newline at end of file diff --git a/src/XrmFramework.XrmToolbox.Plugin/TextHelper.cs b/src/XrmFramework.XrmToolbox.Plugin/TextHelper.cs new file mode 100644 index 00000000..067c7006 --- /dev/null +++ b/src/XrmFramework.XrmToolbox.Plugin/TextHelper.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace XrmFramework.XrmToolbox +{ + internal static class TextHelper + { + internal static string FormatText(this string text) + { + text = text.Replace("'", " ").Replace("‘", " ").Replace("’", " ").Replace("_", " ").Replace(",", " ").Replace("-", " ").Replace("(", " ").Replace(")", " ").Replace(":", " ").Replace("/", " ").Replace("\\", " ").Replace("%", " Pourcent ").Replace("+", " Plus ").Replace("&", " ") + // Characters looking like spaces but not spaces + .Replace(" ", " ").Replace(" ", " "); + text = RemoveDiacritics(text); + + var cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture; + var textInfo = cultureInfo.TextInfo; + + text = textInfo.ToTitleCase(text); + + text = text.Replace(" ", ""); + + return text; + } + + static string RemoveDiacritics(string text) + { + var normalizedString = text.Normalize(NormalizationForm.FormD); + var stringBuilder = new StringBuilder(); + + foreach (var c in normalizedString) + { + var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c); + if (unicodeCategory != UnicodeCategory.NonSpacingMark) + { + stringBuilder.Append(c); + } + } + + return stringBuilder.ToString().Normalize(NormalizationForm.FormC); + } + + internal static string StrongFormat(this string text) + { + text = text.Replace("'", " ").Replace("‘", " ").Replace("’", " ").Replace("_", " ").Replace(",", " ").Replace("-", " ").Replace("(", " ").Replace(")", " ").Replace(":", " ").Replace("/", " ").Replace("\\", " ").Replace("%", " Pourcent ").Replace("+", " Plus ").Replace("&", " ") + // Characters looking like spaces but not spaces + .Replace(" ", " ").Replace(" ", " ").Replace("."," "); + var splitText = text.Split(' '); + for(int i = 0; i < splitText.Length; i++) + { + var word = RemoveDiacritics(splitText[i]); + var cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture; + var textInfo = cultureInfo.TextInfo; + word = textInfo.ToTitleCase(word); + splitText[i] = word; + + } + text = string.Join("",splitText); + return text; + } + } +} diff --git a/src/XrmFramework.XrmToolbox.Plugin/XrmFramework.XrmToolbox.Plugin.csproj b/src/XrmFramework.XrmToolbox.Plugin/XrmFramework.XrmToolbox.Plugin.csproj index fe6f1c83..042ed3fe 100644 --- a/src/XrmFramework.XrmToolbox.Plugin/XrmFramework.XrmToolbox.Plugin.csproj +++ b/src/XrmFramework.XrmToolbox.Plugin/XrmFramework.XrmToolbox.Plugin.csproj @@ -32,6 +32,10 @@ + + {C6444169-E29C-4B5B-B5EE-94E5CA4FF836} + XrmFramework.DeployUtils + true @@ -40,6 +44,7 @@ + @@ -47,6 +52,16 @@ + + + + + + + + + + @@ -61,6 +76,7 @@ False + @@ -83,6 +99,45 @@ + + + + Form + + + AddModelPropertyForm.cs + + + Form + + + AddTableForm.cs + + + Form + + + CreateModelForm.cs + + + Form + + + PickListChoiceForm.cs + + + Form + + + ProjectCreationForm.cs + + + + Form + + + TryOtherNameForm.cs + UserControl @@ -100,6 +155,9 @@ 3.0.6 + + 3.0.41 + 3.6.3 @@ -200,6 +258,30 @@ 1.2022.4.55 + + + AddModelPropertyForm.cs + + + AddTableForm.cs + + + CreateModelForm.cs + + + PickListChoiceForm.cs + + + ProjectCreationForm.cs + + + TryOtherNameForm.cs + + + XrmFrameworkPluginControl.cs + + + @@ -210,6 +292,15 @@ ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 26, 26 + + + 230, 26 + + + True + + + 730, 26 + + + 361, 96 + + + 26, 96 + + + 483, 26 + + + 26, 96 + + + 483, 26 + + + 744, 95 + + + 933, 95 + + + 14, 130 + + + 270, 130 + + + 138, 130 + + + 1454, 26 + + + 1051, 26 + + \ No newline at end of file diff --git a/src/XrmFramework.sln b/src/XrmFramework.sln index d1d4810b..3dee05c9 100644 --- a/src/XrmFramework.sln +++ b/src/XrmFramework.sln @@ -44,8 +44,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XrmFramework.Analyzers.Test EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XrmFramework.ModelManager", "XrmFramework.ModelManager\XrmFramework.ModelManager.csproj", "{24CA564D-6656-4DFF-B4EF-68B2FDFB989F}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GenerateTableFilesFromLocalCode", "GenerateTableFilesFromLocalCode\GenerateTableFilesFromLocalCode.csproj", "{9C53B650-6A44-463F-9380-73EFAF6D3B06}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XrmFramework.XrmToolbox.Plugin", "XrmFramework.XrmToolbox.Plugin\XrmFramework.XrmToolbox.Plugin.csproj", "{7DD9F376-F6BA-426E-A559-28B8216EDCD7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XrmFramework.Plugin.tests", "Tests\XrmFramework.Plugin.tests\XrmFramework.Plugin.tests.csproj", "{AF8361C8-D9CD-45FD-B711-8087BD8DC478}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -104,6 +108,14 @@ Global {24CA564D-6656-4DFF-B4EF-68B2FDFB989F}.Debug|Any CPU.Build.0 = Debug|Any CPU {24CA564D-6656-4DFF-B4EF-68B2FDFB989F}.Release|Any CPU.ActiveCfg = Release|Any CPU {24CA564D-6656-4DFF-B4EF-68B2FDFB989F}.Release|Any CPU.Build.0 = Release|Any CPU + {9C53B650-6A44-463F-9380-73EFAF6D3B06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C53B650-6A44-463F-9380-73EFAF6D3B06}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9C53B650-6A44-463F-9380-73EFAF6D3B06}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9C53B650-6A44-463F-9380-73EFAF6D3B06}.Release|Any CPU.Build.0 = Release|Any CPU + {AF8361C8-D9CD-45FD-B711-8087BD8DC478}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF8361C8-D9CD-45FD-B711-8087BD8DC478}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF8361C8-D9CD-45FD-B711-8087BD8DC478}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF8361C8-D9CD-45FD-B711-8087BD8DC478}.Release|Any CPU.Build.0 = Release|Any CPU {7DD9F376-F6BA-426E-A559-28B8216EDCD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7DD9F376-F6BA-426E-A559-28B8216EDCD7}.Debug|Any CPU.Build.0 = Debug|Any CPU {7DD9F376-F6BA-426E-A559-28B8216EDCD7}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -117,6 +129,7 @@ Global {F640F8B2-D3B3-4407-85B6-20C490C4CD03} = {B88F9CEB-5647-49D0-BD31-27E658C52654} {F0F25FBD-4399-4827-9473-6BF7569B5592} = {B88F9CEB-5647-49D0-BD31-27E658C52654} {9D13B1BA-A572-4E63-9D91-EBDC09C05314} = {B88F9CEB-5647-49D0-BD31-27E658C52654} + {AF8361C8-D9CD-45FD-B711-8087BD8DC478} = {B88F9CEB-5647-49D0-BD31-27E658C52654} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {101361B0-96D3-40B0-8818-D69388B1A16D} diff --git a/src/XrmFramework/Definitions/Businessunit.table b/src/XrmFramework/Definitions/Businessunit.table index 0cc43501..6a1db838 100644 --- a/src/XrmFramework/Definitions/Businessunit.table +++ b/src/XrmFramework/Definitions/Businessunit.table @@ -10,14 +10,16 @@ "PrimaryType": "Id", "Capa": 13, "Locked": true, + "Labels": [ { "Label": "Division", "LangId": 1036 } - ] + ], + "Select": true }, - + { "LogName": "name", "Name": "Name", @@ -31,7 +33,8 @@ "LangId": 1036 } ], - "StrLen": 160 + "StrLen": 160, + "Select": true } ], "NtoN": [], diff --git a/src/XrmFramework/Definitions/Environmentvariabledefinition.table b/src/XrmFramework/Definitions/Environmentvariabledefinition.table index 063dba81..42e89a1a 100644 --- a/src/XrmFramework/Definitions/Environmentvariabledefinition.table +++ b/src/XrmFramework/Definitions/Environmentvariabledefinition.table @@ -16,7 +16,8 @@ "LangId": 1036 } ], - "StrLen": 2000 + "StrLen": 2000, + "Select": true }, { @@ -31,7 +32,8 @@ "LangId": 1036 } ], - "StrLen": 100 + "StrLen": 100, + "Select": true }, { "LogName": "environmentvariabledefinitionid", @@ -45,7 +47,8 @@ "Label": "Environment Variable Definition", "LangId": 1036 } - ] + ], + "Select": true }, { @@ -61,11 +64,12 @@ "LangId": 1036 } ], - "StrLen": 100 + "StrLen": 100, + "Select": true }, - - + + { "LogName": "type", "Name": "Type", @@ -78,7 +82,8 @@ "LangId": 1036 } ], - "EnumName": "environmentvariabledefinition|type" + "EnumName": "environmentvariabledefinition|type", + "Select": true }, { "LogName": "valueschema", @@ -92,7 +97,8 @@ "LangId": 1036 } ], - "StrLen": 2000 + "StrLen": 2000, + "Select": true } ], "NtoN": [ diff --git a/src/XrmFramework/Definitions/Environmentvariablevalue.table b/src/XrmFramework/Definitions/Environmentvariablevalue.table index 39acd420..d9f63a3a 100644 --- a/src/XrmFramework/Definitions/Environmentvariablevalue.table +++ b/src/XrmFramework/Definitions/Environmentvariablevalue.table @@ -14,7 +14,8 @@ "Label": "Environment Variable Definition", "LangId": 1036 } - ] + ], + "Select": true }, { @@ -29,12 +30,13 @@ "LangId": 1036 } ], - "StrLen": 2000 + "StrLen": 2000, + "Select": true } - - - - + + + + ], "NtoN": [], "OneToN": [ diff --git a/src/XrmFramework/Definitions/Pluginassembly.table b/src/XrmFramework/Definitions/Pluginassembly.table index 7d8ab519..9a81666e 100644 --- a/src/XrmFramework/Definitions/Pluginassembly.table +++ b/src/XrmFramework/Definitions/Pluginassembly.table @@ -3,11 +3,11 @@ "Name": "PluginAssembly", "CollName": "pluginassemblies", "Cols": [ - - - - - + + + + + { "LogName": "name", "Name": "Name", @@ -21,7 +21,8 @@ "LangId": 1036 } ], - "StrLen": 256 + "StrLen": 256, + "Select": true }, { "LogName": "pluginassemblyid", @@ -30,7 +31,8 @@ "PrimaryType": "Id", "Capa": 5, "Locked": true, - "Labels": [] + "Labels": [], + "Select": true }, diff --git a/src/XrmFramework/Definitions/Plugintype.table b/src/XrmFramework/Definitions/Plugintype.table index 2705a055..e8303f26 100644 --- a/src/XrmFramework/Definitions/Plugintype.table +++ b/src/XrmFramework/Definitions/Plugintype.table @@ -15,7 +15,8 @@ "LangId": 1036 } ], - "StrLen": 100 + "StrLen": 100, + "Select": true }, { "LogName": "culture", @@ -29,7 +30,8 @@ "LangId": 1036 } ], - "StrLen": 32 + "StrLen": 32, + "Select": true }, @@ -48,7 +50,8 @@ "LangId": 1036 } ], - "StrLen": 256 + "StrLen": 256, + "Select": true }, { @@ -63,7 +66,8 @@ "Label": "Type de plug-in", "LangId": 1036 } - ] + ], + "Select": true }, { "LogName": "publickeytoken", @@ -77,7 +81,8 @@ "LangId": 1036 } ], - "StrLen": 32 + "StrLen": 32, + "Select": true }, { "LogName": "typename", @@ -91,7 +96,8 @@ "LangId": 1036 } ], - "StrLen": 256 + "StrLen": 256, + "Select": true }, { "LogName": "version", @@ -105,7 +111,8 @@ "LangId": 1036 } ], - "StrLen": 48 + "StrLen": 48, + "Select": true } ], "NtoN": [], diff --git a/src/XrmFramework/Definitions/Role.table b/src/XrmFramework/Definitions/Role.table index bc004285..f6f54ee9 100644 --- a/src/XrmFramework/Definitions/Role.table +++ b/src/XrmFramework/Definitions/Role.table @@ -14,7 +14,8 @@ "Label": "Division", "LangId": 1036 } - ] + ], + "Select": true }, { "LogName": "name", @@ -29,7 +30,8 @@ "LangId": 1036 } ], - "StrLen": 100 + "StrLen": 100, + "Select": true }, { "LogName": "parentrootroleid", @@ -42,7 +44,8 @@ "Label": "Rôle racine parent", "LangId": 1036 } - ] + ], + "Select": true }, { "LogName": "roleid", @@ -56,7 +59,8 @@ "Label": "Rôle", "LangId": 1036 } - ] + ], + "Select": true }, { "LogName": "roletemplateid", @@ -69,7 +73,8 @@ "Label": "Modèle de rôle", "LangId": 1036 } - ] + ], + "Select": true } ], "NtoN": [ diff --git a/src/XrmFramework/Definitions/Sdkmessageprocessingstep.table b/src/XrmFramework/Definitions/Sdkmessageprocessingstep.table index 34a9c4fe..c99cc249 100644 --- a/src/XrmFramework/Definitions/Sdkmessageprocessingstep.table +++ b/src/XrmFramework/Definitions/Sdkmessageprocessingstep.table @@ -18,7 +18,8 @@ "LangId": 1036 } ], - "StrLen": 256 + "StrLen": 256, + "Select": true }, { "LogName": "plugintypeid", @@ -31,7 +32,8 @@ "Label": "Type de plug-in", "LangId": 1036 } - ] + ], + "Select": true }, { "LogName": "sdkmessageprocessingstepid", @@ -40,7 +42,8 @@ "PrimaryType": "Id", "Capa": 5, "Locked": true, - "Labels": [] + "Labels": [], + "Select": true }, diff --git a/src/XrmFramework/Definitions/Sdkmessageprocessingstepimage.table b/src/XrmFramework/Definitions/Sdkmessageprocessingstepimage.table index c12d3dd5..fd1a312f 100644 --- a/src/XrmFramework/Definitions/Sdkmessageprocessingstepimage.table +++ b/src/XrmFramework/Definitions/Sdkmessageprocessingstepimage.table @@ -3,7 +3,7 @@ "Name": "Sdkmessageprocessingstepimage", "CollName": "sdkmessageprocessingstepimages", "Cols": [ - + { "LogName": "name", "Name": "Name", @@ -17,7 +17,8 @@ "LangId": 1036 } ], - "StrLen": 256 + "StrLen": 256, + "Select": true }, { "LogName": "sdkmessageprocessingstepimageid", @@ -26,7 +27,8 @@ "PrimaryType": "Id", "Capa": 13, "Locked": true, - "Labels": [] + "Labels": [], + "Select": true } ], "NtoN": [], diff --git a/src/XrmFramework/Definitions/Sdkmessageprocessingstepsecureconfig.table b/src/XrmFramework/Definitions/Sdkmessageprocessingstepsecureconfig.table index 1a0f5f3a..dc479cf9 100644 --- a/src/XrmFramework/Definitions/Sdkmessageprocessingstepsecureconfig.table +++ b/src/XrmFramework/Definitions/Sdkmessageprocessingstepsecureconfig.table @@ -10,7 +10,8 @@ "PrimaryType": "Id", "Capa": 5, "Locked": true, - "Labels": [] + "Labels": [], + "Select": true } ], "NtoN": [], diff --git a/src/XrmFramework/Definitions/Systemuser.table b/src/XrmFramework/Definitions/Systemuser.table index 272ae0d5..e5915e65 100644 --- a/src/XrmFramework/Definitions/Systemuser.table +++ b/src/XrmFramework/Definitions/Systemuser.table @@ -14,7 +14,8 @@ "Label": "Division", "LangId": 1036 } - ] + ], + "Select": true }, { "LogName": "systemuserid", @@ -28,7 +29,8 @@ "Label": "Utilisateur", "LangId": 1036 } - ] + ], + "Select": true } ], "NtoN": [ @@ -28340,7 +28342,7 @@ }, { "LogName": "systemuser|emailrouteraccessapproval", - "Name": "IndiqueSiLAdresseDeMessagerieEstApprouveePourChaqueBoiteAuxLettresPourLeTraitementDuCourrierElectroniqueViaLaSynchronisationCoteServeurOuEMailRouter.", + "Name": "IndiqueSiLAdresseDeMessagerieEstApprouveePourChaqueBoiteAuxLettresPourLeTraitementDuCourrierElectroniqueViaLaSynchronisationCoteServeurOuEMailRouter", "Locked": true, "Values": [ { diff --git a/src/XrmFramework/Definitions/Systemuserroles.table b/src/XrmFramework/Definitions/Systemuserroles.table index 8803c0ca..d5dd8a14 100644 --- a/src/XrmFramework/Definitions/Systemuserroles.table +++ b/src/XrmFramework/Definitions/Systemuserroles.table @@ -8,7 +8,8 @@ "Type": "Uniqueidentifier", "Capa": 1, "Locked": true, - "Labels": [] + "Labels": [], + "Select": true }, { "LogName": "systemuserid", @@ -16,7 +17,8 @@ "Type": "Uniqueidentifier", "Capa": 1, "Locked": true, - "Labels": [] + "Labels": [], + "Select": true }, { "LogName": "systemuserroleid", @@ -25,7 +27,8 @@ "PrimaryType": "Id", "Capa": 5, "Locked": true, - "Labels": [] + "Labels": [], + "Select": true } ], "NtoN": [ diff --git a/src/XrmFramework/Definitions/Team.table b/src/XrmFramework/Definitions/Team.table index b2fbb99a..f753180b 100644 --- a/src/XrmFramework/Definitions/Team.table +++ b/src/XrmFramework/Definitions/Team.table @@ -14,7 +14,8 @@ "Label": "Division", "LangId": 1036 } - ] + ], + "Select": true }, { "LogName": "name", @@ -29,7 +30,8 @@ "LangId": 1036 } ], - "StrLen": 160 + "StrLen": 160, + "Select": true }, { "LogName": "teamid", @@ -43,7 +45,8 @@ "Label": "Équipe", "LangId": 1036 } - ] + ], + "Select": true }, ], diff --git a/src/XrmFramework/Definitions/Workflow.table b/src/XrmFramework/Definitions/Workflow.table index 0fba81aa..8679f4f4 100644 --- a/src/XrmFramework/Definitions/Workflow.table +++ b/src/XrmFramework/Definitions/Workflow.table @@ -9,7 +9,8 @@ "Type": "Lookup", "Capa": 1, "Locked": true, - "Labels": [] + "Labels": [], + "Select": true }, { "LogName": "name", @@ -24,7 +25,8 @@ "LangId": 1036 } ], - "StrLen": 100 + "StrLen": 100, + "Select": true }, { @@ -39,7 +41,8 @@ "Label": "Processus", "LangId": 1036 } - ] + ], + "Select": true } ], "NtoN": [ @@ -589,7 +592,7 @@ }, { "Value": 3, - "Name": "Divis.MereSousDivisions", + "Name": "DivisMereSousDivisions", "Labels": [ { "Label": "Divis. mère : sous-divisions",