Example #1
0
        internal void LoadViews(Action action)
        {
            host.WorkAsync("Loading views...",
                           (a) =>
            {
                views = new Dictionary <string, List <Entity> >();

                if (views.Count == 0)
                {
                    var combinedResult = new Dictionary <string, DataCollection <Entity> >();
                    DataCollection <Entity> singleResult;

                    var qex = new QueryExpression();

                    qex.ColumnSet = new ColumnSet("name", "returnedtypecode", "fetchxml", "layoutxml");
                    qex.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
                    qex.AddOrder("name", OrderType.Ascending);

                    foreach (var entity in new string[] { "savedquery", "userquery" })
                    {
                        qex.EntityName = entity;

                        singleResult = host.Service.RetrieveMultiple(qex).Entities;
                        if (singleResult.Count > 0)
                        {
                            combinedResult.Add(qex.EntityName, singleResult);
                        }
                    }

                    a.Result = combinedResult;
                }
            },
                           (a) =>
            {
                var allViews = (Dictionary <string, DataCollection <Entity> >)a.Result;

                foreach (var key in allViews.Keys)
                {
                    ExtractViews(allViews[key]);
                }

                entities = views.Keys.Select(x => x.Split('|')[0]).Distinct().ToList();

                action();
            });
        }
Example #2
0
        public static void RetrieveTypes(this ComboBox comboBox, PluginControlBase host, PluginAssembly pluginAssembly, bool allTypesOption = false)
        {
            if (comboBox == null || comboBox.Parent == null)
            {
                return;
            }

            var info = new WorkAsyncInfo();

            info.Message = "Loading types...";

            info.Work = (worker, a) =>
            {
                a.Result = host.Service.GetPluginTypes(pluginAssembly.Id);
            };

            info.PostWorkCallBack = (a) =>
            {
                comboBox.Items.Clear();

                if (allTypesOption)
                {
                    comboBox.Items.Add(new PluginType
                    {
                        FriendlyName = "All types"
                    });
                }

                foreach (var type in ((Entity[])a.Result).Select(x => new PluginType(x, pluginAssembly)))
                {
                    comboBox.Items.Add(type);
                }

                if (allTypesOption)
                {
                    // Select all types
                    comboBox.SelectedIndex = 0;
                }
            };

            host.WorkAsync(info);
        }
        private static void PublishEntity(PluginControlBase objPlugin, IOrganizationService serviceProxy, EntityMetadata entityItem)
        {
            string paramXml =
                $" <importexportxml><entities><entity>{entityItem.LogicalName}</entity></entities><nodes/><securityroles/><settings/><workflows/></importexportxml>";

            objPlugin.WorkAsync(new WorkAsyncInfo
            {
                Message = "Publishing Entity  " + entityItem.LogicalName,
                Work    = (bw, ex) =>
                {
                    serviceProxy.Execute(new PublishXmlRequest
                    {
                        ParameterXml = paramXml
                    });
                },
                PostWorkCallBack = ex =>
                {
                    if (ex.Error != null)
                    {
                        MessageBox.Show(objPlugin.ParentForm, ex.Error.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            });
        }