PubSub is working now

This commit is contained in:
Taha authored and John Colvin committed 2023-09-30 12:53:51 -04:00
1 parent 3fa37397d9
commit 7bb7f1a5e2
27 files changed
+1108 -1124

No files matched your search

@@ -7,144 +7,116 @@ using System.Text;
using BCG;
//using BCG.Utilities;
using System.Collections.Generic;
namespace BCG
{
public class MetaData : ICloneable
{
private Hashtable myHash = new Hashtable();
namespace BCG {
// Thhis "wraps" around the following 4 PubSub meta objects, serializes it on the client and
// deserialize it on the pubsub
// PubMetaData
// SubMetaData
// TransactionMetaData
// UnSubMetaData
public class MetaData : ICloneable {
private IDictionary _name_value_map = new Dictionary<string, string>();
int mySize = -1;
public MetaData()
{}
public MetaData() { }
public MetaData(object o)
{copyFrom(o);}
public MetaData(object o) { copyFrom(o); }
public MetaData(Stream s)
{
public MetaData(Stream s) {
long initPos = s.Position;
load(s);
mySize = Convert.ToInt32(s.Position - initPos);
}
public string this[string name]
{
get
{return (string) myHash[name];}
set
{
public string this[string name] {
get { return (string)_name_value_map[name]; }
set {
if (value != null)
myHash[name] = value;
_name_value_map[name] = value;
}
}
public void add(string name, string [] values)
{
private void _add_string_array(string name, string[] values) {
StringBuilder sb = new StringBuilder();
foreach (string s in values)
{
foreach (string s in values) {
if (sb.Length != 0)
sb.Append(" ");
sb.Append(s);
}
myHash[name] = sb.ToString();
_name_value_map[name] = sb.ToString();
}
public int getAsInt(string name)
{return Int32.Parse(this[name]);}
private int getAsInt(string name) { return Int32.Parse(this[name]); }
public string[] getAsStringArray (string name)
{
private string[] _get_as_string_array(string name) {
if (this[name] != "" && this[name] != null)
return this[name].Split(' ');
else
return new string[0];
}
public int size()
{
if (mySize < 0)
{
public int size() {
if (mySize < 0) {
MemoryStream ms = new MemoryStream();
this.save(ms);
return mySize = (int)ms.Position;
}
else
} else
return mySize;
}
public bool isEqual (MetaData md)
{
if (md.myHash.Keys.Count != myHash.Keys.Count)
private bool isEqual(MetaData md) {
if (md._name_value_map.Keys.Count != _name_value_map.Keys.Count)
return false;
foreach (string k in myHash.Keys)
if (!myHash[k].Equals(md.myHash[k]))
foreach (string k in _name_value_map.Keys)
if (!_name_value_map[k].Equals(md._name_value_map[k]))
return false;
return true;
}
public void load(Stream s)
{
myHash = new Hashtable();
string [] state =
// loads the content of the stream into this instance's map
private void load(Stream s) {
_name_value_map = new Hashtable();
string[] state =
new BinaryReader(s).ReadString().Split('\n');
for (int i = 0; i < state.Length-1; i+= 2)
myHash[state[i]] = state[i+1];
for (int i = 0; i < state.Length - 1; i += 2)
_name_value_map[state[i]] = state[i + 1];
}
public void save(Stream s)
{
// writes the content of this instance to stream s
public void save(Stream s) {
new BinaryWriter(s).Write(this.ToString());
}
public override string ToString()
{
public override string ToString() {
StringBuilder sb = new StringBuilder();
foreach (string key in myHash.Keys)
sb.AppendFormat("{0}\n{1}\n",key,myHash[key]);
foreach (string key in _name_value_map.Keys)
sb.AppendFormat("{0}\n{1}\n", key, _name_value_map[key]);
return sb.ToString();
}
public void copyFrom(object o)
{
// iterates through the fields and enters the name, values into _hash
public void copyFrom(object o) {
this["op-code"] = o.GetType().Name;
foreach (FieldInfo fi in o.GetType().GetFields())
{
foreach (FieldInfo fi in o.GetType().GetFields()) {
if (fi.GetValue(o) == null)
continue;
else if (fi.GetValue(o) is String[])
add(fi.Name, (string[])fi.GetValue(o));
_add_string_array(fi.Name, (string[])fi.GetValue(o));
else
myHash[fi.Name] = fi.GetValue(o).ToString();
_name_value_map[fi.Name] = fi.GetValue(o).ToString();
}
}
public void copyTo(object o)
{
foreach (FieldInfo fi in o.GetType().GetFields())
{
// copies the name value map into object o
public void copyTo(object o) {
foreach (FieldInfo fi in o.GetType().GetFields()) {
string value = this[fi.Name];
//this should only be here temporarily, while the new decompression changes are waiting to go into prod.
if (value == null)
{
//BlueEventLog.logEvent("Error: Metadata missing field " + fi.Name, BlueEventLog2Level.MissingMetadata);
}
else
{
if (value == null) {
} else {
if (fi.FieldType.Equals(typeof(string)))
fi.SetValue(o, value);
else if (fi.FieldType.Equals(typeof(int)))
@@ -167,11 +139,10 @@ namespace BCG
}
}
public object Clone()
{
public object Clone() {
MemoryStream ms = new MemoryStream();
this.save(ms);
ms.Seek(0,SeekOrigin.Begin);
ms.Seek(0, SeekOrigin.Begin);
return new MetaData(ms);
}
}