This repository has been archived by the owner on Apr 1, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Perry
authored and
unknown
committed
Jan 24, 2012
1 parent
bfb02c1
commit 98516e6
Showing
15 changed files
with
325 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,76 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>9.0.21022</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{48CCB4E7-FDF0-4F06-ABC1-72E9E52A5632}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>AfterCollege.KISSmetrics</RootNamespace> | ||
<AssemblyName>AfterCollege.KISSmetrics</AssemblyName> | ||
<TargetFrameworkVersion>v3.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="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\Libs\log4net.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core"> | ||
<RequiredTargetFramework>3.5</RequiredTargetFramework> | ||
</Reference> | ||
<Reference Include="System.Web" /> | ||
<Reference Include="System.Xml.Linq"> | ||
<RequiredTargetFramework>3.5</RequiredTargetFramework> | ||
</Reference> | ||
<Reference Include="System.Data.DataSetExtensions"> | ||
<RequiredTargetFramework>3.5</RequiredTargetFramework> | ||
</Reference> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="KISSmetricsClient.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Properties\Settings.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | ||
<DependentUpon>Settings.settings</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
<None Include="Properties\Settings.settings"> | ||
<Generator>SettingsSingleFileGenerator</Generator> | ||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | ||
</None> | ||
</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,151 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Security.Policy; | ||
using System.Net; | ||
using log4net; | ||
using System.Net.Cache; | ||
|
||
namespace AfterCollege.KISSmetrics | ||
{ | ||
public class KISSmetricsException : Exception{ | ||
public KISSmetricsException(string message) : base(message) { } | ||
public KISSmetricsException() : base() { } | ||
public KISSmetricsException(Exception ex):base(ex.Message, ex){} | ||
public KISSmetricsException(string message, Exception ex) : base(message, ex) { } | ||
} | ||
|
||
public class MissingIdentityException : KISSmetricsException | ||
{ | ||
|
||
} | ||
|
||
public class KISSmetricsClient | ||
{ | ||
private string apiKey; | ||
private string identity; | ||
private ILog log = LogManager.GetLogger(typeof(KISSmetricsClient)); | ||
|
||
public KISSmetricsClient(string apiKey) | ||
{ | ||
this.apiKey = apiKey; | ||
log.Info("KISS metrics client created successfully."); | ||
} | ||
|
||
public KISSmetricsClient() | ||
{ | ||
this.apiKey = AfterCollege.KISSmetrics.Properties.Settings.Default.ApiKey; | ||
if (String.IsNullOrEmpty(this.apiKey)) | ||
{ | ||
log.Warn("API Key not found."); | ||
log.Debug("Modify API Key in App.config"); | ||
throw new KISSmetricsException("API Key not found."); | ||
} | ||
log.Info("KISS metrics client created successfully."); | ||
} | ||
|
||
public void SetIdentity(string identity) | ||
{ | ||
log.Info("Setting identiy"); | ||
log.Debug(identity); | ||
this.identity = identity; | ||
} | ||
|
||
public void Alias(string identity1 , string identity2){ | ||
Dictionary<String, String> data = new Dictionary<String, String>(); | ||
data.Add("_p", identity1); | ||
data.Add("_n", identity2); | ||
|
||
try { | ||
string url = BuildUrl("a", data); | ||
log.Debug(url); | ||
SendRequest(url); | ||
} catch (Exception ex) { | ||
throw new KISSmetricsException(ex); | ||
} | ||
} | ||
|
||
public void Record(string name) | ||
{ | ||
Dictionary<string, string> data = new Dictionary<string, string>(); | ||
Record(name, data); | ||
} | ||
|
||
public void Record(string name, Dictionary<string, string> data) | ||
{ | ||
log.Info("Record is triggered"); | ||
|
||
if (identity == null) | ||
throw new MissingIdentityException(); | ||
|
||
data.Add("_p", identity); | ||
data.Add("_n", name); | ||
|
||
try | ||
{ | ||
string url = BuildUrl("e", data); | ||
log.Debug(url); | ||
SendRequest(url); | ||
} | ||
catch (Exception ex) | ||
{ | ||
log.Warn(ex); | ||
throw new KISSmetricsException(ex); | ||
|
||
} | ||
} | ||
|
||
private string BuildUrl(string action, Dictionary<string, string> data){ | ||
|
||
bool isFirst = true; | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
foreach (string key in data.Keys){ | ||
log.Debug(String.Format("{0} {1}", key, data[key])); | ||
|
||
if(!isFirst) | ||
sb.Append("&"); | ||
|
||
sb.Append(System.Web.HttpUtility.UrlEncode(key) + "=" + System.Web.HttpUtility.UrlEncode(data[key])); | ||
|
||
isFirst = false; | ||
} | ||
string retVal = "http://trk.kissmetrics.com/" + action +"?_k=" + apiKey + "&" + sb.ToString(); | ||
log.Debug(retVal); | ||
return retVal; | ||
} | ||
|
||
/// <summary> | ||
/// set method lets you set properties on a person without recording an event. | ||
/// </summary> | ||
/// <param name="data"></param> | ||
public void Set(Dictionary<string, string> data){ | ||
if(identity == null){ | ||
throw new MissingIdentityException(); | ||
} | ||
|
||
data.Add("_p", identity); | ||
|
||
try | ||
{ | ||
string url = BuildUrl("s", data); | ||
log.Debug(url); | ||
SendRequest(url); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new KISSmetricsException(ex); | ||
} | ||
} | ||
|
||
private void SendRequest(string urlForAction){ | ||
log.Debug("Sending a request"); | ||
WebClient client = new WebClient(); | ||
client.CachePolicy = new System.Net.Cache.RequestCachePolicy(RequestCacheLevel.BypassCache); | ||
client.DownloadData(urlForAction); | ||
|
||
log.Debug("Finished sending the request"); | ||
} | ||
} | ||
} |
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("AfterCollege.KISSmetrics")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("AfterCollege.KISSmetrics")] | ||
[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("a712e22c-b07c-41b9-9719-d39d5ae86dc8")] | ||
|
||
// 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")] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
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,15 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<configSections> | ||
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > | ||
<section name="AfterCollege.KISSmetrics.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> | ||
</sectionGroup> | ||
</configSections> | ||
<applicationSettings> | ||
<AfterCollege.KISSmetrics.Properties.Settings> | ||
<setting name="ApiKey" serializeAs="String"> | ||
<value>afe7291fb458664b063479847137bb42dc27fba3</value> | ||
</setting> | ||
</AfterCollege.KISSmetrics.Properties.Settings> | ||
</applicationSettings> | ||
</configuration> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
obj/Debug/AfterCollege.KISSmetrics.csproj.FileListAbsolute.txt
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,7 @@ | ||
C:\wwwroot\rdux\AfterCollege.KISSmetrics\bin\Debug\AfterCollege.KISSmetrics.dll | ||
C:\wwwroot\rdux\AfterCollege.KISSmetrics\bin\Debug\AfterCollege.KISSmetrics.pdb | ||
C:\wwwroot\rdux\AfterCollege.KISSmetrics\obj\Debug\ResolveAssemblyReference.cache | ||
C:\wwwroot\rdux\AfterCollege.KISSmetrics\obj\Debug\AfterCollege.KISSmetrics.dll | ||
C:\wwwroot\rdux\AfterCollege.KISSmetrics\obj\Debug\AfterCollege.KISSmetrics.pdb | ||
C:\wwwroot\rdux\AfterCollege.KISSmetrics\bin\Debug\AfterCollege.KISSmetrics.dll.config | ||
C:\wwwroot\rdux\AfterCollege.KISSmetrics\bin\Debug\log4net.dll |
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
obj/Release/AfterCollege.KISSmetrics.csproj.FileListAbsolute.txt
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,5 @@ | ||
C:\wwwroot\rdux\AfterCollege.KISSmetrics\obj\Release\ResolveAssemblyReference.cache | ||
C:\wwwroot\rdux\AfterCollege.KISSmetrics\bin\Release\AfterCollege.KISSmetrics.dll | ||
C:\wwwroot\rdux\AfterCollege.KISSmetrics\bin\Release\AfterCollege.KISSmetrics.pdb | ||
C:\wwwroot\rdux\AfterCollege.KISSmetrics\obj\Release\AfterCollege.KISSmetrics.dll | ||
C:\wwwroot\rdux\AfterCollege.KISSmetrics\obj\Release\AfterCollege.KISSmetrics.pdb |
Binary file not shown.
Binary file not shown.