/// <summary>
        /// Determines whether an object is structurally equal to the current instance.
        /// </summary>
        /// <param name="other">The object to compare with the current instance.</param>
        /// <param name="comparer">An object that determines whether the current instance and other are equal.</param>
        /// <returns>true if the two objects are equal; otherwise, false.</returns>
        bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
        {
            var   self       = this;
            Array otherArray = other as Array;

            if (otherArray == null)
            {
                var theirs = other as IImmutableArray;
                if (theirs != null)
                {
                    otherArray = theirs.Array;

                    if (self.array == null && otherArray == null)
                    {
                        return(true);
                    }
                    else if (self.array == null)
                    {
                        return(false);
                    }
                }
            }

            IStructuralEquatable ours = self.array;

            return(ours.Equals(otherArray, comparer));
        }
Exemple #2
0
        /// <inheritdoc />
        public new bool Equals(object x, object y)
        {
            if (x == null && y == null)
            {
                return(true);
            }

            if (x == null || y == null)
            {
                return(false);
            }

            // if there is a comparer registered for the type then use that
            IEqualityComparer comparer;

            if (this.comparerPerType.TryGetValue(x.GetType(), out comparer))
            {
                return(comparer.Equals(x, y));
            }

            // check if the type is structurally equatable, and if so pass this comparer as the structural comparer
            IStructuralEquatable structuralEquatable = x as IStructuralEquatable;

            if (structuralEquatable != null)
            {
                return(structuralEquatable.Equals(y, this));
            }

            // otherwise fall back on regular equality
            return(x.Equals(y));
        }
Exemple #3
0
            public void IStructuralEquatable_Equals_NullComparer_ThrowsNullReferenceException()
            {
                // This was not fixed in order to be compatible with the full .NET framework and Xamarin. See #13410
                IStructuralEquatable equatable = (IStructuralEquatable)Tuple;

                Assert.Throws <NullReferenceException>(() => equatable.Equals(Tuple, null));
            }
Exemple #4
0
        public bool WriteToPLC(int startingAddress, int[] values)
        {
            if (!client.Connected)
            {
                try
                {
                    //client.ConnectionTimeout = 5000;
                    //client.Connect();
                    Connect();
                }
                catch (Exception ex)
                {
                    log.Error($"PLC Connecion ex: {ex}");
                    //Thread.Sleep(100);
                    //client.Disconnect();

                    //client.Connect();
                }
            }
            //yazdı
            client.WriteMultipleRegisters(startingAddress, values);

            //yazdıklarını okudu
            var arr = client.ReadHoldingRegisters(startingAddress, values.Length);

            //ikisini karşılaştırdı doğru yazıp yazmadığını kontrol etti
            IStructuralEquatable se1 = values;
            bool isEqual             = se1.Equals(arr, StructuralComparisons.StructuralEqualityComparer);

            client.Disconnect();

            return(isEqual);
        }
Exemple #5
0
        public ImageInfoGet GetImage(string fileName, string mas)
        {
            ImageInfoGet tmp = new ImageInfoGet();

            tmp.Path      = fileName;
            tmp.JpegCover = mas;

            db = new Database.ApplicationContext();
            foreach (var img in db.Images)
            {
                if (fileName == img.Path)
                {
                    var mas1 = Convert.FromBase64String(mas);
                    IStructuralEquatable equ = mas1;
                    var masFromDB            = img.Details.Image;
                    if (equ.Equals(masFromDB, EqualityComparer <object> .Default))
                    {
                        img.count++;
                        db.SaveChanges();
                        tmp.Name       = img.Name;
                        tmp.Class      = img.ClassName;
                        tmp.Confidence = img.Confidence;
                        return(tmp);
                    }
                }
            }
            return(null);
        }
Exemple #6
0
        public static bool ArraysEqual(Array a, Array b)
        {
            IStructuralEquatable se1 = a;

            //Next returns True
            return(se1.Equals(b, StructuralComparisons.StructuralEqualityComparer));
        }
Exemple #7
0
        public static bool HeaderValidation(string[] header, string[] expectedHeader, string resourceType)
        {
            bool correctHeader = false;
            IStructuralEquatable actualHeader = header;

            if (actualHeader.Equals(expectedHeader, StructuralComparisons.StructuralEqualityComparer))
            {
                correctHeader = true;
            }
            else
            {
                string column = string.Empty;
                for (var iterator = 0; iterator < expectedHeader.Length; iterator++)
                {
                    if (!(header[iterator] == expectedHeader[iterator]))
                    {
                        column = expectedHeader[iterator];
                        break;
                    }
                }
                dynamic logHeader = null;
                int     count     = 0;
                foreach (var item in expectedHeader)
                {
                    logHeader = logHeader + item;
                    if (count < expectedHeader.Count() - 1)
                    {
                        logHeader = logHeader + ", ";
                        count++;
                    }
                }
                throw new Exception("Header Mismatch for " + resourceType + " at column " + column + "\n" + "Expected header:" + "\n" + logHeader);
            }
            return(correctHeader);
        }
Exemple #8
0
    static void Main()
    {
        int[] array1 = { 1, 2, 3 };
        int[] array2 = { 1, 2, 3 };
        IStructuralEquatable structuralEquator = array1;

        Console.WriteLine(array1.Equals(array2));                                             // False
        Console.WriteLine(structuralEquator.Equals(array2, EqualityComparer <int> .Default)); // True

        // string arrays
        string[]             a1 = "a b c d e f g".Split();
        string[]             a2 = "A B C D E F G".Split();
        IStructuralEquatable structuralEquator1 = a1;
        bool areEqual = structuralEquator1.Equals(a2, StringComparer.InvariantCultureIgnoreCase);

        Console.WriteLine("Arrays of strings are equal:" + areEqual);

        //tuples
        var firstTuple  = Tuple.Create(1, "aaaaa");
        var secondTuple = Tuple.Create(1, "AAAAA");
        IStructuralEquatable structuralEquator2 = firstTuple;
        bool areTuplesEqual = structuralEquator2.Equals(secondTuple, StringComparer.InvariantCultureIgnoreCase);

        Console.WriteLine("Are tuples equal:" + areTuplesEqual);
        IStructuralComparable sc1 = firstTuple;
        int comparisonResult      = sc1.CompareTo(secondTuple, StringComparer.InvariantCultureIgnoreCase);

        Console.WriteLine("Tuples comarison result:" + comparisonResult);        //0
    }
Exemple #9
0
    public static void Main()
    {
        Tuple <string, double, int>[] scores =
        { Tuple.Create("Ed",          78.8, 8),
          Tuple.Create("Abbey",    92.1, 9),
          Tuple.Create("Jim",      71.2, 9),
          Tuple.Create("Sam",      91.7, 8),
          Tuple.Create("Sandy",    71.2, 5),
          Tuple.Create("Penelope", 82.9, 8),
          Tuple.Create("Serena",   71.2, 9),
          Tuple.Create("Judith",   84.3, 9) };

        for (int ctr = 0; ctr < scores.Length; ctr++)
        {
            IStructuralEquatable score = scores[ctr];
            for (int ctr2 = ctr + 1; ctr2 < scores.Length; ctr2++)
            {
                Console.WriteLine("{0} = {1}: {2}", score,
                                  scores[ctr2],
                                  score.Equals(scores[ctr2],
                                               new Item2Comparer <string, double, int>()));
            }
            Console.WriteLine();
        }
    }
        public void Sort_ArrayAndDescSumElementsComparer_ArraySortedByMaxAbsolutValueByDesc()
        {
            int[][] array = new int[][]
            {
                new int[] { -1, 2 },
                new int[] { 0, 1, 1, 0 },
                new int[] { 0, 0, 0, 0 },
                new int[] { 3, -5, 2, 3 },
                new int[] { 2, 4, 1 }
            };

            int[][] expected = new int[][]
            {
                new int[] { 2, 4, 1 },
                new int[] { 3, -5, 2, 3 },
                new int[] { 0, 1, 1, 0 },
                new int[] { -1, 2 },
                new int[] { 0, 0, 0, 0 }
            };

            JaggedArray.Sort(array, new DescSumElementsComparer());
            IStructuralEquatable actual = array;

            Assert.IsTrue(actual.Equals(expected, StructuralComparisons.StructuralEqualityComparer));
        }
Exemple #11
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            AES256 AES = new AES256();
            string hashString = null; byte[] encryptedBytes = null;

            // 암호화 기본 설정
            AES.KeyString = textBoxKey.Text;
            AES.SaltBytes = CommonData.EncryptSalt;

            // 비밀번호 암호화
            hashString     = Convert.ToBase64String(SHA512.Create().ComputeHash(Encoding.UTF8.GetBytes(CommonData.HashSalt + textBoxPassword.Text)));
            encryptedBytes = AES.EncryptByte(Encoding.UTF8.GetBytes(hashString + textBoxPassword.Text));

            // 정보 로드 및 배열 비교 준비
            byte[] loadData         = File.ReadAllBytes(Path.Combine(Application.StartupPath, CommonData.Folder, CommonData.PasswordFile));
            IStructuralEquatable SE = loadData;

            // 배열 서로 비교
            if (SE.Equals(encryptedBytes, StructuralComparisons.StructuralEqualityComparer))
            {
                frmMain form = new frmMain();
                form.Show(); this.Hide();
            }
            else
            {
                MessageBox.Show("로그인에 실패하였습니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Application.Exit();
            }
        }
        public new bool Equals(Object x, Object y)
        {
            if (x != null)
            {
                IStructuralEquatable seObj = x as IStructuralEquatable;

                if (seObj != null)
                {
                    return(seObj.Equals(y, this));
                }

                if (y != null)
                {
                    return(x.Equals(y));
                }
                else
                {
                    return(false);
                }
            }
            if (y != null)
            {
                return(false);
            }
            return(true);
        }
Exemple #13
0
 public static void Show()
 {
     {
         int[] a1 = { 1, 2, 3 };
         int[] a2 = { 1, 2, 3 };
         IStructuralEquatable se1 = a1;
         Console.WriteLine(a1.Equals(a2));                                                  // False
         Console.WriteLine(se1.Equals(a2, EqualityComparer <int> .Default));                // True
     }
     {
         string[]             a1  = "the quick brown fox".Split();
         string[]             a2  = "THE QUICK BROWN FOX".Split();
         IStructuralEquatable se1 = a1;
         bool isTrue = se1.Equals(a2, StringComparer.InvariantCultureIgnoreCase);
     }
     {
         var t1 = Tuple.Create(1, "foo");
         var t2 = Tuple.Create(1, "FOO");
         IStructuralEquatable se1 = t1;
         Console.WriteLine(se1.Equals(t2, StringComparer.InvariantCultureIgnoreCase));                     // True
         IStructuralComparable sc1 = t1;
         Console.WriteLine(sc1.CompareTo(t2, StringComparer.InvariantCultureIgnoreCase));                  // 0
     }
     {
         var t1 = Tuple.Create(1, "FOO");
         var t2 = Tuple.Create(1, "FOO");
         Console.WriteLine(t1.Equals(t2));                   // True
     }
 }
        private bool CheckSd()
        {
            IStructuralEquatable left = Left.ToByteArray();

            if (left.Equals(Right.ToByteArray(), EqualityComparer <byte> .Default))
            {
                return(true);
            }

            if (!Report)
            {
                return(false);
            }

            if (Left.Control != Right.Control)
            {
                WriteWarning($"Control mismatch, left {Left.Control} right {Right.Control}");
            }

            if (Left.RmControl != Right.RmControl)
            {
                WriteWarning($"RmControl mismatch, left {Left.RmControl} right {Right.RmControl}");
            }

            CompareSid("Owner", Left.Owner?.Sid, Right.Owner?.Sid);
            CompareSid("Group", Left.Group?.Sid, Right.Group?.Sid);
            CompareAcls("DACL", Left.Dacl, Right.Dacl);
            CompareAcls("SACL", Left.Sacl, Right.Sacl);

            return(false);
        }
Exemple #15
0
        public bool Equals(WampMessage <TMessage> x, WampMessage <TMessage> y)
        {
            IStructuralEquatable xArguments = x.Arguments;
            IStructuralEquatable yArguments = y.Arguments;

            return(x.MessageType == y.MessageType &&
                   xArguments.Equals(yArguments, mRawComparer));
        }
            public static void Equals_WithNullComparer()
            {
                // Arrange
                IStructuralEquatable one = One;

                // Act & Assert
                Assert.ThrowsAnexn("comparer", () => one.Equals(One, null !));
            }
            public static void Equals_None_ForReferenceT()
            {
                // Arrange
                IStructuralEquatable none = Maybe <AnyT> .None;
                var same = Maybe <AnyT> .None;
                var some = Maybe.SomeOrNone(AnyT.Value);
                var cmp  = EqualityComparer <AnyT> .Default;

                // Act & Assert
                Assert.False(none.Equals(null, cmp));
                Assert.False(none.Equals(new object(), cmp));

                Assert.True(none.Equals(none, cmp));
                Assert.True(none.Equals(same, cmp));

                Assert.False(none.Equals(some, cmp));
            }
Exemple #18
0
            public void IStructuralEquatable_Equals_NullComparer_ThrowsNullReferenceException()
            {
                // This was not fixed in order to be compatible with the .NET Framework and Xamarin.
                // See https://github.com/dotnet/runtime/issues/19265
                IStructuralEquatable equatable = (IStructuralEquatable)Tuple;

                Assert.Throws <NullReferenceException>(() => equatable.Equals(Tuple, null));
            }
Exemple #19
0
        static void Main(string[] args)
        {
            IContainer container = Container.SingleInstance;

            //var container = new Container();

            container.RegisterType <IEntityBase, StudentClass>();

            //container.RegisterType(action =>
            //{
            //    action.RegisterType<IEntityBase, StudentClass>();
            //});

            IEntityBase aa = container.Resolve <IEntityBase>();
            IEntityBase bb = container.Resolve <IEntityBase>();

            if (aa == bb)
            {
            }
            if (aa.Equals(bb))
            {
            }

            Console.WriteLine("Hello World!");
            //IUnityContainer container = new UnityContainer();
            //container.RegisterType<IEntityBase, Student>();
            //container.RegisterType<IEntityBase, StudentClass>("adasd");
            //container.RegisterType<IEntityBase, StudentClass>("1212");
            //var student = container.Resolve<IEntityBase>("adasd");
            //IEntityBase studentclass = container.Resolve<IEntityBase>("1212");

            string[]             a1  = "the quick brown fox".Split();
            string[]             a2  = "THE QUICK BROWN FOX".Split();
            IStructuralEquatable se1 = a1;
            bool isTrue = se1.Equals(a2, StringComparer.InvariantCultureIgnoreCase);

            string  s   = "1212";
            dynamic sb  = s;
            var     sb1 = s;

            Test1(s, sb1);
            IEntityBase entityBase = new Student();

            Queue queue = new Queue();

            OrderedDictionary dictionary = new OrderedDictionary();


            Stack stack = new Stack();

            //IContainer container = new Container();
            //container.RegisterType<IEntityBase, Student>();
            //container.RegisterType<IEntityBase, StudentClass>();
            ////container.RegisterType<IEntityBase, StudentClass>();
            //IEntityBase student = container.Resolve<IEntityBase>();
            //var studentclass = container.Resolve<StudentClass>();
        }
        public void TestSum()
        {
            int[][] start  = new[] { new[] { 1 }, null, null, new[] { -2, 7, 5 }, null, new[] { 40, 2 } };
            int[][] result = new[] { null, null, null, new[] { 1 }, new[] { -2, 7, 5 }, new[] { 40, 2 } };
            DelegateToInterfaceSort.SortBy(start, new ComparatorByMaxElement().Compare);
            IStructuralEquatable eq = start;

            Assert.AreEqual(eq.Equals(result, StructuralComparisons.StructuralEqualityComparer), true);
        }
Exemple #21
0
        public void Stack_CopyTo_Test(int[] expectedResult)
        {
            int[] intArray = new int[5];
            intArray[0] = 11;
            intArray[1] = 12;
            stack.CopyTo(intArray, 2);
            IStructuralEquatable comparer = intArray;

            Assert.IsTrue(comparer.Equals(expectedResult, EqualityComparer <int> .Default));
        }
        public void Queue_CopyTo_Test(string[] expectedResult)
        {
            string[] strArray = new string[5];
            strArray[0] = "initial 1";
            strArray[1] = "initial 2";
            queue.CopyTo(strArray, 2);
            IStructuralEquatable comparer = strArray;

            Assert.IsTrue(comparer.Equals(expectedResult, EqualityComparer <string> .Default));
        }
    public static void Main()
    {
        var value1 = GetValues(1);
        var value2 = GetValues(2);
        IStructuralEquatable iValue1 = value1;

        Console.WriteLine("{0} =\n{1} :\n{2}", value1, value2,
                          iValue1.Equals(value2,
                                         new DoubleComparer <int, double, double, double, double>(.01)));
    }
        static void Main(string[] args)
        {
            int[] a1 = { 1, 2, 3 };
            int[] a2 = { 1, 2, 3 };

            IStructuralEquatable se1 = a1;

            Console.WriteLine(a1.Equals(a2));
            Console.WriteLine(se1.Equals(a2, EqualityComparer <int> .Default));
            Console.ReadKey();
        }
        public void SortTests(int[] array)
        {
            int[] arraySystem = new int[array.Length];
            Array.Copy(array, arraySystem, array.Length);
            Array.Sort(arraySystem);
            ArrayExtension.Sort(array);

            IStructuralEquatable iArray = arraySystem;

            Assert.IsTrue(iArray.Equals(array, StructuralComparisons.StructuralEqualityComparer));
        }
Exemple #26
0
        public bool is_DATA(UInt16 bloc, byte[] trame)
        {
            byte[] a = op_data.Concat(BitConverter.GetBytes(bloc).Reverse()).ToArray();
            IStructuralEquatable se1 = a;

            if (se1.Equals(trame.Take(4).ToArray(), StructuralComparisons.StructuralEqualityComparer))
            {
                return(true);
            }
            return(false);
        }
Exemple #27
0
 public static bool StructuralEqual(IStructuralEquatable left, IStructuralEquatable right)
 {
     if (left != null && right != null)
     {
         return(left.Equals(right, DefaultComparer));
     }
     else
     {
         return(left == null && right == null);
     }
 }
Exemple #28
0
        public bool Autenticar(string Usuario, string ClaveUsuario)
        {
            bool resultado = false;

            try
            {
                ObjConnection = new SqlConnection(_ConexionData);
                SqlCommand ObjCommand = new SqlCommand("SP_TBC_USUARIO_GetByAll", ObjConnection);
                ObjParam = new SqlParameter();
                ObjCommand.CommandType = CommandType.StoredProcedure;

                ObjCommand.Parameters.AddWithValue("@ID", Usuario);
                ObjCommand.Parameters.AddWithValue("@DS_NOMBRE_USUARIO", "");
                ObjCommand.Parameters.AddWithValue("@CD_CLAVE_USUARIO", "");
                ObjCommand.Parameters.AddWithValue("@ID_PERFIL_USUARIO", "");
                ObjCommand.Parameters.AddWithValue("@DS_DIRE_EMAIL", "");
                ObjCommand.Parameters.AddWithValue("@CD_ESTADO_USUARIO", 0);
                ObjCommand.Parameters.AddWithValue("@OPCI_CONS", 1);

                ObjConnection.Open();

                SqlDataReader objReader = ObjCommand.ExecuteReader();

                CEncriptacion objEncripcion = new CEncriptacion();

                byte[] ClaveEncriptada;
                byte[] ClaveEncriptadaGuardada;

                while (objReader.Read())
                {
                    ClaveEncriptadaGuardada = ((byte[])objReader["CD_CLAVE_USUARIO"]);
                    ClaveEncriptada         = objEncripcion.Encrypt(CEncriptacion.ToBase64(ClaveUsuario));
                    IStructuralEquatable ob1 = ClaveEncriptadaGuardada;

                    if (ob1.Equals(ClaveEncriptada, StructuralComparisons.StructuralEqualityComparer))
                    {
                        resultado = true;
                    }
                }

                ObjConnection.Close();

                if (ObjConnection.State != ConnectionState.Closed)
                {
                    ObjConnection.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(resultado);
        }
Exemple #29
0
    public static void Main()
    {
        var rate1 = Tuple.Create("New York", -.013934, .014505,
                                 -.1042733, .0354833, .093644, .0290792);
        var rate2 = Tuple.Create("Unknown City", -.013934, .014505,
                                 -.1042733, .0354833, .093644, .0290792);
        var rate3 = Tuple.Create("Unknown City", -.013934, .014505,
                                 -.1042733, .0354833, .093644, .029079);
        var rate4 = Tuple.Create("San Francisco", -.0451934, -.0332858,
                                 -.0512803, .0662544, .0728964, .0491912);
        IStructuralEquatable eq = rate1;

        // Compare first tuple with remaining two tuples.
        Console.WriteLine("{0} = ", rate1.ToString());
        Console.WriteLine("   {0} : {1}", rate2,
                          eq.Equals(rate2, new RateComparer <string, double, double, double, double, double, double>()));
        Console.WriteLine("   {0} : {1}", rate3,
                          eq.Equals(rate3, new RateComparer <string, double, double, double, double, double, double>()));
        Console.WriteLine("   {0} : {1}", rate4,
                          eq.Equals(rate4, new RateComparer <string, double, double, double, double, double, double>()));
    }
Exemple #30
0
        private static bool LocalSettingFileIsOriginal()
        {
            if (ComputerFingerprint == null)
            {
                ComputerFingerprint = Fingerprint.Value;
                Update();
                return(true);
            }
            IStructuralEquatable eqa1 = ComputerFingerprint;

            return(eqa1.Equals(Fingerprint.Value, StructuralComparisons.StructuralEqualityComparer));
        }