Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# cleancode-webget-tool
Fork of rhwy/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)
Mathieu Pequin
Mickaël Lafages
17 changes: 17 additions & 0 deletions Students/LafagesMickael/nget-v1/nget.sln
Original file line number Diff line number Diff line change
@@ -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
115 changes: 115 additions & 0 deletions Students/LafagesMickael/nget-v1/nget/CommandLine.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
58 changes: 58 additions & 0 deletions Students/LafagesMickael/nget-v1/nget/Program.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
}
}
27 changes: 27 additions & 0 deletions Students/LafagesMickael/nget-v1/nget/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("")]

43 changes: 43 additions & 0 deletions Students/LafagesMickael/nget-v1/nget/nget.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{D5758D27-F3F0-4417-A80C-C7E528310539}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>nget</RootNamespace>
<AssemblyName>nget</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
<Commandlineparameters>test -url "http://www.google.com" -times 5 -avg</Commandlineparameters>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
<Commandlineparameters>get -url "http://www.google.com" -save "/Users/mickx/Desktop/output"</Commandlineparameters>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CommandLine.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
17 changes: 17 additions & 0 deletions Students/LafagesMickael/nget-v2/nget.sln
Original file line number Diff line number Diff line change
@@ -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
64 changes: 64 additions & 0 deletions Students/LafagesMickael/nget-v2/nget/GetCommand.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

}
12 changes: 12 additions & 0 deletions Students/LafagesMickael/nget-v2/nget/ICommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Net;
using System.IO;

namespace nget
{
public interface ICommand {
bool parse( string[] args );
void execute();
}

}
18 changes: 18 additions & 0 deletions Students/LafagesMickael/nget-v2/nget/NGetUtils.cs
Original file line number Diff line number Diff line change
@@ -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;
}

}
}

Loading