Пример #1
0
        public static Guid GetCrmUserId(int accountId)
        {
            IDataReader reader = DataProvider.GetCrmUser(accountId);
            CrmUser     user   = ObjectUtils.FillObjectFromDataReader <CrmUser>(reader);

            return(user == null ? Guid.Empty :user.CRMUserId);
        }
Пример #2
0
        public async Task <IActionResult> Register(RegisterUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new CrmUser
                {
                    UserName    = model.UserName,
                    DisplayName = model.DisplayName,
                    Email       = model.UserName
                };
                var createResult = await this.userManager.CreateAsync(user, model.Password);

                if (createResult.Succeeded)
                {
                    await this.signInManager.SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("Index", "Home"));
                }
                foreach (var result in createResult.Errors)
                {
                    ModelState.AddModelError("", result.Description);
                }
            }
            return(View());
        }
Пример #3
0
        public async Task <IActionResult> Login(LoginUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new CrmUser
                {
                    UserName = model.UserName
                };
                var loginResult = await signInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, false);

                if (loginResult.Succeeded)
                {
                    if (Url.IsLocalUrl(model.ReturnUrl))
                    {
                        return(Redirect(model.ReturnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }

                ModelState.AddModelError("", "Could not login");
            }
            return(View());
        }
Пример #4
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = new CrmUser
            {
                UserName = model.UserName,
                Email    = model.Email
            };

            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                //await this.signInManager.SignInAsync(user, isPersistent: false);
                await _userManager.AddToRoleAsync(user, "DefaultUser");

                //var confrimationCode =
                //    await _userManager.GenerateEmailConfirmationTokenAsync(user);

                //var callbackurl = Url.Action(
                //    controller: "Security",
                //    action: "ConfirmEmail",
                //    values: new { userId = user.Id, code = confrimationCode },
                //    protocol: Request.Scheme);

                //await _emailSender.SendEmailAsync(
                //    user.Email,
                //    "Confirm Email",
                //    callbackurl);

                return(RedirectToAction("Index", "Home"));
            }

            return(View(model));
        }
    public static List <CrmUser> GetAllCrmUsers()
    {
        List <CrmUser> CrmUsers = new List <CrmUser>();

        try
        {
            ColumnSet       colsPrincipal  = new ColumnSet("lastname", "firstname", "domainname", "systemuserid", "businessunitid");
            QueryExpression queryPrincipal = new QueryExpression();
            queryPrincipal.EntityName = "systemuser";
            queryPrincipal.ColumnSet  = colsPrincipal;

            var myAccounts = CommonCrm.crmContext.RetrieveMultiple(queryPrincipal);

            foreach (var myEntity in myAccounts.Entities)
            {
                //create new crm users and add it to the list
                CrmUser thisOne = new CrmUser();

                thisOne.firstName = myEntity.GetAttributeValue <string>("firstname");
                thisOne.lastName  = myEntity.GetAttributeValue <string>("name");
                thisOne.userId    = myEntity.GetAttributeValue <string>("domainname");
                thisOne.userGuid  = myEntity.GetAttributeValue <Guid>("systemuserid");
                thisOne.buId      = myEntity.GetAttributeValue <EntityReference>("businessunitid").Id;
                // and so on and so forth...
                CrmUsers.Add(thisOne);
            }
        }
        catch (Exception ex)
        {
            CrmUser thisOne = new CrmUser();
            thisOne.firstName = "Crap there was an error";
            thisOne.lastName  = ex.ToString();
            CrmUsers.Add(thisOne);
        }

        return(CrmUsers);
    }
Пример #6
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            if (activity.Type == ActivityTypes.Message)
            {
                ConnectorClient connector   = new ConnectorClient(new Uri(activity.ServiceUrl));
                var             stateClient = activity.GetStateClient(ConfigurationManager.AppSettings["MicrosoftAppId"], ConfigurationManager.AppSettings["MicrosoftAppSecret"]);
                var             userData    = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id);

                var privateData = await stateClient.BotState.GetPrivateConversationDataAsync(activity.ChannelId, activity.Conversation.Id, activity.From.Id);

                // CRMにアクセスしてそのユーザーの本日の予定データを取得します。
                // 本来、この処理は一連のFormFlowの会話が完了する間には一度だけ実行することが望ましい
                CrmService service = new Services.CrmService();
                CrmUser    user    = await service.GetCrmUser(activity.From.Name);

                CrmService.CallerId           = user.Id.ToString();
                AppointmentReport.CrmUserName = user.FullName;
                var appointments = await service.GetCRMAppointments();

                if (appointments.Records.Count() != 0)
                {
                    await Conversation.SendAsync(activity, MakeRootDialog);
                }
                else
                {
                    connector.Conversations.SendToConversation(activity.CreateReply("本日の未報告の訪問はありません。"));
                }
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
Пример #7
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()
            {
                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);

            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];
                }

                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();
        }
Пример #8
0
        public static CrmRolesResult GetCRMRoles(int itemId, int accountId, int packageId)
        {
            CrmRolesResult res = StartTask <CrmRolesResult>("CRM", "GET_CRM_ROLES");

            try
            {
                int serviceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.HostedCRM);
                if (serviceId == 0)
                {
                    CompleteTask(res, CrmErrorCodes.CRM_IS_NOT_SELECTED_IN_HOSTING_PLAN, null, "CRM is not selected in hosting plan.");
                    return(res);
                }

                CRM crm = new CRM();
                ServiceProviderProxy.Init(crm, serviceId);

                Organization org = OrganizationController.GetOrganization(itemId);

                CrmUserResult crmUserResult = GetCrmUser(itemId, accountId);
                res.ErrorCodes.AddRange(crmUserResult.ErrorCodes);
                if (!crmUserResult.IsSuccess)
                {
                    CompleteTask(res);
                    return(res);
                }

                CrmUser        crmUser  = crmUserResult.Value;
                CrmRolesResult crmRoles = crm.GetAllCrmRoles(org.OrganizationId, crmUser.BusinessUnitId);
                res.ErrorCodes.AddRange(crmRoles.ErrorCodes);
                if (!crmRoles.IsSuccess)
                {
                    CompleteTask(res);
                    return(res);
                }
                Guid           userId       = crmUser.CRMUserId;
                CrmRolesResult crmUserRoles = crm.GetCrmUserRoles(org.OrganizationId, userId);

                res.ErrorCodes.AddRange(crmUserRoles.ErrorCodes);
                if (!crmUserRoles.IsSuccess)
                {
                    CompleteTask(res);
                    return(res);
                }

                foreach (CrmRole role in crmUserRoles.Value)
                {
                    CrmRole retRole = crmRoles.Value.Find(delegate(CrmRole currentRole)
                    {
                        return(currentRole.RoleId == role.RoleId);
                    });
                    if (retRole != null)
                    {
                        retRole.IsCurrentUserRole = true;
                    }
                }

                res.Value = crmRoles.Value;
            }
            catch (Exception ex)
            {
                CompleteTask(res, CrmErrorCodes.CANNOT_GET_CRM_ROLES_GENERAL_ERROR, ex);
                return(res);
            }

            CompleteTask();
            return(res);
        }
        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");
            }

            InitializeComponent();

            m_org         = org;
            m_orgControl  = orgControl;
            m_currentStep = step;

            crmFilteringAttributes.Organization = org;

            //Initialize the auto-complete on the Message field
            AutoCompleteStringCollection 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
            CrmUser callingUser = new CrmUser(org);

            callingUser.UserId  = Guid.Empty;
            callingUser.Name    = "Calling User";
            callingUser.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();
        }