protected override IOAttribute DefinePin(string name, Type type, int binSize = -1) { var attr = new OutputAttribute(name); attr.BinVisibility = PinVisibility.Hidden; attr.Order = 1; attr.BinOrder = 2; attr.AutoFlush = false; // need to sync all pins manually return attr; }
#pragma warning restore protected override IOAttribute DefinePin(string name, Type type, int binSize = -1) { var attr = new OutputAttribute(name); attr.BinVisibility = PinVisibility.Hidden; attr.AutoFlush = false; attr.Order = FCount; attr.BinOrder = FCount + 1; return attr; }
protected void CreatePins(int count) { if (pd.OutputPins.Count < count) { for (int i = pd.OutputPins.Count; i < count; i++) { int ii = i + 1; var attr = new OutputAttribute("Output " + ii); attr.Order = i * 2; attr.BinOrder = i * 2 + 1; pd.AddOutput(typeof(object), attr); } } if (pd.OutputPins.Count > count) { for (int i = pd.OutputPins.Count - 1; i >= count; i--) { int ii = i + 1; string name = "Output " + ii; pd.RemoveOutput(name); } } }
public static List <OutputAttribute> OutputAttributes(this MethodBase method) { if (method.IsMultipleOutputs()) { Dictionary <int, MultiOutputAttribute> outputDefs = method.GetCustomAttributes <MultiOutputAttribute>().ToDictionary(x => x.Index); Type[] types = method.OutputType().GetGenericArguments(); List <OutputAttribute> outputs = new List <OutputAttribute>(); for (int i = 0; i < types.Length; i++) { if (outputDefs.ContainsKey(i)) { outputs.Add(new OutputAttribute(outputDefs[i].Name, outputDefs[i].Description)); } else { outputs.Add(new OutputAttribute(types[i].UnderlyingType().Type.Name.Substring(0, 1), "")); } } return(outputs); } else { OutputAttribute attribute = method.GetCustomAttribute <OutputAttribute>(); if (attribute != null) { return new List <OutputAttribute> { attribute } } ; else { return(new List <OutputAttribute>()); } } }
/// <summary>Gets the child elements of this element.</summary> /// <param name="parent">The parent element's context.</param> /// <returns>Enumeration of elements.</returns> public virtual IEnumerable <ElementContext> GetElements(ElementContext parent) { IEnumerable <(object, OutputAttribute)> values = this.GetValues(parent) .Concat(this.GetAdditionalValues()); if (parent.OutputAttribute.AdditionalItems != null) { values = values.Concat(parent.OutputAttribute.AdditionalItems); } Keyword[] excludeKeywords = parent.OutputAttribute.ExcludeKeywords; if (excludeKeywords == null && parent.Parent?.Element is SceneItemWrapper <SceneItem> ) { excludeKeywords = parent.Parent.OutputAttribute.ExcludeKeywords; } foreach ((object valueOrig, OutputAttribute output) in values) { object value = valueOrig; if (value == null || value is IValue v && !v.HasValue) { continue; } if (output != null) { if (output.Wrapper && value is SceneItem item) { value = new SceneItemWrapper <SceneItem>(item); } } OutputAttribute outputAttribute = OutputAttribute.Combine(value.GetType().GetAllAttributes <OutputAttribute>()); if (output != null) { outputAttribute.Combine(output); } if (outputAttribute.Ignore) { continue; } if (outputAttribute.PovVersion > parent.Scene.PovVersion) { continue; } if (excludeKeywords != null) { if (excludeKeywords.Contains(outputAttribute.Keyword)) { continue; } } SceneElement element = value as SceneElement ?? SceneElement.CreateElement(value, outputAttribute); ElementContext context = new ElementContext(parent, element, outputAttribute); yield return(context); } }
/// <summary>Create an element for a non-element object</summary> /// <param name="value"></param> /// <param name="outputAttribute"></param> /// <returns></returns> public static SceneElement CreateElement(object value, OutputAttribute outputAttribute) { return(Activator.CreateInstance( outputAttribute.ElementType ?? typeof(ValueElement), value, outputAttribute) as SceneElement); }
/// <summary> /// Creates a new instance of output parameter for the given property. /// </summary> private static BaseParameter CreateOutputParameter(GisTool tool, PropertyInfo prop, OutputAttribute attr) { var param = CreateParameter(prop.PropertyType, prop); param.ControlHint = prop.GetAttribute <ControlHintAttribute>(); param.Tool = tool; param.ToolProperty = prop; param.Name = prop.Name; param.DisplayName = attr.DisplayName; param.Required = true; param.IsInput = false; param.Index = attr.Index; var olp = param as OutputLayerParameter; if (olp != null) { var layerAttr = prop.GetAttribute <OutputLayerAttribute>(); if (layerAttr != null) { olp.DefaultValue = layerAttr.NameTemplate; olp.SupportInMemory = layerAttr.SupportsInMemory; olp.LayerType = layerAttr.LayerType; } } return(param); }
private IEnumerable <int[]> _GenerateSortedIndexArrays() { //if (StringId == "SOUNDS") //{ // int bp = 0; //} bool appliedPrecedenceHack = false; int[][] sortedIndexArrays = new int[4][]; try // the PrecedenceHack must be reversed if anything f***s up { FieldInfo rowHeaderField = DataType.GetField("header", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (FieldInfo fieldInfo in DataType.GetFields()) { OutputAttribute attribute = GetExcelAttribute(fieldInfo); if (attribute == null || attribute.SortColumnOrder == 0) { continue; } // Precedence Hack - excel files order special characters differently to convention if (!appliedPrecedenceHack) { _DoPrecedenceHack(fieldInfo, attribute); appliedPrecedenceHack = true; } int pos = attribute.SortColumnOrder - 1; // need to order by string, not string offset if (attribute.IsStringOffset) { var sortedList = from element in Rows let rowHeader = (RowHeader)rowHeaderField.GetValue(element) where (rowHeader.Unknown1 != 0x02 && (rowHeader.Unknown2 >= 0x38 && rowHeader.Unknown2 <= 0x3F || rowHeader.Unknown2 == 0x01) && // 56 to 63 or 1 (rowHeader.VersionMajor == 0 || rowHeader.VersionMajor == 10)) group element by fieldInfo.GetValue(element) into groupedElements let elementFirst = groupedElements.First() orderby ReadStringTable((int)fieldInfo.GetValue(elementFirst)) select Rows.IndexOf(elementFirst); sortedIndexArrays[pos] = sortedList.ToArray(); } // we don't want '-1' rows for not-present secondary strings else if (attribute.IsSecondaryString) { var sortedList = from element in Rows let rowHeader = (RowHeader)rowHeaderField.GetValue(element) where (rowHeader.Unknown1 != 0x02 && (rowHeader.Unknown2 >= 0x38 && rowHeader.Unknown2 <= 0x3F || rowHeader.Unknown2 == 0x01) && (rowHeader.VersionMajor == 0 || rowHeader.VersionMajor == 10)) && fieldInfo.GetValue(element).ToString() != "-1" group element by fieldInfo.GetValue(element) into groupedElements let elementFirst = groupedElements.First() orderby fieldInfo.GetValue(elementFirst) select Rows.IndexOf(elementFirst); sortedIndexArrays[pos] = sortedList.ToArray(); } // with two column sorting we don't group else if (!String.IsNullOrEmpty(attribute.SecondarySortColumn)) { FieldInfo sortBy2 = DataType.GetField(attribute.SecondarySortColumn); var sortedList = from element in Rows let rowHeader = (RowHeader)rowHeaderField.GetValue(element) where (rowHeader.Unknown1 != 0x02 && (rowHeader.Unknown2 >= 0x38 && rowHeader.Unknown2 <= 0x3F || rowHeader.Unknown2 == 0x01) && (rowHeader.VersionMajor == 0 || rowHeader.VersionMajor == 10)) orderby fieldInfo.GetValue(element), sortBy2.GetValue(element) select Rows.IndexOf(element); sortedIndexArrays[pos] = sortedList.ToArray(); } // main sorting else { var sortedList = from element in Rows let rowHeader = (RowHeader)rowHeaderField.GetValue(element) where (rowHeader.Unknown1 != 0x02 && (rowHeader.Unknown2 >= 0x38 && rowHeader.Unknown2 <= 0x3F || rowHeader.Unknown2 == 0x01) && (rowHeader.VersionMajor == 0 || rowHeader.VersionMajor == 10)) group element by fieldInfo.GetValue(element) into groupedElements let elementFirst = groupedElements.First() orderby fieldInfo.GetValue(elementFirst) select Rows.IndexOf(elementFirst); sortedIndexArrays[pos] = sortedList.ToArray(); } } } finally { if (appliedPrecedenceHack) { _UndoPrecedenceHack(); } } return(sortedIndexArrays); }
private void ManageDiffOutput(IDiffSpread<bool> advanced) { if (FAdvanced[0]) { Keep.QuickMode = false; var ia = new InputAttribute("Include input in Diff"); ia.Order = 2; ia.IsSingle = true; ia.IsToggle = true; ia.DefaultBoolean = true; Type pinType = typeof(IDiffSpread<>).MakeGenericType(typeof(bool)); DoAllChange = FIOFactory.CreateIOContainer(pinType, ia); var pin = DoAllChange.RawIOObject as IDiffSpread<bool>; pin.Changed += UpdateChangeAll; var attr = new OutputAttribute("Message Diff"); attr.AutoFlush = false; attr.Order = 2; pinType = typeof(Pin<>).MakeGenericType(typeof(Message)); Change = FIOFactory.CreateIOContainer(pinType, attr); FChangeOut = Change.RawIOObject as Pin<Message>; attr = new OutputAttribute("Changed Message Index"); attr.AutoFlush = false; attr.Order = 3; pinType = typeof(ISpread<>).MakeGenericType(typeof(int)); ChangeIndex = FIOFactory.CreateIOContainer(pinType, attr); FChangeIndexOut = ChangeIndex.RawIOObject as Pin<int>; } else { Keep.QuickMode = true; if (DoAllChange!= null) { DoAllChange.Dispose(); DoAllChange = null; ManageAllChanges = true; } if (ChangeIndex != null) { ChangeIndex.Dispose(); ChangeIndex = null; FChangeIndexOut = null; } if (FChangeOut != null) { Change.Dispose(); Change = null; FChangeOut = null; } } }
void FLayout_Changed(IDiffSpread<string> spread) { foreach (IIOContainer sp in this.outspreads) { sp.Dispose(); } this.outspreads.Clear(); layout = spread[0].Split(",".ToCharArray()); int id = 1; foreach (string lay in layout) { OutputAttribute attr = new OutputAttribute("Output " + id.ToString()); IIOContainer container = null; switch (lay) { case "float": container = this.FIO.CreateIOContainer<ISpread<float>>(attr); break; case "float2": container = this.FIO.CreateIOContainer<ISpread<Vector2>>(attr); break; case "float3": container = this.FIO.CreateIOContainer<ISpread<Vector3>>(attr); break; case "float4": container = this.FIO.CreateIOContainer<ISpread<Vector4>>(attr); break; case "float4x4": container = this.FIO.CreateIOContainer<ISpread<Matrix>>(attr); break; case "int": container = this.FIO.CreateIOContainer<ISpread<int>>(attr); break; case "uint": container = this.FIO.CreateIOContainer<ISpread<uint>>(attr); break; case "uint2": //attr.AsInt = true; container = this.FIO.CreateIOContainer<ISpread<Vector2>>(attr); break; case "uint3": //attr.AsInt = true; container = this.FIO.CreateIOContainer<ISpread<Vector3>>(attr); break; } if (container != null) { this.outspreads.Add(container); id++; } } }
protected override void InitializeView() { base.InitializeView(); Type nodeType = ScriptNodeData.GetType(); //Debug.Log($"Node 0x{Id:X} of type {nodeType}"); var connections = nodeType.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) .Where(x => Attribute.IsDefined(x, typeof(ConnectionAttribute))); foreach (FieldInfo connection in connections) { ConnectionAttribute attr = connection.GetCustomAttribute <ConnectionAttribute>(); if (attr.ConnectionDirection != ConnectionAttribute.Direction.Input) { continue; } //Debug.Log($"Add input connection {attr.Name} to node 0x{Id:X}"); ScriptNodePortData inputPort = (ScriptNodePortData)connection.GetValue(ScriptNodeData); ScriptViewPort port = new ScriptViewPort(this, inputPort, Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(ScriptNodePortData)) { portName = attr.Name }; port.AddManipulator(new EdgeConnector <Edge>(EdgeConnectorListener)); Add(port); } var inputs = nodeType.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) .Where(x => Attribute.IsDefined(x, typeof(InputAttribute))); foreach (FieldInfo input in inputs) { InputAttribute attr = input.GetCustomAttribute <InputAttribute>(); //Debug.Log($"Add input {attr.Name} of type {attr.Type} to node 0x{Id:X}"); ScriptNodePortData inputPort = (ScriptNodePortData)input.GetValue(ScriptNodeData); ScriptViewPort port = new ScriptViewPort(this, inputPort, Orientation.Horizontal, Direction.Input, Port.Capacity.Single, attr.Type) { portName = attr.Name }; port.AddManipulator(new EdgeConnector <Edge>(EdgeConnectorListener)); Add(port); } foreach (FieldInfo connection in connections) { ConnectionAttribute attr = connection.GetCustomAttribute <ConnectionAttribute>(); if (attr.ConnectionDirection != ConnectionAttribute.Direction.Output) { continue; } //Debug.Log($"Add output connection {attr.Name} to node 0x{Id:X}"); ScriptNodePortData outputPort = (ScriptNodePortData)connection.GetValue(ScriptNodeData); ScriptViewPort port = new ScriptViewPort(this, outputPort, Orientation.Horizontal, Direction.Output, Port.Capacity.Single, typeof(ScriptNodePortData)) { portName = attr.Name }; port.AddManipulator(new EdgeConnector <Edge>(EdgeConnectorListener)); Add(port); } var outputs = nodeType.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) .Where(x => Attribute.IsDefined(x, typeof(OutputAttribute))); foreach (FieldInfo output in outputs) { OutputAttribute attr = output.GetCustomAttribute <OutputAttribute>(); //Debug.Log($"Add output {attr.Name} of type {attr.Type} to node 0x{Id:X}"); ScriptNodePortData outputPort = (ScriptNodePortData)output.GetValue(ScriptNodeData); ScriptViewPort port = new ScriptViewPort(this, outputPort, Orientation.Horizontal, Direction.Output, Port.Capacity.Single, attr.Type) { portName = attr.Name }; port.AddManipulator(new EdgeConnector <Edge>(EdgeConnectorListener)); Add(port); } }
private void Pinmode_Changed(IDiffSpread<eDepthBufferMode> spread) { if (this.currentmode != spread[0]) { if (this.currentmode == eDepthBufferMode.Standard) { if (this.depthoutputpin != null) { //Destroy depth stencil if (this.depthoutputpin.IOObject[0] != null) { this.depthoutputpin.IOObject[0].Dispose(); } this.depthoutputpin.Dispose(); this.depthformatpin.Dispose(); this.depthformatpin = null; this.depthoutputpin = null; } } if (this.currentmode == eDepthBufferMode.ReadOnly) { if (this.depthinputpin != null) { this.depthinputpin.Dispose(); this.depthinputpin = null; } } this.currentmode = spread[0]; if (this.currentmode == eDepthBufferMode.Standard) { OutputAttribute oattr = new OutputAttribute("Depth Buffer"); oattr.IsSingle = true; this.depthoutputpin = this.factory.CreateIOContainer<Pin<DX11Resource<DX11DepthStencil>>>(oattr); this.depthoutputpin.IOObject[0] = new DX11Resource<DX11DepthStencil>(); ConfigAttribute dfAttr = new ConfigAttribute("Depth Buffer Format"); dfAttr.EnumName = DX11EnumFormatHelper.NullDeviceFormats.GetEnumName(FormatSupport.DepthStencil); dfAttr.DefaultEnumEntry = DX11EnumFormatHelper.NullDeviceFormats.GetAllowedFormats(FormatSupport.DepthStencil)[0]; dfAttr.IsSingle = true; this.depthformatpin = this.factory.CreateIOContainer<IDiffSpread<EnumEntry>>(dfAttr); this.depthformatpin.IOObject[0] = new EnumEntry(dfAttr.EnumName, 1); this.depthformatpin.IOObject.Changed += depthformatpin_Changed; } if (this.currentmode == eDepthBufferMode.ReadOnly) { InputAttribute oattr = new InputAttribute("Depth Buffer"); oattr.IsSingle = true; this.depthinputpin = this.factory.CreateIOContainer<Pin<DX11Resource<DX11DepthStencil>>>(oattr); } this.NeedReset = true; } }
public OutputBinSpread(IIOFactory ioFactory, OutputAttribute attribute, IIOContainer <IOutStream <int> > binSizeIOContainer) : this(ioFactory, attribute, new OutputBinSpreadStream(ioFactory, attribute, _ => binSizeIOContainer)) { }
public OutputBinSpreadStream(IIOFactory ioFactory, OutputAttribute attribute) : this(ioFactory, attribute, c => ioFactory.CreateIOContainer <IOutStream <int> >(attribute.GetBinSizeOutputAttribute(c), false)) { FOwnsBinSizeContainer = true; }
//create pins public override void OnImportsSatisfied() { base.OnImportsSatisfied(); var tempSig = new TSignal(); var t = tempSig.GetType(); var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; //Retrieve all FieldInfos var fields = t.GetFields(flags); foreach (var fi in fields) { if (typeof(SigParamBase).IsAssignableFrom(fi.FieldType)) { var param = (SigParamBase)fi.GetValue(tempSig); var valType = param.GetValueType(); if (!param.IsOutput) { var ia = new InputAttribute(param.Name); ia.Order = param.PinOrder; var spreadType = typeof(IDiffSpread <>).MakeGenericType(valType); if (valType == typeof(double)) { ia.DefaultValue = (double)param.GetDefaultValue(); } else if (valType == typeof(float)) { ia.DefaultValue = (float)param.GetDefaultValue(); } else if (valType == typeof(int)) { ia.DefaultValue = (int)param.GetDefaultValue(); } else if (valType == typeof(long)) { ia.DefaultValue = (long)param.GetDefaultValue(); } else if (valType == typeof(float[])) { spreadType = typeof(IDiffSpread <>).MakeGenericType(typeof(ISpread <float>)); } else if (valType == typeof(int[])) { spreadType = typeof(IDiffSpread <>).MakeGenericType(typeof(ISpread <int>)); } else if (valType == typeof(double[])) { spreadType = typeof(IDiffSpread <>).MakeGenericType(typeof(ISpread <double>)); } else if (typeof(Enum).IsAssignableFrom(valType)) { ia.DefaultEnumEntry = param.GetDefaultValue().ToString(); } else { if (param is SigParamBang) { ia.IsBang = true; } } var inPin = (IDiffSpread)FIOFactory.CreateIO(spreadType, ia); FInputPins[param.Name] = inPin; FDiffInputs.Add(inPin); } else //output { var oa = new OutputAttribute(param.Name); oa.Order = param.PinOrder; var spreadType = typeof(ISpread <>).MakeGenericType(valType); //array types need Spread<Spread<T>> if (valType == typeof(float[])) { spreadType = typeof(ISpread <>).MakeGenericType(typeof(ISpread <float>)); } else if (valType == typeof(int[])) { spreadType = typeof(ISpread <>).MakeGenericType(typeof(ISpread <int>)); } else if (valType == typeof(double[])) { spreadType = typeof(ISpread <>).MakeGenericType(typeof(ISpread <double>)); } var outPin = (ISpread)FIOFactory.CreateIO(spreadType, oa); FOutputPins[param.Name] = outPin; } } } tempSig.Dispose(); }
public void Evaluate(int SpreadMax) { if (this.FCfgShowStack.IsChanged) { if (this.FCfgShowStack[0]) { if (this.FOutputFull == null) { OutputAttribute attr = new OutputAttribute("Stack"); attr.Order = 10000; this.FOutputFull = this.FIOFactory.CreateIOContainer <ISpread <ISpread <T> > >(attr); } } else { if (this.FOutputFull != null) { this.FOutputFull.Dispose(); this.FOutputFull = null; } } } //Update Stack size if (FPinInStackSize.IsChanged) { FStackSize = FPinInStackSize[0]; } if (this.FPinInReset[0]) { FStack.Clear(); if (FPinDefault.SliceCount > 0) { for (int i = 0; i < this.FPinDefault.SliceCount; i++) { FStack.Push(FPinDefault[i].ToList()); } } } else { //Push spread in the stack if required if (FPinInPush[0] && FPinInput.SliceCount > 0) { FStack.Push(FPinInput.ToList()); } //Pop as many items as required to reduce buffer size if (FStackSize >= 0) { while (this.FStack.Count > FStackSize) { FStack.Pop(); } } //Pop an element off the stack and output it if (FPinInPop[0] && this.FStack.Count > 0) { List <T> output = FStack.Pop(); FPinOutput.SliceCount = output.Count; for (int i = 0; i < output.Count; i++) { FPinOutput[i] = output[i]; } } else { FPinOutput.SliceCount = 0; } //Output stack size this.FPinOutStackSize.SliceCount = 1; this.FPinOutStackSize[0] = this.FStack.Count; //Show top level spread if (this.FStack.Count > 0) { List <T> peek = FStack.Peek(); FPinOutPeek.SliceCount = peek.Count; for (int i = 0; i < peek.Count; i++) { FPinOutPeek[i] = peek[i]; } } else { this.FPinOutPeek.SliceCount = 0; } } if (this.FOutputFull != null) { var output = this.FOutputFull.IOObject; output.SliceCount = this.FStack.Count; List <List <T> > lst = this.FStack.ToList(); for (int i = 0; i < this.FStack.Count; i++) { output[i].AssignFrom(lst[i]); } } }
public OutputSpreadList(IIOFactory ioFactory, OutputAttribute attribute) : base(ioFactory, attribute) { }
/// <summary>Gets objects and their output attributes from this element</summary> /// <param name="parent">The element context of the parent element.</param> /// <returns></returns> protected virtual IEnumerable <(object value, OutputAttribute output)> GetValues(ElementContext parent) { string[] excludeMembers = parent.OutputAttribute.ExcludeMembers; if (excludeMembers == null && parent.Parent?.Element is SceneItemWrapper <SceneItem> ) { excludeMembers = parent.Parent.OutputAttribute.ExcludeMembers; } foreach ((object value, MemberInfo type, OutputAttribute output) in this.GetProperties()) { OutputAttribute outputAttr; if (type is PropertyInfo propertyInfo) { if (excludeMembers != null && excludeMembers.Length > 0) { if (excludeMembers.Contains(type.Name)) { continue; } } OutputAttribute[] propertyAttrs = type.GetCustomAttributesFast <OutputAttribute>().ToArray(); if (propertyAttrs.Length == 0) { // Property has no Output attribute continue; } // Combine the attributes of the property outputAttr = OutputAttribute.Combine(propertyAttrs); if (output != null) { outputAttr.Combine(output); } outputAttr.Depth = propertyInfo.GetPropertyInheritanceDepth(); outputAttr.PropertyName = propertyInfo.Name; } else { outputAttr = output; } if (value is ICollection enumerable) { int index = 0; if (enumerable.Cast <object>().All(e => e == null)) { continue; } if (!outputAttr.IsCollection) { outputAttr.IsCollection = true; // Unwrap the enumeration foreach (SceneElement element in enumerable.OfType <SceneElement>()) { outputAttr.Index = index++; yield return(element, outputAttr); } continue; } } yield return(value, outputAttr); } }
void FLayout_Changed(IDiffSpread <string> spread) { foreach (IIOContainer sp in this.outspreads) { sp.Dispose(); } this.outspreads.Clear(); layout = spread[0].Split(",".ToCharArray()); int id = 1; foreach (string lay in layout) { OutputAttribute attr = new OutputAttribute("Output " + id.ToString()); IIOContainer container = null; switch (lay) { case "float": container = this.FIO.CreateIOContainer <ISpread <float> >(attr); break; case "float2": container = this.FIO.CreateIOContainer <ISpread <Vector2> >(attr); break; case "float3": container = this.FIO.CreateIOContainer <ISpread <Vector3> >(attr); break; case "float4": container = this.FIO.CreateIOContainer <ISpread <Vector4> >(attr); break; case "float4x4": container = this.FIO.CreateIOContainer <ISpread <Matrix> >(attr); break; case "int": container = this.FIO.CreateIOContainer <ISpread <int> >(attr); break; case "uint": container = this.FIO.CreateIOContainer <ISpread <uint> >(attr); break; case "uint2": //attr.AsInt = true; container = this.FIO.CreateIOContainer <ISpread <Vector2> >(attr); break; case "uint3": //attr.AsInt = true; container = this.FIO.CreateIOContainer <ISpread <Vector3> >(attr); break; } if (container != null) { this.outspreads.Add(container); id++; } } }
protected override IOAttribute DefinePin(FormularFieldDescriptor field) { var attr = new OutputAttribute("Field"); attr.BinVisibility = PinVisibility.Hidden; attr.Order = 1; attr.BinOrder = 2; attr.AutoFlush = false; // need to sync all pins manually return attr; }
/// <summary> /// Creates a ExcelFile based on the DataTable data. /// </summary> /// <param name="dataTable">The DataTable to read the data from.</param> /// <param name="fileManager">The FileManager to use for script compilations etc.</param> /// <returns>True if the DataTable parsed okay.</returns> public override bool ParseDataTable(DataTable dataTable, FileManager fileManager) { if (dataTable == null) throw new ArgumentNullException("dataTable", "DataTable can not be null!"); if (fileManager == null) throw new ArgumentNullException("fileManager", "FileManager can not be null!"); byte[] newStringBuffer = null; int newStringBufferOffset = 0; byte[] newScriptBuffer = (Attributes.HasScriptTable) ? new byte[1024] : null; int newScriptBufferOffset = 0; // don't start at 1 as it will resize the array wrong byte[][] newStatsBuffer = null; List<String> newSecondaryStrings = null; List<Object> newRows = new List<Object>(); bool failedParsing = false; const BindingFlags bindingFlags = (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo[] dataFields = DataType.GetFields(bindingFlags); OutputAttribute[] excelAttributes; ObjectDelegator objectDelegator; if (fileManager == null || !fileManager.DataFileDelegators.ContainsKey(StringId)) { FieldInfo[] fieldInfos = DataType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); objectDelegator = new ObjectDelegator(fieldInfos); excelAttributes = new OutputAttribute[fieldInfos.Length]; } else { objectDelegator = fileManager.DataFileDelegators[StringId]; excelAttributes = new OutputAttribute[objectDelegator.FieldCount]; } for (int row = 0; row < dataTable.Rows.Count; row++) { int col = 1; // Skip the indice column (column 0) Object rowInstance = Activator.CreateInstance(DataType); foreach (ObjectDelegator.FieldDelegate fieldDelegate in objectDelegator) { //if (fieldInfo.Name == "warpToFloor") //{ // int bp = 0; //} OutputAttribute attribute = GetExcelAttribute(fieldDelegate.Info); // Initialize private fields if (fieldDelegate.IsPrivate) { // will be in DataTable (first column) if (fieldDelegate.FieldType == typeof(RowHeader)) { String headerString = (String)dataTable.Rows[row][col++]; RowHeader rowHeader = FileTools.StringToObject<RowHeader>(headerString, ",", RowHeaderFields); fieldDelegate.SetValue(rowInstance, rowHeader); continue; } // will not be in DataTable MarshalAsAttribute arrayMarshal = null; Array arrayInstance = null; if (fieldDelegate.FieldType.BaseType == typeof(Array)) { arrayMarshal = (MarshalAsAttribute)fieldDelegate.Info.GetCustomAttributes(typeof(MarshalAsAttribute), false).First(); arrayInstance = (Array)Activator.CreateInstance(fieldDelegate.FieldType, arrayMarshal.SizeConst); fieldDelegate.SetValue(rowInstance, arrayInstance); } else if (fieldDelegate.FieldType == typeof(String)) { fieldDelegate.SetValue(rowInstance, String.Empty); } // assign constant non-zero values if (attribute == null || attribute.ConstantValue == null) continue; if (fieldDelegate.FieldType.BaseType == typeof(Array)) { Debug.Assert(arrayInstance != null, "arrayInstance == null"); Debug.Assert(arrayMarshal != null, "arrayMarshal == null"); for (int i = 0; i < arrayMarshal.SizeConst; i++) { arrayInstance.SetValue(attribute.ConstantValue, i); } } else { objectDelegator[fieldDelegate.Name, rowInstance] = attribute.ConstantValue; } continue; } // Public fields -> these are inside the datatable Object value = dataTable.Rows[row][col++]; bool isArray = (fieldDelegate.FieldType.BaseType == typeof(Array)); if (attribute != null) { if (attribute.IsTableIndex) { if (isArray) { int arraySize = 1; MarshalAsAttribute arrayMarshal = (MarshalAsAttribute)fieldDelegate.Info.GetCustomAttributes(typeof(MarshalAsAttribute), false).First(); arraySize = arrayMarshal.SizeConst; Debug.Assert(arraySize > 0); String strValue = value.ToString(); String[] indexStrs = strValue.Split(new[] { ',' }); Int32[] rowIndexValues = new int[arraySize]; for (int i = 0; i < arraySize; i++) rowIndexValues[i] = -1; int maxElements = indexStrs.Length; if (maxElements > arraySize) { Debug.WriteLine(String.Format("{0}: Loss of array elements detected. row = {1}, col = {2}.", StringId, row, col)); maxElements = arraySize; } int[] rowIndices = new int[maxElements]; for (int i = 0; i < maxElements; i++) { rowIndices[i] = int.Parse(indexStrs[i]); } objectDelegator[fieldDelegate.Name, rowInstance] = rowIndices; } else { objectDelegator[fieldDelegate.Name, rowInstance] = int.Parse(value.ToString()); } // we need to make sure the following data column is a relational column; some tables (and thus the relational column) aren't present, even though the column "links" to them (e.g. LEVEL_AREAS) DataColumn dataColumn = dataTable.Columns[col]; if (dataColumn.ExtendedProperties.ContainsKey(ColumnTypeKeys.IsRelationGenerated) && (bool)dataColumn.ExtendedProperties[ColumnTypeKeys.IsRelationGenerated]) { col++; } continue; } if (attribute.IsStringIndex) { fieldDelegate.SetValue(rowInstance, value); col++; // Skip lookup continue; } if (attribute.IsStringOffset) { String strValue = value as String; if (strValue == null) throw new Exception("A script was not presented as a String!"); if (newStringBuffer == null) { newStringBuffer = new byte[1024]; } if (String.IsNullOrEmpty(strValue)) // i.e. is empty { fieldDelegate.SetValue(rowInstance, -1); continue; } fieldDelegate.SetValue(rowInstance, newStringBufferOffset); FileTools.WriteToBuffer(ref newStringBuffer, ref newStringBufferOffset, FileTools.StringToASCIIByteArray(strValue)); FileTools.WriteToBuffer(ref newStringBuffer, ref newStringBufferOffset, (byte)0x00); continue; } if (attribute.IsScript) { String strValue = value as String; if (strValue == null || (fileManager == null && strValue == "0") || strValue == "") { objectDelegator[fieldDelegate.Name, rowInstance] = 0; continue; } //if (strValue == "GetStat666('skill_points_bonus_total', '') > -1;") //{ // int bp = 0; //} int[] scriptByteCode; int firstComma = -1; // is it an uncompiled int array if (strValue[0] >= '0' && strValue[0] <= '9') firstComma = strValue.IndexOf(','); if (fileManager != null && (firstComma == -1 || firstComma > 3)) // biggest opcode is 3 digits (this doesn't account for white space, but meh for now) { ExcelScript excelScript = new ExcelScript(fileManager); scriptByteCode = excelScript.Compile(strValue); } else { scriptByteCode = strValue.ToArray<int>(','); } if (newScriptBufferOffset == 0) newScriptBufferOffset++; // 0 = no/null script objectDelegator[fieldDelegate.Name, rowInstance] = newScriptBufferOffset; FileTools.WriteToBuffer(ref newScriptBuffer, ref newScriptBufferOffset, scriptByteCode.ToByteArray()); continue; } if (attribute.IsSecondaryString) { if (newSecondaryStrings == null) newSecondaryStrings = new List<String>(); String strValue = value as String; if (strValue == null) return false; if (String.IsNullOrEmpty(strValue)) { fieldDelegate.SetValue(rowInstance, -1); continue; } if (newSecondaryStrings.Contains(strValue) == false) { newSecondaryStrings.Add(strValue); } fieldDelegate.SetValue(rowInstance, newSecondaryStrings.IndexOf(strValue)); continue; } } try { if (fieldDelegate.FieldType != value.GetType()) // i.e. if the type hasn't been converted yet (no attributes means it wasn't converted above) { if (fieldDelegate.FieldType.BaseType == typeof(Enum)) { value = Enum.Parse(fieldDelegate.FieldType, value.ToString()); } else if (fieldDelegate.FieldType == typeof(Int32[])) { value = ((String)value).ToArray<Int32>(','); } else if (fieldDelegate.FieldType.BaseType == typeof(Array)) { Type elementType = fieldDelegate.FieldType.GetElementType(); if (elementType.BaseType == typeof(Enum)) { String[] enumStrs = ((String)value).Split(new[] { ',' }, StringSplitOptions.None); Array enumsArray = Array.CreateInstance(elementType, enumStrs.Length); int i = 0; foreach (String enumStr in enumStrs) { enumsArray.SetValue(Enum.Parse(elementType, enumStr), i++); } value = enumsArray; } else { throw new NotImplementedException("if (fieldInfo.FieldType.BaseType == typeof(Array)) :: Type = " + elementType.BaseType); } } else { value = Convert.ChangeType(value, fieldDelegate.FieldType); } } fieldDelegate.SetValue(rowInstance, value); } catch (Exception e) { ExceptionLogger.LogException(e); Console.WriteLine("Critical Parsing Error: " + e.Message); failedParsing = true; break; } } if (failedParsing) break; // For item types, items, missiles, monsters etc // This must be a hex byte delimited array if (Attributes.HasStats) { if (newStatsBuffer == null) { newStatsBuffer = new byte[dataTable.Rows.Count][]; } const char split = ','; string value = dataTable.Rows[row][col] as string; if (String.IsNullOrEmpty(value)) { Console.WriteLine("Error parsing stats string."); return false; } string[] stringArray = value.Split(split); byte[] byteArray = new byte[stringArray.Length]; for (int i = 0; i < byteArray.Length; i++) { byteArray[i] = Byte.Parse(stringArray[i]); } newStatsBuffer[row] = byteArray; } newRows.Add(rowInstance); } // Parsing Complete, assign new references. These arn't assigned before now incase of a parsing error. Rows = newRows; _stringBuffer = newStringBuffer; if (_stringBuffer != null) Array.Resize(ref _stringBuffer, newStringBufferOffset); _scriptBuffer = newScriptBuffer; if (_scriptBuffer != null) Array.Resize(ref _scriptBuffer, newScriptBufferOffset); StatsBuffer = newStatsBuffer; SecondaryStrings = newSecondaryStrings; // assign file header details (they are not all the same!) ExcelHeader excelHeader = (ExcelHeader)dataTable.ExtendedProperties["FileHeader"]; _excelFileHeader = excelHeader.DeepClone(); return true; }
private void Pinmode_Changed(IDiffSpread <eDepthBufferMode> spread) { if (this.currentmode != spread[0]) { if (this.currentmode == eDepthBufferMode.Standard) { if (this.depthoutputpin != null) { //Destroy depth stencil if (this.depthoutputpin.IOObject[0] != null) { this.depthoutputpin.IOObject[0].Dispose(); } this.depthoutputpin.Dispose(); this.depthformatpin.Dispose(); this.depthformatpin = null; this.depthoutputpin = null; } } if (this.currentmode == eDepthBufferMode.ReadOnly) { if (this.depthinputpin != null) { this.depthinputpin.Dispose(); this.depthinputpin = null; } } this.currentmode = spread[0]; if (this.currentmode == eDepthBufferMode.Standard) { OutputAttribute oattr = new OutputAttribute("Depth Buffer"); oattr.IsSingle = true; this.depthoutputpin = this.factory.CreateIOContainer <Pin <DX11Resource <DX11DepthStencil> > >(oattr); this.depthoutputpin.IOObject[0] = new DX11Resource <DX11DepthStencil>(); ConfigAttribute dfAttr = new ConfigAttribute("Depth Buffer Format"); dfAttr.EnumName = DX11EnumFormatHelper.NullDeviceFormats.GetEnumName(FormatSupport.DepthStencil); dfAttr.DefaultEnumEntry = DX11EnumFormatHelper.NullDeviceFormats.GetAllowedFormats(FormatSupport.DepthStencil)[0]; dfAttr.IsSingle = true; this.depthformatpin = this.factory.CreateIOContainer <IDiffSpread <EnumEntry> >(dfAttr); this.depthformatpin.IOObject[0] = new EnumEntry(dfAttr.EnumName, 1); this.depthformatpin.IOObject.Changed += depthformatpin_Changed; } if (this.currentmode == eDepthBufferMode.ReadOnly) { InputAttribute oattr = new InputAttribute("Depth Buffer"); oattr.IsSingle = true; this.depthinputpin = this.factory.CreateIOContainer <Pin <DX11Resource <DX11DepthStencil> > >(oattr); } this.NeedReset = true; } }
private bool _ParseCSV(byte[] csvBytes, FileManager fileManager, Dictionary<String, ExcelFile> csvExcelFiles) { // function setup int stringBufferOffset = 0; int integerBufferOffset = 1; bool isProperties = (StringId == "PROPERTIES" || StringId == "_TCv4_PROPERTIES"); ObjectDelegator objectDelegator; OutputAttribute[] excelAttributes; bool needOutputAttributes = true; if (fileManager == null || !fileManager.DataFileDelegators.ContainsKey(StringId)) { FieldInfo[] fieldInfos = DataType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); fieldInfos = fieldInfos.OrderBy(f => f.MetadataToken).ToArray(); // order by defined order - GetFields does not guarantee ordering objectDelegator = new ObjectDelegator(fieldInfos); excelAttributes = new OutputAttribute[fieldInfos.Length]; } else { objectDelegator = fileManager.DataFileDelegators[StringId]; excelAttributes = new OutputAttribute[objectDelegator.FieldCount]; } String[][] tableRows; if (csvBytes == null) { tableRows = _csvTable; } else { // get columns int offset = 0; int colCount = 1; while (csvBytes[offset++] != '\n') if (csvBytes[offset] == CSVDelimiter) colCount++; tableRows = FileTools.CSVToStringArray(csvBytes, colCount, CSVDelimiter); } int rowCount = tableRows.Length; String[] columns = tableRows[0]; if (isProperties) { ExcelFunctions = new List<ExcelFunction>(); _scriptBuffer = new byte[1]; // properties is weird - do this just to ensure 100% byte-for-byte accuracy } // parse file header - could use Regex here - but don't think that'd but faster, in fact, probably a lot slower(?) - meh // format: %s(%s) // first %s = StringId, second %s = FileHeader as String String fileHeader = columns[0]; int fileHeaderStart = fileHeader.IndexOf("(") + 1; int fileHeaderEnd = fileHeader.IndexOf(")"); String fileHeaderStr = fileHeader.Substring(fileHeaderStart, fileHeaderEnd - fileHeaderStart); _excelFileHeader = FileTools.StringToObject<ExcelHeader>(fileHeaderStr, ",", FileHeaderFields); String strId = fileHeader.Substring(0, fileHeader.IndexOf("(")).Trim(); // asking for exception lol Debug.Assert(strId == StringId); // Parse the tableRows bool failedParsing = false; Rows = new List<Object>(); for (int row = 1; row < rowCount; row++) { int col = -1; int csvCol = 0; Object rowInstance = Activator.CreateInstance(DataType); foreach (ObjectDelegator.FieldDelegate fieldDelegate in objectDelegator) { col++; if (needOutputAttributes) excelAttributes[col] = GetExcelAttribute(fieldDelegate.Info); OutputAttribute excelAttribute = excelAttributes[col]; // columns not present if (!columns.Contains(fieldDelegate.Name)) { // create row header object if (fieldDelegate.FieldType == typeof(RowHeader)) { String headerString = tableRows[row][csvCol++]; RowHeader rowHeader = FileTools.StringToObject<RowHeader>(headerString, ",", RowHeaderFields); objectDelegator[fieldDelegate.Name, rowInstance] = rowHeader; continue; } // assign default values MarshalAsAttribute arrayMarshal = null; Array arrayInstance = null; if (fieldDelegate.FieldType.BaseType == typeof(Array)) { arrayMarshal = (MarshalAsAttribute)fieldDelegate.Info.GetCustomAttributes(typeof(MarshalAsAttribute), false).First(); arrayInstance = (Array)Activator.CreateInstance(fieldDelegate.FieldType, arrayMarshal.SizeConst); objectDelegator[fieldDelegate.Name, rowInstance] = arrayInstance; } else if (fieldDelegate.FieldType == typeof(String)) { objectDelegator[fieldDelegate.Name, rowInstance] = String.Empty; } // assign constant non-zero values if (excelAttribute == null || excelAttribute.ConstantValue == null) continue; if (fieldDelegate.FieldType.BaseType == typeof(Array)) { Debug.Assert(arrayInstance != null, "arrayInstance == null"); Debug.Assert(arrayMarshal != null, "arrayMarshal == null"); for (int i = 0; i < arrayMarshal.SizeConst; i++) { arrayInstance.SetValue(excelAttribute.ConstantValue, i); } } else { objectDelegator[fieldDelegate.Name, rowInstance] = excelAttribute.ConstantValue; } continue; } // columns present String value = tableRows[row][csvCol++]; if (fieldDelegate.Name == "code") { int code = (StringId == "REGION") ? int.Parse(value) : StringToCode(value); if (fieldDelegate.FieldType == typeof(short)) { objectDelegator[fieldDelegate.Name, rowInstance] = (short)code; } else { objectDelegator[fieldDelegate.Name, rowInstance] = code; } continue; } bool isArray = (fieldDelegate.FieldType.BaseType == typeof(Array)); bool isEnum = (fieldDelegate.FieldType.BaseType == typeof(Enum)); if (excelAttribute != null) { if (excelAttribute.IsTableIndex && fileManager != null) { int arraySize = 1; if (isArray) { MarshalAsAttribute arrayMarshal = (MarshalAsAttribute)fieldDelegate.Info.GetCustomAttributes(typeof(MarshalAsAttribute), false).First(); arraySize = arrayMarshal.SizeConst; Debug.Assert(arraySize > 0); } String[] indexStrs = value.Split(new[] { ',' }); Int32[] rowIndexValues = new int[arraySize]; for (int i = 0; i < arraySize; i++) rowIndexValues[i] = -1; int maxElements = indexStrs.Length; if (maxElements > arraySize) { Debug.WriteLine(String.Format("{0}: Loss of array elements detected. row = {1}, col = {2}.", StringId, row, col)); maxElements = arraySize; } for (int i = 0; i < maxElements; i++) { value = indexStrs[i]; if (value == "-1") continue; String tableStringId = excelAttribute.TableStringId; bool hasCodeColumn = fileManager.DataTableHasColumn(tableStringId, "code"); if (value.Length == 0 && hasCodeColumn) continue; //LEVEL references multiple blank TREASURE row index values - all appear to be empty rows though, so meh... //Debug.Assert(!String.IsNullOrEmpty(value)); int isNegative = 1; if (value.Length > 0 && value[0] == '-') { isNegative = -1; value = value.Substring(1, value.Length - 1); } int rowIndex = -1; ExcelFile relatedExcel = null; if (csvExcelFiles != null && csvExcelFiles.TryGetValue(tableStringId, out relatedExcel)) { rowIndex = relatedExcel._GetRowIndexFromValue(value, hasCodeColumn ? "code" : null); } if (relatedExcel == null) { if (hasCodeColumn && value.Length <= 4) { int code = StringToCode(value); rowIndex = fileManager.GetExcelRowIndexFromStringId(tableStringId, code, "code"); } else if (fileManager.DataTableHasColumn(tableStringId, "name")) { rowIndex = fileManager.GetExcelRowIndexFromStringId(tableStringId, value, "name"); } else { rowIndex = fileManager.GetExcelRowIndex(tableStringId, value); } } rowIndexValues[i] = rowIndex * isNegative; } if (isArray) { objectDelegator[fieldDelegate.Name, rowInstance] = rowIndexValues; } else { objectDelegator[fieldDelegate.Name, rowInstance] = rowIndexValues[0]; } continue; } if (excelAttribute.IsStringOffset) { if (_stringBuffer == null) _stringBuffer = new byte[1024]; if (String.IsNullOrEmpty(value)) { objectDelegator[fieldDelegate.Name, rowInstance] = -1; continue; } objectDelegator[fieldDelegate.Name, rowInstance] = stringBufferOffset; FileTools.WriteToBuffer(ref _stringBuffer, ref stringBufferOffset, FileTools.StringToASCIIByteArray(value)); stringBufferOffset++; // \0 continue; } if (excelAttribute.IsScript) { if ((fileManager == null && value == "0") || value == "") { objectDelegator[fieldDelegate.Name, rowInstance] = 0; continue; } if (_scriptBuffer == null) { _scriptBuffer = new byte[1024]; _scriptBuffer[0] = 0x00; } int[] scriptByteCode; if (fileManager != null) { ExcelScript excelScript = new ExcelScript(fileManager); scriptByteCode = excelScript.Compile(value, null, StringId, row, col, fieldDelegate.Name); } else { string[] splitValue = value.Split(','); int count = splitValue.Length; scriptByteCode = new int[count]; for (int i = 0; i < count; i++) { scriptByteCode[i] = int.Parse(splitValue[i]); } } objectDelegator[fieldDelegate.Name, rowInstance] = integerBufferOffset; FileTools.WriteToBuffer(ref _scriptBuffer, ref integerBufferOffset, scriptByteCode.ToByteArray()); continue; } if (excelAttribute.IsSecondaryString) { if (SecondaryStrings == null) SecondaryStrings = new List<String>(); if (value == "") { objectDelegator[fieldDelegate.Name, rowInstance] = -1; continue; } if (!SecondaryStrings.Contains(value)) { SecondaryStrings.Add(value); } objectDelegator[fieldDelegate.Name, rowInstance] = SecondaryStrings.IndexOf(value); continue; } if (excelAttribute.IsBitmask) { if (fieldDelegate.FieldType == typeof(UInt32)) { objectDelegator[fieldDelegate.Name, rowInstance] = UInt32.Parse(value); continue; } Object enumVal; try { enumVal = Enum.Parse(fieldDelegate.FieldType, value); } catch (Exception) { String[] enumStrings = value.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); String[] enumNames = Enum.GetNames(fieldDelegate.FieldType); String enumString = String.Empty; String enumSeperator = String.Empty; foreach (String enumStr in enumStrings) { if (!enumNames.Contains(enumStr)) { Debug.WriteLine(String.Format("{0}: bitfield name '{1}' not found.", StringId, enumStr)); continue; } enumString += enumSeperator + enumStr; enumSeperator = ","; } enumVal = enumString == "" ? 0 : Enum.Parse(fieldDelegate.FieldType, enumString); } objectDelegator[fieldDelegate.Name, rowInstance] = enumVal; continue; } } try { Object objValue; if (isArray) { if (fieldDelegate.FieldType == typeof(Int32[])) { objValue = FileTools.StringToArray<Int32>(value, ","); } else { Type elementType = fieldDelegate.FieldType.GetElementType(); if (elementType.BaseType == typeof(Enum)) { String[] enumStrs = value.Split(new[] { ',' }, StringSplitOptions.None); Array enumsArray = Array.CreateInstance(elementType, enumStrs.Length); int i = 0; foreach (String enumStr in enumStrs) { enumsArray.SetValue(Enum.Parse(elementType, enumStr), i++); } objValue = enumsArray; } else { throw new NotImplementedException("if (fieldInfo.FieldType.BaseType == typeof(Array)) :: Type = " + elementType.BaseType); } } objectDelegator[fieldDelegate.Name, rowInstance] = objValue; } else if (isEnum) { object enumVal = Enum.Parse(fieldDelegate.FieldType, value); objectDelegator[fieldDelegate.Name, rowInstance] = enumVal; } else { objValue = FileTools.StringToObject(value, fieldDelegate.FieldType); objectDelegator[fieldDelegate.Name, rowInstance] = objValue; } } catch (Exception e) { Console.WriteLine("Critical Parsing Error: " + e); failedParsing = true; break; } } if (failedParsing) break; needOutputAttributes = false; // applicable only for Unit type; items, missiles, monsters, objects, players if (Attributes.HasStats) { if (StatsBuffer == null) StatsBuffer = new byte[rowCount - 1][]; String value = tableRows[row][csvCol]; String[] stringArray = value.Split(','); byte[] byteArray = new byte[stringArray.Length]; for (int i = 0; i < byteArray.Length; i++) { byteArray[i] = Byte.Parse(stringArray[i]); } StatsBuffer[row - 1] = byteArray; } // properties has extra Scripts stuffs // yea, this is a bit messy, but it's a single table only and mostly done out of curiosity if (isProperties) { String value = tableRows[row][csvCol]; String[] scripts = value.Split('\n'); ExcelFunction excelScript = new ExcelFunction(); if (scripts.Length > 1) { ExcelFunctions.Add(excelScript); } int i = 0; do { if (scripts.Length == 1) continue; i++; String[] values = scripts[i].Split(','); if (values.Length < 4) continue; // script parameters int typeValuesCount = values.Length - 3; ExcelFunction.Parameter parameter = new ExcelFunction.Parameter { Name = values[0], Unknown = UInt32.Parse(values[1]), TypeId = UInt32.Parse(values[2]), TypeValues = new int[typeValuesCount] }; for (int j = 0; j < typeValuesCount; j++) { parameter.TypeValues[j] = Int32.Parse(values[3 + j]); } excelScript.Parameters.Add(parameter); } while (i < scripts.Length - 1 - 2); // -2 for: last line is blank, and line before *might* be script values // last line will be script values if it exists if (i < scripts.Length - 2) { String[] values = scripts[++i].Split(','); int[] scriptValues = new int[values.Length]; for (int j = 0; j < values.Length; j++) { scriptValues[j] = Int32.Parse(values[j]); } excelScript.ScriptByteCode = scriptValues.ToByteArray(); } } Rows.Add(rowInstance); } // resize the integer and string buffers if they were used if (_stringBuffer != null) Array.Resize(ref _stringBuffer, stringBufferOffset); if (_scriptBuffer != null) Array.Resize(ref _scriptBuffer, integerBufferOffset); return HasIntegrity = true; }
public OutputBinSpread(IIOFactory ioFactory, OutputAttribute attribute, OutputBinSpreadStream stream) : base(ioFactory, attribute, stream) { FStream = stream; }
public PathOutStream(IIOFactory factory, OutputAttribute attribute) { attribute.StringType = StringType.Filename; FContainer = factory.CreateIOContainer <IOutStream <string> >(attribute, false); }
public OutputBinSpread(IIOFactory ioFactory, OutputAttribute attribute) : this(ioFactory, attribute, new OutputBinSpreadStream(ioFactory, attribute)) { }
void LoadFieldAttributes() { //get input variables System.Reflection.FieldInfo[] fInfos = GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); List <string> actualFields = new List <string>(); anchorFieldInfoMap.Clear(); foreach (var field in fInfos) { // reading field informations. actualFields.Add(field.Name); anchorFieldInfoMap[field.Name] = field; if (!anchorFieldDictionary.ContainsKey(field.Name)) { anchorFieldDictionary[field.Name] = CreateAnchorField(); } AnchorField anchorField = anchorFieldDictionary[field.Name]; //detect multi-anchor by checking for PWArray<T> type if (field.FieldType.IsGenericType) { if (field.FieldType.GetGenericTypeDefinition() == typeof(PWArray <>)) { anchorField.multiple = true; } } System.Object[] attrs = field.GetCustomAttributes(true); foreach (var attr in attrs) { InputAttribute inputAttr = attr as InputAttribute; OutputAttribute outputAttr = attr as OutputAttribute; ColorAttribute colorAttr = attr as ColorAttribute; OffsetAttribute offsetAttr = attr as OffsetAttribute; VisibilityAttribute visibilityAttr = attr as VisibilityAttribute; NotRequiredAttribute notRequiredAttr = attr as NotRequiredAttribute; if (inputAttr != null) { anchorField.anchorType = AnchorType.Input; if (inputAttr.name != null) { anchorField.name = inputAttr.name; } } if (outputAttr != null) { anchorField.anchorType = AnchorType.Output; if (outputAttr.name != null) { anchorField.name = outputAttr.name; } } if (colorAttr != null) { anchorField.color = new SerializableColor(colorAttr.color); } if (offsetAttr != null) { anchorField.offset = offsetAttr.offset; anchorField.padding = offsetAttr.padding; } if (notRequiredAttr != null) { anchorField.required = false; } if (visibilityAttr != null) { anchorField.defaultVisibility = visibilityAttr.visibility; } } if (anchorField.anchorType == AnchorType.None) //field does not have a PW attribute { anchorFieldDictionary.Remove(field.Name); } else { //create anchor in this anchorField if there is not existing one if (anchorField.anchors.Count == 0) { anchorField.CreateNewAnchor(); } anchorField.colorSchemeName = ColorTheme.GetAnchorColorSchemeName(field.FieldType); anchorField.fieldName = field.Name; anchorField.fieldType = (SerializableType)field.FieldType; anchorField.fieldValue = field.GetValue(this); anchorField.nodeRef = this; } } //remove inhexistants field dictionary entries (for renamed variables): var toRemoveKeys = new List <string>(); foreach (var kp in anchorFieldDictionary) { if (!actualFields.Contains(kp.Key)) { toRemoveKeys.Add(kp.Key); } } foreach (var toRemoveKey in toRemoveKeys) { anchorFieldDictionary.Remove(toRemoveKey); } }
protected override IOAttribute SetPinAttributes(FormularFieldDescriptor configuration) { var attr = new OutputAttribute(configuration.Name); attr.BinVisibility = PinVisibility.Hidden; attr.AutoFlush = false; attr.Order = DynPinCount; attr.BinOrder = DynPinCount + 1; return attr; }
private void _DoPrecedenceHack(FieldInfo fieldInfo, OutputAttribute outputAttribute) { const char dash = '-'; const char score = '_'; const char dashReplace = '0'; const char scoreReplace = '9'; // back it up, these changes can't be undone if (fieldInfo.FieldType == typeof(String)) { if (_backupRows == null) // back it up, these changes can't be undone { _backupRows = Rows.DeepClone(); } foreach (Object row in Rows) { fieldInfo.SetValue(row, ((String)fieldInfo.GetValue(row)).Replace(dash, dashReplace).Replace(score, scoreReplace)); } } if (outputAttribute.IsStringOffset) { if (_backupStringBuffer == null) // back it up, these changes can't be undone { _backupStringBuffer = new byte[_stringBuffer.Length]; Buffer.BlockCopy(_stringBuffer, 0, _backupStringBuffer, 0, _stringBuffer.Length); } for (int i = 0; i < _stringBuffer.Length; i++) { switch (_stringBuffer[i]) { case (byte)dash: _stringBuffer[i] = (byte)dashReplace; break; case (byte)score: _stringBuffer[i] = (byte)scoreReplace; break; } } } if (String.IsNullOrEmpty(outputAttribute.SecondarySortColumn)) { return; } FieldInfo fieldInfo2 = DataType.GetField(outputAttribute.SecondarySortColumn); if (fieldInfo2.FieldType != typeof(string)) { return; } foreach (object row in Rows) { if (_backupRows == null) // back it up, these changes can't be undone { _backupRows = Rows.DeepClone(); } fieldInfo.SetValue(row, ((string)fieldInfo.GetValue(row)).Replace(dash, dashReplace).Replace(score, scoreReplace)); } }
private bool IsOutput(FieldInfo field, out OutputAttribute attrib) { attrib = field.GetCustomAttribute <OutputAttribute>(false); return(attrib != null ? true : false); }
private void _DoPrecedenceHack(FieldInfo fieldInfo, OutputAttribute outputAttribute) { const char dash = '-'; const char score = '_'; const char dashReplace = '0'; const char scoreReplace = '9'; // back it up, these changes can't be undone if (fieldInfo.FieldType == typeof(String)) { if (_backupRows == null) // back it up, these changes can't be undone { _backupRows = Rows.DeepClone(); } foreach (Object row in Rows) { fieldInfo.SetValue(row, ((String)fieldInfo.GetValue(row)).Replace(dash, dashReplace).Replace(score, scoreReplace)); } } if (outputAttribute.IsStringOffset) { if (_backupStringBuffer == null) // back it up, these changes can't be undone { _backupStringBuffer = new byte[_stringBuffer.Length]; Buffer.BlockCopy(_stringBuffer, 0, _backupStringBuffer, 0, _stringBuffer.Length); } for (int i = 0; i < _stringBuffer.Length; i++) { switch (_stringBuffer[i]) { case (byte)dash: _stringBuffer[i] = (byte)dashReplace; break; case (byte)score: _stringBuffer[i] = (byte)scoreReplace; break; } } } if (String.IsNullOrEmpty(outputAttribute.SecondarySortColumn)) return; FieldInfo fieldInfo2 = DataType.GetField(outputAttribute.SecondarySortColumn); if (fieldInfo2.FieldType != typeof(string)) return; foreach (object row in Rows) { if (_backupRows == null) // back it up, these changes can't be undone { _backupRows = Rows.DeepClone(); } fieldInfo.SetValue(row, ((string)fieldInfo.GetValue(row)).Replace(dash, dashReplace).Replace(score, scoreReplace)); } }