Example #1
0
        /// <summary>
        /// Displays process progress.
        /// </summary>
        public void StartThread()
        {
            this.progressBar.Value = 0;

            try
            {
                this.lblProcess.Text = "Creating import script...";
                appForm.Update();

                //default actions
                List <ImportAction> actions = GetImportActions();

                //process actions
                for (int i = 0; i < actions.Count; i++)
                {
                    ImportAction action = actions[i];
                    this.lblProcess.Text   = action.Description;
                    this.progressBar.Value = i * 100 / actions.Count;
                    appForm.Update();

                    switch (action.ActionType)
                    {
                    case ActionTypes.ImportOrganization:
                        ImportOrganization();
                        break;

                    case ActionTypes.ImportOrganizationDomain:
                        ImportDomain(action.Name);
                        break;

                    case ActionTypes.ImportMailbox:
                        ImportMailbox(action.DirectoryEntry);
                        break;

                    case ActionTypes.ImportContact:
                        ImportContact(action.DirectoryEntry);
                        break;

                    case ActionTypes.ImportGroup:
                        ImportGroup(action.DirectoryEntry);
                        break;
                    }
                }
                this.progressBar.Value = 100;
            }
            catch (Exception ex)
            {
                if (Utils.IsThreadAbortException(ex))
                {
                    return;
                }

                string message = Global.ErrorMessage;
                if (string.IsNullOrEmpty(message))
                {
                    message = "An unexpected error has occurred during import.";
                }
                ShowError(message, ex);
                Cancel();
                return;
            }

            this.lblProcess.Text = string.Empty;
            DialogResult dialogResult = DialogResult.No;

            if (Global.HasErrors)
            {
                dialogResult = MessageBox.Show(appForm, "Import completed with errors. Would you like to see import log?", appForm.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            }
            else
            {
                dialogResult = MessageBox.Show(appForm, "Import completed successfully. Would you like to see import log?", appForm.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            }
            if (dialogResult == DialogResult.Yes)
            {
                Log.ShowLogFile();
            }

            btnImport.Enabled      = true;
            appForm.ImportStarted  = false;
            this.progressBar.Value = 0;
        }
Example #2
0
        private List <ImportAction> GetImportActions()
        {
            List <ImportAction> list   = new List <ImportAction>();
            ImportAction        action = null;

            if (Global.ImportAccountsOnly)
            {
                ServiceProviderItem item = PackageController.GetPackageItemByName(Global.Space.PackageId, ResourceGroups.HostedOrganizations, Global.OrganizationName, typeof(Organization));
                if (item == null)
                {
                    Global.ErrorMessage = string.Format("Organization {0} not found.", Global.OrganizationName);
                    throw new Exception(Global.ErrorMessage);
                }
                Global.ItemId = item.Id;
            }
            else
            {
                action             = new ImportAction(ActionTypes.ImportOrganization);
                action.Description = "Importing organization...";
                list.Add(action);

                DirectoryEntry          org   = Global.OrgDirectoryEntry;
                PropertyValueCollection props = org.Properties["uPNSuffixes"];
                if (props != null)
                {
                    foreach (string domainName in props)
                    {
                        action             = new ImportAction(ActionTypes.ImportOrganizationDomain);
                        action.Description = "Importing organization domains...";
                        action.Name        = domainName;
                        list.Add(action);
                    }
                }
            }

            if (Global.SelectedAccounts != null)
            {
                foreach (DirectoryEntry entry in Global.SelectedAccounts)
                {
                    switch (entry.SchemaClassName)
                    {
                    case "user":
                        action                = new ImportAction(ActionTypes.ImportMailbox);
                        action.Description    = "Importing mailbox...";
                        action.DirectoryEntry = entry;
                        list.Add(action);
                        break;

                    case "contact":
                        action                = new ImportAction(ActionTypes.ImportContact);
                        action.Description    = "Importing contact...";
                        action.DirectoryEntry = entry;
                        list.Add(action);
                        break;

                    case "group":
                        action                = new ImportAction(ActionTypes.ImportGroup);
                        action.Description    = "Importing group...";
                        action.DirectoryEntry = entry;
                        list.Add(action);
                        break;
                    }
                }
            }


            return(list);
        }
		private List<ImportAction> GetImportActions()
		{
			List<ImportAction> list = new List<ImportAction>();
			ImportAction action = null;

			if (Global.ImportAccountsOnly)
			{
				ServiceProviderItem item = PackageController.GetPackageItemByName(Global.Space.PackageId, ResourceGroups.HostedOrganizations, Global.OrganizationName, typeof(Organization));
				if (item == null)
				{
					Global.ErrorMessage = string.Format("Organization {0} not found.", Global.OrganizationName);
					throw new Exception(Global.ErrorMessage);
				}
				Global.ItemId = item.Id;
			}
			else
			{
				action = new ImportAction(ActionTypes.ImportOrganization);
				action.Description = "Importing organization...";
				list.Add(action);

				DirectoryEntry org = Global.OrgDirectoryEntry;
				PropertyValueCollection props = org.Properties["uPNSuffixes"];
				if (props != null)
				{
					foreach (string domainName in props)
					{
						action = new ImportAction(ActionTypes.ImportOrganizationDomain);
						action.Description = "Importing organization domains...";
						action.Name = domainName;
						list.Add(action);
					}
				}
			}

			if (Global.SelectedAccounts != null)
			{
				foreach (DirectoryEntry entry in Global.SelectedAccounts)
				{
					switch (entry.SchemaClassName)
					{
						case "user":
							action = new ImportAction(ActionTypes.ImportMailbox);
							action.Description = "Importing mailbox...";
							action.DirectoryEntry = entry;
							list.Add(action);
							break;
						case "contact":
							action = new ImportAction(ActionTypes.ImportContact);
							action.Description = "Importing contact...";
							action.DirectoryEntry = entry;
							list.Add(action);
							break;
						case "group":
							action = new ImportAction(ActionTypes.ImportGroup);
							action.Description = "Importing group...";
							action.DirectoryEntry = entry;
							list.Add(action);
							break;
					}
				}
			}


			return list;
		}