From 7b88fba80d4253739f63a035828a4086ebedc54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Lafages?= Date: Mon, 1 Jun 2015 17:25:58 +0200 Subject: [PATCH 1/4] update README.md --- README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index 4ceb1eb..8c775fa 100644 --- a/README.md +++ b/README.md @@ -1,6 +1 @@ -# cleancode-webget-tool - -[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rhwy/cleancode-webget-tool?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - - -English readme not available at this time, it's only available in [french](readme.fr.md) +Fork of rhwy/cleancode-webget-tool From 89431ebdcf86345f9320853c843c08b7fb3b0d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Lafages?= Date: Mon, 1 Jun 2015 20:00:32 +0200 Subject: [PATCH 2/4] nget version 1 --- Students/LafagesMickael/nget-v1/nget.sln | 17 +++ .../nget-v1/nget/CommandLine.cs | 115 ++++++++++++++++++ .../LafagesMickael/nget-v1/nget/Program.cs | 58 +++++++++ .../nget-v1/nget/Properties/AssemblyInfo.cs | 27 ++++ .../LafagesMickael/nget-v1/nget/nget.csproj | 43 +++++++ 5 files changed, 260 insertions(+) create mode 100644 Students/LafagesMickael/nget-v1/nget.sln create mode 100644 Students/LafagesMickael/nget-v1/nget/CommandLine.cs create mode 100644 Students/LafagesMickael/nget-v1/nget/Program.cs create mode 100644 Students/LafagesMickael/nget-v1/nget/Properties/AssemblyInfo.cs create mode 100644 Students/LafagesMickael/nget-v1/nget/nget.csproj diff --git a/Students/LafagesMickael/nget-v1/nget.sln b/Students/LafagesMickael/nget-v1/nget.sln new file mode 100644 index 0000000..076d231 --- /dev/null +++ b/Students/LafagesMickael/nget-v1/nget.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nget", "nget\nget.csproj", "{D5758D27-F3F0-4417-A80C-C7E528310539}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D5758D27-F3F0-4417-A80C-C7E528310539}.Debug|x86.ActiveCfg = Debug|x86 + {D5758D27-F3F0-4417-A80C-C7E528310539}.Debug|x86.Build.0 = Debug|x86 + {D5758D27-F3F0-4417-A80C-C7E528310539}.Release|x86.ActiveCfg = Release|x86 + {D5758D27-F3F0-4417-A80C-C7E528310539}.Release|x86.Build.0 = Release|x86 + EndGlobalSection +EndGlobal diff --git a/Students/LafagesMickael/nget-v1/nget/CommandLine.cs b/Students/LafagesMickael/nget-v1/nget/CommandLine.cs new file mode 100644 index 0000000..fdabca3 --- /dev/null +++ b/Students/LafagesMickael/nget-v1/nget/CommandLine.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; + +namespace nget +{ + public class CommandLine + { + public String Command { get; private set; } + public String Url { get; private set; } + public String Output { get; private set; } + public bool WriteInOutput { get; private set; } + public int Times { get; private set; } + public bool MakeAvg { get; private set; } + + private readonly bool correct; + + bool parseTest (string[] args) + { + for(int i = 1; i < args.Length; ++i) { + switch(args[i]) { + case "-url": + if (i < args.Length - 1 && args [++i] [0] != '-') { + Url = args [i]; + if (Url [0] == '\"') + Url = Url.Substring (1, Url.Length - 2); + } + else + return false; + break; + case "-times": + if (i < args.Length - 1 && args [++i] [0] != '-') { + try { + Times = Convert.ToInt32 (args [i]); + } catch { + return false; + } + } + else + return false; + break; + case "-avg": + MakeAvg = true; + break; + + default: + return false; + } + } + return true; + } + + bool parseGet (string[] args) + { + for (int i = 1; i < args.Length; ++i) { + switch (args [i]) { + case "-url": + if (i < args.Length - 1 && args [++i] [0] != '-') { + Url = args [i]; + if (Url[0] == '\"') + Url = Url.Substring (1, Url.Length - 2); + } + else + return false; + break; + case "-save": + if (i < args.Length - 1 && args [++i] [0] != '-') { + Output = args [i]; + WriteInOutput = true; + } else + return false; + break; + default: + return false; + } + } + return true; + } + + bool parse (string[] args) + { + if (args.Length < 3) + return false; + + Command = args[0]; + switch(Command) { + case "test": + if (!parseTest (args)) + return false; + break; + case "get": + if (!parseGet (args)) + return false; + break; + default: + return false; + } + + return Url.Length != 0; + + } + + public CommandLine (string[] args) + { + Times = 1; + MakeAvg = false; + WriteInOutput = false; + correct = parse(args); + } + + public bool isIncorrect() { + return !correct; + } + } + +} diff --git a/Students/LafagesMickael/nget-v1/nget/Program.cs b/Students/LafagesMickael/nget-v1/nget/Program.cs new file mode 100644 index 0000000..5fdb643 --- /dev/null +++ b/Students/LafagesMickael/nget-v1/nget/Program.cs @@ -0,0 +1,58 @@ +using System; +using System.Net; +using System.IO; + +namespace nget +{ + class MainClass + { + public static void Main (string[] args) + { + var cl = new CommandLine (args); // Parsing de la ligne de commande + if(cl.isIncorrect()) { + Console.WriteLine ("Invalid command line"); + return; + } + + if(cl.Command == "get") { + try { + var request = WebRequest.Create (cl.Url); + var response = request.GetResponse (); + var content = new StreamReader (response.GetResponseStream ()).ReadToEnd (); + if(cl.WriteInOutput) { + File.WriteAllText (cl.Output, content); + } + else { + Console.WriteLine (content); + } + } + catch (Exception e) { + Console.WriteLine ("An error occured: {0}", e.Message); + } + } + else { + try { + var avg = TimeSpan.FromMilliseconds (0); + for(int i = 0; i < cl.Times; ++i) { + var begin = DateTime.Now; + var request = WebRequest.Create (cl.Url); + + using(var resp = request.GetResponse ()) { + var duration = DateTime.Now - begin; + avg += duration; + Console.WriteLine ("Duration {0}", duration); + } + + } + if(cl.MakeAvg) { + Console.WriteLine ("Average {0}", TimeSpan.FromMilliseconds(avg.TotalMilliseconds / cl.Times)); + } + } + catch (Exception e) { + Console.WriteLine ("An error occured: {0}", e.Message); + } + } + + } + } +} diff --git a/Students/LafagesMickael/nget-v1/nget/Properties/AssemblyInfo.cs b/Students/LafagesMickael/nget-v1/nget/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8cc1de8 --- /dev/null +++ b/Students/LafagesMickael/nget-v1/nget/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("nget")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("mickx")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Students/LafagesMickael/nget-v1/nget/nget.csproj b/Students/LafagesMickael/nget-v1/nget/nget.csproj new file mode 100644 index 0000000..4c90809 --- /dev/null +++ b/Students/LafagesMickael/nget-v1/nget/nget.csproj @@ -0,0 +1,43 @@ + + + + Debug + x86 + {D5758D27-F3F0-4417-A80C-C7E528310539} + Exe + nget + nget + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + x86 + test -url "http://www.google.com" -times 5 -avg + + + full + true + bin\Release + prompt + 4 + true + x86 + get -url "http://www.google.com" -save "/Users/mickx/Desktop/output" + + + + + + + + + + + \ No newline at end of file From 1175f079bd22fe51f0871fa3a7b6dd6fbc0e6d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Lafages?= Date: Thu, 18 Jun 2015 00:36:36 +0200 Subject: [PATCH 3/4] Ajout des auteurs --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c775fa..4af8f02 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ -Fork of rhwy/cleancode-webget-tool +Fork of rhwy/cleancode-webget-tool + +Mathieu Pequin +Mickaël Lafages From 235efae1bfaeb8e89b5ece1cebca264ba9dcac9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Lafages?= Date: Thu, 18 Jun 2015 00:38:00 +0200 Subject: [PATCH 4/4] Ajout de la version 2 --- Students/LafagesMickael/nget-v2/nget.sln | 17 +++++ .../LafagesMickael/nget-v2/nget/GetCommand.cs | 64 +++++++++++++++++ .../LafagesMickael/nget-v2/nget/ICommand.cs | 12 ++++ .../LafagesMickael/nget-v2/nget/NGetUtils.cs | 18 +++++ .../LafagesMickael/nget-v2/nget/Program.cs | 30 ++++++++ .../nget-v2/nget/Properties/AssemblyInfo.cs | 27 +++++++ .../nget-v2/nget/TestCommand.cs | 72 +++++++++++++++++++ .../LafagesMickael/nget-v2/nget/nget.csproj | 46 ++++++++++++ 8 files changed, 286 insertions(+) create mode 100644 Students/LafagesMickael/nget-v2/nget.sln create mode 100644 Students/LafagesMickael/nget-v2/nget/GetCommand.cs create mode 100644 Students/LafagesMickael/nget-v2/nget/ICommand.cs create mode 100644 Students/LafagesMickael/nget-v2/nget/NGetUtils.cs create mode 100644 Students/LafagesMickael/nget-v2/nget/Program.cs create mode 100644 Students/LafagesMickael/nget-v2/nget/Properties/AssemblyInfo.cs create mode 100644 Students/LafagesMickael/nget-v2/nget/TestCommand.cs create mode 100644 Students/LafagesMickael/nget-v2/nget/nget.csproj diff --git a/Students/LafagesMickael/nget-v2/nget.sln b/Students/LafagesMickael/nget-v2/nget.sln new file mode 100644 index 0000000..076d231 --- /dev/null +++ b/Students/LafagesMickael/nget-v2/nget.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nget", "nget\nget.csproj", "{D5758D27-F3F0-4417-A80C-C7E528310539}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D5758D27-F3F0-4417-A80C-C7E528310539}.Debug|x86.ActiveCfg = Debug|x86 + {D5758D27-F3F0-4417-A80C-C7E528310539}.Debug|x86.Build.0 = Debug|x86 + {D5758D27-F3F0-4417-A80C-C7E528310539}.Release|x86.ActiveCfg = Release|x86 + {D5758D27-F3F0-4417-A80C-C7E528310539}.Release|x86.Build.0 = Release|x86 + EndGlobalSection +EndGlobal diff --git a/Students/LafagesMickael/nget-v2/nget/GetCommand.cs b/Students/LafagesMickael/nget-v2/nget/GetCommand.cs new file mode 100644 index 0000000..7fe1a7c --- /dev/null +++ b/Students/LafagesMickael/nget-v2/nget/GetCommand.cs @@ -0,0 +1,64 @@ +using System; +using System.IO; +using nget; + +namespace nget +{ + class GetCommand : ICommand + { + public String Url { get; private set; } + public String Output { get; private set; } + public bool WriteInOutput { get; private set; } + + public GetCommand() { + WriteInOutput = false; + } + + public bool parse( string[] args ) { + if (args.Length < 3) + return false; + for (int i = 1; i < args.Length; ++i) { + switch (args [i]) { + case "-url": + if (i < args.Length - 1 && args [++i] [0] != '-') { + Url = args [i]; + if (Url[0] == '\"') { + Url = Url.Substring (1, Url.Length - 2); + if(!Uri.IsWellFormedUriString(Url, UriKind.Absolute)) + return false; + } + } + else + return false; + break; + case "-save": + if (i < args.Length - 1 && args [++i] [0] != '-') { + Output = args [i]; + WriteInOutput = true; + } else + return false; + break; + default: + return false; + } + } + return Url.Length != 0; + } + + public void execute() { + try { + String content = NGetUtils.getUrlContent(Url); + if(WriteInOutput) { + File.WriteAllText (Output, content); + } + else { + Console.WriteLine (content); + } + } + catch (Exception e) { + Console.WriteLine ("An error occured: {0}", e.Message); + } + } + } + +} diff --git a/Students/LafagesMickael/nget-v2/nget/ICommand.cs b/Students/LafagesMickael/nget-v2/nget/ICommand.cs new file mode 100644 index 0000000..c4057e3 --- /dev/null +++ b/Students/LafagesMickael/nget-v2/nget/ICommand.cs @@ -0,0 +1,12 @@ +using System; +using System.Net; +using System.IO; + +namespace nget +{ + public interface ICommand { + bool parse( string[] args ); + void execute(); + } + +} diff --git a/Students/LafagesMickael/nget-v2/nget/NGetUtils.cs b/Students/LafagesMickael/nget-v2/nget/NGetUtils.cs new file mode 100644 index 0000000..1b73c43 --- /dev/null +++ b/Students/LafagesMickael/nget-v2/nget/NGetUtils.cs @@ -0,0 +1,18 @@ +using System; +using System.Net; + +namespace nget { + + public class NGetUtils { + + static public String getUrlContent( string url ) { + String content; + using(WebClient client = new WebClient()) { + content = client.DownloadString(url); + } + return content; + } + + } +} + diff --git a/Students/LafagesMickael/nget-v2/nget/Program.cs b/Students/LafagesMickael/nget-v2/nget/Program.cs new file mode 100644 index 0000000..bdc67b8 --- /dev/null +++ b/Students/LafagesMickael/nget-v2/nget/Program.cs @@ -0,0 +1,30 @@ +using System; +using System.Net; +using System.IO; +using System.Collections.Generic; + +namespace nget +{ + class MainClass + { + public static Dictionary commandDictionary = new Dictionary { + {"get",typeof(GetCommand)}, + {"test",typeof(TestCommand)} + }; + + public static void Main (string[] args) + { + Type commandType; + if(commandDictionary.TryGetValue(args[0], out commandType)) { + var command = Activator.CreateInstance(commandType) as ICommand; + if(command.parse(args)) + command.execute(); + else + Console.WriteLine ("Invalid command line"); + } + else { + Console.WriteLine("Invalid command line"); + } + } + } +} diff --git a/Students/LafagesMickael/nget-v2/nget/Properties/AssemblyInfo.cs b/Students/LafagesMickael/nget-v2/nget/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8cc1de8 --- /dev/null +++ b/Students/LafagesMickael/nget-v2/nget/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("nget")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("mickx")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/Students/LafagesMickael/nget-v2/nget/TestCommand.cs b/Students/LafagesMickael/nget-v2/nget/TestCommand.cs new file mode 100644 index 0000000..d0c13f1 --- /dev/null +++ b/Students/LafagesMickael/nget-v2/nget/TestCommand.cs @@ -0,0 +1,72 @@ +using System; +using System.Linq; + +namespace nget +{ + class TestCommand : ICommand + { + public String Url { get; private set; } + public int Times { get; private set; } + public bool MakeAvg { get; private set; } + + public bool parse( string[] args ) { + if (args.Length < 3) + return false; + for(int i = 1; i < args.Length; ++i) { + switch(args[i]) { + case "-url": + if (i < args.Length - 1 && args [++i] [0] != '-') { + Url = args [i]; + if (Url [0] == '\"') { + Url = Url.Substring (1, Url.Length - 2); + if(!Uri.IsWellFormedUriString(Url, UriKind.Absolute)) + return false; + } + } + else + return false; + break; + case "-times": + if (i < args.Length - 1 && args [++i] [0] != '-') { + try { + Times = Convert.ToInt32 (args [i]); + } catch { + return false; + } + } + else + return false; + break; + case "-avg": + MakeAvg = true; + break; + + default: + return false; + } + } + return Url.Length != 0; + } + + public void execute() { + try { + Double[] times = new Double[Times]; + for(int i = 0; i < Times; ++i) { + var watch = System.Diagnostics.Stopwatch.StartNew(); + NGetUtils.getUrlContent(Url); + var duration = watch.ElapsedMilliseconds; + times[i] = duration; + Console.WriteLine ("Duration {0}", duration); + + } + if(MakeAvg) { + Console.WriteLine ("Average {0}", times.Average()); + } + } + catch (Exception e) { + Console.WriteLine ("An error occured: {0}", e.Message); + } + } + } + +} diff --git a/Students/LafagesMickael/nget-v2/nget/nget.csproj b/Students/LafagesMickael/nget-v2/nget/nget.csproj new file mode 100644 index 0000000..99c8f3d --- /dev/null +++ b/Students/LafagesMickael/nget-v2/nget/nget.csproj @@ -0,0 +1,46 @@ + + + + Debug + x86 + {D5758D27-F3F0-4417-A80C-C7E528310539} + Exe + nget + nget + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + x86 + test -url "http://www.google.com" -avg -times 5 + + + full + true + bin\Release + prompt + 4 + true + x86 + get -url "http://www.google.com" -save "/Users/mickx/Desktop/output" + + + + + + + + + + + + + + \ No newline at end of file