Skip to content

Commit 6ab89d6

Browse files
committed
analogy example project
1 parent 9d7dc6a commit 6ab89d6

File tree

6 files changed

+226
-0
lines changed

6 files changed

+226
-0
lines changed

Analogy.Example.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 16
3+
VisualStudioVersion = 16.0.29411.108
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Analogy.Implementation.Example", "Analogy.Implementation.Example\Analogy.Implementation.Example.csproj", "{69EF9461-D518-457B-A354-B8A4407F80FF}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Debug|x86 = Debug|x86
11+
Release|Any CPU = Release|Any CPU
12+
Release|x86 = Release|x86
13+
EndGlobalSection
14+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
15+
{69EF9461-D518-457B-A354-B8A4407F80FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16+
{69EF9461-D518-457B-A354-B8A4407F80FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{69EF9461-D518-457B-A354-B8A4407F80FF}.Debug|x86.ActiveCfg = Debug|Any CPU
18+
{69EF9461-D518-457B-A354-B8A4407F80FF}.Debug|x86.Build.0 = Debug|Any CPU
19+
{69EF9461-D518-457B-A354-B8A4407F80FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{69EF9461-D518-457B-A354-B8A4407F80FF}.Release|Any CPU.Build.0 = Release|Any CPU
21+
{69EF9461-D518-457B-A354-B8A4407F80FF}.Release|x86.ActiveCfg = Release|Any CPU
22+
{69EF9461-D518-457B-A354-B8A4407F80FF}.Release|x86.Build.0 = Release|Any CPU
23+
EndGlobalSection
24+
GlobalSection(SolutionProperties) = preSolution
25+
HideSolutionNode = FALSE
26+
EndGlobalSection
27+
GlobalSection(ExtensibilityGlobals) = postSolution
28+
SolutionGuid = {5545B4EE-30CC-4F7B-8D24-A0FE4C0B6183}
29+
EndGlobalSection
30+
EndGlobal
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{69EF9461-D518-457B-A354-B8A4407F80FF}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Analogy.Implementation.Example</RootNamespace>
11+
<AssemblyName>Analogy.Implementation.Example</AssemblyName>
12+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
<TargetFrameworkProfile />
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Drawing" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Net.Http" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="AnalogyDataSourceFactory.cs" />
47+
<Compile Include="AnalogyExampleFactory.cs" />
48+
<Compile Include="AnalogyOnlineExampleDataProvider.cs" />
49+
<Compile Include="Properties\AssemblyInfo.cs" />
50+
</ItemGroup>
51+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
52+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.Generic;
2+
using Analogy.Interfaces;
3+
using Analogy.Interfaces.Factories;
4+
5+
namespace Analogy.Implementation.Example
6+
{
7+
public class AnalogyDataProviderFactory : IAnalogyDataProvidersFactory
8+
{
9+
public string Title => "Analogy Online example";
10+
11+
public IEnumerable<IAnalogyDataProvider> Items => new List<IAnalogyDataProvider> { new AnalogyOnlineExampleDataProvider() };
12+
}
13+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Analogy.Interfaces;
4+
using Analogy.Interfaces.Factories;
5+
6+
namespace Analogy.Implementation.Example
7+
{
8+
public class AnalogyExampleFactory : IAnalogyFactory
9+
{
10+
public Guid FactoryID => new Guid("4B1EBC0F-64DD-44A1-BC27-79DBFC6384CC");
11+
12+
public string Title => "Analogy Examples";
13+
14+
public IAnalogyDataProvidersFactory DataProviders { get; } = new AnalogyDataProviderFactory();
15+
16+
public IAnalogyCustomActionsFactory Actions => null;
17+
18+
public IEnumerable<IAnalogyChangeLog> ChangeLog { get; } = new List<AnalogyChangeLog>
19+
{
20+
new AnalogyChangeLog("Create example implementation",AnalogChangeLogType.None, "Lior Banai",new DateTime(2019, 08, 15)),
21+
new AnalogyChangeLog("Add Thread ID",AnalogChangeLogType.None, "Lior Banai",new DateTime(2019, 08, 20)),
22+
new AnalogyChangeLog("Add File handler for online data source (aligned with new interface)",AnalogChangeLogType.None, "Lior Banai",new DateTime(2019, 09, 09))
23+
};
24+
public IEnumerable<string> Contributors { get; } = new List<string> { "Lior Banai" };
25+
public string About { get; } = "Analogy Example Data Source";
26+
}
27+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using System.Timers;
7+
using Analogy.Interfaces;
8+
9+
namespace Analogy.Implementation.Example
10+
{
11+
class AnalogyOnlineExampleDataProvider : IAnalogyRealTimeDataProvider
12+
{
13+
public string OptionalTitle { get; } = "Analogy Example: Real time Data Provider";
14+
public Guid ID => new Guid("6642B160-F992-4120-B688-B02DE2E83256");
15+
16+
public bool AutoStartAtLaunch => true;
17+
public bool IsConnected => true;
18+
public event EventHandler<AnalogyDataSourceDisconnectedArgs> OnDisconnected;
19+
public event EventHandler<AnalogyLogMessageArgs> OnMessageReady;
20+
public event EventHandler<AnalogyLogMessagesArgs> OnManyMessagesReady;
21+
22+
public async Task<bool> CanStartReceiving() => await Task.FromResult(true);
23+
24+
public IAnalogyOfflineDataProvider FileOperationsHandler { get; }
25+
private Timer SimulateOnlineMessages;
26+
private int messageCount = 0;
27+
readonly Random random = new Random();
28+
readonly Array values = Enum.GetValues(typeof(AnalogyLogLevel));
29+
private readonly List<string> processes = Process.GetProcesses().Select(p => p.ProcessName).ToList();
30+
public void InitDataProvider()
31+
{
32+
SimulateOnlineMessages = new Timer(100);
33+
34+
SimulateOnlineMessages.Elapsed += (s, e) =>
35+
{
36+
if (OnMessageReady == null)
37+
return;
38+
unchecked
39+
{
40+
41+
AnalogyLogLevel randomLevel = (AnalogyLogLevel)values.GetValue(random.Next(values.Length));
42+
string randomProcess = processes[random.Next(processes.Count)];
43+
AnalogyLogMessage m = new AnalogyLogMessage
44+
{
45+
Text = $"Generated message #{messageCount++}",
46+
Level = randomLevel,
47+
Class = AnalogyLogClass.General,
48+
Source = "Example",
49+
Module = randomProcess
50+
};
51+
52+
OnMessageReady(this, new AnalogyLogMessageArgs(m, Environment.MachineName, "Example", ID));
53+
}
54+
};
55+
}
56+
57+
public void StartReceiving()
58+
{
59+
InitDataProvider();
60+
SimulateOnlineMessages?.Start();
61+
}
62+
63+
public void StopReceiving()
64+
{
65+
SimulateOnlineMessages?.Stop();
66+
OnDisconnected?.Invoke(this, new AnalogyDataSourceDisconnectedArgs("user disconnected", Environment.MachineName, ID));
67+
}
68+
}
69+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("Analogy.Implementation.Example")]
8+
[assembly: AssemblyDescription("Analogy Log Viewer Data Source Example")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("LIor Banai")]
11+
[assembly: AssemblyProduct("Analogy.Implementation.Example")]
12+
[assembly: AssemblyCopyright("Copyright © 2019")]
13+
[assembly: AssemblyTrademark("Lior Banai ([email protected])")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// Setting ComVisible to false makes the types in this assembly not visible
17+
// to COM components. If you need to access a type in this assembly from
18+
// COM, set the ComVisible attribute to true on that type.
19+
[assembly: ComVisible(false)]
20+
21+
// The following GUID is for the ID of the typelib if this project is exposed to COM
22+
[assembly: Guid("69ef9461-d518-457b-a354-b8a4407f80ff")]
23+
24+
// Version information for an assembly consists of the following four values:
25+
//
26+
// Major Version
27+
// Minor Version
28+
// Build Number
29+
// Revision
30+
//
31+
// You can specify all the values or you can default the Build and Revision Numbers
32+
// by using the '*' as shown below:
33+
// [assembly: AssemblyVersion("1.0.*")]
34+
[assembly: AssemblyVersion("1.0.4.0")]
35+
[assembly: AssemblyFileVersion("1.0.4.0")]

0 commit comments

Comments
 (0)