예제 #1
0
 public CrmServiceEndpoint(CrmOrganization org, ServiceEndpoint serviceEndpoint)
     : this(org)
 {
     RefreshFromServiceEndpoint(serviceEndpoint);
 }
        public AttributeSelectionForm(UpdateImageAttributesDelegate updateAttributes, CrmOrganization org,
                                      CrmAttribute[] attributeList, Collection <string> currentValue, bool currentAllChecked)
        {
            if (org == null)
            {
                throw new ArgumentNullException("org");
            }
            else if (attributeList == null)
            {
                throw new ArgumentNullException("attributeList");
            }
            else if (updateAttributes == null)
            {
                throw new ArgumentNullException("updateAttributes");
            }

            InitializeComponent();

            m_org = org;
            m_updateAttributes  = updateAttributes;
            m_currentAllChecked = currentAllChecked;
            m_currentValue      = currentValue;

            //Create a sorter for the listview. This will allow the list to be sorted by different columns
            lsvAttributes.ListViewItemSorter = new ListViewColumnSorter(0, lsvAttributes.Sorting);

            m_attributesList = new List <ListViewItem>();

            foreach (CrmAttribute attribute in attributeList)
            {
                switch (attribute.Type)
                {
                case AttributeTypeCode.Boolean:
                case AttributeTypeCode.Customer:
                case AttributeTypeCode.DateTime:
                case AttributeTypeCode.Decimal:
                case AttributeTypeCode.Double:
                case AttributeTypeCode.Integer:
                case AttributeTypeCode.Lookup:
                case AttributeTypeCode.Memo:
                case AttributeTypeCode.Money:
                case AttributeTypeCode.Owner:
                case AttributeTypeCode.PartyList:
                case AttributeTypeCode.Picklist:
                case AttributeTypeCode.State:
                case AttributeTypeCode.Status:
                case AttributeTypeCode.String:
                {
                    ListViewItem item = new ListViewItem
                    {
                        Name       = attribute.LogicalName.Trim().ToLowerInvariant(),
                        Text       = attribute.FriendlyName,
                        ImageIndex = 0
                    };

                    item.SubItems.Add(attribute.LogicalName);
                    item.SubItems.Add(attribute.Type.ToString());
                    item.Tag = attribute;

                    m_attributesList.Add(item);
                }
                break;

                case AttributeTypeCode.CalendarRules:
                case AttributeTypeCode.Uniqueidentifier:
                case AttributeTypeCode.Virtual:

                    if (attribute.IsPrimaryId)
                    {
                        ListViewItem item = new ListViewItem
                        {
                            Name       = attribute.LogicalName.Trim().ToLowerInvariant(),
                            Text       = attribute.FriendlyName,
                            ImageIndex = 0
                        };

                        item.SubItems.Add(attribute.LogicalName);
                        item.SubItems.Add(attribute.Type.ToString());
                        item.Tag = attribute;

                        m_attributesList.Add(item);
                    }

                    if (attribute.TypeName == "MultiSelectPicklistType")
                    {
                        ListViewItem item = new ListViewItem
                        {
                            Name       = attribute.LogicalName.Trim().ToLowerInvariant(),
                            Text       = attribute.FriendlyName,
                            ImageIndex = 0
                        };

                        item.SubItems.Add(attribute.LogicalName);
                        item.SubItems.Add("MultiSelect Picklist");
                        item.Tag = attribute;

                        m_attributesList.Add(item);
                    }
                    continue;
                }
            }
        }
예제 #3
0
 public CrmServiceEndpoint(CrmOrganization org)
 {
     m_org = org;
 }
예제 #4
0
        public StepRegistrationForm(CrmOrganization org, MainControl orgControl, CrmPlugin plugin, CrmPluginStep step, CrmServiceEndpoint serviceEndpoint)
        {
            if (org == null)
            {
                throw new ArgumentNullException("org");
            }
            else if (orgControl == null)
            {
                throw new ArgumentNullException("control");
            }
            m_org         = org;
            m_orgControl  = orgControl;
            m_currentStep = step;

            #region Initialization of crmFilteringAttributes

            //Seems this was removed automatically by VS designer, so added here instead.
            crmFilteringAttributes = new Controls.CrmAttributeSelectionControl(m_orgControl)
            {
                Organization = org
            };

            //
            // crmFilteringAttributes
            //
            this.crmFilteringAttributes.Anchor          = ((AnchorStyles.Top | AnchorStyles.Left) | AnchorStyles.Right);
            this.crmFilteringAttributes.Attributes      = null;
            this.crmFilteringAttributes.DisabledMessage = "";
            //this.crmFilteringAttributes.EntityName = null;
            this.crmFilteringAttributes.Location = new System.Drawing.Point(127, 91);
            this.crmFilteringAttributes.Margin   = new Padding(4, 5, 4, 5);
            this.crmFilteringAttributes.Name     = "crmFilteringAttributes";
            //this.crmFilteringAttributes.Organization = null;
            this.crmFilteringAttributes.ScrollBars = ScrollBars.None;
            this.crmFilteringAttributes.Size       = new System.Drawing.Size(316, 20);
            this.crmFilteringAttributes.TabIndex   = 9;
            this.crmFilteringAttributes.WordWrap   = false;

            #endregion Initialization of crmFilteringAttributes

            InitializeComponent();
            this.grpGeneral.Controls.Add(this.crmFilteringAttributes);

            //Initialize the auto-complete on the Message field
            var msgList = new AutoCompleteStringCollection();
            foreach (CrmMessage msg in org.Messages.Values)
            {
                msgList.Add(msg.Name);
            }
            txtMessageName.AutoCompleteCustomSource = msgList;

            //Check whether system plugins should be added to the list
            if (step != null && org[step.AssemblyId][step.PluginId].IsSystemCrmEntity && (!OrganizationHelper.AllowStepRegistrationForPlugin(plugin)))
            {
                cmbPlugins.Enabled = false;
            }
            else if ((plugin != null) && (!OrganizationHelper.AllowStepRegistrationForPlugin(plugin)))
            {
                plugin = null;
            }

            //Add the plugins
            CrmPlugin selectPlugin = null;
            foreach (CrmPluginAssembly assembly in org.Assemblies.Values)
            {
                foreach (CrmPlugin pluginType in assembly.Plugins.Values)
                {
                    if (pluginType.PluginType == CrmPluginType.Plugin &&
                        OrganizationHelper.AllowStepRegistrationForPlugin(pluginType))
                    {
                        if (serviceEndpoint == null && pluginType.TypeName == CrmServiceEndpoint.ServiceBusPluginName && pluginType.CustomizationLevel == 0)
                        {
                            continue;
                            // Donot add OOB Service Bus plugin to the list when it it is not a Service Bus Step
                        }
                        else
                        {
                            if (plugin != null && plugin.PluginId == pluginType.PluginId)
                            {
                                selectPlugin = pluginType;
                                cmbPlugins.Items.Add(pluginType);
                            }
                            else
                            {
                                cmbPlugins.Items.Add(pluginType);
                            }
                        }
                    }
                }
            }

            if (cmbPlugins.Items.Count != 0)
            {
                if (selectPlugin == null)
                {
                    cmbPlugins.SelectedIndex = 0;
                }
                else
                {
                    cmbPlugins.SelectedItem = selectPlugin;
                }
            }

            //Create a user that represents the current user
            var callingUser = new CrmUser(org)
            {
                UserId  = Guid.Empty,
                Name    = "Calling User",
                Enabled = true
            };
            cmbUsers.Items.Add(callingUser);

            //Add the users. We do not want to sort because the users list is sorted already and then the calling user
            //will not be at the beginning of the list
            cmbUsers.Sorted = false;
            foreach (CrmUser user in org.Users.Values)
            {
                // Added this check to to prevent OutofMemoryExcetion - When an org is imported, the administrator
                // does not have a name associated with it, Adding Null Names to ComboBox throws OutofMemoryExcetion
                if (null != user && user.Enabled == true && user.Name != null)
                {
                    cmbUsers.Items.Add(user);
                }
                // Special case to add System user
                if (user.Name == "SYSTEM" && user.Enabled == false)
                {
                    cmbUsers.Items.Add(user);
                }
            }

            if (cmbUsers.Items.Count != 0)
            {
                cmbUsers.SelectedIndex = 0;
            }

            CrmServiceEndpoint selectServiceEndpoint = null;
            foreach (CrmServiceEndpoint currentServiceEndpoint in org.ServiceEndpoints.Values)
            {
                if (serviceEndpoint != null && serviceEndpoint.ServiceEndpointId == currentServiceEndpoint.ServiceEndpointId)
                {
                    selectServiceEndpoint = currentServiceEndpoint;
                }
                cmbServiceEndpoint.Items.Add(currentServiceEndpoint);
            }

            if (selectServiceEndpoint != null)
            {
                cmbServiceEndpoint.SelectedItem = selectServiceEndpoint;
            }
            else
            {
                if (cmbServiceEndpoint.Items.Count != 0)
                {
                    cmbServiceEndpoint.SelectedIndex = 0;
                }
            }

            if (serviceEndpoint != null)
            {
                UpdatePluginEventHandlerControls(true);
            }
            else
            {
                UpdatePluginEventHandlerControls(false);
            }

            if (m_currentStep != null)
            {
                txtMessageName.Text = m_org.Messages[m_currentStep.MessageId].Name;

                if (org.MessageEntities.ContainsKey(m_currentStep.MessageEntityId))
                {
                    CrmMessageEntity msgEntity = Message[m_currentStep.MessageEntityId];
                    txtPrimaryEntity.Text   = msgEntity.PrimaryEntity;
                    txtSecondaryEntity.Text = msgEntity.SecondaryEntity;
                }
                else
                {
                    txtPrimaryEntity.Text   = "none";
                    txtSecondaryEntity.Text = "none";
                }

                cmbPlugins.SelectedItem = m_org[m_currentStep.AssemblyId][m_currentStep.PluginId];

                if (m_currentStep.ServiceBusConfigurationId != Guid.Empty)
                {
                    cmbServiceEndpoint.SelectedItem = m_org.ServiceEndpoints[m_currentStep.ServiceBusConfigurationId];
                }

                if (m_currentStep.ImpersonatingUserId == Guid.Empty)
                {
                    cmbUsers.SelectedIndex = 0;
                }
                else
                {
                    cmbUsers.SelectedItem = m_org.Users[m_currentStep.ImpersonatingUserId];
                }
                txtRank.Text = m_currentStep.Rank.ToString();
                switch (m_currentStep.Stage)
                {
                case CrmPluginStepStage.PreValidation:
                    radStagePreValidation.Checked = true;
                    break;

                case CrmPluginStepStage.PreOperation:
                    radStagePreOperation.Checked = true;
                    break;

                case CrmPluginStepStage.PostOperation:
                    radStagePostOperation.Checked = true;
                    break;

                case CrmPluginStepStage.PostOperationDeprecated:
                    radStagePostOperationDeprecated.Checked = true;
                    break;

                default:
                    throw new NotImplementedException("CrmPluginStepStage = " + m_currentStep.Stage.ToString());
                }

                switch (m_currentStep.Mode)
                {
                case CrmPluginStepMode.Asynchronous:

                    radModeAsync.Checked = true;
                    break;

                case CrmPluginStepMode.Synchronous:

                    radModeSync.Checked = true;
                    break;

                default:
                    throw new NotImplementedException("Mode = " + m_currentStep.Mode.ToString());
                }

                switch (m_currentStep.Deployment)
                {
                case CrmPluginStepDeployment.Both:

                    chkDeploymentOffline.Checked = true;
                    chkDeploymentServer.Checked  = true;
                    break;

                case CrmPluginStepDeployment.ServerOnly:

                    chkDeploymentOffline.Checked = false;
                    chkDeploymentServer.Checked  = true;
                    break;

                case CrmPluginStepDeployment.OfflineOnly:

                    chkDeploymentOffline.Checked = true;
                    chkDeploymentServer.Checked  = false;
                    break;

                default:
                    throw new NotImplementedException("Deployment = " + m_currentStep.Deployment.ToString());
                }

                switch (m_currentStep.InvocationSource)
                {
                case null:
                case CrmPluginStepInvocationSource.Parent:

                    radInvocationParent.Checked = true;
                    break;

                case CrmPluginStepInvocationSource.Child:

                    radInvocationChild.Checked = true;
                    break;

                default:
                    throw new NotImplementedException("InvocationSource = " + m_currentStep.InvocationSource.ToString());
                }

                txtDescription.Text = m_currentStep.Description;

                txtSecureConfig.Text = m_currentStep.SecureConfiguration;

                string stepName;
                //if (this.m_currentStep.IsProfiled && org.Plugins[this.m_currentStep.PluginId].IsProfilerPlugin)
                //{
                //    //If the current step is a profiler step, the form that is displayed should use the configuration from the original step.
                //    // ProfilerConfiguration profilerConfig = OrganizationHelper.RetrieveProfilerConfiguration(this.m_currentStep);
                //    // stepName = profilerConfig.OriginalEventHandlerName;
                //    // txtUnsecureConfiguration.Text = profilerConfig.Configuration;
                //}
                //else
                //{
                txtUnsecureConfiguration.Text = m_currentStep.UnsecureConfiguration;
                stepName = m_currentStep.Name;
                //}

                if (stepName == GenerateDescription())
                {
                    m_stepName = GenerateDescription();
                }
                else
                {
                    m_stepName   = null;
                    txtName.Text = stepName;
                }

                if (MessageEntity != null)
                {
                    crmFilteringAttributes.EntityName = MessageEntity.PrimaryEntity;
                }

                crmFilteringAttributes.Attributes           = m_currentStep.FilteringAttributes;
                chkDeleteAsyncOperationIfSuccessful.Checked = m_currentStep.DeleteAsyncOperationIfSuccessful;
                chkDeleteAsyncOperationIfSuccessful.Enabled = (m_currentStep.Mode == CrmPluginStepMode.Asynchronous);

                Text             = "Update Existing Step";
                btnRegister.Text = "Update";

                CheckAttributesSupported();
            }
            else if (!radStagePostOperation.Enabled && radStagePostOperationDeprecated.Enabled)
            {
                radStagePostOperationDeprecated.Checked = true;
            }

            //Check if permissions for the secure configuration was denied
            if (org.SecureConfigurationPermissionDenied)
            {
                picAccessDenied.Visible = true;
                lblAccessDenied.Visible = true;
                txtSecureConfig.Visible = false;

                picAccessDenied.Image = CrmResources.LoadImage("AccessDenied");

                lblAccessDenied.Left = picAccessDenied.Right;

                int groupLeft = (grpSecureConfiguration.ClientSize.Width - (lblAccessDenied.Right - picAccessDenied.Left)) / 2;
                int groupTop  = (grpSecureConfiguration.ClientSize.Height - lblAccessDenied.Height) / 2;

                picAccessDenied.Top = groupTop;
                lblAccessDenied.Top = groupTop;

                picAccessDenied.Left = groupLeft;
                lblAccessDenied.Left = picAccessDenied.Right;
            }
            else if (null != step && step.SecureConfigurationRecordIdInvalid)
            {
                picInvalidSecureConfigurationId.Visible = true;
                lblInvalidSecureConfigurationId.Visible = true;
                lnkInvalidSecureConfigurationId.Visible = true;
                txtSecureConfig.Visible = false;

                picInvalidSecureConfigurationId.Image = CrmResources.LoadImage("AccessDenied");
                lblInvalidSecureConfigurationId.Left  = picInvalidSecureConfigurationId.Right;

                int groupLeft = (grpSecureConfiguration.ClientSize.Width - (lblInvalidSecureConfigurationId.Right - picInvalidSecureConfigurationId.Left)) / 2;
                int groupTop  = (grpSecureConfiguration.ClientSize.Height - (lnkInvalidSecureConfigurationId.Bottom - picInvalidSecureConfigurationId.Top)) / 2;

                picInvalidSecureConfigurationId.Top = groupTop;
                lblInvalidSecureConfigurationId.Top = groupTop;
                lnkInvalidSecureConfigurationId.Top = lblInvalidSecureConfigurationId.Bottom + 6;

                picInvalidSecureConfigurationId.Left = groupLeft;
                lblInvalidSecureConfigurationId.Left = picAccessDenied.Right;
                lnkInvalidSecureConfigurationId.Left = lblInvalidSecureConfigurationId.Left;

                m_secureConfigurationIdIsInvalid = true;
            }

            LoadEntities();
            CheckDeploymentSupported();
        }
 private static List <Guid> RetrievePluginIdsForAssembly(CrmOrganization org, IList <Guid> assemblyIds)
 {
     return(RetrieveReferenceAttributeIds(org, PluginType.EntityLogicalName, "plugintypeid", "pluginassemblyid", assemblyIds));
 }
 public ExportSolutionMessage(CrmOrganization organization) : base(organization)
 {
 }
예제 #7
0
        public ImageRegistrationForm(CrmOrganization org, MainControl orgControl,
                                     ICrmTreeNode[] rootNodes, CrmPluginImage image, Guid selectNodeId)
        {
            if (org == null)
            {
                throw new ArgumentNullException("org");
            }
            else if (orgControl == null)
            {
                throw new ArgumentNullException("orgControl");
            }
            else if (rootNodes == null)
            {
                throw new ArgumentNullException("rootNodes");
            }
            m_org          = org;
            m_orgControl   = orgControl;
            m_currentImage = image;

            InitializeComponent();

            crmParameters.Organization = org;

            trvPlugins.CrmTreeNodeSorter = orgControl.CrmTreeNodeSorter;

            trvPlugins.AutoExpand = m_orgControl.IsAutoExpanded;
            trvPlugins.LoadNodes(rootNodes);

            if (image != null)
            {
                if (trvPlugins.HasNode(image.StepId))
                {
                    trvPlugins.SelectedNode = trvPlugins[image.StepId];
                }

                txtEntityAlias.Text = image.EntityAlias;
                txtName.Text        = image.Name;

                CrmPluginStep step = m_org[image.AssemblyId][image.PluginId][image.StepId];
                if (step.MessageEntityId == Guid.Empty)
                {
                    crmParameters.EntityName = "none";
                    crmParameters.Enabled    = false;
                }
                else
                {
                    crmParameters.EntityName = m_org.Messages[step.MessageId][step.MessageEntityId].PrimaryEntity;
                    crmParameters.Attributes = image.Attributes;
                }

                switch (image.ImageType)
                {
                case CrmPluginImageType.Both:
                    chkImageTypePost.Checked = true;
                    chkImageTypePre.Checked  = true;
                    break;

                case CrmPluginImageType.PostImage:
                    chkImageTypePost.Checked = true;
                    chkImageTypePre.Checked  = false;
                    break;

                case CrmPluginImageType.PreImage:
                    chkImageTypePost.Checked = false;
                    chkImageTypePre.Checked  = true;
                    break;

                default:
                    throw new NotImplementedException("ImageType = " + image.ImageType.ToString());
                }

                Text             = "Update Existing Image";
                btnRegister.Text = "Update";

                trvPlugins.Visible = false;

                int difference = grpEntityAlias.Top - grpSteps.Top;

                grpSteps.Visible = false;
                Height          -= difference;

                crmParameters.Enabled = true;
                btnRegister.Enabled   = true;
            }
            else if (trvPlugins.HasNode(selectNodeId))
            {
                trvPlugins.SelectedNode = trvPlugins[selectNodeId];
            }
            else
            {
                crmParameters.Attributes = null;
            }
        }
        /// <summary>
        /// Unregister entities and cascade the operation
        /// </summary>
        /// <param name="org">Organization to be used</param>
        /// <param name="crmEntity">Entities to be unregistered. If these are not invalid entities, only one can be specified</param>
        /// <param name="cascadeOperation">Cascade the operation</param>
        /// <param name="prog">ProgressIndicator to indicate success</param>
        /// <returns>Statistics of what was unregistered</returns>
        public static Dictionary <string, int> Unregister(CrmOrganization org, ProgressIndicator prog, params ICrmEntity[] crmEntity)
        {
            if (org == null)
            {
                throw new ArgumentNullException("org");
            }
            else if (crmEntity == null || crmEntity.Length == 0)
            {
                throw new ArgumentNullException("crmEntity");
            }

            var serviceEndpointList = new Collection <Guid>();
            var assemblyList        = new Collection <Guid>();
            var pluginList          = new Collection <Guid>();
            var stepList            = new Collection <Guid>();
            var secureConfigList    = new Collection <Guid>();
            var imageList           = new Collection <Guid>();

            //Create the list of various objects that need to be unregistered
            foreach (var entity in crmEntity)
            {
                switch (entity.EntityType)
                {
                case ServiceEndpoint.EntityLogicalName:
                    serviceEndpointList.Add(entity.EntityId);
                    break;

                case PluginAssembly.EntityLogicalName:
                    assemblyList.Add(entity.EntityId);
                    break;

                case PluginType.EntityLogicalName:
                    pluginList.Add(entity.EntityId);
                    break;

                case SdkMessageProcessingStep.EntityLogicalName:
                    stepList.Add(entity.EntityId);
                    break;

                case SdkMessageProcessingStepImage.EntityLogicalName:
                    imageList.Add(entity.EntityId);
                    break;

                default:
                    throw new NotImplementedException($"Type = {entity.EntityType.ToString()}");
                }
            }

            //Retrieve the up-to-date list of steps for the service endpoints and add them to the unregister list
            foreach (var stepId in RetrieveStepIdsForServiceEndpoint(org, serviceEndpointList))
            {
                if (!stepList.Contains(stepId))
                {
                    stepList.Add(stepId);
                }
            }
            //Retrieve the up-to-date list of plugins for the assemblies and add them to the unregister list
            foreach (var pluginId in RetrievePluginIdsForAssembly(org, assemblyList))
            {
                if (!pluginList.Contains(pluginId))
                {
                    pluginList.Add(pluginId);
                }
            }

            //Retrieve the up-to-date list of steps for the plugins and add them to the unregister list
            foreach (var stepId in RetrieveStepIdsForPlugins(org, pluginList))
            {
                if (!stepList.Contains(stepId))
                {
                    stepList.Add(stepId);
                }
            }

            //Retrieve all of the profiler steps that need to be deleted
            for (int i = stepList.Count - 1; i >= 0; i--)
            {
                CrmPluginStep step;
                if (org.Steps.TryGetValue(stepList[i], out step))
                {
                    var profilerStepId = step.ProfilerStepId.GetValueOrDefault();
                    if (Guid.Empty != profilerStepId && profilerStepId != step.StepId)
                    {
                        stepList.Add(profilerStepId);
                    }
                }
            }

            //Retrieve the up-to-date list of secure configs for the steps and add them to the unregister list
            foreach (var secureConfigId in RetrieveSecureConfigIdsForStepId(org, stepList))
            {
                if (!secureConfigList.Contains(secureConfigId))
                {
                    secureConfigList.Add(secureConfigId);
                }
            }

            //Retrieve the up-to-date list of images for the steps and add them to the unregister list
            foreach (var imageId in RetrieveImageIdsForStepId(org, stepList))
            {
                if (!imageList.Contains(imageId))
                {
                    imageList.Add(imageId);
                }
            }

            //Loop through each object and delete them
            var deleteStats = new Dictionary <string, int>();
            int totalSteps  = secureConfigList.Count + 1;

            if (serviceEndpointList.Count != 0)
            {
                deleteStats.Add(serviceEndpointList.Count == 1 ? "ServiceEndpoint" : "ServiceEndpoints", serviceEndpointList.Count);
                totalSteps += serviceEndpointList.Count;
            }
            if (assemblyList.Count != 0)
            {
                deleteStats.Add(assemblyList.Count == 1 ? "Assembly" : "Assemblies", assemblyList.Count);
                totalSteps += assemblyList.Count;
            }
            if (pluginList.Count != 0)
            {
                deleteStats.Add(pluginList.Count == 1 ? "Plugin" : "Plugins", pluginList.Count);
                totalSteps += pluginList.Count;
            }
            if (stepList.Count != 0)
            {
                deleteStats.Add(stepList.Count == 1 ? "Step" : "Steps", stepList.Count);
                totalSteps += stepList.Count;
            }
            if (imageList.Count != 0)
            {
                deleteStats.Add(imageList.Count == 1 ? "Image" : "Images", imageList.Count);
                totalSteps += imageList.Count;
            }

            try
            {
                if (prog != null)
                {
                    prog.Initialize(totalSteps, "Unregistering Images");
                }
                foreach (var imageId in imageList)
                {
                    org.OrganizationService.Delete(SdkMessageProcessingStepImage.EntityLogicalName, imageId);
                    if (prog != null)
                    {
                        prog.Increment();
                    }
                }

                if (prog != null)
                {
                    prog.SetText("Unregistering Steps");
                }
                foreach (var stepId in stepList)
                {
                    org.OrganizationService.Delete(SdkMessageProcessingStep.EntityLogicalName, stepId);
                    if (prog != null)
                    {
                        prog.Increment();
                    }
                }

                if (prog != null)
                {
                    prog.SetText("Unregistering Secure Configuration");
                }
                foreach (Guid secureConfigId in secureConfigList)
                {
                    org.OrganizationService.Delete(SdkMessageProcessingStepSecureConfig.EntityLogicalName, secureConfigId);
                    if (prog != null)
                    {
                        prog.Increment();
                    }
                }

                if (prog != null)
                {
                    prog.SetText("Unregistering Plugins");
                }
                foreach (var pluginId in pluginList)
                {
                    org.OrganizationService.Delete(PluginType.EntityLogicalName, pluginId);
                    if (prog != null)
                    {
                        prog.Increment();
                    }
                }

                if (prog != null)
                {
                    prog.SetText("Unregistering Assemblies");
                }
                foreach (var assemblyId in assemblyList)
                {
                    org.OrganizationService.Delete(PluginAssembly.EntityLogicalName, assemblyId);
                    if (prog != null)
                    {
                        prog.Increment();
                    }
                }

                if (prog != null)
                {
                    prog.SetText("Unregistering ServiceEndpoints");
                }
                foreach (var serviceEndpointId in serviceEndpointList)
                {
                    org.OrganizationService.Delete(ServiceEndpoint.EntityLogicalName, serviceEndpointId);
                    if (prog != null)
                    {
                        prog.Increment();
                    }
                }
            }
            finally
            {
                if (prog != null)
                {
                    prog.Complete(true);
                }
            }

            return(deleteStats);
        }
        public static bool UpdateStep(CrmOrganization org, CrmPluginStep step, Guid?origSecureConfigId, IList <CrmPluginImage> updateImages)
        {
            if (org == null)
            {
                throw new ArgumentNullException("org");
            }
            else if (step == null)
            {
                throw new ArgumentNullException("step");
            }

            var entityList = step.GenerateCrmEntities();
            var sdkStep    = (SdkMessageProcessingStep)entityList[SdkMessageProcessingStep.EntityLogicalName];

            // Loop through each image and set the new message property
            List <SdkMessageProcessingStepImage> sdkImages = null;

            if (null != updateImages)
            {
                // Ensure that the given message supports images
                var message = org.Messages[step.MessageId];
                if (0 == message.ImageMessagePropertyNames.Count && step.Images.Count > 0)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                                      "The step has images registered, but the \"{0}\" message doesn't support images.{1}In order to change the message to \"{0}\", delete the existing images.",
                                                                      message.Name, Environment.NewLine));
                }

                // Loop through the existing images and update their message property name values
                sdkImages = new List <SdkMessageProcessingStepImage>(updateImages.Count);
                foreach (CrmPluginImage image in updateImages)
                {
                    // Set the message property name for each of the images
                    string propertyName = MessagePropertyNameForm.SelectMessagePropertyName(message);
                    if (string.IsNullOrWhiteSpace(propertyName))
                    {
                        return(false);
                    }
                    else if (string.Equals(image.MessagePropertyName, propertyName, StringComparison.Ordinal))
                    {
                        continue;
                    }

                    // Create the entity to update the value
                    var sdkImage = new SdkMessageProcessingStepImage
                    {
                        Id = image.ImageId,
                        MessagePropertyName = propertyName,
                        EntityState         = EntityState.Changed
                    };

                    sdkImages.Add(sdkImage);
                }
            }

            //This is a sanity check. The UI won't allow a user to set the secure configuration.
            if (org.SecureConfigurationPermissionDenied)
            {
                sdkStep.Attributes.Remove("sdkmessageprocessingstepsecureconfigid");
                sdkStep.RelatedEntities.Clear();
                origSecureConfigId = null;
            }
            else if (entityList.ContainsKey(Entities.SdkMessageProcessingStepSecureConfig.EntityLogicalName))
            {
                if (null == origSecureConfigId)
                {
                    entityList.Remove(Entities.SdkMessageProcessingStepSecureConfig.EntityLogicalName);
                }
                else
                {
                    SdkMessageProcessingStepSecureConfig sdkSecureConfig =
                        (SdkMessageProcessingStepSecureConfig)entityList[SdkMessageProcessingStepSecureConfig.EntityLogicalName];

                    Guid        secureConfigId;
                    EntityState secureConfigState;
                    if (step.SecureConfigurationId == origSecureConfigId && origSecureConfigId.GetValueOrDefault() != Guid.Empty)
                    {
                        //Set the ID of the secure configuration to be the
                        secureConfigId    = origSecureConfigId.GetValueOrDefault();
                        secureConfigState = EntityState.Changed;

                        //Set the original secure config id so that the current id is not deleted
                        sdkStep.SdkMessageProcessingStepSecureConfigId =
                            new EntityReference(SdkMessageProcessingStepSecureConfig.EntityLogicalName, secureConfigId);
                    }
                    else
                    {
                        secureConfigId    = Guid.NewGuid();
                        secureConfigState = EntityState.Created;
                    }

                    //Set the configuration id for the step
                    step.SecureConfigurationId = secureConfigId;

                    //Populate the secure configuration object and add it to the related entities
                    sdkSecureConfig.SdkMessageProcessingStepSecureConfigId = secureConfigId;
                    sdkSecureConfig.EntityState = secureConfigState;

                    //Update the related entities
                    sdkStep.sdkmessageprocessingstepsecureconfigid_sdkmessageprocessingstep = sdkSecureConfig;

                    //Reset the original secure configuration
                    origSecureConfigId = null;
                }
            }
            else if (null != origSecureConfigId)
            {
                // To null out if it was set before
                sdkStep.SdkMessageProcessingStepSecureConfigId = null;
                step.SecureConfigurationId = Guid.Empty;

                if (Guid.Empty == origSecureConfigId)
                {
                    origSecureConfigId = null;
                }
            }

            // If the images need to be updated, there are two possible scenarios:
            // 1) The step is profiled -- The parent of the image is not the step that is currently being updated
            //    but rather the profiler step itself. In order to avoid changing this, there will have to be two SDK
            //    operations (update the step and update the images). Otherwise, the next time the profiled step executes,
            //    the images won't be present.
            // 2) The step is not profiled -- The image can be added to the related entities because the parent step is the
            //    current step being updated.
            if (null != sdkImages && sdkImages.Count > 0)
            {
                if (!step.IsProfiled || step.ProfilerStepId == step.StepId)
                {
                    sdkStep.sdkmessageprocessingstepid_sdkmessageprocessingstepimage = sdkImages;
                }
            }

            //Update the step
            org.OrganizationService.Update(sdkStep);

            if (step.IsProfiled && null != sdkImages && sdkImages.Count > 0)
            {
                // Update the Profiler step with the new property values as a single transaction to minimize the
                // possibility of data corruption.
                SdkMessageProcessingStep profilerStep = new SdkMessageProcessingStep
                {
                    Id = step.ProfilerStepId.GetValueOrDefault(),
                    sdkmessageprocessingstepid_sdkmessageprocessingstepimage = sdkImages
                };
                org.OrganizationService.Update(profilerStep);
            }

            // Refresh the objects so that the caller has up-to-date data
            OrganizationHelper.RefreshStep(org, step);
            if (null != updateImages)
            {
                foreach (CrmPluginImage image in updateImages)
                {
                    OrganizationHelper.RefreshImage(org, image, step);
                }
            }

            // Delete the orphaned Secure config when nulling out the value on the step
            if (null != origSecureConfigId)
            {
                org.OrganizationService.Delete(SdkMessageProcessingStepSecureConfig.EntityLogicalName, origSecureConfigId.GetValueOrDefault());
            }

            return(true);
        }
 public static List <Guid> RetrieveSecureConfigIdsForStepId(CrmOrganization org, IList <Guid> stepIds)
 {
     return(RetrieveReferenceAttributeIds(org, SdkMessageProcessingStep.EntityLogicalName,
                                          "sdkmessageprocessingstepsecureconfigid", "sdkmessageprocessingstepid", stepIds));
 }
 /// <summary>
 /// Unregister entities
 /// </summary>
 /// <param name="org">Organization to be used</param>
 /// <param name="cascadeOperation">Cascade the operation</param>
 /// <param name="crmEntity">Entities to be unregistered. If these are not invalid entities, only one can be specified</param>
 /// <returns>Statistics of what was unregistered</returns>
 public static Dictionary <string, int> Unregister(CrmOrganization org, params ICrmEntity[] crmEntity)
 {
     return(Unregister(org, null, crmEntity));
 }
 private static List <Guid> RetrieveStepIdsForServiceEndpoint(CrmOrganization org, IList <Guid> serviceEndpointIds)
 {
     return(RetrieveReferenceAttributeIds(org, SdkMessageProcessingStep.EntityLogicalName, "sdkmessageprocessingstepid", "eventhandler", serviceEndpointIds));
 }
 private static List <Guid> RetrieveStepIdsForPlugins(CrmOrganization org, IList <Guid> pluginIds)
 {
     return(RetrieveReferenceAttributeIds(org, SdkMessageProcessingStep.EntityLogicalName, "sdkmessageprocessingstepid", "plugintypeid", pluginIds));
 }
        /// <summary>
        /// Retrieve the Id for each entityName that has a filterAttribute value in the filterIdList.
        /// </summary>
        private static List <Guid> RetrieveReferenceAttributeIds(CrmOrganization org, string entityName, string retrieveAttribute, string filterAttribute, IList <Guid> filterIdList)
        {
            #region Argument Validation

            if (org == null)
            {
                throw new ArgumentNullException("org");
            }
            else if (entityName == null)
            {
                throw new ArgumentNullException("entityName");
            }
            else if (retrieveAttribute == null)
            {
                throw new ArgumentNullException("retrieveAttribute");
            }
            else if (filterAttribute == null)
            {
                throw new ArgumentNullException("filterAttribute");
            }
            else if (retrieveAttribute == filterAttribute)
            {
                throw new ArgumentException("Attributes must be different");
            }

            #endregion Argument Validation

            if (filterIdList.Count == 0)
            {
                return(new List <Guid>());
            }

            //Generate the query
            var cols = new ColumnSet();
            cols.AddColumns(retrieveAttribute);

            var idCondition = new ConditionExpression();
            idCondition.AttributeName = filterAttribute;
            idCondition.Operator      = ConditionOperator.In;
            idCondition.Values.Clear();
            idCondition.Values.AddRange(ConvertIdArrayToObjectArray(filterIdList));

            var query = new QueryExpression();
            query.ColumnSet = cols;
            query.Criteria.AddCondition(idCondition);
            query.EntityName = entityName;

            //Loop through the results
            var resultList = new List <Guid>();
            foreach (var entity in org.OrganizationService.RetrieveMultipleAllPages(query).Entities)
            {
                foreach (KeyValuePair <string, object> prop in entity.Attributes)
                {
                    if (prop.Key == retrieveAttribute)
                    {
                        var propType = prop.Value.GetType();
                        if (propType == typeof(Guid))
                        {
                            resultList.Add((Guid)prop.Value);
                        }
                        else if (propType == typeof(EntityReference))
                        {
                            resultList.Add(((EntityReference)prop.Value).Id);
                        }
                        else
                        {
                            throw new ArgumentException("Unknown property returned " + prop.GetType().FullName);
                        }
                    }
                }
            }

            return(resultList);
        }
예제 #15
0
 public void LoadSolutions(CrmOrganization crmOrg)
 {
     CrmOrg = crmOrg;
     ReLoadSolutions();
 }
예제 #16
0
        public AttributeSelectionForm(UpdateImageAttributesDelegate updateAttributes, CrmOrganization org,
                                      CrmAttribute[] attributeList, Collection <string> currentValue, bool currentAllChecked)
        {
            if (org == null)
            {
                throw new ArgumentNullException("org");
            }
            else if (attributeList == null)
            {
                throw new ArgumentNullException("attributeList");
            }
            else if (updateAttributes == null)
            {
                throw new ArgumentNullException("updateAttributes");
            }

            InitializeComponent();

            m_org = org;
            m_updateAttributes = updateAttributes;

            //Create a sorter for the listview. This will allow the list to be sorted by different columns
            lsvAttributes.ListViewItemSorter = new ListViewColumnSorter(0, lsvAttributes.Sorting);

            foreach (CrmAttribute attribute in attributeList)
            {
                switch (attribute.Type)
                {
                case AttributeTypeCode.Boolean:
                case AttributeTypeCode.Customer:
                case AttributeTypeCode.DateTime:
                case AttributeTypeCode.Decimal:
                case AttributeTypeCode.Double:
                case AttributeTypeCode.Integer:
                case AttributeTypeCode.Lookup:
                case AttributeTypeCode.Memo:
                case AttributeTypeCode.Money:
                case AttributeTypeCode.Owner:
                case AttributeTypeCode.PartyList:
                case AttributeTypeCode.Picklist:
                case AttributeTypeCode.State:
                case AttributeTypeCode.Status:
                case AttributeTypeCode.String:
                {
                    ListViewItem item = lsvAttributes.Items.Add(attribute.LogicalName.Trim().ToLowerInvariant(), attribute.FriendlyName, 0);
                    item.SubItems.Add(attribute.LogicalName);
                    item.SubItems.Add(attribute.Type.ToString());
                    item.Tag = attribute;
                }
                break;

                case AttributeTypeCode.CalendarRules:
                case AttributeTypeCode.Uniqueidentifier:
                case AttributeTypeCode.Virtual:

                    if (attribute.IsPrimaryId)
                    {
                        ListViewItem item = lsvAttributes.Items.Add(attribute.LogicalName.Trim().ToLowerInvariant(), attribute.FriendlyName, 0);
                        item.SubItems.Add(attribute.LogicalName);
                        item.SubItems.Add(attribute.Type.ToString());
                        item.Tag = attribute;
                    }
                    continue;
                }
            }

            if (currentAllChecked)
            {
                chkSelectAll.Checked = true;
                foreach (ListViewItem item in lsvAttributes.Items)
                {
                    item.Checked = true;
                }
            }
            else if (currentValue != null && currentValue.Count != 0)
            {
                foreach (string value in currentValue)
                {
                    if (!string.IsNullOrEmpty(value) && lsvAttributes.Items.ContainsKey(value.Trim().ToLowerInvariant()))
                    {
                        lsvAttributes.Items[value.ToLowerInvariant()].Checked = true;
                    }
                }
            }
        }
 public ImportSolutionMessage(CrmOrganization organization) : base(organization)
 {
     this.ImportJobId = Guid.NewGuid();
     this.AsyncJobId  = Guid.NewGuid();
 }
예제 #18
0
 public EnableEntityChangeTrackingMessage(CrmOrganization crm) : base(crm)
 {
 }
예제 #19
0
 public RetrieveSolutionDataMessage(CrmOrganization organization) : base(organization)
 {
 }
예제 #20
0
        public PluginRegistrationForm(CrmOrganization org, MainControl orgControl, CrmPluginAssembly assembly)
        {
            if (org == null)
            {
                throw new ArgumentNullException("org");
            }
            else if (orgControl == null)
            {
                throw new ArgumentNullException("orgControl");
            }

            InitializeComponent();

            m_org              = org;
            m_orgControl       = orgControl;
            m_progRegistration = new ProgressIndicator(ProgressIndicatorInit, ProgressIndicatorComplete,
                                                       ProgressIndicatorAddText, ProgressIndicatorSetText,
                                                       ProgressIndicatorIncrement, null);
            m_currentAssembly = assembly;

            trvPlugins.CrmTreeNodeSorter = orgControl.CrmTreeNodeSorter;

            //Check if this is a known assembly
            if (null == assembly)
            {
                //If this is a known assembly, check for the default isolation mode for each authentication type
                if (null != org.ConnectionDetail)
                {
                    // TODO: Come back
                    //switch (org.ConnectionDetail.GetDiscoveryService().ServiceConfiguration.AuthenticationType)
                    //{
                    //    case Microsoft.Xrm.Sdk.Client.AuthenticationProviderType.ActiveDirectory:
                    //        radIsolationNone.Checked = true;
                    //        break;
                    //    default:
                    //        radIsolationSandbox.Checked = true;
                    //        break;
                    //}
                }
            }
            else
            {
                m_registeredPluginList = new List <CrmPlugin>();

                LoadAssembly(assembly, false);

                switch (assembly.IsolationMode)
                {
                case CrmAssemblyIsolationMode.Sandbox:
                    radIsolationSandbox.Checked = true;
                    break;

                case CrmAssemblyIsolationMode.None:
                    radIsolationNone.Checked = true;
                    break;

                default:
                    throw new NotImplementedException("IsolationMode = " + assembly.IsolationMode.ToString());
                }

                switch (assembly.SourceType)
                {
                case CrmAssemblySourceType.Database:
                    radDB.Checked = true;
                    break;

                case CrmAssemblySourceType.Disk:
                    radDisk.Checked = true;
                    break;

                case CrmAssemblySourceType.GAC:
                    radGAC.Checked = true;
                    break;

                default:
                    throw new NotImplementedException("SourceType = " + assembly.SourceType.ToString());
                }

                txtServerFileName.Text = assembly.ServerFileName;

                Text             = string.Format("Update Assembly: {0}", assembly.Name);
                btnRegister.Text = "Update Selected Plugins";
            }

            EnableRegistrationControls();
        }
 public DeleteSolutionMessage(CrmOrganization organization) : base(organization)
 {
 }
예제 #22
0
 public Message(CrmOrganization organization)
 {
     this.CrmOrganization = organization;
 }
        public PluginRegistrationForm(CrmOrganization org, MainControl orgControl, CrmPluginAssembly assembly, List <PluginAssemblyFileMapping> mapping)
        {
            if (org == null)
            {
                throw new ArgumentNullException("org");
            }
            else if (orgControl == null)
            {
                throw new ArgumentNullException("orgControl");
            }

            InitializeComponent();

            m_org              = org;
            m_orgControl       = orgControl;
            m_progRegistration = new ProgressIndicator(ProgressIndicatorInit, ProgressIndicatorComplete,
                                                       ProgressIndicatorAddText, ProgressIndicatorSetText,
                                                       ProgressIndicatorIncrement, null);
            m_currentAssembly = assembly;
            m_mapping         = mapping;

            radIsolationSandbox.Checked = org.ConnectionDetail.UseOnline;

            trvPlugins.CrmTreeNodeSorter = orgControl.CrmTreeNodeSorter;

            //Check if this is a known assembly
            if (null == assembly)
            {
                //If this is a known assembly, check for the default isolation mode for each authentication type
                if (null != org.ConnectionDetail)
                {
                    // TODO: Come back
                    //switch (org.ConnectionDetail.GetDiscoveryService().ServiceConfiguration.AuthenticationType)
                    //{
                    //    case Microsoft.Xrm.Sdk.Client.AuthenticationProviderType.ActiveDirectory:
                    //        radIsolationNone.Checked = true;
                    //        break;
                    //    default:
                    //        radIsolationSandbox.Checked = true;
                    //        break;
                    //}
                }
            }
            else
            {
                m_registeredPluginList = new List <CrmPlugin>();

                LoadAssembly(assembly, false);

                switch (assembly.IsolationMode)
                {
                case CrmAssemblyIsolationMode.Sandbox:
                    radIsolationSandbox.Checked = true;
                    break;

                case CrmAssemblyIsolationMode.None:
                    radIsolationNone.Checked = true;
                    break;

                default:
                    throw new NotImplementedException($"IsolationMode = { assembly.IsolationMode.ToString() }");
                }

                switch (assembly.SourceType)
                {
                case CrmAssemblySourceType.Database:
                    radDB.Checked = true;
                    break;

                case CrmAssemblySourceType.Disk:
                    radDisk.Checked = true;
                    break;

                case CrmAssemblySourceType.GAC:
                    radGAC.Checked = true;
                    break;

                default:
                    throw new NotImplementedException($"SourceType = {assembly.SourceType.ToString()}");
                }

                txtServerFileName.Text = assembly.ServerFileName;

                var mappedFileName = mapping.FirstOrDefault(m => m.PluginAssemblyName == assembly.Name)?.FilePath;
                if (!string.IsNullOrEmpty(mappedFileName) && File.Exists(mappedFileName))
                {
                    AssemblyPathControl.FileName = mappedFileName;
                    AssemblyPathControl_PathChanged(AssemblyPathControl, new EventArgs());
                    btnLoadAssembly_Click(btnLoadAssembly, new EventArgs());
                }

                Text             = $"Update Assembly: {assembly.Name}";
                btnRegister.Text = "Update Selected Plugins";
            }

            EnableRegistrationControls();
        }
 private static List <Guid> RetrieveImageIdsForStepId(CrmOrganization org, IList <Guid> stepIds)
 {
     return(RetrieveReferenceAttributeIds(org, SdkMessageProcessingStepImage.EntityLogicalName, "sdkmessageprocessingstepimageid", "sdkmessageprocessingstepid", stepIds));
 }