Пример #1
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            int llen = (explicitTagging) ?
            MatchTag (buffer, Asn1Tag.SEQUENCE) : implicitLength;

             Init ();

             // decode SEQUENCE

             Asn1BerDecodeContext _context =
            new Asn1BerDecodeContext (buffer, llen);

             IntHolder elemLen = new IntHolder();

             // decode type

             if (_context.MatchElemTag (Asn1Tag.UNIV, Asn1Tag.PRIM, 4, elemLen, false)) {
            type = new AttributeDescription();
            type.Decode (buffer, true, elemLen.mValue);
             }
             else throw new Asn1MissingRequiredException (buffer);

             // decode vals

             if (_context.MatchElemTag (Asn1Tag.UNIV, Asn1Tag.CONS, 17, elemLen, false)) {
            vals = new _SetOfAttributeValue();
            vals.Decode (buffer, true, elemLen.mValue);
             }
             else throw new Asn1MissingRequiredException (buffer);

             if (explicitTagging && llen == Asn1Status.INDEFLEN) {
            MatchTag (buffer, Asn1Tag.EOC);
             }
        }
Пример #2
0
        public static void Deconstruct1()
        {
            var tuple = Tuple.Create(1);
            var h = new IntHolder();

            tuple.Deconstruct(out h.x1);
            Assert.Equal("1", h.ToString());
        }
Пример #3
0
        public static void Deconstruct7()
        {
            var tuple = Tuple.Create(1, 2, 3, 4, 5, 6, 7);
            var h = new IntHolder();

            tuple.Deconstruct(out h.x1, out h.x2, out h.x3, out h.x4, out h.x5, out h.x6, out h.x7);
            Assert.Equal("1 2 3 4 5 6 7", h.ToString());
        }
        public void TestExceptionOnInvalidProperty()
        {
            var obj = new IntHolder();
            PropertyInfo property = obj.GetType().GetProperties().Where(pi => pi.Name == "NotConvertible").First();

            Assert.That(() => underTest.GetHtmlInfo(property)
                , Throws.InstanceOf<ArgumentException>());
        }
Пример #5
0
    public void Deconstruct2()
    {
        var tuple = Tuple.Create(1, 2);
        var h = new IntHolder();

        tuple.Deconstruct(out h.x1, out h.x2);
        Assert.Equal("1 2", h.ToString());
    }
Пример #6
0
        public static void Deconstruct4()
        {
            var tuple = Tuple.Create(1, 2, 3, 4);
            var h = new IntHolder();

            tuple.Deconstruct(out h.x1, out h.x2, out h.x3, out h.x4);
            Assert.Equal("1 2 3 4", h.ToString());
        }
        public void TestIntPropertyConversion()
        {
            var obj = new IntHolder();
            PropertyInfo property = obj.GetType().GetProperties().Where(pi => pi.Name == "I").First();

            HtmlPropertyInfo htmlProperty = underTest.GetHtmlInfo(property);

            Assert.That(htmlProperty.Data, Is.EqualTo(HtmlPropertyInfo.DataType.Number), "Wrong datatype for property");
        }
        public void TestPropertyConversionName()
        {
            var obj = new IntHolder();
            PropertyInfo property = obj.GetType().GetProperties().Where(pi => pi.Name == "I").First();

            HtmlPropertyInfo htmlProperty = underTest.GetHtmlInfo(property);

            Assert.That(htmlProperty.Name , Is.EqualTo(property.Name), "Wrong name for property");
        }
Пример #9
0
        public void HistoricalProperty01()
        {
            History history = new History();
            IntHolder ih = new IntHolder();
            ih.IP = 5;

            HistoricalProperty<int> ip = new HistoricalProperty<int>(history, ih, "IP");

            int s1 = history.TakeSnapshot();

            HistoricalStack<int> stack = new HistoricalStack<int>(history);

            ip.Value = 6;
            ip.Value = 7;
            stack.Push(ip.Value);

            int s2 = history.TakeSnapshot();

            stack.Push(++ip.Value);
            stack.Push(ip.Value = stack.Pop() * stack.Pop());

            int s3 = history.TakeSnapshot();

            history.RevertToSnapshot(s1);

            Assert.AreEqual(ih.IP, 5);
            Assert.IsTrue(stack.IsEmpty);

            history.RevertToSnapshot(s2);

            Assert.AreEqual(7, ih.IP);
            Assert.AreEqual(7, stack[0]);

            history.RevertToSnapshot(s3);

            Assert.AreEqual(56, ih.IP);
            Assert.AreEqual(56, stack[0]);

            // Once again
            history.RevertToSnapshot(s1);

            Assert.AreEqual(ih.IP, 5);
            Assert.IsTrue(stack.IsEmpty);

            history.RevertToSnapshot(s2);

            Assert.AreEqual(7, ih.IP);
            Assert.AreEqual(7, stack[0]);

            history.RevertToSnapshot(s3);

            Assert.AreEqual(56, ih.IP);
            Assert.AreEqual(56, stack[0]);
        }
        public void Execute()
        {
            //A reference type is a type which has its value, a reference to the appropriate data, rather than the data itself. 
            StringBuilder r1 = new StringBuilder();
            r1.Append("hello");
            StringBuilder r2 = r1;
            Console.WriteLine(r2); // Prints hello

            StringBuilder r11 = new StringBuilder();
            r11.Append("hello");
            StringBuilder r22 = r11;
            r11.Append(" world");
            Console.WriteLine(r22); // Prints hello world

            StringBuilder r111 = new StringBuilder();
            r111.Append("hello");
            StringBuilder r222 = r111;
            r111.Append(" world");
            r111 = new StringBuilder("goodbye"); //New reference created
            Console.WriteLine(r111); // Prints goodbye
            Console.WriteLine(r222); // Still prints hello world

            //Parameter Passing of reference value
            StringBuilder s = new StringBuilder();
            s.Append("hello");
            Change1(s);
            Console.WriteLine(s == null);//False

            StringBuilder s1 = new StringBuilder();
            s1.Append("hello");
            Change2(s1);
            Console.WriteLine(s1);//Hello world

            List<string> ls = new List<string>();
            ls.Add("hello");
            ChangeList1(ls);
            foreach(string lss in ls)Console.WriteLine(lss);//hello

            List<string> ls1 = new List<string>();
            ls1.Add("hello");
            ChangeList2(ls1);
            foreach (string lss in ls1) Console.WriteLine(lss);//hello world

            //While reference types have a layer of indirection between the variable and the real data, value types don't. 
            //Variables of a value type directly contain the data. Assignment of a value type involves the actual data being copied
            IntHolder v1 = new IntHolder();
            v1.i = 5;
            IntHolder v2 = v1;
            v1.i = 6;
            Console.WriteLine(v2.i);
        }
Пример #11
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            var context   = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0, ObjectIdentifierTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            EncryptionParamSet = new Gost2814789ParamSet();
            EncryptionParamSet.Decode(buffer, true, parsedLen.Value);

            if (context.MatchElemTag(0x80, 0x20, EocTypeCode, parsedLen, true))
            {
                EphemeralPublicKey = new SubjectPublicKeyInfo();
                EphemeralPublicKey.Decode(buffer, false, parsedLen.Value);
            }

            if (!context.MatchElemTag(0, 0, OctetStringTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            Ukm = new Asn1OctetString();
            Ukm.Decode(buffer, true, parsedLen.Value);

            if (Ukm.Length != 8)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, "Ukm.Length", Ukm.Length);
            }
        }
Пример #12
0
 /// <summary>
 /// Refreshes the replication information.
 /// </summary>
 /// <param name="commands">The commands.</param>
 public void RefreshReplicationInformation(ServerClient commands)
 {
     lock (replicationLock)
     {
         lastReplicationUpdate = DateTime.UtcNow;
         var document = commands.DirectGet(commands.Url, RavenReplicationDestinations);
         failureCounts[commands.Url] = new IntHolder();                // we just hit the master, so we can reset its failure count
         if (document == null)
         {
             return;
         }
         var replicationDocument = document.DataAsJson.JsonDeserialization <ReplicationDocument>();
         replicationDestinations = replicationDocument.Destinations.Select(x => x.Url).ToList();
         foreach (var replicationDestination in replicationDestinations)
         {
             IntHolder value;
             if (failureCounts.TryGetValue(replicationDestination, out value))
             {
                 continue;
             }
             failureCounts[replicationDestination] = new IntHolder();
         }
     }
 }
Пример #13
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            var context   = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0, ObjectIdentifierTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            EncryptionParamSet = new Gost2814789ParamSet();
            EncryptionParamSet.Decode(buffer, true, parsedLen.Value);

            if (!context.Expired())
            {
                if (buffer.PeekTag().Equals(0, 0, ObjectIdentifierTypeCode))
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1SeqOrderException);
                }

                _extElem1 = new Asn1OpenExt();

                while (!context.Expired())
                {
                    _extElem1.DecodeComponent(buffer);
                }
            }
            else
            {
                _extElem1 = null;
            }
        }
Пример #14
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            var context   = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0, OctetStringTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            EncryptedKey = new Gost2814789Key();
            EncryptedKey.Decode(buffer, true, parsedLen.Value);

            if (context.MatchElemTag(0x80, 0, EocTypeCode, parsedLen, true))
            {
                _maskKey = new Gost2814789Key();
                _maskKey.Decode(buffer, false, parsedLen.Value);
            }

            if (!context.MatchElemTag(0, 0, OctetStringTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            MacKey = new Gost2814789Mac();
            MacKey.Decode(buffer, true, parsedLen.Value);

            if (MacKey.Length != 4)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, "MacKey.Length", MacKey.Length);
            }
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            SessionEncryptedKey = null;
            TransportParams     = null;

            var context   = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0x20, SequenceTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            SessionEncryptedKey = new Gost_28147_89_EncryptedKey();
            SessionEncryptedKey.Decode(buffer, true, parsedLen.Value);

            if (context.MatchElemTag(0x80, 0x20, EocTypeCode, parsedLen, true))
            {
                TransportParams = new Gost_R3410_TransportParams();
                TransportParams.Decode(buffer, false, parsedLen.Value);
            }
        }
Пример #16
0
 public ImmutableStruct(int immutableInt, IntHolder myIntHolder)     //: this()
 {
     ImmutableInt = immutableInt;
     IntHolder    = new ImmutableIntHolder(myIntHolder);  // convert here.
 }
 public int big(IntHolder ih1, IntHolder ih2, int x)
 {
     return(ih1.y + ih2.z + x);
 }
Пример #18
0
 static void Foo(IntHolder x)
 {
     x = new IntHolder();
 }
Пример #19
0
 void Foo(ref IntHolder x)
 {
     x.I = 10;
 }
Пример #20
0
        /// <summary>
        /// Resets the failure count for the specified URL
        /// </summary>
        /// <param name="operationUrl">The operation URL.</param>
        public void ResetFailureCount(string operationUrl)
        {
            IntHolder value = GetHolder(operationUrl);

            Thread.VolatileWrite(ref value.Value, 0);
        }
 public ImmutableStruct(int immutableInt, IntHolder myIntHolder) : this()
 {
     ImmutableInt = immutableInt;
     IntHolder    = myIntHolder.ToImmutable();  // convert to immutable
 }
Пример #22
0
        public static void Deconstruct21()
        {
            var tuple = ValueTupleTests.CreateLongRef(1, 2, 3, 4, 5, 6, 7, ValueTupleTests.CreateLongRef(8, 9, 10, 11, 12, 13, 14, Tuple.Create(15, 16, 17, 18, 19, 20, 21)));
            var h = new IntHolder();

            tuple.Deconstruct(out h.x1, out h.x2, out h.x3, out h.x4, out h.x5, out h.x6, out h.x7, out h.x8, out h.x9, out h.x10, out h.x11, out h.x12, out h.x13, out h.x14, out h.x15, out h.x16, out h.x17, out h.x18, out h.x19, out h.x20, out h.x21);
            Assert.Equal("1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21", h.ToString());
        }
Пример #23
0
        public static void Deconstruct14()
        {
            var tuple = ValueTupleTests.CreateLongRef(1, 2, 3, 4, 5, 6, 7, Tuple.Create(8, 9, 10, 11, 12, 13, 14));
            var h = new IntHolder();

            tuple.Deconstruct(out h.x1, out h.x2, out h.x3, out h.x4, out h.x5, out h.x6, out h.x7, out h.x8, out h.x9, out h.x10, out h.x11, out h.x12, out h.x13, out h.x14);
            Assert.Equal("1 2 3 4 5 6 7 8 9 10 11 12 13 14", h.ToString());
        }
Пример #24
0
 public void TestValueTypes()
 {
     // We create a new IntHolder struct (a value type) and assign
     // the integer value of 5. Then we create a second IntHolder
     // and assign it with the value of first. This *copies*
     // the value into second - it doesn't create a reference.
     // Therefore, when we change first to 6, the second variable
     // remains with the value of 5 we copied into it.
     IntHolder first = new IntHolder();
     first.i = 5;
     IntHolder second = first;
     first.i = 6;
     Assert.AreEqual(second, new IntHolder { i = 5 });
 }
        private static async Task RunConsumerAsync(IAsyncBatchCollection <int> queue, IntHolder itemsTakeHolder, int itemsAddedTotal, CancellationTokenSource cancelSource)
        {
            try
            {
                CancellationToken cancelToken = cancelSource.Token;

                while (true)
                {
                    IReadOnlyList <int> items = await queue.TakeAsync(cancelToken).ConfigureAwait(false);

                    int itemsTakenLocal = Interlocked.Add(ref itemsTakeHolder.Value, items.Count);

                    if (itemsTakenLocal >= itemsAddedTotal)
                    {
                        cancelSource.Cancel();
                    }
                }
            }
            catch (OperationCanceledException)
            {
            }
        }
Пример #26
0
 static void Foo(IntHolder x)
 {
     x = new IntHolder();
     //x = null;
     //x.i = 99999;
 }
Пример #27
0
        /// <summary>
        /// Determines whether this is the first failure on the specified operation URL.
        /// </summary>
        /// <param name="operationUrl">The operation URL.</param>
        public bool IsFirstFailure(string operationUrl)
        {
            IntHolder value = GetHolder(operationUrl);

            return(Thread.VolatileRead(ref value.Value) == 0);
        }
Пример #28
0
        /// <summary>
        /// Increments the failure count for the specified operation URL
        /// </summary>
        /// <param name="operationUrl">The operation URL.</param>
        public void IncrementFailureCount(string operationUrl)
        {
            IntHolder value = GetHolder(operationUrl);

            Interlocked.Increment(ref value.Value);
        }
Пример #29
0
 public ImmutableIntHolder(IntHolder intHolder)
 {
     //map all properties
     X = intHolder.X;
 }
Пример #30
0
        public static void Deconstruct9()
        {
            var tuple = ValueTupleTests.CreateLongRef(1, 2, 3, 4, 5, 6, 7, Tuple.Create(8, 9));
            var h = new IntHolder();

            tuple.Deconstruct(out h.x1, out h.x2, out h.x3, out h.x4, out h.x5, out h.x6, out h.x7, out h.x8, out h.x9);
            Assert.Equal("1 2 3 4 5 6 7 8 9", h.ToString());
        }
Пример #31
0
 public Data(int first, int second, int third)
 {
     _first  = first;
     _second = second;
     _third  = new IntHolder(third);
 }
Пример #32
0
 public Data(int first, int second, int third)
 {
     _first = first;
     _second = second;
     _third = new IntHolder(third);
 }
Пример #33
0
        public virtual bool MatchElemTag(short tagClass, short tagForm, int tagIdCode, IntHolder parsedLen, bool advance)
        {
            if (Expired())
            {
                return(false);
            }

            var flag = _decodeBuffer.MatchTag(tagClass, tagForm, tagIdCode, _tagHolder, parsedLen);

            if ((_elemLength != Asn1Status.IndefiniteLength) && (parsedLen.Value != Asn1Status.IndefiniteLength))
            {
                var num = _decodeBuffer.ByteCount - _decBufByteCount;

                if ((parsedLen.Value < 0) || (parsedLen.Value > (_elemLength - num)))
                {
                    throw new Exception("Asn1 Invalid Length Exception");
                }
            }

            if (flag && !advance)
            {
                _decodeBuffer.Reset();
            }

            return(flag);
        }
Пример #34
0
 void Foo(IntHolder x)
 {
     x.I = 10;
 }
Пример #35
0
    public void Deconstruct12()
    {
        var tuple = CreateLongRef(1, 2, 3, 4, 5, 6, 7, Tuple.Create(8, 9, 10, 11, 12));
        var h = new IntHolder();

        tuple.Deconstruct(out h.x1, out h.x2, out h.x3, out h.x4, out h.x5, out h.x6, out h.x7, out h.x8, out h.x9, out h.x10, out h.x11, out h.x12);
        Assert.Equal("1 2 3 4 5 6 7 8 9 10 11 12", h.ToString());
    }
Пример #36
0
 public virtual bool MatchElemTag(Asn1Tag tag, IntHolder parsedLen, bool advance)
 {
     return(MatchElemTag(tag.Class, tag.Form, tag.IdCode, parsedLen, advance));
 }
Пример #37
0
    public void Deconstruct8()
    {
        var tuple = CreateLongRef(1, 2, 3, 4, 5, 6, 7, Tuple.Create(8));
        var h = new IntHolder();

        tuple.Deconstruct(out h.x1, out h.x2, out h.x3, out h.x4, out h.x5, out h.x6, out h.x7, out h.x8);
        Assert.Equal("1 2 3 4 5 6 7 8", h.ToString());
    }
Пример #38
0
		/// <summary>
		/// Refreshes the replication information.
		/// </summary>
		/// <param name="commands">The commands.</param>
		public void RefreshReplicationInformation(ServerClient commands)
		{
			lock (replicationLock)
			{

				lastReplicationUpdate = DateTime.UtcNow;
				var document = commands.DirectGet(commands.Url, RavenReplicationDestinations);
				failureCounts[commands.Url] = new IntHolder();// we just hit the master, so we can reset its failure count
				if (document == null)
					return;
				var replicationDocument = document.DataAsJson.JsonDeserialization<ReplicationDocument>();
				replicationDestinations = replicationDocument.Destinations.Select(x => x.Url).ToList();
				foreach (var replicationDestination in replicationDestinations)
				{
					IntHolder value;
					if (failureCounts.TryGetValue(replicationDestination, out value))
						continue;
					failureCounts[replicationDestination] = new IntHolder();
				}
			}
		}
Пример #39
0
    public void Deconstruct19()
    {
        var tuple = CreateLongRef(1, 2, 3, 4, 5, 6, 7, CreateLongRef(8, 9, 10, 11, 12, 13, 14, Tuple.Create(15, 16, 17, 18, 19)));
        var h = new IntHolder();

        tuple.Deconstruct(out h.x1, out h.x2, out h.x3, out h.x4, out h.x5, out h.x6, out h.x7, out h.x8, out h.x9, out h.x10, out h.x11, out h.x12, out h.x13, out h.x14, out h.x15, out h.x16, out h.x17, out h.x18, out h.x19);
        Assert.Equal("1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19", h.ToString());
    }