Exemplo n.º 1
0
        public MigrationAccount()
        {
            // Dont know the account num yet
            AccountNum = -1;

            // Holds info about the folder currently being migrated
            CurrFolder = new MigrationFolder();

            // Track tags for this account
            TagDict = new Dictionary <string, string>();

            AccountStartTicks = Environment.TickCount;
        }
Exemplo n.º 2
0
 public MigrationAccount()
 {
     AccountNum = -1;
     migrationFolder = new MigrationFolder();
     tagDict = new Dictionary<string, string>();
 }
Exemplo n.º 3
0
 public MigrationAccount()
 {
     AccountNum      = -1;
     migrationFolder = new MigrationFolder();
     tagDict         = new Dictionary <string, string>();
 }
Exemplo n.º 4
0
        // Background thread stuff
        private void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            eventArglist.Add(e);

            int num = (int)e.Argument;
            Log.info(" In Do work for threads for user number", num);
            MigrationAccount MyAcct = new MigrationAccount();
            UsersViewModel usersViewModel = ((UsersViewModel)ViewModelPtrs[(int)ViewType.USERS]);
            AccountResultsViewModel accountResultsViewModel =
            ((AccountResultsViewModel)ViewModelPtrs[(int)ViewType.RESULTS]);    // main one
            string accountname = accountResultsViewModel.AccountResultsList[num].AccountName;
            string accountid = "";

            if (isServer)
            {
            accountname = accountname + "@" + usersViewModel.ZimbraDomain;
            accountid = usersViewModel.UsersList[num].Username;

            int idx = accountid.IndexOf("@");

            if (idx != -1)                      // domain would be Exchange domain, not Zimbra domain
                accountid = accountid.Substring(0, idx);
            }
            else
            {
            ConfigViewModelU sourceModel =
                ((ConfigViewModelU)ViewModelPtrs[(int)ViewType.USRSRC]);
            ConfigViewModelUDest destModel =
                ((ConfigViewModelUDest)ViewModelPtrs[(int)ViewType.USRDEST]);

            accountname = ZimbraValues.GetZimbraValues().AccountName;//accountname + "@" + destModel.ZimbraServerHostName;
            accountid = (sourceModel.IspST) ? sourceModel.PSTFile :
                sourceModel.ProfileList[sourceModel.CurrentProfileSelection];
            }
            MyAcct.AccountName = accountname;
            MyAcct.AccountID = accountid;
            MyAcct.AccountNum = num;
            MyAcct.OnChanged += new MigrationObjectEventHandler(Acct_OnAcctChanged);

            MigrationFolder MyFolder = new MigrationFolder();

            MyFolder.AccountNum = num;
            MyFolder.OnChanged += new MigrationObjectEventHandler(Folder_OnChanged);

            MyAcct.migrationFolder = MyFolder;

            CSMigrationWrapper mw = ((IntroViewModel)ViewModelPtrs[(int)ViewType.INTRO]).mw;
            MigrationOptions importOpts = SetOptions();
            bool isVerbose = ((OptionsViewModel)ViewModelPtrs[(int)ViewType.OPTIONS]).LoggingVerbose;
            bool doRulesAndOOO = ((OptionsViewModel)ViewModelPtrs[(int)ViewType.OPTIONS]).OEnableRulesAndOOO;

            if (isVerbose)
            {
            if (importOpts.VerboseOn < LogLevel.Debug)
            {
                importOpts.VerboseOn = LogLevel.Debug;
            }

            }

            Log.info(" start migration for account ", MyAcct.AccountNum);

            //mw.StartMigration(MyAcct, importOpts, isServer, (isVerbose ? (LogLevel.Debug):(LogLevel.Info)), m_isPreview);
            mw.StartMigration(MyAcct, importOpts, isServer, importOpts.VerboseOn, m_isPreview, doRulesAndOOO);

            // special case to format last user progress message
            int count = accountResultsViewModel.AccountResultsList[num].UserResultsList.Count;
            if (count > 0)
            {
            if (!m_isPreview)
            {
                string lastmsg = accountResultsViewModel.AccountResultsList[num].UserResultsList[count - 1].UserProgressMsg;
                int len = lastmsg.Length;
                bool isOOOorRules = ((MyFolder.FolderView == "OOO") || (MyFolder.FolderView == "All Rules"));
                accountResultsViewModel.AccountResultsList[num].UserResultsList[count - 1].UserProgressMsg = FormatTheLastMsg(MyFolder, isOOOorRules);
                accountResultsViewModel.AccountResultsList[num].PBValue = 100;  // to make sure
                if (accountResultsViewModel.AccountResultsList[num].CurrentItemNum != accountResultsViewModel.AccountResultsList[num].TotalItemsToMigrate)
                {
                    FormatGlobalMsg(accountResultsViewModel.AccountResultsList[num]);
                }
            }
            else
            {   // For preview, take the "foldername (n items)" message we constructed, extract the n, and make "Total n"
                string msg = "";
                string lastmsg = accountResultsViewModel.AccountResultsList[num].PBMsgValue;
                int idxParen = lastmsg.IndexOf("(");
                int idxItems = lastmsg.IndexOf("items");
                if ((idxParen != -1) && (idxItems != -1))
                {
                    int numLen = idxItems - idxParen - 2;   // for the paren and the space
                    string numStr = lastmsg.Substring(idxParen + 1, numLen);
                    msg = "Total: " + numStr;
                    accountResultsViewModel.AccountResultsList[num].UserResultsList[count - 1].UserProgressMsg = (msg.Length > 0) ? msg : "";
                }
            }
            }
            /////

            if (!m_isPreview)
            {
            int tnum = GetThreadNum(MyAcct.AccountNum);
            //Log.info(" in worker_RunWorkerCompleted  for ThreadNum : " + tnum);

            if ((!(MyAcct.IsValid)) && (MyAcct.TotalErrors > 0))
            {
                Log.info(" in DOWORK -- Migration failed for usernum: " + MyAcct.AccountNum + " and threadnum" + tnum);
                accountResultsViewModel.AccountResultsList[num].PBMsgValue = "Migration Failed - Invalid account";
                accountResultsViewModel.AccountResultsList[num].AcctProgressMsg = "Failed";
            }
            else
            {
                if ((!(MyAcct.IsCompletedMigration)) && (MyAcct.TotalErrors > 0))
                {
                    Log.info(" in DOWORK -- Migration Incomplete for usernum: " + MyAcct.AccountNum + " and threadnum" + tnum);
                    accountResultsViewModel.AccountResultsList[num].PBMsgValue = "Migration Incomplete - Please Re-Run Migration";
                    accountResultsViewModel.AccountResultsList[num].AcctProgressMsg = "Incomplete";
                }
                else
                {
                    Log.info(" in DOWORK -- Migration completed for usernum: " + MyAcct.AccountNum + " and threadnum" + tnum);
                    accountResultsViewModel.AccountResultsList[num].PBMsgValue = "Migration complete";
                    accountResultsViewModel.AccountResultsList[num].AcctProgressMsg = "Complete";
                }
            }
            }
            else
            {
            string msg = "Total items: {0}";
            accountResultsViewModel.AccountResultsList[num].PBMsgValue = String.Format(msg, accountResultsViewModel.AccountResultsList[num].TotalItemsToMigrate);
            }

            if (importOpts.IsMaintainenceMode)
            {

            accountResultsViewModel.AccountResultsList[num].PBMsgValue = "Migration Incomplete";
            accountResultsViewModel.AccountResultsList[num].AcctProgressMsg = "InComplete";
            }
        }
Exemplo n.º 5
0
 // FBS 4/13/12 -- rewrite to fix bug 71048
 private string FormatTheLastMsg(MigrationFolder lastFolder, bool isOOOorRules)
 {
     string retval = (isOOOorRules) ? "1 of 1" : ""; // if it's Out of Office or Rules, just say 1 of 1
     if (!isOOOorRules)
     {
     string msg = "{0} of {1}";
     retval = String.Format(msg, lastFolder.CurrentCountOfItems, lastFolder.TotalCountOfItems);
     }
     return retval;
 }
Exemplo n.º 6
0
        public void Folder_OnChanged(object sender, CssLib.MigrationObjectEventArgs e)     // See similar code in ScheduleViewModel......can we dedupe?
        {
            //while (!_shouldStop)
            {
                CssLib.MigrationFolder f = (CssLib.MigrationFolder)sender;
                string sAcccountID       = "[" + f.AccountID.ToString() + "]";

                if (e.PropertyName == "NumFolderItemsMigrated")
                {
                    if (f.FolderName != null)
                    {
                        if (e.NewValue.ToString() != "0")
                        {
                            if (f.NumFolderItemsMigrated > 0)
                            {
                                string msg1 = sAcccountID.PadRight(25, ' ') + f.FolderName.PadRight(25, ' ') + "{0,5:#} of {1,5:#} migrated successfully";
                                string msgF = String.Format(msg1, f.NumFolderItemsMigrated, f.NumFolderItemsToMigrate);
                                System.Console.WriteLine(msgF);
                            }
                        }
                    }
                }

                if (e.PropertyName == "NumFolderItemsToMigrate")      // finish up with the last folder DCB I don't think it goes down this code path
                {
                    if (f.FolderName != null)
                    {
                        if (f.NumFolderItemsMigrated > 0)
                        {
                            string msg2 = sAcccountID.PadRight(25, ' ') + f.FolderName.PadRight(25, ' ') + "{0,5:#} of {1,5:#} migrated successfully";
                            string msgF = String.Format(msg2, f.NumFolderItemsMigrated, f.NumFolderItemsToMigrate);

                            System.Console.WriteLine(msgF);
                        }
                    }
                }

                if (e.PropertyName == "FolderName")
                {
                    if (e.NewValue != null)
                    {
                        string folderName = e.NewValue.ToString();

                        string msg3 = sAcccountID.PadRight(25, ' ') + "Starting migration of folder '{0}'";
                        string msgF = String.Format(msg3, folderName);
                        System.Console.WriteLine("");
                        System.Console.WriteLine(msgF);
                        System.Console.WriteLine("");
                    }

                    if (_shouldStop)
                    {
                        System.Console.WriteLine();
                        System.Console.WriteLine();
                        string Messg = "Migration For UserAccount   Cancelled";
                        // ProgressUtil.RenderConsoleProgress(30, '\u2591', ConsoleColor.Red, "Migration For UserAccount    Cancelled");
                        System.Console.WriteLine(Messg);
                        System.Console.WriteLine();
                        System.Console.WriteLine();
                        Countdown.Signal();
                        CancelAsync();
                        Thread.CurrentThread.Abort();
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void accountToMigrate_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            Account accnt = e.Argument as Account;

            // ------------------------------------------------
            // Create a thread-specific log for this thread
            // ------------------------------------------------
            string AccountName = accnt.AccountName;
            int    i           = AccountName.IndexOf("@");

            if (i != -1)
            {
                AccountName = AccountName.Substring(0, i);
            }

            // Similar code in ScheduleViewModel.cs::worker_DoWork
            // Log suffix  [src accnt] to [targ accnt]
            string sSrc = Path.GetFileNameWithoutExtension(accnt.AccountID);

            Log.StartNewLogfileForThisThread("[" + sSrc + "] to [" + AccountName + "]"); // If you change this, also change OpenLogFile()


            using (LogBlock logblock = Log.NotTracing() ? null : new LogBlock(GetType() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name)) // LogBlock not available here...it is now logging moved to ZimbraAPI
            {
                // Get argument from DoWorkEventArgs argument.  Can use any type here with cast
                // int myProcessArguments = (int)e.Argument;
                // "ProcessFile" is the name of my method that does the main work.  Replace with your own method!
                // Can return reulsts from this method, i.e. a status (OK, FAIL etc)
                //e.Result = ProcessFile(myProcessArgument);
                BackgroundWorker worker = sender as BackgroundWorker;

                // Assign the result of the computation
                // to the Result property of the DoWorkEventArgs
                // object. This is will be available to the
                // RunWorkerCompleted eventhandler.
                // e.Result = Accounworker, e);
                //int num = 0;

                //while (!_shouldStop)
                {
                    accnt.WorkerSupportsCancellation = true;

                    CssLib.MigrationAccount MyAcct = new CssLib.MigrationAccount();
                    MyAcct.AccountName   = accnt.AccountName;
                    MyAcct.AccountID     = accnt.AccountID;
                    MyAcct.MaxErrorCount = accnt.Mailoptions.MaxErrorCnt;
                    MyAcct.AccountNum    = accnt.num;
                    MyAcct.OnChanged    += new CssLib.MigrationObjectEventHandler(Acct_OnChanged);

                    CssLib.MigrationFolder MyFolder = new CssLib.MigrationFolder();


                    //MyFolder.AccountNum = argumentTest.num;
                    int idx = MyAcct.AccountName.IndexOf("@");
                    if (idx != -1)
                    {
                        MyFolder.AccountID = MyAcct.AccountName.Substring(0, idx);
                    }


                    // MyFolder.AccountID = argumentTest.AccountID;
                    MyFolder.OnChanged += new CssLib.MigrationObjectEventHandler(Folder_OnChanged);

                    MyAcct.CurrFolder = MyFolder;


                    CssLib.CSMigrationWrapper mw = accnt.TestObj;

                    if (accnt.CancellationPending)
                    {
                        e.Cancel = true;
                    }
                    else
                    {
                        // TestObj.Migrate(MigrateOptions);

                        mw.StartMigration(MyAcct, accnt.Mailoptions, accnt.serverMigration);
                        if (accnt.Mailoptions.IsMaintainenceMode)
                        {
                            System.Console.WriteLine("Mailbox is in Maintainence mode. Try again Later");
                        }

                        accnt.NumofErrors = MyAcct.NumAccountErrs;

                        //Last item migration
                        string sAcccountID = "[" + MyFolder.AccountID.ToString() + "]";
                        string msg2        = sAcccountID.PadRight(25, ' ') + MyFolder.FolderName.PadRight(25, ' ') + "{0,5:#} of {1,5:#} migrated successfully";
                        string msgF        = String.Format(msg2, MyFolder.NumFolderItemsMigrated, MyFolder.NumFolderItemsToMigrate);
                        System.Console.WriteLine(msgF);
                    }
                }

                if (_shouldStop)
                {
                    worker.CancelAsync();
                    accnt.CancelAsync();
                    accnt.countdown.Signal();
                    e.Cancel = true;
                }

                if (_shouldCancel)
                {
                    //worker.CancelAsync();
                    // argumentTest.CancelAsync();
                    // argumentTest.NumofErrors = NumofErrors;
                    accnt.CancelAsync();
                }
            }
        }
Exemplo n.º 8
0
        public void test(string accountname, object Test, string accountid, MigrationOptions opts, bool ServerMigration)
        {
            MigrationAccount MyAcct = new MigrationAccount();

            MyAcct.AccountName = accountname;
            MyAcct.AccountID = accountid;
            MyAcct.OnChanged += new MigrationObjectEventHandler(i_OnChanged1);

            MigrationFolder MyFolder = new MigrationFolder();

            MyFolder.OnChanged += new MigrationObjectEventHandler(i_OnChanged12);

            MyAcct.migrationFolder = MyFolder;

            /* CSMigrationwrapper test = new CSMigrationwrapper();
             * test.StartMigration(MyAcct);*/

            CSMigrationWrapper test = (CSMigrationWrapper)Test;

            // test.StartMigration(MyAcct,opts);
            test.StartMigration(MyAcct, opts, ServerMigration);
        }