Example #1
0
        static void Main(string[] args)
        {
            Console.Write("\n  CoreConsoleClient");
            Console.Write("\n ===================\n");

            if (!parseCommandLine(args))
            {
                return;
            }
            Console.Write("Press key to start: ");
            Console.ReadKey();

            //string url = "https://localhost:44342/api/Files";
            string url = args[0];

            CoreConsoleClient client = new CoreConsoleClient(url);

            //Dispatcher disp = createDispatcher(client);

            showCommandLine(args);
            Console.Write("\n  sending request to {0}\n", url);

            switch (args[1])
            {
            case "/fl":
                Task <IEnumerable <string> > tfl = client.GetFileList();
                //Task<HttpResponseMessage> t = disp[args[1]](param1, param2);
                var resultfl = tfl.Result;
                foreach (var item in resultfl)
                {
                    Console.Write("\n  {0}", item);
                }
                break;

            case "/up":
                Task <HttpResponseMessage> tup = client.SendFile(args[2]);
                Console.Write(tup.Result);
                break;

            case "/dn":
                int id = Int32.Parse(args[2]);
                Task <HttpResponseMessage> tdn = client.GetFile(id);
                Console.Write(tdn.Result);
                break;

            case "/dl":
                break;
            }

            Console.WriteLine("\n  Press Key to exit: ");
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Console.Write("\n  CoreConsoleClient");
            Console.Write("\n ===================\n");

            if (!parseCommandLine(args))
            {
                return;
            }
            Console.Write("Press key to start: ");
            Console.ReadKey();

            string            url    = args[0];
            CoreConsoleClient client = new CoreConsoleClient(url);

            showCommandLine(args);
            Console.Write("\n  sending request to {0}\n", url);

            switch (args[1])
            {
            case "/fl":
                Task <IEnumerable <string> > tfl = client.GetFileList();
                var resultfl = tfl.Result;
                foreach (var item in resultfl)
                {
                    Console.Write("\n  {0}", item);
                }
                break;

            case "/up":
                try
                {
                    Task <HttpResponseMessage> tup = client.SendFile(args[2]);
                    Console.Write(tup.Result);
                }
                catch (AggregateException ex)
                {
                    Console.Write(ex + "No such file exists");
                }
                break;

            case "/dn":
                try
                {
                    int id = Int32.Parse(args[2]);
                    Task <HttpResponseMessage> tdn = client.GetFile(id);
                    var    content = tdn.Result.Content;
                    string x       = tdn.Result.Content.Headers.ContentDisposition.FileNameStar;
                    ToLocalSystem(content, x);
                    Console.Write(tdn);
                }

                catch (Exception ex)
                {
                    Console.WriteLine(ex + "An error occurred while downloading");
                }
                break;
            }

            Console.WriteLine("\n  Press Key to exit: ");
            Console.ReadKey();
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.Write("\n  CoreConsoleClient");
            Console.Write("\n ===================\n");

            if (!parseCommandLine(args))
            {
                return;
            }
            Console.Write("Press key to start: ");
            Console.ReadKey();

            string            url    = args[0];
            CoreConsoleClient client = new CoreConsoleClient(url);

            showCommandLine(args);
            Console.Write("\n  sending request to {0}\n", url);

            switch (args[1])
            {
            case "/fl":
                Task <IEnumerable <string> > tfl = client.GetFileList();
                var resultfl = tfl.Result;
                foreach (var item in resultfl)
                {
                    Console.Write("\n  {0}", item);
                }
                break;

            case "/up":
                Task <HttpResponseMessage> tup = client.SendFile(args[2]);
                Console.Write(tup.Result);
                break;

            case "/dn":
                string        fileName             = args[2];
                List <string> fileListdl           = new List <string>();
                Task <IEnumerable <string> > tfldn = client.GetFileList();
                var resultfldn = tfldn.Result;
                foreach (var item in resultfldn)
                {
                    fileListdl.Add(item);
                }
                if (fileListdl.Contains(fileName))
                {
                    Task <HttpResponseMessage> tdn = client.GetFile(fileName);
                }
                else
                {
                    Console.Write("File not found");
                }
                break;

            case "/dl":
                string        file                 = args[2];
                List <string> fileList             = new List <string>();
                Task <IEnumerable <string> > tfldl = client.GetFileList();
                var resultfldl = tfldl.Result;
                foreach (var item in resultfldl)
                {
                    fileList.Add(item);
                }
                if (fileList.Contains(file))
                {
                    Task <HttpResponseMessage> tdl = client.DeleteFile(file);
                    Console.Write(tdl.Result);
                    if (tdl.Result.IsSuccessStatusCode)
                    {
                        Console.Write("File Deleted Successfully");
                    }
                }
                else
                {
                    Console.Write("File not found");
                }
                break;
            }

            Console.WriteLine("\n  Press Key to exit: ");
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Console.Write("\n  CoreConsoleClient");
            Console.Write("\n ===================\n");

            if (!parseCommandLine(args))
            {
                return;
            }
            Console.Write("Press key to start: ");
            Console.ReadKey();

            string            url    = args[0];
            CoreConsoleClient client = new CoreConsoleClient(url);

            showCommandLine(args);
            Console.Write("\n  sending request to {0}\n", url);


            switch (args[1])
            {
            case "/fl":
                Task <IEnumerable <string> > tfl = client.GetFileList();
                var resultfl = tfl.Result;
                foreach (var item in resultfl)
                {
                    Console.Write("\n  {0}", item);
                }
                break;

            case "/up":
                Task <HttpResponseMessage> tup = client.SendFile(args[2]);
                Console.Write(tup.Result);
                break;

            case "/dn":
                int id = Int32.Parse(args[2]);
                Task <HttpResponseMessage> tdn = client.GetFile(id);
                Console.Write(tdn.Result);
                break;

            case "/dl":
                int id0 = Int32.Parse(args[2]);
                Task <HttpResponseMessage> tdl = client.DeleteFile(id0);
                Console.Write(tdl.Result);
                break;

            case "/getStory":
                Task <IEnumerable <string> > stl = client.GetStory();
                var resulstl = stl.Result;
                foreach (var item in resulstl)
                {
                    Console.Write("\n  {0}", item);
                }
                break;

            case "/getDetails":
                Task <IEnumerable <string> > sdt = client.GetStoryDetails(Int32.Parse(args[2]));
                var resulsdt = sdt.Result;
                foreach (var item in resulsdt)
                {
                    Console.Write("\n  {0}", item);
                }
                break;
            }

            Console.WriteLine("\n  Press Key to exit: ");
            Console.ReadKey();
        }
Example #5
0
        static void Main(string[] args)
        {
            Console.Write("\n  CoreConsoleClient");
            Console.Write("\n ===================\n");
            string url = args[0];
            int    ch  = 1;

            do
            {
                Console.Write("\nChoices \n 1.Upload file \n 2. Exit \n");
                Console.Write("Enter choice: ");
                int choice = Int32.Parse(Console.ReadLine());
                CoreConsoleClient client = new CoreConsoleClient(url);
                switch (choice)
                {
                case 1:
                    try
                    {
                        Console.Write("\n  sending request to {0}\n", url);
                        Task <IEnumerable <object> > tfl = client.GetFileList();
                        var resultfl = tfl.Result;
                        int i        = 0;
                        foreach (var item in resultfl)
                        {
                            if (i % 2 == 0)
                            {
                                Console.Write("\n Genre Name: {0}  ", item);
                                i++;
                            }
                            else if (i % 2 != 0)
                            {
                                Console.Write("GenreID: {0} ", item);
                                i++;
                            }
                        }
                        Console.Write("\nEnter GenreId in which you wish to add book: ");
                        string genreId = Console.ReadLine();

                        Console.Write("\nEnter book title: ");
                        string title = Console.ReadLine();

                        Console.Write("\nEnter book author: ");
                        string author = Console.ReadLine();

                        Console.Write("\nEnter book ISBN: ");
                        string isbn = Console.ReadLine();

                        Console.Write("\nBook Access (Enter 1 for private, or 0 to keep book public): ");
                        string priv = Console.ReadLine();

                        Console.Write("\nEnter book path (only pdf files supported): ");
                        string path = Console.ReadLine();

                        Task <HttpResponseMessage> tup = client.SendFile(title, author, isbn, priv, genreId, path);
                        Console.Write(tup.Result);
                    }
                    catch (Exception)
                    {
                        Console.Write("\nError...");
                    }
                    break;

                case 2:
                    break;

                default:
                    Console.Write("\nIncorrect choice, try again...");
                    break;
                }
                Console.Write("\nPress 1 to continue, 0 to quit: ");
                ch = Int32.Parse(Console.ReadLine());
            } while (ch == 1);
        }