Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
193 changes: 193 additions & 0 deletions Core/Cryptany.Core.Caching/Cache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
Copyright 2006-2017 Cryptany, 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.
*/

using System;
using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;
using System.Configuration;
using System.Diagnostics;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using System.Collections.Generic;


namespace Cryptany.Core.Caching
{

public delegate void ItemAddedOrRemovedEventHandler();

public class Cache
{
private CacheManager CacheMan;
public TimeSpan _expirationTimeSpan;
//string LogName = "Application";
CacheItemPriority _CacheItemPriority;
public event ItemAddedOrRemovedEventHandler ItemAddedOrRemoved;

public ICacheItemRefreshAction refreshener;

public Cache()
{

try
{
CacheMan = CacheFactory.GetCacheManager();
CacheMan.Add("Items", new List<string>());
}

catch (Exception ex)
{
ExceptionPolicy.HandleException(ex, "LoggingPolicy");
}


try
{
string CacheItemPriorityStr = ConfigurationManager.AppSettings["CacheItemPriority"];
_CacheItemPriority = (CacheItemPriority)Enum.Parse(typeof(CacheItemPriority), CacheItemPriorityStr);
}
catch (Exception ex)
{
ExceptionPolicy.HandleException(ex, "LoggingPolicy");
_CacheItemPriority = CacheItemPriority.Normal;
}

int Timeout;
try
{
Timeout = Convert.ToInt32(ConfigurationManager.AppSettings["Timeout"]);
}

catch (Exception ex)
{
ExceptionPolicy.HandleException(ex, "LoggingPolicy");
Timeout = 5;
}
_expirationTimeSpan = TimeSpan.FromMinutes(Timeout);


}

public void Add<T>(string key, T _value)
{

object obj = _value;
try
{

Trace.WriteLine("Cache: Adding to cache key " + key + " Value " + _value);
//ItemsRemover _itemsRemover = new ItemsRemover();
//Trace.WriteLine("Cache: ������� _itemsRemover ");
// _itemsRemover.ItemRemoved += new ItemAddedOrRemovedEventHandler(ItemAddedOrRemoved);
Trace.WriteLine(" Cache: Adding key " + key + " obj " + obj + " ItemPriority " + _CacheItemPriority + " expiration " + _expirationTimeSpan);
CacheMan.Add(key, obj, _CacheItemPriority, refreshener, new SlidingTime(_expirationTimeSpan));
Trace.WriteLine("Cache: Successfully added to cache");
(CacheMan["Items"] as List<string>).Add(key);
Trace.WriteLine("Cache: Updated Items");

if (ItemAddedOrRemoved != null)
ItemAddedOrRemoved();
}
catch (Exception ex)
{
Trace.WriteLine(ex);
ExceptionPolicy.HandleException(ex, "LoggingPolicy");
throw new ArgumentException();
}

}
public void Remove(string key)
{
if (CacheMan.Contains(key))
{
CacheMan.Remove(key);

(CacheMan["Items"] as List<string>).Remove(key);

if (ItemAddedOrRemoved != null) ItemAddedOrRemoved();
}
}

public void Flush()
{
CacheMan.Flush();
(CacheMan["Items"] as List<string>).Clear();
if (ItemAddedOrRemoved != null) ItemAddedOrRemoved();
}

public bool GetItem<T>(string key, out T val)
{


if (CacheMan.Contains(key))
{
val = (T)CacheMan.GetData(key);
return true;

}
val = default(T);
return false;
// throw new ElementNotInCacheException();

}

public bool Contains(string key)
{

return CacheMan.Contains(key);

}

public int Count
{
get { return CacheMan.Count - 1; }
}

//private void WriteToLog(Exception ex)
//{
// EventInstance eventInst = new EventInstance(0, 0, EventLogEntryType.Error);
// EventLog.WriteEvent(LogName, eventInst, ex.ToString());

//}

public List<string> CacheItems
{
get { return CacheMan["Items"] as List<string>; }
}


}


//[Serializable]
//public class ItemsRemover : ICacheItemRefreshAction
//{
// public event ItemAddedOrRemovedEventHandler ItemRemoved;

// public void Refresh(string removedKey,
// Object expiredValue,
// CacheItemRemovedReason removalReason)
// {

// ItemRemoved();

// }
//}

//public class ElementNotInCacheException : Exception
//{
//}

}
105 changes: 105 additions & 0 deletions Core/Cryptany.Core.Caching/Cryptany.Core.Caching.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D32B90E6-AFDD-409F-980A-7BEE94E1D245}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Cryptany.Core.Caching</RootNamespace>
<AssemblyName>Cryptany.Core.Caching</AssemblyName>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
</SccLocalPath>
<SccAuxPath>
</SccAuxPath>
<SccProvider>
</SccProvider>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</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="Microsoft.Practices.EnterpriseLibrary.Caching, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\thirdparty\Microsoft Enterprise Library 3.1 - May 2007\Bin\Microsoft.Practices.EnterpriseLibrary.Caching.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\thirdparty\Microsoft Enterprise Library 3.1 - May 2007\Bin\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Cache.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\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>
63 changes: 63 additions & 0 deletions Core/Cryptany.Core.MsmqLog/Cryptany.Core.MsmqLog.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A4195E02-6916-4B90-9067-566AB24E2526}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Cryptany.Core.MsmqLog</RootNamespace>
<AssemblyName>Cryptany.Core.MsmqLog</AssemblyName>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
</SccLocalPath>
<SccAuxPath>
</SccAuxPath>
<SccProvider>
</SccProvider>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
</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>
<DocumentationFile>
</DocumentationFile>
</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>
<DocumentationFile></DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="MSMQLogEntry.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\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>
Loading