Ejemplo n.º 1
0
        public bool Reader(OperationType type, ref AddressBooks addressBooks)
        {
            LogDetails           logDetails = new LogDetails();
            IDataSourceOperation dataSourceOperation;

            if (type == OperationType.Mock)
            {
                dataSourceOperation = new MockDataSourceOperation();
            }
            else
            {
                dataSourceOperation = new JsonOperation();
            }
            try
            {
                addressBooks = DictToListMapping.ListToDictionary(Reader(dataSourceOperation));
            }
            catch (Exception e)
            {
                logDetails.LogDebug("IO Error in Reading operation");
                logDetails.LogError(e.Message);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Switch Cases for address books operation
        /// </summary>
        /// <param name="addressBooksCollection">addressbooks instance to perform operations</param>
        /// <param name="choice">User input to choose operation among available options</param>
        /// <returns></returns>
        private static void AddressBookOperationSwitch(ref AddressBooks addressBooksCollection, string choice)
        {
            LogDetails logDetails = new LogDetails();

            switch (choice)
            {
            case "1":
                addressBooksCollection.AddNewContactInAddressBook();
                break;

            case "2":
                addressBooksCollection.EditDetailsInAddressBook();
                break;

            case "3":
                addressBooksCollection.DeleteOneContactDetail();
                break;

            case "4":
                Console.Write("Enter State Name to search : ");
                string stateToSearch = Console.ReadLine();
                addressBooksCollection.SearchCurrentAddressBookByState(stateToSearch);
                break;

            case "5":
                Console.WriteLine("Enter\n" +
                                  "1 : Sort by name\n" +
                                  "2 : Sort by city\n" +
                                  "3 : Sort by state\n" +
                                  "4 : Sort by Zip");
                int userChoiceToSort;
                try
                {
                    userChoiceToSort = Int32.Parse(Console.ReadLine());
                }
                catch (Exception e)
                {
                    logDetails.LogDebug("Error in sorting section");
                    logDetails.LogError(e.Message);
                    Console.WriteLine("Wrong Choice\nSorting by Name(default)");
                    userChoiceToSort = 1;
                }
                string[] property = new string[5] {
                    "", "FirstName", "City", "State", "Zip"
                };
                addressBooksCollection.SortPersonsByProperty(property[userChoiceToSort]);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Read contact details from XML/ CSV / JSON file
        /// and store in AddressBooks class instance
        /// </summary>
        /// <param name="addressBooksCollection">reference to addressbooks instance to store contact details</param>
        private static void FileReadingOperation(ref AddressBooks addressBooksCollection)
        {
            LogDetails logDetails = new LogDetails();

            try
            {
                //IoOperations.DeserializeAddressBooks(ref addressBooksCollection);
                //CsvOperations.ReadFromCsv(ref addressBooksCollection);
                //JsonOperation.ReadFromJson(ref addressBooksCollection);
                SqlServerOperation.ReadFromSqlServer(ref addressBooksCollection);
            }
            catch (Exception e)
            {
                logDetails.LogDebug("IO Error in Reading operation");
                logDetails.LogError(e.Message);
            }
        }
Ejemplo n.º 4
0
        //----------------------------------- [ Private Methods ]----------------------------------------//
        /// <summary>
        /// Write contact details of all address books in XML, CSV & JSON file
        /// </summary>
        /// <param name="addressBooksCollection"></param>
        private static void FileWritingOperation(AddressBooks addressBooksCollection)
        {
            LogDetails logDetails = new LogDetails();

            try
            {
                //IoOperations.SerializeAddressBooks(addressBooksCollection);
                //CsvOperations.WriteToCsv(addressBooksCollection);
                JsonOperation.WriteToJson(addressBooksCollection);
                //SqlServerOperation.WriteToSqlServer(addressBooksCollection);
            }
            catch (Exception e)
            {
                Console.WriteLine("In catch block : " + e.Message);
                logDetails.LogDebug("IO Error in Writing operation");
                logDetails.LogError(e.Message);
            }
        }