Esempio n. 1
0
        static void Main(string[] args)
        {
            Client     client    = new Client();
            IPrototype prototype = client.Copy();

            Console.WriteLine(prototype);
        }
Esempio n. 2
0
        private void RegisterPrototype(string uri, IPrototype prototype)
        {
            if (Prototypes == null)
            {
                //Prototypes = new Dictionary<string, IPrototype>();
                Prototypes = new List <LoadedPrototype>();
            }

            if (string.IsNullOrEmpty(uri))
            {
                throw new ArgumentNullException("uri");
            }

            if (prototype == null)
            {
                throw new ArgumentNullException("prototype");
            }

            if (Prototypes.Any(lp => lp.Uri == uri))
            {
                Debug.LogWarning("Double assignement for prototype: " + uri);
            }

            Prototypes.Add(new LoadedPrototype
            {
                Uri       = uri,
                Prototype = prototype
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Copies the content of the collection to a fixed length array
        /// </summary>
        /// <param name="includeSystemPrototypes">Indicates if system prototypes will be included or excluded</param>
        /// <returns>A copy of the content of the collection</returns>
        public IPrototype[] ToArray(bool includeSystemPrototypes)
        {
            if (includeSystemPrototypes)
            {
                return(this.ToArray());
            }

            this.rwLock.AcquireReaderLock(-1);
            int count = 0;

            foreach (IPrototype p in this.prototypes.Values)
            {
                if ((p is Prototype) && ((Prototype)p).IsSystem)
                {
                    continue;
                }
                ++count;
            }
            IPrototype[] pArray = new IPrototype[count];
            int          ix     = 0;

            foreach (IPrototype p in this.prototypes.Values)
            {
                if ((p is Prototype) && ((Prototype)p).IsSystem)
                {
                    continue;
                }
                pArray[ix++] = p;
            }
            this.rwLock.ReleaseReaderLock();
            Array.Sort(pArray);
            return(pArray);
        }
Esempio n. 4
0
        public GameObject Create(IPrototype proto)
        {
            var objFromPool = new CreatingObjectEventArgs(proto);

            OnCreatingObject(objFromPool);

            GameObject go = objFromPool.Data;

            if (go == null)
            {
                go = Instantiate(Resources.Load(proto.SubTag.ToString())
                                 as GameObject);
                go.AddComponent <MetaInfo>().SetValue(proto);

                // Puslish an event to add specific components when necessary.
                OnAddingComponent(new AddingComponentEventArgs(go));
            }
            else
            {
                go.SetActive(true);
                // TODO: Puslish an event to reset object data.
            }
            go.transform.position = GetComponent <ConvertCoordinate>().Convert(
                proto.Position);

            OnCreatedObject(new CreatedObjectEventArgs(go));
            return(go);
        }
        public IComponent <T> Share(T set, IComponent <T> toHere)
        {
            IPrototype <IComponent <T> > prototype = this.Find(set) as IPrototype <IComponent <T> >;
            IComponent <T> copy = prototype.DeepCopy() as IComponent <T>;

            toHere.Add(copy);
            return(toHere);
        }
Esempio n. 6
0
 private void WritePrototype(IPrototype p)
 {
     Console.Write(p.Command.PadRight(20, ' '));
     Console.Write("{0} ", p.HasPriority ? "H" : " ");
     Console.Write("{0} ", p.ResponseRequired ? "R" : " ");
     Console.Write("{0} ", p.ParamsRequired ? "P" : " ");
     Console.WriteLine("\ttimeout: {0}ms", p.Timeout.ToString().PadLeft(6, ' '));
 }
Esempio n. 7
0
 public void SetValue(IPrototype proto)
 {
     if ((MainTag == MainTag.INVALID) && (SubTag == SubTag.INVALID))
     {
         MainTag = proto.MainTag;
         SubTag  = proto.SubTag;
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Removes the specified Prototype from the parent Module's PrototypeCollection object
 /// </summary>
 /// <param name="item">The Prototype to be removed</param>
 /// <returns>true if the specified Prototype exists in the collection; otherwise, false</returns>
 public bool Remove(IPrototype item)
 {
     if (item == null)
     {
         return(false);
     }
     return(Remove(item.Command));
 }
Esempio n. 9
0
 private void copyButton1_Click(object sender, EventArgs e)
 {
     TakeBoxes(_left.Matrix, _leftBoxes);
     _buffer = _left.Copy();
     if (_left is TimeDecorator timeDecorator)
     {
         timeLabel.Text = timeDecorator.Time + " ms";
     }
 }
Esempio n. 10
0
        public static void TestPrototype()
        {
            Console.WriteLine("-- TEST PROTOTYPE --");
            IPrototype proA = new PrototypeA("ProtoA");
            IPrototype proB = proA.Clone();

            Console.WriteLine($"Original - {proA.GetName()}");
            Console.WriteLine($"Clone - {proB.GetName()}");
        }
Esempio n. 11
0
        /// <summary>
        /// Measures the time of the algorithm.
        /// Calls Paste method of MatrixFacade instance.
        /// </summary>
        /// <param name="matrix">Matrix to be pasted.</param>
        public override void Paste(IPrototype matrix)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            _facade.Paste(matrix);
            stopwatch.Stop();
            Time = stopwatch.ElapsedMilliseconds;
        }
        public void Test()
        {
            sample.Name = "A";
            IPrototype image = sample.Clone();

            Assert.AreEqual <string>("A", image.Name);                          // 副本与样本当时的内容一致
            Assert.AreEqual <Type>(typeof(ConcretePrototype), image.GetType()); //具体类型
            image.Name = "B";                                                   // 独立修改副本的内容
            Assert.IsTrue(sample.Name != image.Name);                           // 证明是两个独立的个体
        }
Esempio n. 13
0
        public ICheckBox CreateCheckBox(string canvas)
        {
            IPrototype clone = _checkBoxPrototype.Clone();

            clone.Init(canvas);
            ICheckBox box = (ICheckBox)clone;

            box.Toggle();
            return(box);
        }
Esempio n. 14
0
        public IButton CreateButton(string canvas)
        {
            IPrototype clone = _buttonProtype.Clone();

            clone.Init(canvas);
            IButton button = (IButton)clone;

            button.Enable(true);
            return(button);
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            SwordManager SwordManager = SwordManager.Instance;

            SwordManager.LoadConfig();

            IPrototype Supersword = SwordManager.GetClone("Longsword");

            Console.ReadKey();
        }
        public void TestPrototype(IPrototype testedPrototype, string expectedToString)
        {
            Assert.Equal(expectedToString, testedPrototype.ToString());

            var clone = testedPrototype.Copy();

            Assert.NotNull(clone);
            Assert.NotSame(clone, testedPrototype);
            Assert.Same(testedPrototype.GetType(), clone.GetType());
            Assert.Equal(clone, testedPrototype);
        }
Esempio n. 17
0
            // Deep Copy
            public IPrototype DeepCopy()
            {
                MemoryStream    stream    = new MemoryStream();
                BinaryFormatter formatter = new BinaryFormatter();

                formatter.Serialize(stream, this);
                stream.Seek(0, SeekOrigin.Begin);
                IPrototype copy = (IPrototype)formatter.Deserialize(stream);

                stream.Close();
                return(copy);
            }
Esempio n. 18
0
        public IPrototype Make(IPrototype prototype, Slot position, Slot size)
        {
            IPrototype item = prototype.Make(_board);

            item.Position = position;
            if (size != null)
            {
                ((IPrototype)item).Size = size;
            }
            item.Init();
            return(item);
        }
Esempio n. 19
0
        /// <summary>
        /// Determines whether the specified Module is in the parent Module's PrototypeCollection object
        /// </summary>
        /// <param name="item">The Prototype to search for in the collection</param>
        /// <returns>true if the specified Prototype exists in the collection; otherwise, false</returns>
        public bool Contains(IPrototype item)
        {
            if (item == null)
            {
                return(false);
            }
            this.rwLock.AcquireReaderLock(-1);
            bool result = this.prototypes.ContainsKey(item.Command);

            this.rwLock.ReleaseReaderLock();
            return(result);
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            //Singleton
            Creater player = Creater.getInstance("*****@*****.**");

            Console.WriteLine(player.Email);

            //Abstract Factory
            Chess Whitechesses = new Chess(new WhiteChess(), 2, 8);

            Whitechesses.HorseMove(2);
            Whitechesses.PawnMove(1);


            Chess Blackchesses = new Chess(new BlackChess(), 2, 8);

            Blackchesses.HorseMove(2);
            Blackchesses.PawnMove(4);

            //Builder
            Director     director     = new Director();
            BoardBuilder boardbuilder = new ClassicBoard();
            Board        classicboard = director.Construct(boardbuilder);

            Console.WriteLine(classicboard.ToString());

            boardbuilder = new BorderBoard();
            Board borderboard = director.Construct(boardbuilder);

            Console.WriteLine(borderboard.ToString());

            //Prototype
            IPrototype figure       = new WhitePawn(true);
            IPrototype clonedFigure = figure.Clone();

            figure.GetInfo();
            clonedFigure.GetInfo();

            figure       = new BlackPawn(false);
            clonedFigure = figure.Clone();
            figure.GetInfo();
            clonedFigure.GetInfo();

            Console.WriteLine($"Main {DateTime.Now.TimeOfDay}");
            Console.WriteLine(Singleton.text);

            Singleton singleton1 = Singleton.GetInstance();

            Console.WriteLine(singleton1.Date);

            Console.ReadLine();
        }
Esempio n. 21
0
        public void Prototype()
        {
            IPrototype prototype = new Prototype();
            IPrototype clone1    = prototype.Clone();

            Assert.AreEqual(prototype.Identifier, clone1.Identifier);

            prototype.Identifier = Rand.NewIdentifier();
            IPrototype clone2 = prototype.Clone();

            Assert.AreNotEqual(prototype.Identifier, clone1.Identifier);
            Assert.AreEqual(prototype.Identifier, clone2.Identifier);
        }
Esempio n. 22
0
    public static T DeepCopy <T>(this IPrototype <T> target)
    {
        T copy;

        using (var stream = new MemoryStream())
        {
            var formatter = new BinaryFormatter();
            formatter.Serialize(stream, (T)target);
            stream.Seek(0, SeekOrigin.Begin);
            copy = (T)formatter.Deserialize(stream);
            stream.Close();
        }
        return(copy);
    }
Esempio n. 23
0
        /// <summary>
        /// Copies the content of the collection to a fixed length array
        /// </summary>
        /// <returns>A copy of the content of the collection</returns>
        public IPrototype[] ToArray()
        {
            this.rwLock.AcquireReaderLock(-1);
            IPrototype[] pArray = new IPrototype[this.prototypes.Count];
            int          ix     = 0;

            foreach (IPrototype p in this.prototypes.Values)
            {
                pArray[ix++] = p;
            }
            this.rwLock.ReleaseReaderLock();
            Array.Sort(pArray);
            return(pArray);
        }
Esempio n. 24
0
        public Brush SetBackgroundColor()
        {
            if (!(DataContext is IPrototype))
            {
                return(new SolidColorBrush(Colors.SlateGray));
            }

            IPrototype p = (IPrototype)this.DataContext;

            if (p.Position.Y >= 0)
            {
                return(new SolidColorBrush(Colors.SlateGray));
            }
            return(new SolidColorBrush(Colors.DarkSlateGray));
        }
Esempio n. 25
0
        public IPrototype CreateInstance(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            IPrototype masterInstance = null;

            if (masterInstances.TryGetValue(name, out masterInstance))
            {
                return(masterInstance.Clone());
            }
            return(null);
        }
Esempio n. 26
0
        public double SetBackgroundOpacity()
        {
            if (!(DataContext is IPrototype))
            {
                return(1d);
            }

            IPrototype p = (IPrototype)this.DataContext;

            if (p.Position.Y >= 0)
            {
                return(0.8d);
            }
            return(1d);
        }
Esempio n. 27
0
 public static bool CreateUser(string username, string email, string password)
 {
     try
     {
         using (UserContext db = new UserContext())
         {
             //создаем прототип
             IPrototype figure = new User
             {
                 BTCBalance  = 0,
                 ETHBalance  = 0,
                 BNBBalance  = 0,
                 USDTBalance = 0,
                 DOTBalance  = 0,
                 ADABalance  = 0,
                 XRPBalance  = 0,
                 LINKBalance = 0,
                 BCHBalance  = 0,
                 XLMBalance  = 0,
                 UNIBalance  = 0,
                 USDCBalance = 0,
                 DOGEBalance = 0,
                 WBTCBalance = 0,
                 XEMBalance  = 0,
                 EOSBalance  = 0,
                 HTBalance   = 0,
                 ATOMBalance = 0,
                 XMRBalance  = 0,
                 TRXBalance  = 0,
                 IOTABalance = 0,
                 NEOBalance  = 0,
                 VETBalance  = 0
             };
             string     md5          = GetHash(password);
             IPrototype clonedFigure = figure.Clone(username, email, md5);
             // добавляем пользователя в бд
             db.Users.Add((User)clonedFigure);
             db.SaveChanges();
             Status = true;
             return(clonedFigure.Status());
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
Esempio n. 28
0
        public object SerializePrototype(IPrototype proto, bool pretty)
        {
            JSONPrototype jsonProto = proto as JSONPrototype;

            if (jsonProto == null)
            {
                return(null);
            }

            string json = _js.Serialize(jsonProto.Children);

            if (json == null)
            {
                return(null);
            }

            return(pretty ? Prettify(json) : json);
        }
Esempio n. 29
0
 /// <summary>
 /// Adds the specified Prototype object to the collection.
 /// </summary>
 /// <param name="item">The Prototype to add to the collection</param>
 public void Add(IPrototype item)
 {
     this.rwLock.AcquireWriterLock(-1);
     item.Parent = owner;
     if (prototypes.ContainsKey(item.Command))
     {
         if (prototypes[item.Command] != item)
         {
             prototypes[item.Command] = item;
         }
     }
     else
     {
         prototypes.Add(item.Command, item);
     }
     this.rwLock.ReleaseWriterLock();
     OnPrototypeCollectionStatusChanged();
 }
Esempio n. 30
0
        public IEvent GetEvent(IPrototype prototype)
        {
            var founded = _prototypes.FirstOrDefault(p => p.IsInstanceOfType(prototype));

            var genericType = typeof(IEvent <>).MakeGenericType(founded);

            foreach (var type in _events)
            {
                var any = genericType.IsAssignableFrom(type);
                if (!any)
                {
                    continue;
                }
                return((IEvent)Activator.CreateInstance(type, new object[] { prototype }));
            }

            throw new KeyNotFoundException("EventAgent");
        }
Esempio n. 31
0
 /// <summary>
 /// Look for a module in the blackboard that supports specified command
 /// </summary>
 /// <param name="commandName">The name of the command to look for</param>
 /// <param name="destination">When this method returns, contains the Module that supports the command
 /// specified, if the conversion succeeded, or null if no module supports the command.
 /// The search fails if the s parameter is a null reference (Nothing in Visual Basic) or is not of the correct format.
 /// This parameter is passed uninitialized</param>
 /// <param name="prototype">When this method returns, contains the Prototype for the command
 /// specified, if the conversion succeeded, or null if no module supports the command.
 /// The conversion fails if the s parameter is a null reference (Nothing in Visual Basic) or is not of the correct format.
 /// This parameter is passed uninitialized</param>
 /// <returns>true if a destination module was found, false otherwise</returns>
 public bool FindDestinationModule(string commandName, out IModuleClient destination, out IPrototype prototype)
 {
     destination = null;
     prototype = null;
     if (commandName == null) return false;
     if (VirtualModule.SupportCommand(commandName, out prototype))
     {
         destination = VirtualModule;
         return true;
     }
     this.prototypesLock.AcquireReaderLock(-1);
     if (!this.prototypes.ContainsKey(commandName))
         return false;
     prototype = this.prototypes[commandName];
     destination = prototype.Parent;
     return destination.Enabled;
 }
 /// <summary>
 /// Creates a new instance of the behaviour.
 /// </summary>
 /// <param name="respondsTo">The message the behaviour responds to.</param>
 /// <param name="config">The configuration elements to use in configuring this behaviour.</param>
 protected PrototypedBehaviour(string respondsTo, IEnumerable<IConfigurationElement> config)
     : base(respondsTo)
 {
     _prototype = new Prototype(config);
 }
 /// <summary>
 /// Creates a new instance of the behaviour.
 /// </summary>
 /// <param name="respondsTo">The message the behaviour responds to.</param>
 /// <param name="prototype">The prototype to use in configuring this behaviour.</param>
 protected PrototypedWebBehaviour(string respondsTo, IPrototype prototype)
     : base(respondsTo, prototype)
 {
 }
 /// <summary>
 /// Creates a new instance of the behaviour.
 /// </summary>
 /// <param name="respondsTo">The message the behaviour responds to.</param>
 /// <param name="prototype">The prototype to use in configuring this behaviour.</param>
 protected PrototypedBehaviour(string respondsTo, IPrototype prototype)
     : base(respondsTo)
 {
     _prototype = prototype;
 }
Esempio n. 35
0
 /// <summary>
 /// Returns a value indicating if the command is supported by this module
 /// </summary>
 /// <param name="commandName">The name of the command to search for</param>
 /// <param name="prototype">When this method returns, contains the Prototype that brings support to this command
 /// if the search succeeded, or null if the module does not supports the command.
 /// The conversion fails if the s parameter is a null reference (Nothing in Visual Basic) or is not of the correct format.
 /// This parameter is passed uninitialized</param>
 /// <returns>True if the command was found. false otherwise</returns>
 public bool SupportCommand(string commandName, out IPrototype prototype)
 {
     prototype = null;
     if (commandName == null)
         return false;
     if (!this.prototypes.Contains(commandName))
         return false;
     prototype = this.prototypes[commandName];
     return true;
 }
 /// <summary>
 /// Creates a new instance of the behaviour.
 /// </summary>
 /// <param name="respondsTo">The message the behaviour responds to.</param>
 /// <param name="prototype">The prototype to use in configuring this behaviour.</param>
 public SetFlagBehaviour(string respondsTo, IPrototype prototype)
     : base(respondsTo, prototype)
 {
 }
Esempio n. 37
0
 /// <summary>
 /// Safely removes support for a existing command from the system
 /// </summary>
 /// <param name="module">The module which will host the new command</param>
 /// <param name="proto">The prototype which contains command information</param>
 internal void RemovePrototype(IPrototype proto)
 {
     if ((proto == null) || (modules.Contains(proto.Parent) && proto.Parent.Enabled))
         return;
     prototypesLock.AcquireWriterLock(-1);
     if (prototypes.ContainsKey(proto.Command))
         prototypes[proto.Command].Parent.Prototypes.Remove(proto.Command);
     prototypes.Remove(proto.Command);
     prototypesLock.ReleaseWriterLock();
 }
Esempio n. 38
0
        /// <summary>
        /// Safely adds support for a new command to the system, avoiding duplicates in a thread-safe way
        /// </summary>
        /// <param name="module">The module which will host the new command</param>
        /// <param name="proto">The prototype which contains command information</param>
        /// <returns>true if the new prototype was added, false otherwise</returns>
        internal bool AddPrototype(IModuleClient module, IPrototype proto)
        {
            if ((proto == null) || (module == null) || !module.Enabled || ((proto is Prototype) && ((Prototype)proto).IsSystem) || !modules.Contains(module))
                return false;

            prototypesLock.AcquireWriterLock(-1);
            if (this.prototypes.ContainsKey(proto.Command))
            {
                //if (this.prototypes[proto.Command] == proto)
                //    return;
                //if ((proto.Parent != null) && this.prototypes[proto.Command].Parent != proto.Parent)
                //    proto.Parent.Prototypes.Remove(proto.Command);
                //return;
                prototypesLock.ReleaseWriterLock();
                return false;

            }
            module.Prototypes.Add(proto);
            this.prototypes.Add(proto.Command, proto);
            prototypesLock.ReleaseWriterLock();
            return true;
        }
Esempio n. 39
0
 private void WritePrototype(IPrototype p)
 {
     Console.Write(p.Command.PadRight(20, ' '));
     Console.Write("{0} ", p.HasPriority ? "H" : " ");
     Console.Write("{0} ", p.ResponseRequired ? "R" : " ");
     Console.Write("{0} ", p.ParamsRequired ? "P" : " ");
     Console.WriteLine("\ttimeout: {0}ms", p.Timeout.ToString().PadLeft(6, ' '));
 }