public void Generate(IUnique key) { string[] titles = { "Mr", "Miss", "Mrs", "Sir", "Lord", "Esquire", "King", "God", "Chief", "Master" }; string[] first = { "Badger", "Squirrel", "Narwhal", "Frog", "Horse", "Cow", "Monkey", "Hedgehog", "Platypus", "Pig", "Termite" }; string[] last = { "Banana", "Cheese", "Crackers", "Hummus", "Marmite", "Cucumber", "Crisps", "Chicken", "Pork", "Beef" }; CustomerID = key.Next(); Random rand = new Random(CustomerID); Name = titles[rand.Next(0, titles.Length)] + " "; Name += first[rand.Next(0, first.Length)] + " "; Name += last[rand.Next(0, last.Length)]; int total = rand.Next(1, 3); for (int i = 0; i < total; ++i) { Number temp = new Number(); temp.ID = i + 1; temp.CustomerID = CustomerID; temp.Active = rand.Next(0, 2) == 0 ? true : false; temp.Value = ""; for (int j = 0; j < 9; ++j) { temp.Value += rand.Next(0, 9).ToString(); } Numbers.Add(temp); } }
public static IEnumerable <Customer> Generate(IUnique key) { for (int i = 0; i < 20; ++i) { yield return(new Customer(key)); } }
public string FormatUnique(string prefix, IUnique unique) { prefix.ThrowIfNull("prefix"); unique.ThrowIfNull("unique"); return String.Format("{0} ID: {1}", prefix, unique.Id); }
public void Serialize(Stream stream, IUnique source, AlertLog log = null) { log?.RaiseAlert("BEG", "Beginning serialisation..."); _Format = new Dictionary <string, TypeFieldsFormat>(); _Aliases = new Dictionary <Type, string>(); _Uniques = new UniquesCollection(); _Writer = new StreamWriter(stream); // Write base item: _Writer.WriteLine(SerializeItem(source)); // Write uniques: int i = 0; while (i < _Uniques.Count) { log?.RaiseAlert("PROG", "Writing...", (double)i / (double)_Uniques.Count, AlertLevel.Information); IUnique unique = _Uniques[i]; _Writer.WriteLine(SerializeItem(unique)); i++; } //_Writer.WriteLine(); //_Writer.WriteLine(FORMAT); //_Writer.Write(GenerateFormatDescription()); _Writer.Flush(); log?.RaiseAlert("BEG", "Serialisation complete."); }
/// <summary> /// Write /// </summary> /// <param name="value"></param> /// <param name="sb"></param> protected void WriteValue(object value, StringBuilder sb) { if (value == null) { } else if (value is IntPtr[]) { //Nope! } else if (value is IUnique) { //Write GUID, put in queue: IUnique unique = (IUnique)value; if (!_Uniques.Contains(unique.GUID)) { _Uniques.Add(unique); } //TODO: Write GUID sb.Append(unique.GUID); } else { WriteObject(value, sb); } }
protected static string FormatUniqueDetailText(string prefix, IUnique unique) { prefix.ThrowIfNull("prefix"); unique.ThrowIfNull("unique"); return DetailTextFormatter.Instance.FormatUnique(prefix, unique); }
protected bool NotifyInput(IUnique caller) { if (caller is IObjectContainer) { SerialPort.Write((caller as IObjectContainer).PopObject().ToString()); } return(true); }
protected bool NotifyOutput(IUnique caller) { if (caller is IObjectContainer) { Console.Write((caller as IObjectContainer).PopObject().ToString()); } return(true); }
public virtual bool CallDelegate(IUnique caller) { if (NotifyDelegate != null) { return(NotifyDelegate.Invoke(caller)); } return(false); }
/// <summary> /// Serialize a unique item to a string /// </summary> /// <param name="source"></param> /// <returns></returns> protected string SerializeItem(IUnique source) { var sb = new StringBuilder(); sb.Append(DATA); sb.Append(source.GUID); sb.Append(KEY_SEPARATOR); WriteObject(source, sb); return(sb.ToString()); }
public virtual bool Equals(IUnique <T> other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (HasOidAssigned && other.HasOidAssigned && Oid.Equals(other.Oid)) { var otherType = other.GetEntityType(); var thisType = GetEntityType(); return(thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType)); } return(false); }
public virtual bool Equals(IUnique <T> other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (IsEntityPersistent(this) && IsEntityPersistent(other) && Equals(other.Id, Id)) { var otherType = other.GetEntityType(); var thisType = GetEntityType(); return(thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType)); } return(false); }
static void Main(string[] args) { var queryvar = (from arg in args where arg.Length > 0 select arg) .Where(arg2 => arg2.Length == 0) .ToList(); var testing = new Testing(); testing.Testing1(); IUnique monoType = null; monoType.DoSomething(); var test = new Test(); test.DoTest(); var test3 = new Test3(); test3.DoTest(); var c2 = new LocalClass2(); c2.Bar(); var c3 = new RemoteClass1(); c3.Bar(); test.CallBar(c3); // Recall type(c3) = RemoteClass1 #region Demo Delegates TestDelegate.Test(); TestDelegate.Test2(); #endregion }
private static bool IsEntityPersistent(IUnique <T> e) { return(e != null && !Equals(e.Id, default(T))); }
/// <summary> /// The Key. /// </summary> /// <param name="obj">The obj<see cref="IUnique"/>.</param> /// <param name="seed">The seed<see cref="ulong"/>.</param> /// <returns>The <see cref="UInt64"/>.</returns> public override UInt64 Key(IUnique obj, ulong seed) { return(ComputeKey(obj.GetUniqueBytes(), seed)); }
public Command WithTag(IUnique tag) { Tag = tag.IfNotNull(arg => (Guid?)arg.Id); return this; }
public ReferenceConstraint(IUnique referencing, string @ref, Type type) { Referencing = referencing; Referenced = new MvdItemReference(@ref, type); }
public static bool NotifyOutput2(IUnique caller) { Console.WriteLine("2 " + caller.UniqueId); return true; }
public static Command Tagged(Command command, IUnique tag) { command.ThrowIfNull("command"); return command.WithTag(tag); }
/// <summary> /// The Key. /// </summary> /// <param name="obj">The obj<see cref="IUnique"/>.</param> /// <returns>The <see cref="UInt64"/>.</returns> public virtual UInt64 Key(IUnique obj) { return(obj.UniqueKey); }
/// <summary> /// The Key. /// </summary> /// <param name="obj">The obj<see cref="IUnique"/>.</param> /// <param name="seed">The seed<see cref="ulong"/>.</param> /// <returns>The <see cref="UInt64"/>.</returns> public virtual UInt64 Key(IUnique obj, ulong seed) { return(unique.ComputeKey(obj.GetUniqueBytes(), seed)); }
/// <summary> /// The Bytes. /// </summary> /// <param name="obj">The obj<see cref="IUnique"/>.</param> /// <returns>The <see cref="Byte[]"/>.</returns> public virtual Byte[] Bytes(IUnique obj) { return(obj.GetBytes()); }
/// <summary> /// The Key. /// </summary> /// <typeparam name="V">.</typeparam> /// <param name="obj">The obj<see cref="IUnique{V}"/>.</param> /// <param name="seed">The seed<see cref="ulong"/>.</param> /// <returns>The <see cref="UInt64"/>.</returns> public override UInt64 Key <V>(IUnique <V> obj, ulong seed) { return(Key(obj.UniqueValues(), seed)); }
/// <summary> /// The Key. /// </summary> /// <typeparam name="V">.</typeparam> /// <param name="obj">The obj<see cref="IUnique{V}"/>.</param> /// <returns>The <see cref="UInt64"/>.</returns> public override UInt64 Key <V>(IUnique <V> obj) { return(obj.UniquesAsKey()); }
public int CompareTo(IUnique g) { return((int)(UniqueKey - g.UniqueKey())); }
/// <summary> /// The Key. /// </summary> /// <typeparam name="V">.</typeparam> /// <param name="obj">The obj<see cref="IUnique{V}"/>.</param> /// <param name="seed">The seed<see cref="ulong"/>.</param> /// <returns>The <see cref="UInt64"/>.</returns> public virtual UInt64 Key <V>(IUnique <V> obj, ulong seed) { return(unique.Key(obj.UniqueValues(), seed)); }
public bool Equals(IUnique g) { return(UniqueKey == g.UniqueKey()); }
/// <summary> /// The Bytes. /// </summary> /// <param name="obj">The obj<see cref="IUnique"/>.</param> /// <returns>The <see cref="Byte[]"/>.</returns> public override Byte[] Bytes(IUnique obj) { return(obj.GetBytes()); }
public UniqueConstraint(IUnique src) : base(src) { }
public Customer(IUnique key) { Clear(); Generate(key); }
public static bool NotifyOutput2(IUnique caller) { Console.WriteLine("2 " + caller.UniqueId); return(true); }
public IUnique Deserialize(Stream stream, AlertLog log = null) { IUnique result = null; _Format = new Dictionary <string, TypeFieldsFormat>(); _Aliases = new Dictionary <Type, string>(); _Uniques = new UniquesCollection(); _Reader = new StreamReader(stream); // First, read through once to end: log?.RaiseAlert("FORM", "Reading format data..."); string line; int lineCount = 0; while ((line = _Reader.ReadLine()) != null) { lineCount++; if (line.StartsWith(FORMAT)) { ReadFormat(line, log); } else if (line.StartsWith(DATA)) { // Initial pass: Create object int i = DATA.Length; string guid = line.NextChunk(ref i, KEY_SEPARATOR); string typeAlias = line.NextChunk(ref i, OPEN_DATABLOCK); if (_Format.ContainsKey(typeAlias)) { TypeFieldsFormat format = _Format[typeAlias]; IUnique unique = format.Type.Instantiate() as IUnique;//FormatterServices.GetUninitializedObject(format.Type) as IUnique; if (unique is IUniqueWithModifiableGUID) { var uniqueMG = (IUniqueWithModifiableGUID)unique; uniqueMG.SetGUID(new Guid(guid)); } else { FieldInfo fI = format.Type.GetBaseField("_GUID"); // Will not work if backing field is named differently! fI.SetValue(unique, new Guid(guid)); } _Uniques.Add(unique); if (result == null) { result = unique; // Set primary output object } } else { log?.RaiseAlert("FNF" + typeAlias, "Formatting data for type alias '" + typeAlias + "' not found.", AlertLevel.Warning); } } } log?.RaiseAlert("FORM", "Format data read."); // Next: Second pass - populate fields with data // Rewind: stream.Seek(0, SeekOrigin.Begin); _Reader = new StreamReader(stream); int lineNum = 0; while ((line = _Reader.ReadLine()) != null) { log?.RaiseAlert("DAT", "Reading data...", (double)lineNum / (double)lineCount); if (line.StartsWith(DATA)) { // Initial pass: Create object int i = DATA.Length; string guid = line.NextChunk(ref i, KEY_SEPARATOR); string typeAlias = line.NextChunk(ref i, OPEN_DATABLOCK); if (_Format.ContainsKey(typeAlias)) { TypeFieldsFormat format = _Format[typeAlias]; object unique = _Uniques[new Guid(guid)]; PopulateFields(ref unique, format, ref i, line, log); } } lineNum++; } log?.RaiseAlert("DAT", "Reading data complete.", 1.0); log?.RaiseAlert("FIN", "Finalising..."); // Finally: Call OnDeserialized function on each object foreach (var unique in _Uniques) { MethodInfo mInfo = unique.GetType().GetOnDeserializedMethod(); if (mInfo != null) { mInfo.Invoke(unique, new object[] { new StreamingContext() }); } // TODO: Pass in populated streamingcontext arguments? } log?.RaiseAlert("FIN", "Finalised"); return(result); }
public MvdItemReference(IUnique item) { ReferencedUuid = item.GetUuid(); ReferencedType = item.GetType(); }
public virtual bool CallDelegate(IUnique caller) { if(NotifyDelegate != null) return NotifyDelegate.Invoke(caller); return false; }
/// <summary> /// The Key. /// </summary> /// <typeparam name="V">.</typeparam> /// <param name="obj">The obj<see cref="IUnique{V}"/>.</param> /// <returns>The <see cref="UInt64"/>.</returns> public virtual UInt64 Key <V>(IUnique <V> obj) { return(obj.UniquesAsKey()); }
/// <summary> /// The Key. /// </summary> /// <param name="obj">The obj<see cref="IUnique"/>.</param> /// <returns>The <see cref="UInt64"/>.</returns> public override UInt64 Key(IUnique obj) { return(obj.UniqueKey); }