-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First rough working prototype for LINQ to Loggly
No device support yet, only HTTP. Search api not fully mapped. No error checking. No doc comments.
- Loading branch information
1 parent
fffc821
commit 3c68221
Showing
27 changed files
with
1,434 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright 2013 Applied Duality, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Loggly", "Loggly\Loggly.csproj", "{CD3B0557-018C-4AF2-A71D-51175839A501}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Playground", "Playground\Playground.csproj", "{A6A093E5-61E2-4C0E-8A32-17FD5872DD6D}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E9379F8A-0BC8-4978-9A49-49BBA483116A}" | ||
ProjectSection(SolutionItems) = preProject | ||
License.txt = License.txt | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{CD3B0557-018C-4AF2-A71D-51175839A501}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CD3B0557-018C-4AF2-A71D-51175839A501}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CD3B0557-018C-4AF2-A71D-51175839A501}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CD3B0557-018C-4AF2-A71D-51175839A501}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{A6A093E5-61E2-4C0E-8A32-17FD5872DD6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A6A093E5-61E2-4C0E-8A32-17FD5872DD6D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A6A093E5-61E2-4C0E-8A32-17FD5872DD6D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A6A093E5-61E2-4C0E-8A32-17FD5872DD6D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#region Apache 2 License | ||
// Copyright (c) Applied Duality, Inc., All rights reserved. | ||
// See License.txt in the project root for license information. | ||
#endregion | ||
|
||
using System.Threading.Tasks; | ||
|
||
namespace Loggly | ||
{ | ||
public static class Extensions | ||
{ | ||
public static async void ToBackGround(this Task task) | ||
{ | ||
try{ await task; } catch {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#region Apache 2 License | ||
// Copyright (c) Applied Duality, Inc., All rights reserved. | ||
// See License.txt in the project root for license information. | ||
#endregion | ||
|
||
using System.Net.Http; | ||
|
||
// Great blog post about HttpClient | ||
// http://pfelix.wordpress.com/2012/01/11/the-new-net-httpclient-class/ | ||
|
||
namespace Loggly | ||
{ | ||
/// <summary> | ||
/// JsonContent helper class. | ||
/// </summary> | ||
public class JsonContent : StringContent | ||
{ | ||
public JsonContent() : this(content: "{}") { } | ||
|
||
public JsonContent(System.Json.JsonValue content) : this(content: content.ToString()) { } | ||
|
||
public JsonContent(string content) | ||
: base(content: content) | ||
{ | ||
base.Headers.ContentType.CharSet = ""; | ||
base.Headers.ContentType.MediaType = "application/json"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{CD3B0557-018C-4AF2-A71D-51175839A501}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Loggly</RootNamespace> | ||
<AssemblyName>Loggly</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<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|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Json"> | ||
<HintPath>..\..\..\..\..\Dropbox\Dlls\System.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Net.Http.WebRequest" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Retrieval\Client.cs" /> | ||
<Compile Include="Retrieval\QueryInputs\Filtered.cs" /> | ||
<Compile Include="Retrieval\QueryInputs\Inputs.cs" /> | ||
<Compile Include="Retrieval\QueryEvents\Dated.cs" /> | ||
<Compile Include="Retrieval\QueryEvents\Events.cs" /> | ||
<Compile Include="Retrieval\QueryEvents\Filtered.cs" /> | ||
<Compile Include="Retrieval\QueryEvents\Ordered.cs" /> | ||
<Compile Include="Retrieval\QueryEvents\Projected.cs" /> | ||
<Compile Include="Retrieval\QueryEvents\Query.cs" /> | ||
<Compile Include="Retrieval\QueryEvents\Skipped.cs" /> | ||
<Compile Include="Retrieval\QueryEvents\Taken.cs" /> | ||
<Compile Include="Submission\Client.cs" /> | ||
<Compile Include="Extensions\Extensions.cs" /> | ||
<Compile Include="Extensions\JsonContent.cs" /> | ||
<Compile Include="Messages\Messages.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Retrieval\QueryInputs\Selected.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#region Apache 2 License | ||
// Copyright (c) Applied Duality, Inc., All rights reserved. | ||
// See License.txt in the project root for license information. | ||
#endregion | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Json; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
|
||
namespace Loggly | ||
{ | ||
|
||
public enum EventFormat { Other, Text, Json } | ||
|
||
public struct Service | ||
{ | ||
dynamic _json; | ||
public Service(JsonValue json) { this._json = json; } | ||
|
||
public string Name { get { return _json.name; } } | ||
public string Display { get { return _json.display; } } | ||
|
||
public override string ToString() | ||
{ | ||
return _json.ToString(); | ||
} | ||
} | ||
|
||
public struct HttpInput | ||
{ | ||
dynamic _json; | ||
public HttpInput(JsonValue json) { this._json = json; } | ||
public HttpInput(string json):this(JsonValue.Parse(json)) { } | ||
public string Description { get { return _json.description; } } | ||
public int Id { get { return _json.id; } } | ||
public Guid InputToken { get { return Guid.Parse(_json.input_token); } } | ||
public DateTimeOffset Created { get { return DateTimeOffset.Parse(_json.created); } } | ||
public EventFormat Format | ||
{ | ||
get | ||
{ | ||
string format = _json.format; | ||
return format == "text" ? EventFormat.Text : format == "json" ? EventFormat.Json : EventFormat.Other; | ||
} | ||
} | ||
public string Name { get { return _json.name; } } | ||
public Uri LoggingUrl | ||
{ | ||
get | ||
{ | ||
string uri = _json.logging_url; | ||
return new Uri(uri); | ||
} | ||
} | ||
public Service Service { get { return new Service(_json.service); } } | ||
|
||
public override string ToString() | ||
{ | ||
return _json.ToString(); | ||
} | ||
} | ||
|
||
public struct _HttpInputs | ||
{ | ||
dynamic _json; | ||
internal _HttpInputs(string json) | ||
{ | ||
var p = JsonValue.Parse(json); | ||
if (p.JsonType != JsonType.Array) p = new JsonArray(p); | ||
_json = p; | ||
|
||
} | ||
|
||
public IEnumerable<HttpInput> Inputs | ||
{ | ||
get | ||
{ | ||
var xs = _json as IEnumerable<JsonValue>; | ||
return (xs).Select(input => new HttpInput(input)); | ||
} | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return _json.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("Loggly")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Loggly")] | ||
[assembly: AssemblyCopyright("Copyright © 2013")] | ||
[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("7ed8efe8-0be0-433e-b55a-606368a8ebfe")] | ||
|
||
// 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")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#region Apache 2 License | ||
// Copyright (c) Applied Duality, Inc., All rights reserved. | ||
// See License.txt in the project root for license information. | ||
#endregion | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Loggly.Retrieval | ||
{ | ||
public partial class Client | ||
{ | ||
HttpClient _client; | ||
public Client(string username, string password, string subdomain) | ||
{ | ||
_client = new HttpClient(); | ||
var header = new AuthenticationHeaderValue | ||
("Basic" | ||
, Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(string.Format("{0}:{1}", username, password))) | ||
); | ||
_client.DefaultRequestHeaders.Authorization = header; | ||
var baseUri = new Uri(string.Format("https://{0}.loggly.com/api/",subdomain)); | ||
_client.BaseAddress = baseUri; | ||
} | ||
|
||
public Inputs GetInputsAsync() | ||
{ | ||
return new Inputs(_client); | ||
} | ||
|
||
public async Task<HttpInput?> CreateHttpInputAsync(string name, string description = "", EventFormat format = EventFormat.Json) | ||
{ | ||
var content = new FormUrlEncodedContent | ||
(new Dictionary<string, string> | ||
{ | ||
{"name" , name}, | ||
{"description", description}, | ||
{"service", "http" }, | ||
{ "format", "json" }, | ||
}); | ||
var response = await _client.PostAsync("inputs/", content); | ||
if (response.IsSuccessStatusCode) | ||
{ | ||
var json = await response.Content.ReadAsStringAsync(); | ||
return new HttpInput(json); | ||
} | ||
else | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public async Task<bool> DeleteHttpInputAsync(HttpInput input) | ||
{ | ||
var response = await _client.DeleteAsync(string.Format("inputs/{0}", input.Id)); | ||
return response.StatusCode == System.Net.HttpStatusCode.NoContent; | ||
} | ||
|
||
public async Task<string> SearchAsync(string query) | ||
{ | ||
var response = await _client.GetAsync(string.Format("search?{0}",query)); | ||
return await response.Content.ReadAsStringAsync(); | ||
} | ||
|
||
public Events QueryEventsAsync() | ||
{ | ||
return new Loggly.Retrieval.Events(_client); | ||
} | ||
} | ||
} |
Oops, something went wrong.