Beispiel #1
0
        private void SaveCSV()
        {
            if (!ValidateUsersList(true))
            {
                return;
            }
            List <Users> ListofUsers = new List <Users>();

            for (int i = 0; i < UsersList.Count; i++)
            {
                string users = UsersList[i].Username + ',' + UsersList[i].MappedName;

                string[] nameTokens = users.Split(',');

                Users tempUser = new Users();

                tempUser.UserName   = nameTokens.GetValue(0).ToString();
                tempUser.MappedName = nameTokens.GetValue(1).ToString();
                if (nameTokens.Length > 2)
                {
                    tempUser.ChangePWD = Convert.ToBoolean(nameTokens.GetValue(2).ToString());
                }
                else
                {
                    tempUser.ChangePWD = false;
                }

                // tempUser.PWDdefault = nameTokens.GetValue(3).ToString();

                ListofUsers.Add(tempUser);
            }

            string resultcsv = Users.ToCsv <Users>(",", ListofUsers);

            Microsoft.Win32.SaveFileDialog fDialog = new Microsoft.Win32.SaveFileDialog();
            fDialog.Filter = "User Map Files|*.csv";

            // fDialog.CheckFileExists = true;
            // fDialog.Multiselect = false;

            ScheduleViewModel scheduleViewModel =
                ((ScheduleViewModel)ViewModelPtrs[(int)ViewType.SCHED]);

            if (fDialog.ShowDialog() == true)
            {
                string filename = fDialog.FileName;

                // +".csv";
                System.IO.File.WriteAllText(filename, resultcsv);
                scheduleViewModel.SetUsermapFile(filename);
            }
            // /Domain information gets stored in the xml
            // ///will have to revisit.
            SaveDomain();
        }
Beispiel #2
0
        private void UserMap()
        {
            ScheduleViewModel scheduleViewModel =
                ((ScheduleViewModel)ViewModelPtrs[(int)ViewType.SCHED]);
            bool bCSV = false;

            Microsoft.Win32.OpenFileDialog fDialog = new Microsoft.Win32.OpenFileDialog();
            fDialog.Filter          = "User Map Files|*.xml;*.csv";
            fDialog.CheckFileExists = true;
            fDialog.Multiselect     = false;
            if (fDialog.ShowDialog() == true)
            {
                int lastDot = fDialog.FileName.LastIndexOf(".");

                if (lastDot != -1)
                {
                    string substr = fDialog.FileName.Substring(lastDot, 4);

                    if (substr == ".csv")
                    {
                        bCSV = true;

                        /*try
                        * {
                        *  string names = File.ReadAllText(fDialog.FileName);
                        *  string[] nameTokens = names.Split(',');
                        *  foreach (string name in nameTokens)
                        *  {
                        *      UsersList.Add(name);
                        *      scheduleViewModel.SchedList.Add(name);
                        *  }
                        * }
                        * catch (IOException ex)
                        * {
                        *  MessageBox.Show(ex.Message, "Zimbra Migration", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        * }*/
                        List <string[]> parsedData = new List <string[]>();
                        try
                        {
                            if (File.Exists(fDialog.FileName))
                            {
                                using (StreamReader readFile = new StreamReader(fDialog.FileName)) {
                                    string line;

                                    string[] row;
                                    while ((line = readFile.ReadLine()) != null)
                                    {
                                        row = line.Split(',');
                                        parsedData.Add(row);
                                    }
                                    readFile.Close();
                                }
                            }
                            else
                            {
                                MessageBox.Show(
                                    "There is no user information stored.Please enter some user info",
                                    "Zimbra Migration", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                            }
                        }
                        catch (Exception e)
                        {
                            string message = e.Message;
                        }
                        // for (int i = 1; i < parsedData.Count; i++)
                        {
                            string[] strres = new string[parsedData.Count];

                            Users tempuser = new Users();

                            try
                            {
                                for (int j = 0; j < parsedData.Count; j++)
                                {
                                    bool bFoundSharp = false;
                                    strres = parsedData[j];
                                    int num = strres.Count();
                                    for (int k = 0; k < num; k++)
                                    {
                                        if (strres[k].Contains("#"))
                                        {
                                            bFoundSharp = true;
                                            break;
                                        }
                                    }
                                    if (!bFoundSharp) // FBS bug 71933 -- 3/21/12
                                    {
                                        tempuser.UserName   = strres[0];
                                        tempuser.MappedName = strres[1];

                                        tempuser.ChangePWD = Convert.ToBoolean(strres[2]);
                                        // tempuser.PWDdefault = strres[3];
                                        // string result = tempuser.UserName + "," + tempuser.MappedName +"," + tempuser.ChangePWD + "," + tempuser.PWDdefault;
                                        string result = tempuser.Username + "," + tempuser.MappedName;

                                        Username   = strres[0];
                                        MappedName = strres[1];
                                        UsersViewModel uvm = new UsersViewModel(Username, MappedName);
                                        uvm.MustChangePassword = tempuser.ChangePWD;
                                        UsersList.Add(uvm);
                                        scheduleViewModel.SchedList.Add(new SchedUser(Username, false));
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                MessageBox.Show("Incorrect .csv file format", "Zimbra Migration", MessageBoxButton.OK, MessageBoxImage.Error);
                                return;
                            }

                            EnableNext = (UsersList.Count > 0);
                        }
                        scheduleViewModel.EnableMigrate = (scheduleViewModel.SchedList.Count > 0);
                        scheduleViewModel.EnablePreview = scheduleViewModel.EnableMigrate;

                        // /
                        // Domain information is stored in the xml and not in  the usermap.
                        // will have to revisit

                        System.Xml.Serialization.XmlSerializer reader =
                            new System.Xml.Serialization.XmlSerializer(typeof(Config));
                        if (File.Exists(scheduleViewModel.GetConfigFile()))
                        {
                            System.IO.StreamReader fileRead = new System.IO.StreamReader(
                                scheduleViewModel.GetConfigFile());

                            Config Z11 = new Config();

                            Z11 = (Config)reader.Deserialize(fileRead);
                            fileRead.Close();
                            ZimbraDomain = Z11.UserProvision.DestinationDomain;
                            if (DomainList.Count > 0)
                            {
                                CurrentDomainSelection = (ZimbraDomain == null) ? 0 :
                                                         DomainList.IndexOf(ZimbraDomain);
                            }

                            else
                            {
                                DomainList.Add(ZimbraDomain);
                            }
                        }
                        scheduleViewModel.SetUsermapFile(fDialog.FileName);
                    }
                }
                if (!bCSV)
                {
                    MessageBox.Show("Only CSV files are supported", "Zimbra Migration",
                                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
        }
Beispiel #3
0
        private void SaveCSV()
        {
            if (!ValidateUsersList(true))
            {
                return;
            }

            ScheduleViewModel scheduleViewModel =
                ((ScheduleViewModel)ViewModelPtrs[(int)ViewType.SCHED]);

            System.Xml.Serialization.XmlSerializer reader =
                new System.Xml.Serialization.XmlSerializer(typeof(Config));
            if (File.Exists(scheduleViewModel.GetConfigFile()))
            {
                System.IO.StreamReader fileRead = new System.IO.StreamReader(
                    scheduleViewModel.GetConfigFile());

                Config Z11 = new Config();

                Z11 = (Config)reader.Deserialize(fileRead);
                fileRead.Close();

                CSVDelimiter = Z11.AdvancedImportOptions.CSVDelimiter;
            }
            List <Users> ListofUsers = new List <Users>();

            for (int i = 0; i < UsersList.Count; i++)
            {
                if (CSVDelimiter == null)
                {
                    CSVDelimiter = ",";
                }
                string users = UsersList[i].Username + CSVDelimiter /*','*/ + UsersList[i].MappedName;

//            string[] nameTokens = users.Split(',');
                string[] nameTokens = users.Split(CSVDelimiter.ToCharArray());

                Users tempUser = new Users();

                tempUser.UserName   = nameTokens.GetValue(0).ToString();
                tempUser.MappedName = nameTokens.GetValue(1).ToString();
                if (nameTokens.Length > 2)
                {
                    tempUser.ChangePWD = Convert.ToBoolean(nameTokens.GetValue(2).ToString());
                }
                else
                {
                    tempUser.ChangePWD = false;
                }

                // tempUser.PWDdefault = nameTokens.GetValue(3).ToString();

                ListofUsers.Add(tempUser);
            }

            //string resultcsv = Users.ToCsv<Users>(",", ListofUsers);
            string resultcsv = Users.ToCsv <Users>(CSVDelimiter, ListofUsers);

            Microsoft.Win32.SaveFileDialog fDialog = new Microsoft.Win32.SaveFileDialog();
            fDialog.Filter = "User Map Files|*.csv";

            // fDialog.CheckFileExists = true;
            // fDialog.Multiselect = false;

            /*ScheduleViewModel scheduleViewModel =
             *  ((ScheduleViewModel)ViewModelPtrs[(int)ViewType.SCHED]);*/

            if (fDialog.ShowDialog() == true)
            {
                string filename = fDialog.FileName;

                // +".csv";
                System.IO.File.WriteAllText(filename, resultcsv);
                scheduleViewModel.SetUsermapFile(filename);
            }
            // /Domain information gets stored in the xml
            // ///will have to revisit.
            SaveDomain();
        }