コード例 #1
0
            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);
                }
            }
コード例 #2
0
 public static IEnumerable <Customer> Generate(IUnique key)
 {
     for (int i = 0; i < 20; ++i)
     {
         yield return(new Customer(key));
     }
 }
コード例 #3
0
        public string FormatUnique(string prefix, IUnique unique)
        {
            prefix.ThrowIfNull("prefix");
            unique.ThrowIfNull("unique");

            return String.Format("{0} ID: {1}", prefix, unique.Id);
        }
コード例 #4
0
ファイル: UniqueFormatter.cs プロジェクト: lulzzz/Nucleus
        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.");
        }
コード例 #5
0
ファイル: UniqueFormatter.cs プロジェクト: lulzzz/Nucleus
        /// <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);
            }
        }
コード例 #6
0
ファイル: Event.cs プロジェクト: tj-miller/TextAdventure
        protected static string FormatUniqueDetailText(string prefix, IUnique unique)
        {
            prefix.ThrowIfNull("prefix");
            unique.ThrowIfNull("unique");

            return DetailTextFormatter.Instance.FormatUnique(prefix, unique);
        }
コード例 #7
0
ファイル: SerialFitting.cs プロジェクト: icprog/Sewer
 protected bool NotifyInput(IUnique caller)
 {
     if (caller is IObjectContainer)
     {
         SerialPort.Write((caller as IObjectContainer).PopObject().ToString());
     }
     return(true);
 }
コード例 #8
0
ファイル: SerialFitting.cs プロジェクト: icprog/Sewer
 protected bool NotifyOutput(IUnique caller)
 {
     if (caller is IObjectContainer)
     {
         Console.Write((caller as IObjectContainer).PopObject().ToString());
     }
     return(true);
 }
コード例 #9
0
ファイル: Notify.cs プロジェクト: icprog/Sewer
 public virtual bool CallDelegate(IUnique caller)
 {
     if (NotifyDelegate != null)
     {
         return(NotifyDelegate.Invoke(caller));
     }
     return(false);
 }
コード例 #10
0
ファイル: UniqueFormatter.cs プロジェクト: lulzzz/Nucleus
        /// <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());
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: Unique.cs プロジェクト: Sony-NS/SharpMap
        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);
        }
コード例 #13
0
        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
        }
コード例 #14
0
ファイル: Unique.cs プロジェクト: Sony-NS/SharpMap
 private static bool IsEntityPersistent(IUnique <T> e)
 {
     return(e != null && !Equals(e.Id, default(T)));
 }
コード例 #15
0
 /// <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));
 }
コード例 #16
0
        public Command WithTag(IUnique tag)
        {
            Tag = tag.IfNotNull(arg => (Guid?)arg.Id);

            return this;
        }
コード例 #17
0
 public ReferenceConstraint(IUnique referencing, string @ref, Type type)
 {
     Referencing = referencing;
     Referenced  = new MvdItemReference(@ref, type);
 }
コード例 #18
0
ファイル: Program.cs プロジェクト: bolke/Sewer
 public static bool NotifyOutput2(IUnique caller)
 {
     Console.WriteLine("2 " + caller.UniqueId);
     return true;
 }
コード例 #19
0
ファイル: Commands.cs プロジェクト: tj-miller/TextAdventure
        public static Command Tagged(Command command, IUnique tag)
        {
            command.ThrowIfNull("command");

            return command.WithTag(tag);
        }
コード例 #20
0
 /// <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);
 }
コード例 #21
0
 /// <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));
 }
コード例 #22
0
 /// <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());
 }
コード例 #23
0
 /// <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));
 }
コード例 #24
0
 /// <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());
 }
コード例 #25
0
 public int CompareTo(IUnique g)
 {
     return((int)(UniqueKey - g.UniqueKey()));
 }
コード例 #26
0
 /// <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));
 }
コード例 #27
0
 public bool Equals(IUnique g)
 {
     return(UniqueKey == g.UniqueKey());
 }
コード例 #28
0
 /// <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());
 }
コード例 #29
0
 public UniqueConstraint(IUnique src)
     : base(src)
 {
 }
コード例 #30
0
 public Customer(IUnique key)
 {
     Clear();
     Generate(key);
 }
コード例 #31
0
ファイル: Program.cs プロジェクト: icprog/Sewer
 public static bool NotifyOutput2(IUnique caller)
 {
     Console.WriteLine("2 " + caller.UniqueId);
     return(true);
 }
コード例 #32
0
ファイル: UniqueFormatter.cs プロジェクト: lulzzz/Nucleus
        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);
        }
コード例 #33
0
 public MvdItemReference(IUnique item)
 {
     ReferencedUuid = item.GetUuid();
     ReferencedType = item.GetType();
 }
コード例 #34
0
ファイル: Notify.cs プロジェクト: bolke/Sewer
 public virtual bool CallDelegate(IUnique caller)
 {
     if(NotifyDelegate != null)
         return NotifyDelegate.Invoke(caller);
     return false;
 }
コード例 #35
0
 /// <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());
 }
コード例 #36
0
 /// <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);
 }