private void ExportDatablocks(Type datablockType, string saveLocation) { outputStringBuilder = new StringBuilder(); var headers = new List <string>() { "Name", "Parent" }; IEnumerable <Datablock> baseDatablocks = DatablockManager.Instance.GetDatablocks(datablockType).Where(d => d.Parent == null); datablockFields = Datablock.GetFields(datablockType); foreach (FieldInfo memberInfo in datablockFields) { headers.Add(memberInfo.Name); } // Add the headers outputStringBuilder.Append(String.Join(fieldDelimiter, headers.ToArray()) + "\r\n"); // Process the datablocks from the base to their children foreach (var baseDatablock in baseDatablocks) { ProcessChildren(baseDatablock); } // Write the file File.WriteAllText(saveLocation, outputStringBuilder.ToString()); Debug.Log("Datablocks exported to " + saveLocation); }
public void ReadWriteTest(int count) { var bw = new BlockWriter(_filepath); var r = new Random(); var testData = new byte[count]; var testblock = new Datablock { Data = testData, Count = testData.Length }; bw.Write(testblock, 0); var testblock2 = new Datablock { Data = new byte[count] }; var br = new BlockReader(_filepath); br.Read(testblock2, 0, testblock.Count); CollectionAssert.AreEqual(testblock.Data, testblock2.Data); Assert.AreEqual(testblock.Count, testblock.Count); }
private void bValidate_Click(object sender, RoutedEventArgs e) { if (this.m_bValidateCorrect == true) { if (this.validator.verifyRsaSignature(Datablock.getInstance().Message, signature.GetSignature())) { this.ResultValid(); } else { this.ResultNotValid(); } } else if (this.m_bValidateCorrect == false) { if (this.validator.verifyRsaSignatureWithFlaw(Datablock.getInstance().Message, signature.GetSignature())) { this.ResultValid(); } else { this.ResultNotValid(); } } }
private void ExportDatablocks(Type datablockType, string saveLocation) { IEnumerable <Datablock> baseDatablocks = DatablockManager.Instance.GetDatablocks(datablockType).Where(d => d.Parent == null); datablockFields = Datablock.GetFields(datablockType); var sb = new StringBuilder(); var sw = new StringWriter(sb); writer = new JsonTextWriter(sw); writer.WriteStartArray(); // Process the datablocks from the base to their children foreach (var baseDatablock in baseDatablocks) { ProcessChildren(baseDatablock); } writer.WriteEndArray(); File.WriteAllText(saveLocation, sb.ToString()); Debug.Log("Datablocks exported to " + saveLocation); writer.Close(); }
private void ImportRows(DatablockDetectionInfo datablockDetectionInfo) { using (TextReader reader = File.OpenText(csvFilePath)) { var parser = new CsvParser2(); parser.TrimTrailingEmptyLines = true; string[][] parsed = parser.Parse(reader); for (int i = 1; i < parsed.GetLength(0); i++) { string[] row = parsed[i]; string datablockName = row[nameIndex]; Datablock datablock = GetNamedDatablock(datablockDetectionInfo, datablockName); for (int index = 0; index < parsed[i].Length; index++) { if (index == headers.Count) { break; } string fieldValue = parsed[i][index]; string fieldName = headers[index]; ProcessRawField(datablockDetectionInfo, fieldName, datablock, fieldValue); } } Debug.Log("Imported " + (parsed.GetLength(0) - 1) + " datablocks."); } }
public SigGenBleichenbControl() { InitializeComponent(); RsaKey.Instance.RaiseKeyGeneratedEvent += handleCustomEvent; // listen Datablock.getInstance().RaiseParamChangedEvent += handleCustomEvent; this.handleCustomEvent(ParameterChangeType.RsaKey); this.loadComboDataBlocPos(24); }
public bool Equals(Datablock datablock) { if ((this.type_f & 0x80) == 0x80) { this.Confirm(); } return(object.Equals(this.refValue, datablock)); }
private void ImportRows(DatablockDetectionInfo datablockDetectionInfo) { var myFile = new StreamReader(jsonFilePath); var jsonStr = myFile.ReadToEnd(); myFile.Close(); var ct = 0; var datablockValues = new Dictionary <string, string>(); var reader = new JsonTextReader(new StringReader(jsonStr)); while (reader.Read()) { if (reader.TokenType == JsonToken.StartObject) { // New datablock datablockValues = new Dictionary <string, string>(); } else if (reader.TokenType == JsonToken.PropertyName) { var fieldName = reader.Value as string; reader.Read(); datablockValues[fieldName] = reader.Value as string; } else if (reader.TokenType == JsonToken.EndObject) { if (!datablockValues.ContainsKey("Name")) { Debug.LogWarning("Datalock missing Name field"); continue; } var datablockName = datablockValues["Name"]; Datablock datablock = GetNamedDatablock(datablockDetectionInfo, datablockName); foreach (var datablockValue in datablockValues) { var fieldName = datablockValue.Key; var fieldValue = datablockValue.Value; if (fieldName == "Name") { continue; } ProcessRawField(datablockDetectionInfo, fieldName, datablock, fieldValue); } ct++; } } Debug.Log("Imported " + ct + " datablocks."); }
public virtual void OnEnable() { datablock = (Datablock)target; renameAssetTempName = datablock.name; members = Datablock.GetFields(datablock.GetType()); DatablockManager.EnsureInitilized(); }
public void ProviderTakeTest() { var provider = new DatablockProvider(); Datablock firstBlock = provider.Take(); Datablock secondDatablock = provider.Take(); Assert.AreNotSame(firstBlock, secondDatablock); }
// fired when Checkbox Selection changed // Hashfunction IdentificationTextbox filled & selected Hashfunction is set private void cbHashFunc_SelectionChanged(object sender, SelectionChangedEventArgs e) { Datablock.getInstance().HashFunctionIdent = (HashFunctionIdent)this.cbHashFunc.SelectedValue; this.tbHashIdent.Text = Datablock.getInstance().HashFunctionIdent.DERIdent; // HashDigest Textboxen leeren; werden bei Execute befüllt this.tbHashDigest.Text = String.Empty; this.lblHashDigestLength.Content = String.Empty; }
private void CreateChildDatablock(Datablock datablock) { var newDatablock = CreateInstance(datablock.GetType()) as Datablock; newDatablock.Parent = datablock; string pathName = AssetDatabase.GenerateUniqueAssetPath(AssetDatabase.GetAssetPath(datablock)); AssetDatabase.CreateAsset(newDatablock, pathName); Selection.activeObject = newDatablock; }
private void handleParamChanged(ParameterChangeType type) { if (ParameterChangeType.Message == type) { if (true == this.tbInputText.IsEnabled) { this.tbInputText.Text = Encoding.ASCII.GetString(Datablock.getInstance().Message); } this.tbHashDigest.Text = Datablock.getInstance().GetHashDigestToHexString(); } }
protected override void ProcessDatablock(Datablock datablock) { SetNextCellValue(datablock.name); SetNextCellValue(datablock.Parent ? datablock.Parent.name : ""); foreach (FieldInfo field in datablockFields) { string value = GetFieldValue(datablock, field); SetNextCellValue(value); } }
protected void ProcessChildren(Datablock datablock) { ProcessDatablock(datablock); var children = datablock.GetChildren(); foreach (var child in children) { ProcessChildren(child); } }
public void Write(Datablock block, long startPosition) { using (FileStream fstream = File.OpenWrite(_filepath)) { using (var wr = new BinaryWriter(fstream)) { wr.BaseStream.Position = startPosition; wr.Write(block.Data, 0, block.Count); } } }
public void Compress(Datablock src, Datablock trg) { using (var targetStream = new MemoryStream()) { using (var compressionStream = new GZipStream(targetStream, CompressionMode.Compress, true)) { compressionStream.Write(src.Data, 0, src.Count); } ArchiverHelper.GetHeaderWithLength(targetStream, trg); } }
protected Datablock GetNamedDatablock(DatablockDetectionInfo datablockDetectionInfo, string datablockName) { Datablock datablock = DatablockManager.Instance.GetDatablock(datablockName, datablockDetectionInfo.datablockType, true); if (datablock == null) { datablock = CreateInstance(datablockDetectionInfo.datablockType) as Datablock; string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(newDatablockDir + "/" + datablockName + ".asset"); AssetDatabase.CreateAsset(datablock, assetPathAndName); } return(datablock); }
private void loadComboDataBlocPos(int start) { this.cbPosDataBlock.Items.Clear(); int lengthDatablock = Datablock.getInstance().HashFunctionIdent.DERIdent.Length * 4 + Datablock.getInstance().HashFunctionIdent.digestLength + 8; int end = RsaKey.Instance.RsaKeySize - lengthDatablock - start; for (int i = start; i <= end; i += 8) { this.cbPosDataBlock.Items.Add(i); } this.cbPosDataBlock.SelectedIndex = (end - start) / 10; }
public bool GetDatablock(out Datablock datablock) { if ((this.type_f & 0x80) == 0x80) { this.Confirm(); } if (this.type_f == 0) { datablock = null; return(false); } datablock = (Datablock)this.refValue; return((bool)datablock); }
public bool Read(Datablock block, long startPosition, int count) { using (FileStream fstream = File.OpenRead(_filepath)) { using (var wr = new BinaryReader(fstream)) { wr.BaseStream.Position = startPosition; wr.Read(block.Data, 0, count); } } block.Count = count; return(true); }
private int ParentDepthCheck(Datablock datablock, int depth = 0) { if (datablock == this) { return(depth); } if (Parent != null) { depth++; return(Parent.ParentDepthCheck(datablock, depth)); } return(-1); }
private void ExportDatablocks(Type datablockType) { var worksheet = (WorksheetEntry)spreadsheet.Worksheets.Entries[0]; IEnumerable <Datablock> datablocks = DatablockManager.Instance.GetDatablocks(datablockType); datablockFields = Datablock.GetFields(datablockType); List <string> headers = datablockFields.Select(f => f.Name).ToList(); headers.Insert(0, "Parent"); headers.Insert(0, "Name"); // Set the worksheet to a single row for our headers worksheet.Cols = (uint)headers.Count; worksheet.Rows = (exportData ? (uint)datablocks.Count() : 0) + 1; worksheet.Update(); if (exportData) { // Fetch the cell feed of the worksheet. var cellQuery = new CellQuery(worksheet.CellFeedLink); cellQuery.ReturnEmpty = ReturnEmptyCells.yes; cellFeed = sheetsAPI.Service.Query(cellQuery); batchRequest = new CellFeed(cellQuery.Uri, sheetsAPI.Service); currentCellIndex = 0; // Set headers for (int index = 0; index < headers.Count; index++) { string cellValue = headers[index]; SetNextCellValue(cellValue); } currentCellIndex = headers.Count; IEnumerable <Datablock> baseDatablocks = datablocks.Where(d => d.Parent == null); // Process the datablocks from the base to their children foreach (Datablock baseDatablock in baseDatablocks) { ProcessChildren(baseDatablock); } sheetsAPI.Service.Batch(batchRequest, new Uri(cellFeed.Batch)); } Debug.Log("Datablocks saved to " + spreadsheet.Title.Text); }
public void Initialize() { // ComboBox befüllen this.cbHashFunc.Items.Add(HashFuncIdentHandler.SHA1); this.cbHashFunc.Items.Add(HashFuncIdentHandler.SHA256); this.cbHashFunc.Items.Add(HashFuncIdentHandler.SHA384); this.cbHashFunc.Items.Add(HashFuncIdentHandler.SHA512); this.cbHashFunc.Items.Add(HashFuncIdentHandler.MD2); this.cbHashFunc.Items.Add(HashFuncIdentHandler.MD5); this.cbHashFunc.SelectedIndex = 0; this.rbTextFromBox.IsChecked = true; Datablock.getInstance().RaiseParamChangedEvent += handleParamChanged; }
protected override void ProcessDatablock(Datablock datablock) { writer.WriteStartObject(); AddColumn("Name", datablock.name); AddColumn("Parent", datablock.Parent ? datablock.Parent.name : ""); foreach (FieldInfo field in datablockFields) { var value = GetFieldValue(datablock, field); AddColumn(field.Name, value); } writer.WriteEndObject(); }
public void Decompress(Datablock src, Datablock trg) { var oLength = 0; for (var i = 1; i <= 4; i++) { oLength = (oLength << 8) | src.Data[src.Count - i]; } trg.Count = oLength; using (var targetStream = new MemoryStream(src.Data)) { using (var compressionStream = new GZipStream(targetStream, CompressionMode.Decompress)) { compressionStream.Read(trg.Data, 0, trg.Count); } } }
protected override void ProcessDatablock(Datablock datablock) { AddColumn(datablock.name); AddColumn(datablock.Parent ? datablock.Parent.name : ""); foreach (FieldInfo field in datablockFields) { var value = GetFieldValue(datablock, field).Replace("\"", "\"\""); AddColumn(value); } // strip triailing delimiter outputStringBuilder.Length--; outputStringBuilder.Append("\r\n"); }
public void TestHeaderWithLegthAndLenthTest(int length) { var r = new Random(); var srcArray = new byte[length]; srcArray[0] = 31; srcArray[1] = 139; srcArray[2] = 8; srcArray[3] = 0; srcArray[4] = 0; srcArray[5] = 0; srcArray[6] = 0; srcArray[7] = 0; srcArray[8] = 4; srcArray[9] = 0; for (var i = 10; i < length; i++) { srcArray[i] = (byte)r.Next(); } var dataBlock = new Datablock { Count = length, Data = new byte[length + ArchiverHelper.EXTRA_FIELD_LENGTH] }; using (var ms = new MemoryStream(srcArray)) { ArchiverHelper.GetHeaderWithLength(ms, dataBlock); } Assert.AreEqual(srcArray.Length + ArchiverHelper.EXTRA_FIELD_LENGTH, dataBlock.Count); Assert.AreNotEqual(srcArray[3], dataBlock.Data[3]); var resultCount = 0; using (var ms = new MemoryStream(dataBlock.Data, 0, dataBlock.Count)) { resultCount = ArchiverHelper.GetBlockLegth(ms); } Assert.AreEqual(dataBlock.Count, resultCount); }
public static void loadRtbColoredSig(RichTextBox richTB, string decryptedSig) { FlowDocument flowDoc = new FlowDocument(); Paragraph para = new Paragraph(); Run run = new Run(decryptedSig); para.Inlines.Add(run); int paddingEnd = decryptedSig.IndexOf("ff0030"); // Ende des Padding int identEnd = paddingEnd + 10 + Datablock.getInstance().HashFunctionIdent.DERIdent.Length; int digestEnd = identEnd + 2 + (Datablock.getInstance().HashFunctionIdent.digestLength / 4); TextRange rangePadding = UserControlHelper.GenTextRange(run, 4, paddingEnd + 2, Colors.Green); TextRange rangeIdent = UserControlHelper.GenTextRange(run, paddingEnd + 8, identEnd, Colors.Blue); TextRange rangeDigest = UserControlHelper.GenTextRange(run, identEnd, digestEnd, Colors.Red); flowDoc.Blocks.Add(para); richTB.Document = flowDoc; }
public void Work(int blockNumber) { var blockReader = new BlockReader(_srcFilePath); var blockArchiver = new BlockArchiver(); var blockWriter = new BlockWriter(_trgFilePath); var readBlock = new Datablock { Data = new byte[1100000], Count = 1000000 }; var writeBlock = new Datablock { Data = new byte[1100000] }; blockReader.Read(readBlock, 0, 1000000); blockArchiver.Compress(readBlock, writeBlock); blockWriter.Write(writeBlock, 0); }
protected void ProcessRawField(DatablockDetectionInfo datablockDetectionInfo, string fieldName, Datablock datablock, string fieldValue) { if (fieldName.Equals("parent", StringComparison.OrdinalIgnoreCase)) { datablock.Parent = DatablockManager.Instance.GetDatablock(fieldValue, datablockDetectionInfo.datablockType); return; } FieldInfo field = datablockDetectionInfo.fields.FirstOrDefault(f => f.Name.Equals(fieldName, StringComparison.OrdinalIgnoreCase)); if (field == null) return; if (string.IsNullOrEmpty(fieldValue)) { datablock.SetOverridesParent(field, false); return; } SetField(datablock, field, fieldValue); }
protected abstract void ProcessDatablock(Datablock datablock);
protected string GetFieldValue(Datablock datablock, FieldInfo field) { // If the field uses its parent's value, return an empty string if (!datablock.DoesOverridesParent(field) && !exportFullValues) return ""; if (field.FieldType == typeof(int)) { return ((int)datablock.GetFieldValue(field)).ToString(); } else if (field.FieldType == typeof(float)) { return ((float)field.GetValue(datablock)).ToString(); } else if (field.FieldType == typeof(bool)) { return ((bool)field.GetValue(datablock)) ? "True" : "False"; } else if (field.FieldType == typeof(double)) { return ((double)field.GetValue(datablock)).ToString(); } else if (field.FieldType == typeof(string)) { var str = ((string)field.GetValue(datablock)); if (string.IsNullOrEmpty(str)) return "(null)"; return str; } else if (field.FieldType == typeof(Color)) { var val = (Color)field.GetValue(datablock); return val.r.ToString() + ',' + val.g.ToString() + ',' + val.b.ToString() + ',' + val.a.ToString(); } else if (field.FieldType == typeof(Vector2)) { var val = (Vector2)field.GetValue(datablock); return val.x.ToString() + ',' + val.y.ToString(); } else if (field.FieldType == typeof(Vector3)) { var val = (Vector3)field.GetValue(datablock); return val.x.ToString() + ',' + val.y.ToString() + ',' + val.z.ToString(); } else if (field.FieldType == typeof(Vector4)) { var val = (Vector4)field.GetValue(datablock); return val.x.ToString() + ',' + val.y.ToString() + ',' + val.z.ToString() + ',' + val.w.ToString(); } else if (field.FieldType.IsSubclassOf(typeof(Object))) { var obj = ((Object)field.GetValue(datablock)); if (!obj) return ""; return obj.name; } else if (field.FieldType.IsGenericType && field.FieldType.GetGenericTypeDefinition() == typeof(DatablockRef<>)) { return ((IDatablockRef)field.GetValue(datablock)).GetPath(); } else if (field.FieldType.IsEnum) { return ((Enum)field.GetValue(datablock)).ToString(); } return ""; }
protected void SetField(Datablock datablock, FieldInfo field, string rawValue) { object newVal = null; if (field.FieldType == typeof (int)) { int intVal; int.TryParse(rawValue, out intVal); newVal = intVal; } else if (field.FieldType == typeof(float)) { float floatVal; float.TryParse(rawValue, out floatVal); newVal = floatVal; } else if (field.FieldType == typeof(bool)) { if (rawValue.Equals("True", StringComparison.InvariantCultureIgnoreCase) || rawValue.Equals("T", StringComparison.InvariantCultureIgnoreCase) || rawValue.Equals("Yes", StringComparison.InvariantCultureIgnoreCase)) { newVal = true; } else { newVal = false; } } else if (field.FieldType == typeof (double)) { double doubleVal; double.TryParse(rawValue, out doubleVal); newVal = doubleVal; } else if (field.FieldType == typeof (string)) { if (rawValue.Equals("(null)", StringComparison.OrdinalIgnoreCase)) { newVal = null; } else { newVal = rawValue; } } else if (field.FieldType == typeof (Color)) { Color colorVal = Color.white; try { string[] splitColor = rawValue.Split(','); if (splitColor.Length == 3) colorVal = new Color(float.Parse(splitColor[0].Trim()), float.Parse(splitColor[1].Trim()), float.Parse(splitColor[2].Trim())); else if (splitColor.Length == 4) colorVal = new Color(float.Parse(splitColor[0].Trim()), float.Parse(splitColor[1].Trim()), float.Parse(splitColor[2].Trim()), float.Parse(splitColor[3].Trim())); } catch { } newVal = colorVal; } else if (field.FieldType == typeof (Vector2)) { Vector2 vector = Vector2.zero; try { string[] splitVec = rawValue.Split(','); vector = new Vector2(float.Parse(splitVec[0].Trim()), float.Parse(splitVec[1].Trim())); } catch { } newVal = vector; } else if (field.FieldType == typeof (Vector3)) { Vector3 vector = Vector3.zero; try { string[] splitVec = rawValue.Split(','); vector = new Vector3(float.Parse(splitVec[0].Trim()), float.Parse(splitVec[1].Trim()), float.Parse(splitVec[2].Trim())); } catch { } newVal = vector; } else if (field.FieldType == typeof (Vector4)) { Vector4 vector = Vector4.zero; try { string[] splitVec = rawValue.Split(','); vector = new Vector4(float.Parse(splitVec[0].Trim()), float.Parse(splitVec[1].Trim()), float.Parse(splitVec[2].Trim()), float.Parse(splitVec[3].Trim())); } catch { } newVal = vector; } else if (field.FieldType.IsSubclassOf(typeof (Object))) { string[] matchingAssets = AssetDatabase.FindAssets(rawValue + " t:" + field.FieldType.Name); if (!matchingAssets.Any()) { Debug.LogWarning("Unable to find object: " + rawValue + " for " + field.Name + " on datablock " + datablock.name); return; } Object obj = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(matchingAssets[0]), field.FieldType); newVal = obj; } else if (field.FieldType.IsGenericType && field.FieldType.GetGenericTypeDefinition() == typeof (DatablockRef<>)) { Object obj = Resources.Load(rawValue); if (!obj) { Debug.LogWarning("Unable to load resource: " + rawValue + " for " + field.Name + " on datablock " + datablock.name); return; } newVal = Activator.CreateInstance(field.FieldType, new object[] {obj}); } else if (field.FieldType.IsEnum) { try { newVal = Enum.Parse(field.FieldType, rawValue); } catch (Exception) { Debug.LogError("Invalid enum vlue " + rawValue + " for " + field.Name + " on datablock " + datablock.name); } } field.SetValue(datablock, newVal); datablock.SetOverridesParent(field, true); }