public void Duplicate(IPersonalArtefact artefact, User owner)
        {
            var viewArtefact = (PersonalView)artefact;
            var viewEntity   = viewArtefact.Entity;

            _pluginContext.WorkAsync(new WorkAsyncInfo
            {
                Message = $"Duplicating userquery {viewEntity.GetAttributeValue<string>("name")} ({viewEntity.Id.ToString()}) for user {owner.Id}...",
                Work    = (worker, args) =>
                {
                    var client       = _pluginContext.ConnectionDetail.GetCrmServiceClient();
                    var userIdBefore = client.CallerId;
                    client.CallerId  = owner.Id;

                    try
                    {
                        // Define list of attributes that can safely be copied
                        var attribsToBeCopied = new string[]
                        {
                            "advancedgroupby", "columnsetxml", "conditionalformatting", "description", "fetchxml",
                            "layoutxml", "name", "parentqueryid", "querytype", "returnedtypecode", "statecode",
                            "statuscode"
                        };

                        var newViewEntity = new Entity(viewEntity.LogicalName);
                        newViewEntity.Attributes["ownerid"] = owner.Entity.ToEntityReference();
                        foreach (var key in attribsToBeCopied)
                        {
                            if (viewEntity.Contains(key))
                            {
                                newViewEntity.Attributes[key] = viewEntity.Attributes[key];
                            }
                        }

                        var response = _pluginContext.Service.Create(newViewEntity);
                        args.Result  = response;
                    }
                    catch (Exception exc)
                    {
                        args.Result     = null;
                        client.CallerId = userIdBefore;
                        throw exc;
                    }
                },
                PostWorkCallBack = (args) =>
                {
                    if (args.Error != null)
                    {
                        ErrorHelper.ShowExceptionMessageDialog(args.Error);
                    }
                    else
                    {
                        var newRecordId = (Guid)args.Result;
                        Clipboard.SetText(newRecordId.ToString());
                        MessageBox.Show($"Personal View successfully assigned to user \"{owner.Fullname}\" ({owner.Email} / {owner.Id}). New record Id was copied to clipboard ({newRecordId.ToString()})", "Info", MessageBoxButtons.OK, MessageBoxIcon.None);
                    }
                }
            });
        }
Exemplo n.º 2
0
        public void Duplicate(IPersonalArtefact artefact, User owner)
        {
            var diagramArtefact = (PersonalDiagram)artefact;
            var diagramEntity   = diagramArtefact.Entity;

            _pluginContext.WorkAsync(new WorkAsyncInfo
            {
                Message = $"Duplicating userqueryvisualization {diagramEntity.GetAttributeValue<string>("name")} ({diagramEntity.Id.ToString()}) for user {owner.Id}...",
                Work    = (worker, args) =>
                {
                    var client       = _pluginContext.ConnectionDetail.GetCrmServiceClient();
                    var userIdBefore = client.CallerId;
                    client.CallerId  = owner.Id;

                    try
                    {
                        // Define list of attributes that can safely be copied
                        var attribsToBeCopied = new string[]
                        {
                            "datadescription", "isdefault", "name", "presentationdescription", "primaryentitytypecode", "webresourceid"
                        };

                        var newDiagramEntity = new Entity(diagramEntity.LogicalName);
                        newDiagramEntity.Attributes["ownerid"] = owner.Entity.ToEntityReference();
                        foreach (var key in attribsToBeCopied)
                        {
                            if (diagramEntity.Contains(key))
                            {
                                newDiagramEntity.Attributes[key] = diagramEntity.Attributes[key];
                            }
                        }

                        var response = _pluginContext.Service.Create(newDiagramEntity);
                        args.Result  = response;
                    }
                    catch (Exception exc)
                    {
                        args.Result     = null;
                        client.CallerId = userIdBefore;
                        throw exc;
                    }
                },
                PostWorkCallBack = (args) =>
                {
                    if (args.Error != null)
                    {
                        ErrorHelper.ShowExceptionMessageDialog(args.Error);
                    }
                    else
                    {
                        var newRecordId = (Guid)args.Result;
                        Clipboard.SetText(newRecordId.ToString());
                        MessageBox.Show($"Personal Diagram successfully duplicated and assigned to user \"{owner.Fullname}\" ({owner.Email} / {owner.Id}). New record Id was copied to clipboard ({newRecordId.ToString()})", "Info", MessageBoxButtons.OK, MessageBoxIcon.None);
                    }
                }
            });
        }
Exemplo n.º 3
0
        public void LoadSystemUsers()
        {
            _pluginContext.WorkAsync(new WorkAsyncInfo
            {
                Message = "Query list of systemusers",
                Work    = (worker, args) =>
                {
                    args.Result = _pluginContext.Service.RetrieveMultiple(new QueryExpression("systemuser")
                    {
                        Orders       = { new OrderExpression("internalemailaddress", OrderType.Ascending) },
                        PageInfo     = { ReturnTotalRecordCount = true },
                        ColumnSet    = new ColumnSet("systemuserid", "isdisabled", "internalemailaddress", "fullname"),
                        LinkEntities = { new LinkEntity("systemuser", "systemuserroles", "systemuserid", "systemuserid", JoinOperator.Inner) },
                        Distinct     = true
                    });
                },
                PostWorkCallBack = (args) =>
                {
                    // Clear user list
                    Users = new User[] { };

                    if (args.Error != null)
                    {
                        MessageBox.Show(args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        var resultSet = args.Result as EntityCollection;
                        if (resultSet != null)
                        {
                            Users = resultSet.Entities.Select(e => new User(e)).ToArray();
                        }
                    }


                    // Notify all subscribers
                    UserListUpdated(this, null);
                }
            });
        }