// helper method to get query value from the user static ServiceReference1.QueryType QueryTypeFactory(int queryTypeNumber, string queryTypeName) { ServiceReference1.QueryType queryType = new ServiceReference1.QueryType(); queryType.Type = queryTypeNumber; Console.WriteLine("Please enter the " + queryTypeName + ":"); queryType.Value = Console.ReadLine(); return(queryType); }
// query to service static void SearchInLibrary(ServiceReference1.Service1Client proxy, ServiceReference1.QueryType queryType) { ServiceReference1.BookType[] receiveBooks = proxy.SearchLibrary(queryType); PrintBookList(receiveBooks); }
static void Main(string[] args) { bool shouldRun = true; PrintMenu(); ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client(); while (shouldRun) { Console.WriteLine("Give the option: "); string option = Console.ReadLine(); switch (option) { case "1": try { int signatureToBorrow = AskForSignature("borrow"); SendBorrowRequest(proxy, signatureToBorrow); } catch (FormatException e) { Console.WriteLine("Wrong input - book not borrowed"); } break; case "2": try { int signatureToReturn = AskForSignature("return"); SendReturnBookRequest(proxy, signatureToReturn); } catch (FormatException e) { Console.WriteLine("Wrong input - book not borrowed"); } break; case "3": ServiceReference1.QueryType queryType = QueryTypeFactory((int)SearchingTypeEnum.ByTitle, "title"); try { SearchInLibrary(proxy, queryType); } catch (FaultException <ServiceReference1.LibrarySearchingException> e) { Console.WriteLine(e.Detail.CustomMessage + "\nOperation type:" + e.Detail.OperationType); } break; case "4": ServiceReference1.QueryType queryTypeAuthor = QueryTypeFactory((int)SearchingTypeEnum.ByAuthor, "name/surname"); try { SearchInLibrary(proxy, queryTypeAuthor); } catch (FaultException <ServiceReference1.LibrarySearchingException> e) { Console.WriteLine(e.Detail.CustomMessage + "\nOperation type:" + e.Detail.OperationType); } break; case "5": ServiceReference1.QueryType queryTypeSignature = QueryTypeFactory((int)SearchingTypeEnum.BySignature, "signature"); try { SearchInLibrary(proxy, queryTypeSignature); } catch (FaultException <ServiceReference1.LibrarySearchingException> e) { Console.WriteLine(e.Detail.CustomMessage + "\nOperation type:" + e.Detail.OperationType); } break; case "6": PrintMenu(); break; case "7": string libraryInfoString = proxy.GetLibraryInfo(); Console.WriteLine(libraryInfoString); break; case "8": shouldRun = false; break; } if (!option.Equals("8") && !option.Equals("6")) { PrintMenu(); } } }