示例#1
0
        public IQuoteDataProvider GetProvider()
        {
            SourceSelectionForm sourceForm = new SourceSelectionForm();

            while (true)
            {
                sourceForm.ShowDialog();

                IQuoteDataProvider provider = null;

                if (sourceForm.FilePath != null)
                {
                    try
                    {
                        provider = new FileQuoteProvider(sourceForm.FilePath);
                    }
                    catch (Exception ex)
                    {
                        sourceForm.OnErrorOccurred(ex);
                        continue;
                    }
                }
                else if (sourceForm.ServerAddress != null && sourceForm.Port != -1)
                {
                    ServerLoginForm loginForm = new ServerLoginForm();
                    loginForm.ShowDialog();

                    if (loginForm.Username == null && loginForm.Password == null)
                    {
                        sourceForm.ResetServerAddress();
                        continue;
                    }

                    try
                    {
                        provider = new TcpQuoteProvider(sourceForm.ServerAddress, sourceForm.Port,
                                                        loginForm.Username, loginForm.Password);
                    }
                    catch (Exception ex)
                    {
                        sourceForm.OnErrorOccurred(ex);
                        continue;
                    }
                }

                return(provider);
            }
        }
示例#2
0
        public static IQuoteProvider GetQuoteProvider()
        {
            IQuoteProvider fileQuoteProvider;

#if !DEBUG
            var path = $"{Path.GetDirectoryName(Application.ExecutablePath)}/quotes.txt";
            fileQuoteProvider = new FileQuoteProvider(path);
#endif

#if DEBUG
            fileQuoteProvider = new FakeQuoteProvider();
#endif


            return(fileQuoteProvider);
        }
示例#3
0
        private static IQuoteDataProvider GetProvider()
        {
            IQuoteDataProvider provider = null;

            while (true)
            {
                Console.WriteLine("Choose source: 1. Internet. 2. Local file.");
                Console.Write("Type your choice here: ");
                ConsoleKeyInfo key = Console.ReadKey();
                Console.WriteLine();

                switch (key.Key)
                {
                case ConsoleKey.D1:
                    Console.Write("Username: "******"Password: "******"180.166.86.198", 8301, username, password);
                    break;

                case ConsoleKey.D2:
                    Console.Write("Local path: ");
                    string filePath = Console.ReadLine();

                    provider = new FileQuoteProvider(filePath);
                    break;

                default:
                    Console.WriteLine("Invalid response. Try Again...");
                    break;
                }

                if (provider != null)
                {
                    break;
                }
            }

            Console.WriteLine();

            Debug.Assert(provider != null);
            return(provider);
        }