daily update on 20240528 by nitload youmu

This commit is contained in:
Nitload
2024-05-28 17:45:54 +08:00
parent de399e22c2
commit 70890e3e33
88 changed files with 10678 additions and 5761 deletions
@@ -30,9 +30,12 @@
//-----------------------------------------------------------------------
using StgSharp.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -52,59 +55,64 @@ namespace StgSharp.Logic
/// Reset pipeline has risk, this operation is a direct operation to port
/// in current node, the port on the other node cannot get the change.
/// </risk>
#pragma warning disable CA1036
public class BlueprintNode : IComparable<BlueprintNode>
#pragma warning restore CA1036
{
private Blueprint local;
private BlueprintNodeAction mainOperation;
private bool levelAvailabel, nativeRequested;
private int level;
private protected bool levelAvailable, nativeRequested;
private protected int _level;
private string name;
protected Dictionary<string, BlueprintPipeline> inputInterfaces;
protected Dictionary<string, BlueprintPipeline> outputInterfaces;
private protected Dictionary<string, BlueprintPipeline> _inputInterfaces;
private protected Dictionary<string, BlueprintPipeline> _outputInterfaces;
internal BlueprintNode(string name,
BlueprintNodeAction operation, bool isNative,
string[] inputPorts,
string[] outputPorts)
{
this.levelAvailabel = false;
this.levelAvailable = false;
this.name = name;
nativeRequested = isNative;
mainOperation = operation;
inputInterfaces = new Dictionary<string, BlueprintPipeline>();
outputInterfaces = new Dictionary<string, BlueprintPipeline>();
if (inputPorts.Length * outputPorts.Length == 0)
_inputInterfaces = new Dictionary<string, BlueprintPipeline>();
_outputInterfaces = new Dictionary<string, BlueprintPipeline>();
if (inputPorts.Length == 0 )
{
throw new Exception();
throw new ArgumentNullException(nameof(inputPorts));
}
if (outputPorts.Length == 0)
{
throw new ArgumentNullException(nameof(outputPorts));
}
foreach (var portName in inputPorts)
{
inputInterfaces.Add(portName, null);
_inputInterfaces.Add(portName, null);
}
foreach (var portName in outputPorts)
{
outputInterfaces.Add(portName, null);
_outputInterfaces.Add(portName, null);
}
}
public BlueprintNode(string name, IConvertableToBlueprintNode convertable)
{
this.levelAvailabel = false;
this.levelAvailable = false;
this.name = name;
inputInterfaces = new Dictionary<string, BlueprintPipeline>();
outputInterfaces = new Dictionary<string, BlueprintPipeline>();
_inputInterfaces = new Dictionary<string, BlueprintPipeline>();
_outputInterfaces = new Dictionary<string, BlueprintPipeline>();
mainOperation = convertable.MainExecution;
foreach (var soket in convertable.InputInterfacesName)
{
inputInterfaces.Add(soket, null);
_inputInterfaces.Add(soket, null);
}
foreach (var soket in convertable.OutputInterfacesName)
{
outputInterfaces.Add(soket, null);
_outputInterfaces.Add(soket, null);
}
}
@@ -113,21 +121,21 @@ namespace StgSharp.Logic
string[] outputPorts
)
{
this.levelAvailabel = false;
this.levelAvailable = false;
this.name = name;
inputInterfaces = new Dictionary<string, BlueprintPipeline>();
outputInterfaces = new Dictionary<string, BlueprintPipeline>();
_inputInterfaces = new Dictionary<string, BlueprintPipeline>();
_outputInterfaces = new Dictionary<string, BlueprintPipeline>();
if (inputPorts.Length * outputPorts.Length == 0)
{
throw new Exception();
}
foreach (var portName in inputPorts)
{
inputInterfaces.Add(portName, null);
_inputInterfaces.Add(portName, null);
}
foreach (var portName in outputPorts)
{
outputInterfaces.Add(portName, null);
_outputInterfaces.Add(portName, null);
}
}
@@ -136,35 +144,36 @@ namespace StgSharp.Logic
get => nativeRequested;
internal set => nativeRequested = value;
}
public int Level
{
get
{
if (levelAvailabel)
if (levelAvailable)
{
return level;
return _level;
}
level = 0;
foreach (var item in inputInterfaces)
_level = 0;
foreach (var item in _inputInterfaces)
{
if (item.Value == null)
{
continue;
}
if (level <= item.Value.Level)
if (_level <= item.Value.Level)
{
level = item.Value.Level;
_level = item.Value.Level;
}
}
level += 1;
return level;
_level += 1;
return _level;
}
}
public string Name => name;
internal Dictionary<string, BlueprintPipeline> InputInterfaces => inputInterfaces;
internal Dictionary<string, BlueprintPipeline> OutputInterfaces => outputInterfaces;
internal Dictionary<string, BlueprintPipeline> InputInterfaces => _inputInterfaces;
internal Dictionary<string, BlueprintPipeline> OutputInterfaces => _outputInterfaces;
public void AddAfter(
@@ -172,7 +181,7 @@ namespace StgSharp.Logic
string formerOutputPortName,
string thisInputPortName)
{
this.levelAvailabel = false;
this.levelAvailable = false;
BlueprintPipeline pipeline = new BlueprintPipeline(former, this);
if (former is BeginningNode bnode)
{
@@ -191,7 +200,7 @@ namespace StgSharp.Logic
string thisOutputPortName,
string afterInputPortName)
{
this.levelAvailabel = false;
this.levelAvailable = false;
BlueprintPipeline pipeline = new BlueprintPipeline(this, after);
if (after is EndingNode enode)
{
@@ -210,8 +219,8 @@ namespace StgSharp.Logic
try
{
//Console.WriteLine(name);
BlueprintPipeline.WaitAll(inputInterfaces);
mainOperation(in inputInterfaces, in outputInterfaces);
BlueprintPipeline.WaitAll(_inputInterfaces);
mainOperation(in _inputInterfaces, in _outputInterfaces);
}
catch (Exception)
{
@@ -219,55 +228,58 @@ namespace StgSharp.Logic
}
}
int IComparable<BlueprintNode>.CompareTo(BlueprintNode other)
public int CompareTo(BlueprintNode other)
{
#pragma warning disable CA1062
return this.Level.CompareTo(other.Level);
#pragma warning restore CA1062
}
#region port operation
public BlueprintPipeline GetCertainInputPort(string name)
{
if (!inputInterfaces.ContainsKey(name))
BlueprintPipeline ret;
if (!_inputInterfaces.TryGetValue(name,out ret))
{
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
}
return inputInterfaces[name];
return ret;
}
public BlueprintPipeline GetCertainOutputPort(string name)
{
if (!outputInterfaces.ContainsKey(name))
BlueprintPipeline ret;
if (!_outputInterfaces.TryGetValue(name, out ret))
{
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
}
return outputInterfaces[name];
return ret;
}
public void SetCertainInputPort(string name, BlueprintPipeline pipeline)
{
if (!inputInterfaces.ContainsKey(name))
if (!_inputInterfaces.ContainsKey(name))
{
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
}
inputInterfaces[name] = pipeline;
_inputInterfaces[name] = pipeline;
}
public void SetCertainOutputPort(string name, BlueprintPipeline pipeline)
{
if (!outputInterfaces.ContainsKey(name))
if (!_outputInterfaces.ContainsKey(name))
{
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
}
outputInterfaces[name] = pipeline;
_outputInterfaces[name] = pipeline;
}
#endregion
}//--------------------------------- end of class -----------------------------
}//--------------------------------- end of class -----------------------------------
public interface IConvertableToBlueprintNode
{
@@ -280,15 +292,25 @@ namespace StgSharp.Logic
public class BlueprintNodeRunException : Exception
{
public BlueprintNodeRunException()
{
}
public BlueprintNodeRunException(Exception ex) : base(string.Empty, ex)
{
}
public BlueprintNodeRunException(string message, Exception ex) : base(message, ex)
public BlueprintNodeRunException(string message) : base(message)
{
}
public BlueprintNodeRunException(string message, Exception innerException) : base(message, innerException)
{
}
protected BlueprintNodeRunException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}