Equals() public method

public Equals ( System obj ) : bool
obj System
return bool
Ejemplo n.º 1
0
 //---------------------------------------------------------------------------
 #endregion
 //---------------------------------------------------------------------------
 #region Methods
 //---------------------------------------------------------------------------
 /// <summary>
 /// Метод вызывается при добавлении в коллекцию, для установки свойства
 /// _Device. Данный объект modbus-устройства, является владельцем данной
 /// коллекции регистров-хранения. Если владелец не равен null, то данная
 /// коллекция уже принадлежит другой коллекции. При это вызывается
 /// исключение
 /// </summary>
 /// <param name="owner">Владелец данного файла</param>
 internal void SetOwner(Device owner)
 {
     if (_Device == null)
     {
         _Device = owner;
         _RecordsCollection.SetOwner(owner);
     }
     else
     {
         if (owner == null)
         {
             // Освобождаем параметр от владельца
             _Device = owner;
         }
         else
         {
             // Если устройство, которому принадлежит данный файл
             // эквивалентен устанавливаемому, тогда ничего не делаем.
             // Здесь нет ошибки. В противном случае, генерируем исключение
             if (_Device.Equals(owner) == false)
             {
                 throw new InvalidOperationException(
                           "Данный файл уже принадлежит другому устройству");
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void EqualsShouldReturnFalseIfObjIsNull()
        {
            var platform = new Platform(new IntPtr(1), FakeOpenClApi);
            var device   = new Device(platform, new IntPtr(1), FakeOpenClApi.DeviceApi);

            Assert.False(device.Equals((object)null));
        }
Ejemplo n.º 3
0
        public void testEquals_shouldReturnFalseWithNonNestDevice()
        {
            Object o      = new Object();
            Device device = new Device();

            Assert.IsFalse(device.Equals(o));
        }
Ejemplo n.º 4
0
        public void EqualsShouldReturnTrueIfOtherIsSameReference()
        {
            var platform = new Platform(new IntPtr(1), FakeOpenClApi);
            var device   = new Device(platform, new IntPtr(1), FakeOpenClApi.DeviceApi);

            Assert.True(device.Equals(device));
        }
Ejemplo n.º 5
0
        public void EqualsShouldReturnFalseIfObjIsOfDifferentType()
        {
            var platform = new Platform(new IntPtr(1), FakeOpenClApi);
            var device1  = new Device(platform, new IntPtr(1), FakeOpenClApi.DeviceApi);
            var device2  = (object)new SuspiciousDevice(platform, new IntPtr(1), FakeOpenClApi.DeviceApi);

            Assert.False(device1.Equals(device2));
        }
Ejemplo n.º 6
0
        public void EqualsShouldReturnTrueIfDevicesHaveSameIds()
        {
            var platform = new Platform(new IntPtr(1), FakeOpenClApi);
            var device1  = new Device(platform, new IntPtr(1), FakeOpenClApi.DeviceApi);
            var device2  = new Device(platform, new IntPtr(1), FakeOpenClApi.DeviceApi);

            Assert.True(device1.Equals(device2));
        }
Ejemplo n.º 7
0
        public void EqualsShouldReturnTrueIfObjIsOfSameTypeAndHasSameId()
        {
            var    platform = new Platform(new IntPtr(1), FakeOpenClApi);
            var    device1  = new Device(platform, new IntPtr(1), FakeOpenClApi.DeviceApi);
            object device2  = new Device(platform, new IntPtr(1), FakeOpenClApi.DeviceApi);

            Assert.True(device1.Equals(device2));
        }
Ejemplo n.º 8
0
 public override bool Equals(object obj)
 {
     if (obj == null && Device == null)
     {
         return(true);
     }
     return(Device?.Equals(obj) ?? false);
 }
Ejemplo n.º 9
0
        int getFirstDeviceId()
        {
            Device device = devices.First();

            if (device.Equals(null))
            {
                throw new IndexOutOfRangeException("Message");
            }
            return(devices.First().Id);
        }
Ejemplo n.º 10
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Device.Equals("pc"))
         {
             function.Script(this, "showinpc();");
         }
         MyBind();
     }
 }
Ejemplo n.º 11
0
 //<---------------------Thread Functions--------------------------------->
 public void GetBracePositionThreadCall()
 {
     if (!epos.Equals(null))
     {
         if (!brace_position_worker.IsBusy)
         {
             stop_watch.Start();
             brace_position_worker.RunWorkerAsync(brace_position_thread);
         }
     }
 }
Ejemplo n.º 12
0
        public void EqualsTest1()
        {
            Device target   = new Device(); // TODO: Initialize to an appropriate value
            object obj      = null;         // TODO: Initialize to an appropriate value
            bool   expected = false;        // TODO: Initialize to an appropriate value
            bool   actual;

            actual = target.Equals(obj);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 13
0
        public void setMVBDDevice()
        {
            Device device = getDeviceByName("MVDB_2");

            if (!device.Equals(new Device()))
            {
                strategyMgr.getSpecifiedDisplayStrategy().setActiveDevice(device);
                Console.WriteLine("Ausgabegerät auf {0} geändert.", device.ToString());
            }
            else
            {
                //strategyMgr.getSpecifiedDisplayStrategy().setActiveDevice(new Device(64, 30, OrientationEnum.Front, "MVDB_2", this.GetType()));
                Settings s = new Settings();
                strategyMgr.setSpecifiedDisplayStrategy(s.getPosibleDisplayStrategies()[0].className);
                Console.WriteLine("Ausgabegerät auf 'MVBD' geändert.");
            }
        }
Ejemplo n.º 14
0
        internal void setBrailleDis()
        {
            Device device = getDeviceByName("BrailleDis");

            if (!device.Equals(new Device()))
            {
                strategyMgr.getSpecifiedDisplayStrategy().setActiveDevice(device);
                Console.WriteLine("Ausgabegerät auf {0} geändert.", device.ToString());
            }
            else
            {
                // strategyMgr.getSpecifiedDisplayStrategy().setActiveDevice(new Device(64, 30, OrientationEnum.Front, "BrailleDisSimulator", this.GetType()));
                Settings s = new Settings();
                strategyMgr.setSpecifiedDisplayStrategy(s.getPosibleDisplayStrategies()[2].className);
                Console.WriteLine("Ausgabegerät auf 'Simulator-BrailleIO' geändert.");
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        ///     Compares this object to another one to determine if they are equal.  Equality for this type of object simply means
        ///     that the other object must be of the same type and must be monitoring the same DirectInput device.
        /// </summary>
        /// <param name="obj">An object to compare this object to</param>
        /// <returns>
        ///     a boolean, set to true, if the this object is equal to the specified object, and set to false, if they are not
        ///     equal.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (GetType() != obj.GetType())
            {
                return(false);
            }

            // safe because of the GetType check
            var js = (BIDeviceMonitor)obj;

            // use this pattern to compare value members
            return(Device.Equals(js.Device));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Separates collection of <see cref="IDeviceProvider" /> interface objects into individual collections by
        /// <see cref="Device" />
        /// objects.
        /// </summary>
        /// <typeparam name="T">The type of the device</typeparam>
        /// <param name="collection">The collection.</param>
        /// <returns>
        /// dictionary with devices
        /// </returns>
        public static IDictionary <Device, IList <T> > SeparateByDevice <T>(ICollection <T> collection)
            where T : IDeviceProvider
        {
            Dictionary <Device, IList <T> > dictionary = new Dictionary <Device, IList <T> >(1);

            if (collection.Count > 0)
            {
                Device    thisDevice = null;
                IList <T> list       = collection as IList <T>;
                if (list == null)
                {
                    SeparateByDeviceImpl(dictionary, collection);
                }
                else
                {
                    bool useOriginalCollection = true;
                    foreach (T item in collection)
                    {
                        Device device = item.Device;
                        if (thisDevice == null)
                        {
                            thisDevice = device;
                            continue;
                        }
                        if (device.Equals(thisDevice))
                        {
                            continue;
                        }
                        useOriginalCollection = false;
                        break;
                    }
                    if (useOriginalCollection)
                    {
                        dictionary.Add(thisDevice, list);
                    }
                    else
                    {
                        SeparateByDeviceImpl(dictionary, collection);
                    }
                }
            }
            return(dictionary);
        }
Ejemplo n.º 17
0
        static void SeparateByDeviceImpl <T>(IDictionary <Device, IList <T> > dictionary, ICollection <T> collection)
            where T : IDeviceProvider
        {
            IList <T> records    = null;
            Device    thisDevice = null;

            foreach (T item in collection)
            {
                Device device          = item.Device;
                bool   addToDictionary = records == null || !device.Equals(thisDevice) && !dictionary.TryGetValue(device, out records);
                thisDevice = device;
                if (addToDictionary)
                {
                    records = new List <T>(100);
                    dictionary.Add(thisDevice, records);
                }
                records.Add(item);
            }
        }
Ejemplo n.º 18
0
        protected void Add_B_Click(object sender, EventArgs e)
        {
            M_UserInfo    mu      = buser.GetLogin();
            M_Design_Page pageMod = new M_Design_Page();

            if (!string.IsNullOrEmpty(Guid))
            {
                pageMod            = pageBll.SelModelByGuid(Guid);
                pageMod.Title      = Title_T.Text;
                SFile_Up.SaveUrl   = SiteConfig.SiteOption.UploadDir + "User/" + mu.UserName + mu.UserID + "/";
                pageMod.PreviewImg = SFile_Up.SaveFile();
                pageBll.UpdateByID(pageMod);
                Response.Redirect("/design/user/default2.aspx");
            }
            else
            {
                pageMod.guid     = System.Guid.NewGuid().ToString();
                pageMod.Title    = Title_T.Text;
                pageMod.CUser    = mu.UserID;
                pageMod.UserID   = mu.UserID;
                pageMod.UserName = mu.UserName;
                pageMod.ZType    = 0;
                //预览图
                SFile_Up.SaveUrl   = SiteConfig.SiteOption.UploadDir + "User/" + mu.UserName + mu.UserID + "/";
                pageMod.PreviewImg = SFile_Up.SaveFile();
                //初始化场景数据
                InitPage(pageMod);
                pageBll.Insert(pageMod);
                if (Device.Equals("pc"))
                {
                    function.Script(this, "top.CloseDiag();top.location='/design/h5/default.aspx?id=" + pageMod.guid + "';");
                }
                else
                {
                    Response.Redirect("/design/mbh5/default.aspx?id=" + pageMod.guid);
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Метод вызывается при добавлении в коллекцию, для установки свойства
        /// _Device. Данный объект modbus-устройства, является владельцем данной
        /// коллекции дискретных вводов/выводов. Если владелец не равен null, то данная
        /// коллекция уже принадлежит другой коллекции. При это вызывается
        /// исключение
        /// </summary>
        /// <param name="owner">Владелец данной коллекции</param>
        internal void SetOwner(Device owner)
        {
            if (_Device == null)
            {
                _Device = owner;

                for (int i = 0; i < Count; i++)
                {
                    this[i].SetOwner(_Device);
                }
            }
            else
            {
                // Если устройство, которому принадлежит данная коллекция дискретный
                // входов/выходов эквивалента устанавливаемой, тогда ничего не делаем.
                // Здесь нет ошибки. В противном случае, генерируем исключение
                if (_Device.Equals(owner) == false)
                {
                    throw new InvalidOperationException(
                              "Данная коллекция дискретных входов/выходов уже принадлежит другому устройству");
                }
            }
        }
Ejemplo n.º 20
0
 public bool AreEqual(Device m1, Device m2) => m1.Equals(m2);
Ejemplo n.º 21
0
 public bool Equals(ErrorLineModel other)
 {
     return(Device.Equals(other.Device) && Detail.Equals(other.Detail));
 }
Ejemplo n.º 22
0
        private void ListenThread(Object obj)
        {
            byte[] bytes = new byte[1024];

            ThreadParam arg = (ThreadParam)obj;
            TcpListener tcplistener;

            tcplistener = new TcpListener(IPAddress.Parse("0.0.0.0"), arg.port);
            tcplistener.Start();

            while (true)
            {
                if (tcplistener.Pending())
                {
                    string    remoteaddr;
                    TcpClient tcpclient = tcplistener.AcceptTcpClient();
                    remoteaddr = ((IPEndPoint)tcpclient.Client.RemoteEndPoint).Address.ToString();

                    Device d = new Device(arg.username, arg.password, tcpclient, remoteaddr, ((IPEndPoint)tcpclient.Client.RemoteEndPoint).Port);
                    d.loginState = 1;
                    DeviceList.Add(d);
                }

                bool modify = false;
                foreach (Device d in DeviceList)
                {
                    int rlen;
                    lock (d)//if (d.tcpClient.Connected) //lock (d)
                    {
                        if (d.tcpClient.Connected)
                        //lock(d)
                        {
                            if (d.tcpClient.Available > 0)
                            {
                                NetworkStream ns = d.tcpClient.GetStream();
                                rlen = ns.Read(bytes, 0, bytes.Length);
                                {
                                    if (rlen > 0)
                                    {
                                        d.PushBytes(bytes, rlen);
                                    }
                                }
                            }
                        }
                        else
                        {
                            EventDeviceLogout(d);
                        }

                        string jsontext = d.GetOneJsonText();
                        if (jsontext != null)
                        {
                            CommandStatus c = JsonConvert.DeserializeObject <CommandStatus>(jsontext);
                            if (c.command.Equals("register"))
                            {
                                CommandRegister cr = JsonConvert.DeserializeObject <CommandRegister>(jsontext);
                                if (d.loginState == 1)
                                {
                                    if (cr.session != null)
                                    {
                                        //新的登录方式
                                        if (cr.authentication != null)
                                        {
                                            MD5    md5    = new MD5CryptoServiceProvider();
                                            byte[] auth   = System.Text.Encoding.Default.GetBytes(cr.session + "@" + arg.username + "@" + arg.password);
                                            byte[] tmp    = md5.ComputeHash(auth);
                                            string md5str = null;

                                            for (int i = 0; i < tmp.Length; i++)
                                            {
                                                md5str += tmp[i].ToString("x2");
                                            }

                                            if (cr.authentication.Equals(md5str))
                                            {
                                                string session = Guid.NewGuid().ToString("N");
                                                byte[] bs1     = System.Text.Encoding.Default.GetBytes(session + "@" + arg.username + "@" + arg.password);
                                                byte[] tmp1    = md5.ComputeHash(bs1);
                                                string md52    = null;

                                                for (int i = 0; i < tmp.Length; i++)
                                                {
                                                    md52 += tmp1[i].ToString("x2");
                                                }

                                                CommandRegister cr2 = new CommandRegister();
                                                cr2.command        = "register";
                                                cr2.result         = 200;
                                                cr2.session        = session;
                                                cr2.authentication = md52;

                                                string        jsontext1 = JsonConvert.SerializeObject(cr2);
                                                NetworkStream ns        = d.tcpClient.GetStream();
                                                //if (ns.CanWrite)
                                                {
                                                    byte[] bs = System.Text.Encoding.Default.GetBytes(jsontext1);
                                                    ns.Write(bs, 0, bs.Length);
                                                }
                                                d.id         = cr.id;
                                                d.version    = cr.version;
                                                d.devicetype = cr.type;
                                                d.loginState = 2;
                                            }
                                        }
                                    }
                                    else //旧登录方式
                                    {
                                        if (cr.authentication != null)
                                        {
                                            MD5    md5    = new MD5CryptoServiceProvider();
                                            byte[] auth   = System.Text.Encoding.Default.GetBytes(arg.password + "@" + arg.username);
                                            byte[] tmp    = md5.ComputeHash(auth);
                                            string md5str = null;

                                            for (int i = 0; i < tmp.Length; i++)
                                            {
                                                md5str += tmp[i].ToString("x2");
                                            }

                                            if (cr.authentication.Equals(md5str))
                                            {
                                                string session = Guid.NewGuid().ToString("N");
                                                byte[] bs1     = System.Text.Encoding.Default.GetBytes(arg.password);
                                                byte[] tmp1    = md5.ComputeHash(bs1);
                                                string md52    = null;

                                                for (int i = 0; i < tmp.Length; i++)
                                                {
                                                    md52 += tmp1[i].ToString("x2");
                                                }

                                                CommandRegister cr2 = new CommandRegister();
                                                cr2.command = "register";
                                                cr2.result  = 200;

                                                if ((cr.auth_dir != null) && (cr.auth_dir.Equals("bi-direction")))
                                                {
                                                    cr2.authentication = md52;
                                                }
                                                string        jsontext1 = JsonConvert.SerializeObject(cr2);
                                                NetworkStream ns        = d.tcpClient.GetStream();
                                                //if (ns.CanWrite)
                                                {
                                                    byte[] bs = System.Text.Encoding.Default.GetBytes(jsontext1);
                                                    ns.Write(bs, 0, bs.Length);
                                                }
                                                d.id         = cr.id;
                                                d.version    = cr.version;
                                                d.devicetype = cr.type;
                                                d.loginState = 2;
                                            }
                                        }
                                    }

                                    /*
                                     * if ((cr.authentication != null) && (cr.session != null))
                                     * {
                                     *  MD5 md5 = new MD5CryptoServiceProvider();
                                     *  byte[] auth = System.Text.Encoding.Default.GetBytes(cr.session + "@" + arg.username + "@" + arg.password);
                                     *  byte[] tmp = md5.ComputeHash(auth);
                                     *  string md5str = null;
                                     *
                                     *  for (int i = 0; i < tmp.Length; i++)md5str += tmp[i].ToString("x2");
                                     *
                                     *  if (cr.authentication.Equals(md5str))
                                     *  {
                                     *      string session = Guid.NewGuid().ToString("N");
                                     *      byte[] bs1 = System.Text.Encoding.Default.GetBytes(session + "@" + arg.username + "@" + arg.password);
                                     *      byte[] tmp1 = md5.ComputeHash(bs1);
                                     *      string md52 = null;
                                     *
                                     *      for (int i = 0; i < tmp.Length; i++)md52 += tmp1[i].ToString("x2");
                                     *
                                     *      CommandRegister cr2 = new CommandRegister();
                                     *      cr2.command = "register";
                                     *      cr2.result = 200;
                                     *      cr2.session = session;
                                     *      cr2.authentication = md52;
                                     *
                                     *      string jsontext1 = JsonConvert.SerializeObject(cr2);
                                     *      NetworkStream ns = d.tcpClient.GetStream();
                                     *      //if (ns.CanWrite)
                                     *      {
                                     *          byte[] bs = System.Text.Encoding.Default.GetBytes(jsontext1);
                                     *          ns.Write(bs, 0, bs.Length);
                                     *      }
                                     *      d.id = cr.id;
                                     *      d.version = cr.version;
                                     *      d.devicetype = cr.type;
                                     *      d.loginState = 2;
                                     *  }
                                     * }
                                     */
                                }
                                else if (d.loginState == 2)
                                {
                                    if (cr.result == 200)
                                    {
                                        d.loginState = 3;
                                        EventDeviceLogin(d);

                                        for (int i = DeviceList.Count - 1; i >= 0; i--)
                                        {
                                            Device d1 = DeviceList[i];
                                            if (d1.id == d.id)
                                            {
                                                if (!d1.Equals(d))
                                                {
                                                    this.Remove(d1);
                                                    modify = true;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else if (c.command.Equals("status"))
                            {
                                CommandStatus cs = JsonConvert.DeserializeObject <CommandStatus>(jsontext);
                                d.systick = DateTime.Now.Ticks;
                            }
                        }
                    }
                    if (modify)
                    {
                        break;
                    }
                }
                Thread.Sleep(10);
            }
        }