예제 #1
0
 private void ProcessingComplete(Xrm2TypeScriptGenerator renderer)
 {
     using (var view = new GeneratedResultsForm())
     {
         view.ShowResults(renderer.GeneratedOutput.ToString(), renderer.Logger.ToString());
         view.ShowDialog();
     }
 }
예제 #2
0
        /// <summary>
        /// Based on the current selection, generate the templates
        /// </summary>
        /// <param name="generateCheckedItems">Flag indicating whether to generate the checked items or the single selected item</param>
        private void GenerateTemplates(bool generateCheckedItems = false)
        {
            ToggleMainControlsEnabled(false);

            var entitiesList = new List <string>();

            // generate checked vs selected items.
            if (generateCheckedItems)
            {
                foreach (ListViewItem item in listViewEntities.CheckedItems)
                {
                    entitiesList.Add(item.SubItems["Name"].Text);
                }
            }
            else
            {
                var selItem = listViewEntities.SelectedItems[0];
                entitiesList.Add(selItem.SubItems["Name"].Text);
            }

            WorkAsync(new WorkAsyncInfo
            {
                Message       = "Generating the script template for selected entities",
                AsyncArgument = new List <object>()
                {
                    entitiesList, propertyGridConfig.SelectedObject
                },
                IsCancelable  = true,
                MessageWidth  = 340,
                MessageHeight = 150,
                Work          = (w, e) =>
                {
                    Xrm2TypeScriptGenerator xrm2ts = null;
                    try
                    {
                        var args      = e.Argument as List <object>;
                        var namesList = args[0] as List <string>;
                        var config    = args[1] as ConfigurationInfo;

                        // collect all of the entity metadata items with the attribubte metadata
                        var selectedEntities = new List <EntityMetadata>();

                        var counter = 0;
                        var total   = namesList.Count;
                        //foreach selected entity in the listbox
                        foreach (string logicalName in namesList)
                        {
                            w.ReportProgress((counter++ / total) * 100, "Loading Entity: " + logicalName);
                            selectedEntities.Add(CrmActions.RetrieveEntityAttributeMeta(Service, config, logicalName));
                        }

                        w.ReportProgress(100, "Loading Entities Complete");

                        // generate the list of selected entities
                        xrm2ts = new Xrm2TypeScriptGenerator(config, selectedEntities);

                        // TODO move the type into the script types
                        xrm2ts.GenerateAllClassTemplates();

                        e.Result = xrm2ts;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("An error occurred attempting to generate the template for your selection:\n" + ex.Message + "\n Logging results:\n" + xrm2ts.Logger.ToString());
                    }
                },
                ProgressChanged = e =>
                {
                    SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(e.ProgressPercentage, e.UserState.ToString()));
                },
                PostWorkCallBack = e =>
                {
                    // let them do stuff again
                    ToggleMainControlsEnabled(true);

                    // launch the results window... get off this worker thread so we can work with the dialog correctly
                    BeginInvoke(new ProcessingCompleteDelegate(ProcessingComplete), new object[] { e.Result as Xrm2TypeScriptGenerator });
                }
            });
        }