Skip to content

Commit

Permalink
V1.0 同步更新
Browse files Browse the repository at this point in the history
  • Loading branch information
cdy816 committed Jun 6, 2023
1 parent 2a4ebc7 commit 5bb8e78
Show file tree
Hide file tree
Showing 640 changed files with 105,184 additions and 6,239 deletions.
1 change: 1 addition & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"ExpandedNodes": [
""
],
"SelectedNode": "\\LICENSE",
"PreviewInSolutionExplorer": false
}
Binary file modified .vs/slnx.sqlite
Binary file not shown.
247 changes: 247 additions & 0 deletions Common/Cdy.Tag.Common/Common/ArrayList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
using System;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace Cdy.Tag
{
/// <summary>
///
/// </summary>
public class ArrayList<T>:IDisposable, IEnumerable<T>, IEnumerable
{
private T[] array;

private int mIndex;

private int mcapital;

/// <summary>
///
/// </summary>
/// <param name="capital"></param>
public ArrayList(int capital)
{
array = ArrayPool<T>.Shared.Rent(capital);
array.AsSpan<T>().Fill(default(T));
mcapital =capital;
}

/// <summary>
///
/// </summary>
public ArrayList():this(64)
{

}

private int mCountInner = 0;

private object mLocker = new object();

/// <summary>
///
/// </summary>
/// <param name="value"></param>
public void Add(T value)
{
lock (mLocker)
{
if (mIndex < array.Length)
{
array[mIndex++] = value;
}
else
{
var aar2 = ArrayPool<T>.Shared.Rent(array.Length * 2);
aar2.AsSpan<T>().Fill(default(T));
array.CopyTo(aar2, 0);
ArrayPool<T>.Shared.Return(array);
array = aar2;
array[mIndex++] = value;
}
}
mCountInner++;
}

/// <summary>
///
/// </summary>
/// <param name="values"></param>
public void AddRange(IEnumerable<T> values)
{
foreach(var vv in values)
{
Add(vv);
}
}

/// <summary>
///
/// </summary>
/// <param name="values"></param>
public void Remove(IEnumerable<T> values)
{
var array2 = ArrayPool<T>.Shared.Rent(mcapital);
List<T> ll = new List<T>(this.array.Take(mIndex));
foreach(var vv in values)
{
if(ll.Contains(vv))
ll.Remove(vv);
}
ll.CopyTo(array2);
this.mIndex = ll.Count;
array = array2;
}

/// <summary>
///
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public T this[int index]
{
get
{
if(index<this.mIndex)
return array[index];
else
{
return default(T);
}
}
}

/// <summary>
///
/// </summary>
public int Count
{
get
{
return mIndex;
}
}

/// <summary>
///
/// </summary>
public void Clear()
{
array.AsSpan().Clear();
mIndex = 0;
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public IEnumerable<T> List()
{
for(int i=0;i< mIndex; i++)
{
yield return array[i];
}
}

/// <summary>
///
/// </summary>
public void Dispose()
{
ArrayPool<T>.Shared.Return(array);
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public IEnumerator<T> GetEnumerator()
{
return new Enumerator(this);
}

/// <summary>
///
/// </summary>
/// <returns></returns>
IEnumerator IEnumerable.GetEnumerator()
{
return new Enumerator(this);
}

/// <summary>
///
/// </summary>
public struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator
{
private ArrayList<T> list;
private T currentElement;
private int mIndex;
internal Enumerator(ArrayList<T> stack)
{
list = stack;
mIndex = 0;
if(list.Count>0)
this.currentElement = list[0];
else
{
this.currentElement = default(T);
}
}

/// <summary>
///
/// </summary>
public object Current => currentElement;

/// <summary>
///
/// </summary>
T IEnumerator<T>.Current => currentElement;

/// <summary>
///
/// </summary>
public void Dispose()
{
list = null;
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public bool MoveNext()
{
if(mIndex < list.mIndex)
{
currentElement = list[mIndex];
mIndex++;
return true;
}
else
{
return false;
}
}

/// <summary>
/// /
/// </summary>
public void Reset()
{
mIndex = 0;
if (list.Count > 0)
this.currentElement = list[0];
else
{
this.currentElement = default(T);
}
}
}

}
}
131 changes: 131 additions & 0 deletions Common/Cdy.Tag.Common/Common/ClientAuthorization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Cdy.Tag.Common
{
/// <summary>
///
/// </summary>
public class ClientAuthorization
{
/// <summary>
///
/// </summary>
public static ClientAuthorization Instance = new ClientAuthorization();

/// <summary>
/// 允许的IP地址
/// </summary>
public List<string> AllowIps { get; set; }

/// <summary>
/// 允许的程序的HashCode值
/// </summary>
public List<string> AllowApplication { get; set; }

/// <summary>
/// 使能白名单策略
/// </summary>
public bool EnableAllows { get; set; }=false;


/// <summary>
/// 禁止的IP地址
/// </summary>
public List<string> ForbiddenIps { get; set; }

/// <summary>
/// 禁止的程序的HashCode值
/// </summary>
public List<string> ForbiddenApplication { get; set; }

/// <summary>
/// 使能黑名单策略
/// </summary>
public bool EnableForbidden { get; set; } = true;

/// <summary>
/// 检查IP可用
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
public bool CheckIp(string ip)
{
if (EnableAllows && AllowIps!=null)
{
return AllowIps.Contains(ip);
}
if(EnableForbidden && ForbiddenIps!=null)
{
return !ForbiddenIps.Contains(ip);
}
return true;
}

/// <summary>
/// 检查程序的HashCode 是否可用
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public bool CheckApplication(string code)
{
if (EnableAllows)
{
return AllowApplication.Contains(code);
}
if (EnableForbidden)
{
return !ForbiddenApplication.Contains(code);
}
return true;
}

/// <summary>
///
/// </summary>
/// <param name="xe"></param>
public void LoadAllowFromXML(XElement xe)
{
if(xe.Attribute("Enable") !=null)
{
this.EnableAllows = bool.Parse(xe.Attribute("Enable").Value);
}

if (xe.Attribute("Ips") != null)
{
this.AllowIps = xe.Attribute("Ips").Value.Split(",",StringSplitOptions.RemoveEmptyEntries).ToList();
}

if (xe.Attribute("ApplicationCode") != null)
{
this.AllowApplication = xe.Attribute("ApplicationCode").Value.Split(",", StringSplitOptions.RemoveEmptyEntries).ToList();
}
}

/// <summary>
///
/// </summary>
/// <param name="xe"></param>
public void LoadForbiddenFromXML(XElement xe)
{
if (xe.Attribute("Enable") != null)
{
this.EnableForbidden = bool.Parse(xe.Attribute("Enable").Value);
}

if (xe.Attribute("Ips") != null)
{
this.ForbiddenIps = xe.Attribute("Ips").Value.Split(",", StringSplitOptions.RemoveEmptyEntries).ToList();
}

if (xe.Attribute("ApplicationCode") != null)
{
this.ForbiddenApplication = xe.Attribute("ApplicationCode").Value.Split(",", StringSplitOptions.RemoveEmptyEntries).ToList();
}
}

}
}
Loading

0 comments on commit 5bb8e78

Please sign in to comment.