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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

[![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)

Cloned by Teybeo

English readme not available at this time, it's only available in [french](readme.fr.md)
18 changes: 18 additions & 0 deletions Students/Teybeo/nget-v1/nget.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.4
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nget", "nget\nget.csproj", "{98625EA3-2BCD-4938-B748-7C5CD260A80B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{98625EA3-2BCD-4938-B748-7C5CD260A80B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98625EA3-2BCD-4938-B748-7C5CD260A80B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98625EA3-2BCD-4938-B748-7C5CD260A80B}.Release|Any CPU.Build.0 = Release|Any CPU
{98625EA3-2BCD-4938-B748-7C5CD260A80B}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
EndGlobal
120 changes: 120 additions & 0 deletions Students/Teybeo/nget-v1/nget/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;

namespace nget
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine(args.Length);

if (args.Length == 0)
return;

var url = extractArg(args, "-url");

// The url is mandatory, so stop here if there is none
if (url == null) {
Console.WriteLine("The -url <url> argument is missing");
return;
}

if (args[0].Equals("get")) {

// save file is optional
var fileOutput = extractArg(args, "-save");

var result = getUrl(url);

// if -save <path> is valid, we save in file, else print on console
if (fileOutput != null) {
saveFile(fileOutput, result);
} else {
Console.WriteLine(result);
}

} else if (args[0].Equals("test")) {

// samples count is mandatory
string samplesCountString = extractArg(args, "-times");
if (samplesCountString == null) {
Console.WriteLine("The -times <count> argument is missing");
return;
}

int samplesCount = int.Parse(samplesCountString);
var samples = new long[samplesCount];

for (int i = 0; i < samplesCount; i++) {
getUrl(url, ref samples[i]);
}

if (args.Contains("-avg")) {
Console.WriteLine("average: " + computeAvg(samples) + "ms");
} else {
printTimes(samples);
}
}
}

public static string extractArg(string[] args, string argName) {

// For each string in the array
for (int i = 0; i < args.Length; i++) {

// If we find the string we are looking for, return the next string (if it exists)
if (args[i].Equals(argName)) {
if (i + 1 < args.Length)
return args[i + 1];
}
}

return null;
}

public static string getUrl(string url) {
long duration = 0;
return getUrl(url, ref duration);
}

public static string getUrl(string url, ref long duration) {

string response = null;
var webclient = new WebClient();

var chrono = new Stopwatch();
chrono.Start();
using (webclient) {
response = webclient.DownloadString(url);
}
chrono.Stop();
duration = chrono.ElapsedMilliseconds;
return response;
}

public static void saveFile(string fileName, string data) {
File.WriteAllText(fileName, data);
}

public static void printTimes(long[] times) {
for (int i = 0; i < times.Length; i++) {
Console.WriteLine(times[i]);
}
}

public static long computeAvg(long[] times) {

long avg = 0;

for (int i = 0; i < times.Length; i++) {
avg += times[i];
}

return avg / times.Length;
}
}
}
31 changes: 31 additions & 0 deletions Students/Teybeo/nget-v1/nget/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#region Using directives

using System;
using System.Reflection;
using System.Runtime.InteropServices;

#endregion

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("nget")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("nget")]
[assembly: AssemblyCopyright("Copyright 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]

// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
68 changes: 68 additions & 0 deletions Students/Teybeo/nget-v1/nget/nget.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{98625EA3-2BCD-4938-B748-7C5CD260A80B}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Exe</OutputType>
<RootNamespace>nget</RootNamespace>
<AssemblyName>nget</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<AppDesignerFolder>Properties</AppDesignerFolder>
<NoWin32Manifest>False</NoWin32Manifest>
<SignAssembly>False</SignAssembly>
<DelaySign>False</DelaySign>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>
<BaseAddress>4194304</BaseAddress>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
<StartAction>Project</StartAction>
<StartArguments>get -url "http://api.openweathermap.org/data/2.5/weather?q=paris&amp;units=metric"</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
18 changes: 18 additions & 0 deletions Students/Teybeo/nget-v2/nget-v2.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.4
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nget-v2", "nget-v2\nget-v2.csproj", "{EAEEF979-34F9-4C1B-9507-0D4289892F85}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EAEEF979-34F9-4C1B-9507-0D4289892F85}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EAEEF979-34F9-4C1B-9507-0D4289892F85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EAEEF979-34F9-4C1B-9507-0D4289892F85}.Release|Any CPU.Build.0 = Release|Any CPU
{EAEEF979-34F9-4C1B-9507-0D4289892F85}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
EndGlobal
28 changes: 28 additions & 0 deletions Students/Teybeo/nget-v2/nget-v2/Arg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

using System;

namespace nget_v2
{
/// <summary>
/// Description of Arg.
/// </summary>
public class Arg
{
public string name {
get; set;
}
public bool isRequired {
get; set;
}
public bool hasValue {
get; set;
}

public Arg(string _name, bool _isRequired, bool _hasValue)
{
name = _name;
isRequired = _isRequired;
hasValue = _hasValue;
}
}
}
57 changes: 57 additions & 0 deletions Students/Teybeo/nget-v2/nget-v2/Get.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;

namespace nget_v2
{
/// <summary>
/// Description of Get.
/// </summary>
public class Get: ICommand
{
string fileOutput;
string url;

public Get()
{
}
public string getName()
{
return "get";
}

public List<Arg> getArgs() {
var list = new List<Arg>();
list.Add(new Arg("-save", false, true));
list.Add(new Arg("-url", true, true));
return list;
}

public void setValues(Dictionary<string, string> values) {

// save file is optional
fileOutput = values["-save"];
url = values["-url"];
}

public void execute() {

var result = UrlDownloader.download(url);

// if -save <path> is valid, we save in file, else print on console
if (fileOutput != null) {
saveFile(fileOutput, result);
} else {
Console.WriteLine(result);
}
}

private static void saveFile(string fileName, string data) {
File.WriteAllText(fileName, data);
}

}
}
17 changes: 17 additions & 0 deletions Students/Teybeo/nget-v2/nget-v2/ICommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

using System;
using System.Collections.Generic;

namespace nget_v2
{
/// <summary>
/// Description of ICommand.
/// </summary>
public interface ICommand
{
string getName();
List<Arg> getArgs();
void execute();
void setValues(Dictionary<string, string> values);
}
}
Loading