Exemple #1
0
        public void TestCsvImportWithOptionalFields()
        {
            Users importedUsers = null;

            byte[] abBytes = GetBytesFromImportFile("OptionalFields.csv");

            IImportParser csvParser = new CsvImportParser();

            csvParser.Parse(abBytes, out importedUsers);

            Assert.That(importedUsers, Is.Not.Null);
            Assert.That(importedUsers.Count, Is.EqualTo(1));
            Assert.That(importedUsers[0].LName, Is.EqualTo("Chatilov"));
            Assert.That(importedUsers[0].FName, Is.EqualTo("Alexandre"));
            Assert.That(importedUsers[0].Ext, Is.EqualTo("8888"));
            Assert.That(importedUsers[0].Email, Is.EqualTo(""));
            Assert.That(importedUsers[0].Username, Is.EqualTo(""));
            Assert.That(importedUsers[0].Domain, Is.EqualTo(""));
            Assert.That(importedUsers[0].MobileNumber, Is.EqualTo("8580000000"));
            Assert.That(importedUsers[0].PagerNumber, Is.EqualTo("6190000000"));
        }
Exemple #2
0
        public void TestCsvImportWithMandatoryFieldsOnly()
        {
            Users importedUsers = null;

            byte[] abBytes = GetBytesFromImportFile("MandatoryFields.csv");

            IImportParser csvParser = new CsvImportParser();

            csvParser.Parse(abBytes, out importedUsers);

            Assert.That(importedUsers, Is.Not.Null);
            Assert.That(importedUsers.Count, Is.EqualTo(1));
            Assert.That(importedUsers[0].LName, Is.EqualTo("Abercrombie"));
            Assert.That(importedUsers[0].FName, Is.EqualTo("Neil"));
            Assert.That(importedUsers[0].Ext, Is.EqualTo("8888"));
            Assert.That(importedUsers[0].Email, Is.EqualTo(""));
            Assert.That(importedUsers[0].Username, Is.EqualTo(""));
            Assert.That(importedUsers[0].Domain, Is.EqualTo(""));
            Assert.That(importedUsers[0].MobileNumber, Is.EqualTo(""));
            Assert.That(importedUsers[0].PagerNumber, Is.EqualTo(""));
        }
Exemple #3
0
        private static int ImportDirectory(string i_sFileType, string i_sFileName, bool i_bMerge)
        {
            int iExitCode = EXIT_CODE_SUCCESS;

            IImportParser importParser = null;

            switch (i_sFileType.ToLower())
            {
            case "csv":
                importParser = new CsvImportParser();
                break;

            case "allworx":
                importParser = new AllworxImportParser();
                break;

            case "shoretel":
                importParser = new ShoreTelImportParser();
                break;

            default:
                iExitCode = EXIT_CODE_ILLEGAL_ARGUMENT;
                Console.Error.WriteLine("ERROR: Invalid type specified {0} - valid types are: csv, allworx, shoretel", i_sFileType);
                break;
            }

            if (null != importParser)
            {
                byte[] importBytes = GetBytesFromImportFile(i_sFileName);

                if ((null != importBytes) && (importBytes.Length > 0))
                {
                    bool bContinueImport = true;

                    if (!i_bMerge)
                    {
                        bContinueImport = DeleteAllUsersExceptAdmin();
                    }

                    if (bContinueImport)
                    {
                        SBConfigStor.Directory sbcDir = new SBConfigStor.Directory();
                        SBConfigStor.Directory.eImportStatus importStatus = sbcDir.Persist(importBytes, importParser, GetNumberOfUsersThatCanBeAdded());

                        if (SBConfigStor.Directory.eImportStatus.eFailure == importStatus)
                        {
                            iExitCode = EXIT_CODE_IMPORT_ERROR;
                            Console.Error.WriteLine("ERROR: There was an error importing the file ('{0}', '{1}').", i_sFileType, i_sFileName);
                        }
                        else
                        {
                            if (SBConfigStor.Directory.eImportStatus.eIncomplete == importStatus)
                            {
                                iExitCode = EXIT_CODE_IMPORT_INCOMPLETE;
                                Console.Error.WriteLine("WARNING: Import incomplete since licensed number of Directory Entries exceeded.");
                            }

                            ConfigParams.SetVoicexmlDirty(true);
                        }
                    }
                    else
                    {
                        iExitCode = EXIT_CODE_IMPORT_ERROR;
                    }
                }
                else
                {
                    iExitCode = EXIT_CODE_IMPORT_ERROR;
                    Console.Error.WriteLine("ERROR: Import file was empty or doesn't exist {0}.", i_sFileName);
                }
            }

            return(iExitCode);
        }