From 4ebe3250437021cb59de2cc8d52b1643a4415457 Mon Sep 17 00:00:00 2001 From: dmpopov4 <31319286+dmpopov4@users.noreply.github.com> Date: Tue, 29 Aug 2017 21:05:53 +0300 Subject: [PATCH 1/2] MSMQ log library --- .../Cryptany.Core.MsmqLog.csproj | 63 +++++++++++++++++++ Core/Cryptany.Core.MsmqLog/MSMQLogEntry.cs | 53 ++++++++++++++++ .../Properties/AssemblyInfo.cs | 35 +++++++++++ 3 files changed, 151 insertions(+) create mode 100644 Core/Cryptany.Core.MsmqLog/Cryptany.Core.MsmqLog.csproj create mode 100644 Core/Cryptany.Core.MsmqLog/MSMQLogEntry.cs create mode 100644 Core/Cryptany.Core.MsmqLog/Properties/AssemblyInfo.cs diff --git a/Core/Cryptany.Core.MsmqLog/Cryptany.Core.MsmqLog.csproj b/Core/Cryptany.Core.MsmqLog/Cryptany.Core.MsmqLog.csproj new file mode 100644 index 0000000..70abd92 --- /dev/null +++ b/Core/Cryptany.Core.MsmqLog/Cryptany.Core.MsmqLog.csproj @@ -0,0 +1,63 @@ + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {A4195E02-6916-4B90-9067-566AB24E2526} + Library + Properties + Cryptany.Core.MsmqLog + Cryptany.Core.MsmqLog + + + + + + + + + v2.0 + + + + + 2.0 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + \ No newline at end of file diff --git a/Core/Cryptany.Core.MsmqLog/MSMQLogEntry.cs b/Core/Cryptany.Core.MsmqLog/MSMQLogEntry.cs new file mode 100644 index 0000000..f9fcc48 --- /dev/null +++ b/Core/Cryptany.Core.MsmqLog/MSMQLogEntry.cs @@ -0,0 +1,53 @@ +/* + 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 System.Collections; + +namespace Cryptany.Core.MsmqLog +{ + [Serializable] + public class MSMQLogEntry + { + private string _dbName; + public string DatabaseName + { + get { return _dbName; } + set { _dbName = value; } + } + private int _commandTimeout = 500; + + public int CommandTimeout + { + get { return _commandTimeout; } + set { _commandTimeout = value; } + } + + private string _commandText; + public string CommandText + { + get { return _commandText; } + set { _commandText = value; } + } + + private readonly Hashtable _parameters = new Hashtable(); + public Hashtable Parameters + { + get { return _parameters; } + + } + + } +} diff --git a/Core/Cryptany.Core.MsmqLog/Properties/AssemblyInfo.cs b/Core/Cryptany.Core.MsmqLog/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..74cbb6c --- /dev/null +++ b/Core/Cryptany.Core.MsmqLog/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +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("Cryptany.Core.MsmqLog")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Cryptany, Inc.")] +[assembly: AssemblyProduct("Cryptany.Core.MsmqLog")] +[assembly: AssemblyCopyright("Copyright © Cryptany, Inc. 2009-2017")] +[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("305cd008-aa97-4b07-8237-9e16cd010feb")] + +// 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 Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] From 07b847551e244c5b4945ea2acd7ca4e1d90a4aeb Mon Sep 17 00:00:00 2001 From: dmpopov4 <31319286+dmpopov4@users.noreply.github.com> Date: Tue, 29 Aug 2017 21:12:03 +0300 Subject: [PATCH 2/2] Imported cache library --- Core/Cryptany.Core.Caching/Cache.cs | 193 ++++++++++++++++++ .../Cryptany.Core.Caching.csproj | 105 ++++++++++ 2 files changed, 298 insertions(+) create mode 100644 Core/Cryptany.Core.Caching/Cache.cs create mode 100644 Core/Cryptany.Core.Caching/Cryptany.Core.Caching.csproj diff --git a/Core/Cryptany.Core.Caching/Cache.cs b/Core/Cryptany.Core.Caching/Cache.cs new file mode 100644 index 0000000..f1eb383 --- /dev/null +++ b/Core/Cryptany.Core.Caching/Cache.cs @@ -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()); + } + + 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(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).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).Remove(key); + + if (ItemAddedOrRemoved != null) ItemAddedOrRemoved(); + } + } + + public void Flush() + { + CacheMan.Flush(); + (CacheMan["Items"] as List).Clear(); + if (ItemAddedOrRemoved != null) ItemAddedOrRemoved(); + } + + public bool GetItem(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 CacheItems + { + get { return CacheMan["Items"] as List; } + } + + + } + + + //[Serializable] + //public class ItemsRemover : ICacheItemRefreshAction + //{ + // public event ItemAddedOrRemovedEventHandler ItemRemoved; + + // public void Refresh(string removedKey, + // Object expiredValue, + // CacheItemRemovedReason removalReason) + // { + + // ItemRemoved(); + + // } + //} + + //public class ElementNotInCacheException : Exception + //{ + //} + +} diff --git a/Core/Cryptany.Core.Caching/Cryptany.Core.Caching.csproj b/Core/Cryptany.Core.Caching/Cryptany.Core.Caching.csproj new file mode 100644 index 0000000..fe067e9 --- /dev/null +++ b/Core/Cryptany.Core.Caching/Cryptany.Core.Caching.csproj @@ -0,0 +1,105 @@ + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {D32B90E6-AFDD-409F-980A-7BEE94E1D245} + Library + Properties + Cryptany.Core.Caching + Cryptany.Core.Caching + + + + + + + + + + + 3.5 + + + v2.0 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\release\ + TRACE + prompt + 4 + + + + False + ..\..\thirdparty\Microsoft Enterprise Library 3.1 - May 2007\Bin\Microsoft.Practices.EnterpriseLibrary.Caching.dll + + + False + ..\..\thirdparty\Microsoft Enterprise Library 3.1 - May 2007\Bin\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll + + + + + + + + + + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + + + False + Windows Installer 3.1 + true + + + + + + + + \ No newline at end of file