[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct SIGMPGroup
{
public int temp;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
public string name; //name of group
public int port;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)]
public string addr;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LibClass
{
public interface IClass
{
void Write();
int Ref(ref int f);
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace My_Project.Trace
{
class IncludeLibrary
{
public IncludeLibrary(string PathDll)
{
if (System.IO.File.Exists(PathDll))
{
Assembly Ass = Assembly.LoadFrom(PathDll);
ListTypes = Ass.GetTypes(); // Чтение всех типов
isValid = true;
}
else
{
Console.WriteLine("Dll не найдена:" + PathDll);
}
}
public bool isValid = false;
public static bool operator ==(IncludeLibrary LibA, IncludeLibrary LibB)
{
if ((object)LibA != null && !LibA.isValid)
{
LibA = null;
}
if ((object)LibB != null && !LibA.isValid)
{
LibB = null;
}
return object.Equals(LibA, LibB);
}
public static bool operator !=(IncludeLibrary LibA, IncludeLibrary LibB)
{
return !(LibA == LibB);
}
public object DllClass(string FindClass, params object[] argsClass)
{
findDllClass = null;
if (ListTypes != null)
{
foreach (Type type in ListTypes)
{
if (type.FullName.Equals(FindClass))
{
findClassType = type;
if (argsClass != null)
{
findDllClass = Activator.CreateInstance(findClassType, argsClass);
}
else
{
findDllClass = Activator.CreateInstance(findClassType);
}
}
}
if (findDllClass == null)
{
Console.WriteLine("Plugin"+ FindClass + " not find");
}
}
return findDllClass;
}
/// <summary>
/// Запустить метод класса, найденный при вызове DllClass
/// </summary>
/// <param name="function"></param>
/// <param name="argsClass"></param>
/// <returns></returns>
public object Method(string function, params object[] argsClass)
{
return Method(findDllClass, function, argsClass);
}
public object Method(object Class, string function, params object[] argsClass)
{
object ret = null;
MethodInfo mi = null;
bool InvokeCorrect = false;
try
{
if (Class != null)
{
mi = Class.GetType().GetMethod(function);
if (mi != null)
{
ret = mi.Invoke(Class, argsClass);
InvokeCorrect = true;
}
}
}
catch
{
ret = null;
}
if (!InvokeCorrect)
{
Console.WriteLine(String.Format("{0}.{1} error in Plugin {2}", (Class != null) ? Class.GetType().Name : "null", function, (mi == null) ? "or function not find" : ""));
}
return ret;
}
object findDllClass = null;
Type findClassType = null;
Type[] ListTypes = null;
}
}
public static bool isHaveSpread
{
get
{
if (!First_isHaveSpread) // в первый раз спрашиваю ?
{
First_isHaveSpread = true;
if (!System.IO.File.Exists(System.Windows.Forms.Application.StartupPath + "\\" + NameDll))
{
Result_isHaveSpread = false;
}
else
{
Result_isHaveSpread = true;
}
}
return Result_isHaveSpread;
}
}
static object _spread = null;
private static object spread
{
get{
if (isHaveSpread && !OneProxod)
try
{
OneProxod = true;
if (_spread != null) Close();
_spread = new spread.LibSpread.Spread(Address,Port, User, System.Reflection.Assembly.GetExecutingAssembly().FullName);
}catch(Exception e){
System.Diagnostics.Debug.WriteLine("UserSpread.spread: " + e.Message);
//MVB.ImitarorMVB.IMITATOR_MVB = false;
}
//if(_spread!=null)
return _spread;
}
}
public static void Send<T>(T ob)
{
if (spread != null)
((spread.LibSpread.Spread)_spread).Send(ob);
}
public static int ExecuteNonQuery(string query)
{
int ret = 0;
// return ret; если раскоментировать употребление памяти не увеличивается
lock (Lock)
{
try
{
using (OdbcConnection Connection = new OdbcConnection(ConnectionString))
{
Connection.Open();
if (Connection.State == System.Data.ConnectionState.Open)
{
using (var command = new OdbcCommand(query, Connection))
{
ret = command.ExecuteNonQuery();
}
}
Connection.Close();
//OdbcConnection.ReleaseObjectPool();
}
OdbcConnection.ReleaseObjectPool();
}
catch (Exception e)
{
Console.WriteLine("ExecuteNonQuery=" + e.Message);
}
}
return ret;
}
public static void AddRecordsInArhiveAsync(ushort Code, bool NewData, DateTime Now, bool Finish = false)
{
Thread _trdAddRecords = new Thread(
delegate()
{
lock (LockThis)
AddRecordsInArhive(Code, NewData, Now, Finish); // Внутри вызывается функция ExecuteNonQuery(string query)
}
);
_trdAddRecords.Priority = ThreadPriority.Normal;
_trdAddRecords.Start();
}
public static void AddRecordsInArhiveSync(ushort Code, bool NewData, DateTime Now, bool Finish = false)
{
lock (LockThis)
AddRecordsInArhive(Code, NewData, Now, Finish);
}