Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Target netstandard 1.3 #51

Merged
merged 22 commits into from
Jul 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
afbb43f
Add an editorconfig file to maintain the current tab indentation sett…
spewu Jun 15, 2017
0355b05
Add ncrunch stuff to gitignore
spewu Jun 15, 2017
633becd
Change Analytics to target netstandard 1.6
spewu Jun 15, 2017
270c284
Cleaned usings, as System.Runtime.Serialization.Json is not used and …
spewu Jun 15, 2017
fb12486
Changed Encoding.Default to Encoding.GetEncoding(0), as that is the w…
spewu Jun 15, 2017
31345dd
Format file to align on tabs and brace positioning
spewu Jun 15, 2017
ca07e74
Make client readonly
spewu Jun 15, 2017
c529e97
Rewrite BlockingRequestHandler to use HttpClient instead of HttpWebRe…
spewu Jun 15, 2017
0f178f9
Deleted some classes that are not used
spewu Jun 15, 2017
2a306c4
In the async flush handler that runs on its own thread, make sure to …
spewu Jun 15, 2017
e437edf
In the blocking flush handler use async/await - so change it to retur…
spewu Jun 15, 2017
65dcc7e
Make all the client methods async
spewu Jun 15, 2017
bdb0a9f
Retarget towards netstandard 1.3
spewu Jun 15, 2017
6589636
Change the Test project to a netcoreapp library
spewu Jun 15, 2017
50373dc
Format files to align on tab indentation and brace allignment
spewu Jun 15, 2017
8275627
Updated Actions to be async
spewu Jun 15, 2017
0ec746a
Updated ActionTests to be async
spewu Jun 15, 2017
97a027b
Updated FlushTests to be async
spewu Jun 15, 2017
a606b27
Add note in History.md about new changes
spewu Jun 15, 2017
9a34a6c
Content type encoding should be specified on the StringContent object
spewu Jun 16, 2017
c46113b
Make client operations syncronous
spewu Jun 20, 2017
2e7d43d
Update history
spewu Jun 20, 2017
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
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true

[*.cs]
charset = utf-8
indent_style = tab
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ ClientBin
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
_NCrunch*
*.ncrunch

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have
Expand Down
30 changes: 18 additions & 12 deletions Analytics.NET.sln
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
# Visual Studio 15
VisualStudioVersion = 15.0.26430.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Analytics", "Analytics\Analytics.csproj", "{E79E6240-4954-41D0-BCE4-573B800EF006}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Analytics", "Analytics\Analytics.csproj", "{A386CF02-D902-4B22-90A8-E828093E3AA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{5FF5800A-DB9C-4E5A-8DD2-7AD661487F33}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{6AE99FF7-EECF-4639-B6B1-3E7CF1CC3048}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C316F1BB-6C70-4DEB-BC04-5664C39313F3}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E79E6240-4954-41D0-BCE4-573B800EF006}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E79E6240-4954-41D0-BCE4-573B800EF006}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E79E6240-4954-41D0-BCE4-573B800EF006}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E79E6240-4954-41D0-BCE4-573B800EF006}.Release|Any CPU.Build.0 = Release|Any CPU
{5FF5800A-DB9C-4E5A-8DD2-7AD661487F33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5FF5800A-DB9C-4E5A-8DD2-7AD661487F33}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5FF5800A-DB9C-4E5A-8DD2-7AD661487F33}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5FF5800A-DB9C-4E5A-8DD2-7AD661487F33}.Release|Any CPU.Build.0 = Release|Any CPU
{A386CF02-D902-4B22-90A8-E828093E3AA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A386CF02-D902-4B22-90A8-E828093E3AA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A386CF02-D902-4B22-90A8-E828093E3AA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A386CF02-D902-4B22-90A8-E828093E3AA4}.Release|Any CPU.Build.0 = Release|Any CPU
{6AE99FF7-EECF-4639-B6B1-3E7CF1CC3048}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6AE99FF7-EECF-4639-B6B1-3E7CF1CC3048}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6AE99FF7-EECF-4639-B6B1-3E7CF1CC3048}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6AE99FF7-EECF-4639-B6B1-3E7CF1CC3048}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
98 changes: 7 additions & 91 deletions Analytics/Analytics.csproj
Original file line number Diff line number Diff line change
@@ -1,96 +1,12 @@
<?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')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E79E6240-4954-41D0-BCE4-573B800EF006}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Segment</RootNamespace>
<AssemblyName>Analytics.NET</AssemblyName>
<FileAlignment>512</FileAlignment>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFramework>netstandard1.3</TargetFramework>
</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' ">
<Optimize>True</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Client.cs" />
<Compile Include="Defaults.cs" />
<Compile Include="Exception\BadParameter.cs" />
<Compile Include="Exception\NotInitializedException.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Model\BaseAction.cs" />
<Compile Include="Model\Batch.cs" />
<Compile Include="Model\Context.cs" />
<Compile Include="Model\Identify.cs" />
<Compile Include="Model\Properties.cs" />
<Compile Include="Model\Traits.cs" />
<Compile Include="Request\IRequestHandler.cs" />
<Compile Include="Analytics.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Stats\Statistics.cs" />
<Compile Include="Model\Providers.cs" />
<Compile Include="Model\Alias.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Flush\IFlushHandler.cs" />
<Compile Include="Flush\AsyncFlushHandler.cs" />
<Compile Include="Flush\BlockingQueue.cs" />
<Compile Include="Request\BlockingRequestHandler.cs" />
<Compile Include="Flush\BlockingFlushHandler.cs" />
<Compile Include="Flush\IBatchFactory.cs" />
<Compile Include="Flush\SimpleBatchFactory.cs" />
<Compile Include="Model\Options.cs" />
<Compile Include="Model\Dict.cs" />
<Compile Include="Config.cs" />
<Compile Include="Model\Group.cs" />
<Compile Include="Model\Page.cs" />
<Compile Include="Model\Screen.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="Model\Track.cs" />
</ItemGroup>

<ItemGroup>
<None Include="History.md" />
<None Include="Analytics.nuspec" />
<None Include="packages.config" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
</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>
-->
<ItemGroup />

</Project>
9 changes: 3 additions & 6 deletions Analytics/Client.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

using System.Threading.Tasks;
using Segment.Flush;
using Segment.Request;
using Segment.Exception;
using Segment.Model;
using Segment.Request;
using Segment.Stats;

namespace Segment
Expand Down Expand Up @@ -648,7 +645,7 @@ public void Dispose()

private void Enqueue(BaseAction action)
{
_flushHandler.Process(action);
_flushHandler.Process(action).GetAwaiter().GetResult();

this.Statistics.Submitted = Statistics.Increment(this.Statistics.Submitted);
}
Expand Down
16 changes: 5 additions & 11 deletions Analytics/Flush/AsyncFlushHandler.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Collections.Generic;
using System.Threading;

using Segment;
using Segment.Request;
using System.Threading.Tasks;
using Segment.Model;
using Segment.Exception;
using Segment.Request;

namespace Segment.Flush
{
Expand Down Expand Up @@ -71,7 +65,7 @@ internal AsyncFlushHandler(IBatchFactory batchFactory,
_flushingThread.Start();
}

public void Process(BaseAction action)
public async Task Process(BaseAction action)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be left void?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on which layer in the application you want to switch from async to sync. In my pull request I suggest to do that switch in the topmost layer (the client). That makes is easy to add async overloads of the client methods if you want that in the future (which I think would be a good idea).

However, we can also choose to do that in the lower layer, e.g. where we are making the http requests. That means we can keep the rest of the layers without modification.

I don't see the harm in changing this method to async, as it is an internal class - so I don't consider this a breaking change.

In any case, the decision is yours. Let me know if you need me to modify it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot this was internal. This looks good!

{
int size = _queue.Count;

Expand Down Expand Up @@ -166,7 +160,7 @@ private void Loop()
});

// make the request here
_requestHandler.MakeRequest(batch);
_requestHandler.MakeRequest(batch).GetAwaiter().GetResult();

// mark the current batch as null
current = new List<BaseAction>();
Expand Down
17 changes: 5 additions & 12 deletions Analytics/Flush/BlockingFlushHandler.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Threading;

using Segment;
using Segment.Request;
using System.Collections.Generic;
using System.Threading.Tasks;
using Segment.Model;
using Segment.Exception;
using Segment.Request;

namespace Segment.Flush
{
Expand All @@ -32,10 +25,10 @@ internal BlockingFlushHandler(IBatchFactory batchFactory,
this._requestHandler = requestHandler;
}

public void Process(BaseAction action)
public async Task Process(BaseAction action)
{
Batch batch = _batchFactory.Create(new List<BaseAction>() { action });
_requestHandler.MakeRequest(batch);
await _requestHandler.MakeRequest(batch).ConfigureAwait(false);
}

/// <summary>
Expand Down
8 changes: 3 additions & 5 deletions Analytics/Flush/IFlushHandler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;

using System;
using System.Threading.Tasks;
using Segment.Model;
using Segment.Request;

namespace Segment.Flush
{
Expand All @@ -14,12 +13,11 @@ public interface IFlushHandler : IDisposable
/// Validates an action and begins the process of flushing it to the server
/// </summary>
/// <param name="action">Action.</param>
void Process(BaseAction action);
Task Process(BaseAction action);

/// <summary>
/// Blocks until all processing messages are flushed to the server
/// </summary>
void Flush();
}
}

6 changes: 5 additions & 1 deletion Analytics/History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

X.X.X / June 20, 2017
=================
* now targeting netstandard 1.3

2.0.1 / July 1, 2015
=================
* anonymous id fixes
Expand All @@ -18,4 +22,4 @@

1.2.0 / May 16, 2014
=================
* updating to spec v1
* updating to spec v1
34 changes: 0 additions & 34 deletions Analytics/Properties/AssemblyInfo.cs

This file was deleted.

26 changes: 0 additions & 26 deletions Analytics/Request/BatchState.cs

This file was deleted.

Loading