Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

requester initial commit

  • Loading branch information...
commit b328c995d7e985c946d1143102f9e903961eef95 0 parents
@haf authored
6 .gitignore
@@ -0,0 +1,6 @@
+bin/
+obj/
+*.suo
+*resharper*
+_ReSharper.*/
+packages/
6 src/.nuget/NuGet.Config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <solution>
+ <add key="disableSourceControlIntegration" value="true" />
+ </solution>
+</configuration>
BIN  src/.nuget/NuGet.exe
Binary file not shown
52 src/.nuget/NuGet.targets
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
+ <NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
+ <NuGetExePath>$(NuGetToolsPath)\nuget.exe</NuGetExePath>
+ <PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
+ <PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
+ <PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
+
+ <!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
+ <PackageSources>""</PackageSources>
+
+ <!-- Enable the restore command to run before builds -->
+ <RestorePackages Condition="$(RestorePackages) == ''">false</RestorePackages>
+
+ <!-- Property that enables building a package from a project -->
+ <BuildPackage Condition="$(BuildPackage) == ''">false</BuildPackage>
+
+ <!-- Commands -->
+ <RestoreCommand>"$(NuGetExePath)" install "$(PackagesConfig)" -source $(PackageSources) -o "$(PackagesDir)"</RestoreCommand>
+ <BuildCommand>"$(NuGetExePath)" pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>
+
+ <!-- Make the build depend on restore packages -->
+ <BuildDependsOn Condition="$(RestorePackages) == 'true'">
+ RestorePackages;
+ $(BuildDependsOn);
+ </BuildDependsOn>
+
+ <!-- Make the build depend on restore packages -->
+ <BuildDependsOn Condition="$(BuildPackage) == 'true'">
+ $(BuildDependsOn);
+ BuildPackage;
+ </BuildDependsOn>
+ </PropertyGroup>
+
+ <Target Name="CheckPrerequisites">
+ <!-- Raise an error if we're unable to locate nuget.exe -->
+ <Error Condition="!Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
+ </Target>
+
+ <Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
+ <Exec Command="$(RestoreCommand)"
+ LogStandardErrorAsError="true"
+ Condition="Exists('$(PackagesConfig)')" />
+ </Target>
+
+ <Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
+ <Exec Command="$(BuildCommand)"
+ LogStandardErrorAsError="true" />
+ </Target>
+</Project>
26 src/Requester.sln
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Requester", "Requester\Requester.csproj", "{D691EE4A-1B24-4445-BED3-080F677423A3}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{35BB208D-2DF0-4995-8F91-7A906A2F01BE}"
+ ProjectSection(SolutionItems) = preProject
+ .nuget\NuGet.exe = .nuget\NuGet.exe
+ .nuget\NuGet.targets = .nuget\NuGet.targets
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x86 = Debug|x86
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {D691EE4A-1B24-4445-BED3-080F677423A3}.Debug|x86.ActiveCfg = Debug|x86
+ {D691EE4A-1B24-4445-BED3-080F677423A3}.Debug|x86.Build.0 = Debug|x86
+ {D691EE4A-1B24-4445-BED3-080F677423A3}.Release|x86.ActiveCfg = Release|x86
+ {D691EE4A-1B24-4445-BED3-080F677423A3}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
118 src/Requester/Program.cs
@@ -0,0 +1,118 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Net;
+using System.Net.Http;
+using System.Text;
+using System.Threading;
+using Topshelf;
+using log4net.Config;
+
+namespace Requester
+{
+ class Program
+ {
+ private const string _urlFile = "url.txt";
+ private const string _intervalFile = "interval.txt";
+ private CancellationToken _token;
+ private CancellationTokenSource _tokenSource;
+ private TimeSpan _timeout;
+
+ static void Main(string[] args)
+ {
+ BasicConfigurator.Configure();
+
+ if (args.Length < 2)
+ {
+ PrintHelp();
+ Environment.Exit(-1);
+ return;
+ }
+
+ var isInstallOrUninstall = args[0].Contains("install");
+ var url = args[isInstallOrUninstall ? 1 : 0];
+ var interval = args[isInstallOrUninstall? 2 : 1];
+
+ int res;
+ if (!int.TryParse(interval, out res))
+ {
+ PrintHelp();
+ Environment.Exit(-1);
+ return;
+ }
+
+ if (!File.Exists(_urlFile))
+ {
+ File.WriteAllText(_urlFile, "http://google.com");
+ }
+
+ if (!File.Exists(_intervalFile))
+ {
+ File.WriteAllText(_intervalFile, "40");
+ }
+
+ Thread.CurrentThread.Name = "Requester Entrypoint Thread";
+
+ HostFactory.Run(x =>
+ {
+ x.Service<Program>(s =>
+ {
+ s.ConstructUsing(name => new Program());
+ s.WhenStarted(p => p.Start(File.ReadAllText(_urlFile), int.Parse(File.ReadAllText(_intervalFile))));
+ s.WhenStopped(p => p.Stop());
+ });
+ x.RunAsLocalSystem();
+ x.BeforeInstall(() =>
+ {
+ File.WriteAllText(_urlFile, args[1]);
+ File.WriteAllText("inteval.txt", interval);

Spelling error and dup code? "inteval.txt" => _intervalFile.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ });
+ x.SetDescription(string.Format("Requests an url every interval"));
+ x.SetDisplayName("Requester");
+ x.SetServiceName("Requester");
+ });
+ }
+
+ private static void PrintHelp()
+ {
+ Console.WriteLine(
+@"Too few args: requester install <url> <interval>
+
+Sample usage; request
+ url: ""https://github.com""
+ interval: 300 seconds
+
+requester install https://github.com 300
+");
+ }
+
+ private void Start(string url, int interval)
+ {
+ _tokenSource = new CancellationTokenSource();
+ _token = _tokenSource.Token;
+
+ while (!_token.IsCancellationRequested)
+ {
+ //httpClient.DefaultRequestHeaders
+ // .Add("Authorization", string.Format("Basic {0}",
+ // Convert.ToBase64String(Encoding.UTF8.GetBytes("{0}:{1}".FormatWith(_username, _password)))));
+
+ try
+ {
+ new HttpClient().GetAsync(url).Wait(20000, _token);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+ }
+
+ Thread.Sleep(TimeSpan.FromSeconds(interval));
+ }
+ }
+
+ private void Stop()
+ {
+ _tokenSource.Cancel();
+ }
+ }
+}
36 src/Requester/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 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("Requester")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Requester")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("619bc0de-7daf-43a3-be80-7a4700070d3f")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
83 src/Requester/Requester.csproj
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{D691EE4A-1B24-4445-BED3-080F677423A3}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Requester</RootNamespace>
+ <AssemblyName>Requester</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\src\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="log4net">
+ <HintPath>..\packages\log4net.1.2.11\lib\net40-client\log4net.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Json">
+ <HintPath>..\packages\JsonValue.0.6.0\lib\40\Microsoft.Json.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Net.Http.Formatting">
+ <HintPath>..\packages\HttpClient.0.6.0\lib\40\Microsoft.Net.Http.Formatting.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Server.Common">
+ <HintPath>..\packages\JsonValue.0.6.0\lib\40\Microsoft.Server.Common.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Net.Http">
+ <HintPath>..\packages\HttpClient.0.6.0\lib\40\System.Net.Http.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="Topshelf">
+ <HintPath>..\packages\Topshelf.2.2.3.0\lib\NET40\Topshelf.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
6 src/Requester/Requester.csproj.user
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
+ <StartArguments>https://haf.github.com 40000</StartArguments>
+ </PropertyGroup>
+</Project>
3  src/Requester/app.config
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
7 src/Requester/packages.config
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="HttpClient" version="0.6.0" />
+ <package id="JsonValue" version="0.6.0" />
+ <package id="log4net" version="1.2.11" />
+ <package id="Topshelf" version="2.2.3.0" />
+</packages>
Please sign in to comment.
Something went wrong with that request. Please try again.