public override object ConvertFrom(ITypeDescriptorContext context,
                                    CultureInfo culture, object value)
 {
     if (value is string)
     {
         // Cannot do JsonConvert.DeserializeObject here because it will cause a stackoverflow exception.
         using (var reader = new JsonTextReader(new StringReader((string)value)))
         {
             JObject item = JObject.Load(reader);
             if (item == null)
             {
                 return(null);
             }
             MyValue myValue = new MyValue();
             var     prop1   = item["Prop1"];
             if (prop1 != null)
             {
                 myValue.Prop1 = prop1.ToString();
             }
             var prop2 = item["Prop2"];
             if (prop2 != null)
             {
                 myValue.Prop2 = prop2.ToString();
             }
             return(myValue);
         }
     }
     return(base.ConvertFrom(context, culture, value));
 }
 //constructor
 public Proposer(Acceptor[] acceptors)
 {
     //this.myAcceptor = myAcceptor;
     this.acceptors  = acceptors;
     proposalNumber  = GenerateNextProposalNumber();
     MyProposedValue = new MyValue("Yanxin Wang");
 }
        public void HashTableValuesSameHashcode()
        {
            var _10 = new MyValue {
                Value = 10
            };
            var _110 = new MyValue {
                Value = 110
            };
            var _1010 = new MyValue {
                Value = 1010
            };
            var table = new HashTable <MyValue, int>
            {
                { _10, 10 },
                { _110, 110 },
                { _1010, 1010 }
            };

            Assert.AreEqual(table.Count, 3);
            Assert.IsTrue(table.Contains(_10));
            Assert.IsTrue(table.Contains(_110));
            Assert.IsTrue(table.Contains(_1010));
            Assert.IsTrue(table.Remove(_1010));
            Assert.AreEqual(table.Count, 2);
            Assert.IsTrue(table.Contains(_10));
            Assert.IsTrue(table.Contains(_110));
        }
Esempio n. 4
0
        //フォーカス時に文字列全部を選択
        private void MyTextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            var tb = sender as TextBox;

            tb.Text = MyValue.ToString();
            tb.SelectAll();
        }
Esempio n. 5
0
        public void ObjectsOfDifferentTypeAreNotEqual_EvenIfSubclass()
        {
            var value1 = new MyValue();
            var value2 = new MyValue2();

            Assert.IsFalse(value1.Equals(value2));
        }
Esempio n. 6
0
        // have a look at  : http://stackoverflow.com/questions/7903595/loading-modules-in-all-assemblies-in-ninject

        static void Main(string[] args)
        {
            IKernel kernel = new StandardKernel(new TopModule());

            //var modules = new List<INinjectModule>
            //{
            //    new MiddleModule(),
            //    new BottomModule()
            //};
            //kernel.Load(modules);


            kernel.Load("*.dll"); // or : kernel.Load(AppDomain.CurrentDomain.GetAssemblies());

            var topClass = kernel.Get <ITopClass>();

            var myValue = new MyValue()
            {
                Value = 5
            };
            var message = topClass.GetResult(myValue);

            Console.WriteLine(message);

            Console.WriteLine("Press enter to continue...");
            Console.ReadLine();
        }
Esempio n. 7
0
        public void JsonDeserializesAsSingleValue()
        {
            string  json  = "\"hello\"";
            MyValue value = JsonConvert.DeserializeObject <MyValue>(json);

            value.Value.Should().Be("hello");
        }
Esempio n. 8
0
        public async Task Post([FromBody] MyValue value)
        {
            var queueClient  = new QueueClient(ServiceBusConnectionString, QueueName);
            var queueMessage = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value)));

            _logger.LogInformation($"Sending message:\n{value.ToString()}");
            await queueClient.SendAsync(queueMessage);
        }
 /// <summary>
 /// Disposes of the Concurrent Weak Dictionary, cleaning up any weak references
 /// </summary>
 public void Dispose()
 {
     // Free our GC Handles so we don't create a memory leak
     foreach (var MyValue in _Dictionary.Values)
     {
         MyValue.Dispose();
     }
 }
Esempio n. 10
0
        public void Concordance(StreamWriter writer, int numOfLines)
        {
            int    currentPage = 1;
            string tempStr;
            SortedDictionary <string, MyValue> dictionary = new SortedDictionary <string, MyValue>();//MySortedDictionary();
            MyValue temp  = new MyValue();
            int     lines = numOfLines;

            for (int i = 0; i < Length; i++)
            {
                if (i > lines)
                {
                    currentPage++;
                    lines = lines + numOfLines;
                }
                for (int j = 0; j < sentences[i].Length; j++)
                {
                    tempStr = sentences[i].words[j].symbol.Content;
                    if (dictionary.TryGetValue(tempStr.ToLower(), out temp))
                    {
                        temp.pageNumbers.Add(currentPage);
                        temp.numOfRepetitions++;
                        dictionary[tempStr.ToLower()] = temp;
                    }
                    else
                    {
                        temp = new MyValue();
                        temp.pageNumbers.Add(currentPage);
                        temp.numOfRepetitions = 1;
                        dictionary.Add(tempStr.ToLower(), temp);
                    }
                    tempStr = "";
                }
            }
            char ch, pre_ch = ' ';
            bool newLetter = false;

            foreach (var word in dictionary)
            {
                ch = word.Key[0];
                if (ch != pre_ch)
                {
                    newLetter = true;
                }
                pre_ch = ch;
                if (newLetter)
                {
                    writer.WriteLine(Char.ToUpper(word.Key[0]));
                }
                writer.Write("{0,-20}.................{1,5}: ", word.Key, word.Value.numOfRepetitions);
                foreach (int value in word.Value.pageNumbers)
                {
                    writer.Write(value + " ");
                }
                writer.WriteLine();
                newLetter = false;
            }
        }
Esempio n. 11
0
        public void Post(MyValueRequest request)
        {
            var newValue = new MyValue {
                Name = request.Name
            };

            _context.MyValues.Add(newValue);
            _context.SaveChanges();
        }
        /// <summary>
        /// Disposes of the Weak Dictionary, cleaning up any weak references
        /// </summary>
        public void Dispose()
        {
            foreach (var MyValue in _Dictionary.Values)
            {
                MyValue.Dispose();
            }

            GC.SuppressFinalize(this);
        }
    public void testing()
    {
        string  key   = "Mykey" + NextNumber.toString();
        MyValue value = new MyValue();

        value.Name   = "Tony";
        value.Width  = "150";
        value.Height = "320";
        dic.Add(key, value);
    }
Esempio n. 14
0
    public void testing()
    {
        MyValue value = new MyValue();

        value.Name   = "Tony";
        value.Width  = "150";
        value.Height = "320";
        dynamic jsonValue = new { keyA = value };
        string  height    = jsonValue.keyA.Height;
    }
Esempio n. 15
0
        public void JsonSerializesAsSingleValue()
        {
            var value = new MyValue("hello");

            string json   = JsonConvert.SerializeObject(value);
            JToken jtoken = JToken.Parse(json);

            jtoken.Type.Should().Be(JTokenType.String);
            jtoken.Value <string>().Should().Be("hello");
        }
    static void Main()
    {
        MyValue myval = new MyValue();

        myval.x = 123;

        // must box the value
        IPrint printer = myval;

        printer.Print();
    }
Esempio n. 17
0
    static void Main()
    {
        int     i = 1;
        MyValue v = new MyValue(1);

        if (i == null)
        {
            Console.WriteLine("a");
        }                                              // warning
        if (v == null)
        {
            Console.WriteLine("a");
        }                                              // no warning
    }
		public void TestReplaceAll()
		{
			MyValue one = new MyValue(1);
			MyValue two = new MyValue(2);
			SetList<MyValue> set = new SetList<MyValue>();
			set.Add(one);
			set.Add(two);

			Assert.AreEqual(2, set.Count);
			Assert.IsTrue(Object.ReferenceEquals(one, set[0]));
			Assert.IsTrue(set.ReplaceAll(new MyValue[] { new MyValue(1), new MyValue(3) }));
			Assert.IsFalse(Object.ReferenceEquals(one, set[0]));
			Assert.AreEqual(3, set.Count);
		}
Esempio n. 19
0
        public void testWeakHashMap1()
        {
            var key1 = new MyKey();
            var key2 = new MyKey();
            var value1 = new MyValue();
            var value2 = new MyValue();

            var map = new OpenWeakReferenceHashMap<MyKey, MyValue>(16);

            map.Put(key1, value1);
            map.Put(key2, value2);

            AssertEquals(value1, map.Get(key1));
            AssertEquals(value2, map.Get(key2));
            AssertEquals(2, map.Size);
        }
Esempio n. 20
0
        public void testWeakHashMap1()
        {
            var key1   = new MyKey();
            var key2   = new MyKey();
            var value1 = new MyValue();
            var value2 = new MyValue();

            var map = new OpenWeakReferenceHashMap <MyKey, MyValue>(16);

            map.Put(key1, value1);
            map.Put(key2, value2);

            AssertEquals(value1, map.Get(key1));
            AssertEquals(value2, map.Get(key2));
            AssertEquals(2, map.Size);
        }
Esempio n. 21
0
        public void GenerateRandomData()
        {
            var rand = new Random(DateTime.Now.Millisecond);

            foreach (var dict in _data)
            {
                // Add a number of rows
                for (var i = 0; i < NumberOfRows; i++)
                {
                    var integer = rand.Next(10);        // We use a value of 10 so we have many collisions.
                    dict["ValueOf" + integer] = new MyValue {
                        Value = integer
                    };
                }
            }
        }
		public void TestReplaceOne()
		{
			MyValue one = new MyValue(1);
			MyValue two = new MyValue(2);
			SetList<MyValue> set = new SetList<MyValue>();
			set.Add(one);
			set.Add(two);

			Assert.IsTrue(Object.ReferenceEquals(one, set[0]));
			Assert.IsTrue(set.Replace(new MyValue(1)));
			Assert.IsFalse(Object.ReferenceEquals(one, set[0]));

			Assert.AreEqual(2, set.Count);
			Assert.IsFalse(set.Replace(new MyValue(3))); //not replaced, then added
			Assert.AreEqual(3, set.Count);
		}
Esempio n. 23
0
        public void testWeakPutIfAbsent()
        {
            var key1   = new MyKey();
            var key2   = new MyKey();
            var value1 = new MyValue();
            var value2 = new MyValue();

            var map = new OpenWeakReferenceHashMap <MyKey, MyValue>(16);

            AssertEquals(null, map.Put(key1, value1));
            AssertEquals(value1, map.Put(key1, value2));
            AssertEquals(value2, map.Put(key1, value1));

            AssertEquals(value1, map.PutIfAbsent(key1, value2));
            AssertEquals(null, map.PutIfAbsent(key2, value2));
            AssertEquals(value2, map.PutIfAbsent(key2, value1));
        }
Esempio n. 24
0
        public void testWeakPutIfAbsent()
        {
            var key1 = new MyKey();
            var key2 = new MyKey();
            var value1 = new MyValue();
            var value2 = new MyValue();

            var map = new OpenWeakReferenceHashMap<MyKey, MyValue>(16);

            AssertEquals(null, map.Put(key1, value1));
            AssertEquals(value1, map.Put(key1, value2));
            AssertEquals(value2, map.Put(key1, value1));

            AssertEquals(value1, map.PutIfAbsent(key1, value2));
            AssertEquals(null, map.PutIfAbsent(key2, value2));
            AssertEquals(value2, map.PutIfAbsent(key2, value1));
        }
Esempio n. 25
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (My.Count > 27)
     {
         My.RemoveAt(0);
     }
     //if the amount of letters exceeding the limit then we deleting the first occurence '
     // regular case of using
     My.Add(new KeyValuePair <char, int>(MyValue.First().Key, MyValue.First().Value));// change to collection values
     MyValue.RemoveAt(0);
     series.Dispatcher.BeginInvoke(new Action(() => {
         series.ItemsSource = null;
         series.InvalidateVisual();
         series.ItemsSource = My;
         BetterThanAnyGraph.InvalidateVisual();
     }));
 }
Esempio n. 26
0
 public override void DispatchMessage(Message result)
 {
     //Console.WriteLine("{0}", result.GetType().Name.ToString());
     if (result.GetType().Name.ToString() == "Proposal")
     {
         Proposal propose = (Proposal)result;
         if (propose.ProposalNumber >= this.ProposalNumber)
         {
             //Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!{0}", this.PreviousAcceptedNumber);
             SendMessage(new Promise
             {
                 Originator             = this,
                 Destination            = propose.Originator,
                 ProposalNumber         = propose.ProposalNumber,
                 PreviousAcceptedNumber = this.PreviousAcceptedNumber,
                 PreviousAcceptedValue  = this.PreviousAcceptedValue
             });
             this.ProposalNumber = propose.ProposalNumber;
         }
         Console.WriteLine("send Promise");
     }
     else if (result.GetType().Name.ToString() == "Accept")
     {
         Accept accept = (Accept)result;
         foreach (var learner in learners)
         {
             SendMessage(new Accepted
             {
                 Originator     = this,
                 Destination    = learner,
                 ProposalNumber = accept.ProposalNumber,
                 AcceptedValue  = accept.ProposalValue
             });
         }
         Console.WriteLine("send Accepted to learners");
         this.PreviousAcceptedNumber = accept.ProposalNumber;
         this.PreviousAcceptedValue  = accept.ProposalValue;
         //ExecuteWork = false;
     }
     //Thread.Sleep(500);
     //waitForMessages.Release(1);
     //Thread.Sleep(10);
 }
Esempio n. 27
0
        public void testPutIfAbsent()
        {
            var key1   = new MyKey();
            var key2   = new MyKey();
            var key3   = new MyKey();
            var value1 = new MyValue();
            var value2 = new MyValue();
            var value3 = new MyValue();

            var map = new OpenIdentityHashMap <MyKey, MyValue>();

            AssertEquals(null, map.Put(key1, value1));
            AssertEquals(value1, map.Put(key1, value2));
            AssertEquals(value2, map.Put(key1, value1));
            AssertEquals(null, map.Put(key3, value3));

            AssertEquals(value1, map.PutIfAbsent(key1, value2));
            AssertEquals(null, map.PutIfAbsent(key2, value2));
            AssertEquals(value2, map.PutIfAbsent(key2, value1));
            AssertEquals(value3, map.Put(key3, value2));
        }
Esempio n. 28
0
        public void testPutIfAbsent()
        {
            var key1 = new MyKey();
            var key2 = new MyKey();
            var key3 = new MyKey();
            var value1 = new MyValue();
            var value2 = new MyValue();
            var value3 = new MyValue();

            var map = new OpenIdentityHashMap<MyKey, MyValue>();

            AssertEquals(null, map.Put(key1, value1));
            AssertEquals(value1, map.Put(key1, value2));
            AssertEquals(value2, map.Put(key1, value1));
            AssertEquals(null, map.Put(key3, value3));

            AssertEquals(value1, map.PutIfAbsent(key1, value2));
            AssertEquals(null, map.PutIfAbsent(key2, value2));
            AssertEquals(value2, map.PutIfAbsent(key2, value1));
            AssertEquals(value3, map.Put(key3, value2));
        }
Esempio n. 29
0
    static int Main()
    {
        MyValue p1 = new MyValue(10);
        MyValue p2 = new MyValue(20);

        MyStruct c1 = new MyStruct(p1, p2);
        MyStruct c2 = new MyStruct(p2, p1);

        bool b1 = Program.IsXGeater(c1);
        bool b2 = Program.IsXGeater(c2);
        bool b3 = Program.IsXGeater(c1);
        bool b4 = Program.IsXGeater(c2);

        if (b1)
        {
            Console.WriteLine("Fail");
            return(-1);
        }

        if (!b2)
        {
            Console.WriteLine("Fail");
            return(-1);
        }

        if (b3)
        {
            Console.WriteLine("Fail");
            return(-1);
        }

        if (!b4)
        {
            Console.WriteLine("Fail");
            return(-1);
        }

        Console.WriteLine("Pass");
        return(100);
    }
Esempio n. 30
0
    static int Main()
    {
        MyValue p1 = new MyValue(10);
        MyValue p2 = new MyValue(20);

        MyStruct c1 = new MyStruct(p1, p2);
        MyStruct c2 = new MyStruct(p2, p1);

        bool b1 = Program.IsXGeater(c1);
        bool b2 = Program.IsXGeater(c2);
        bool b3 = Program.IsXGeater(c1);
        bool b4 = Program.IsXGeater(c2);

        if (b1)
        {
            Console.WriteLine("Fail");
            return -1;
        }

        if (!b2)
        {
            Console.WriteLine("Fail");
            return -1;
        }

        if (b3)
        {
            Console.WriteLine("Fail");
            return -1;
        }

        if (!b4)
        {
            Console.WriteLine("Fail");
            return -1;
        }

        Console.WriteLine("Pass");
        return 100;
    }
 public override object ConvertTo(ITypeDescriptorContext context,
                                  CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == typeof(string))
     {
         MyValue myValue = (MyValue)value;
         // Cannot do JsonConvert.SerializeObject here because it will cause a stackoverflow exception.
         StringBuilder sb = new StringBuilder();
         using (StringWriter sw = new StringWriter(sb, CultureInfo.InvariantCulture))
             using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
             {
                 jsonWriter.WriteStartObject();
                 jsonWriter.WritePropertyName("Prop1");
                 jsonWriter.WriteValue(myValue.Prop1);
                 jsonWriter.WritePropertyName("Prop2");
                 jsonWriter.WriteValue(myValue.Prop2);
                 jsonWriter.WriteEndObject();
                 return(sw.ToString());
             }
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
Esempio n. 32
0
        public static void Run([ServiceBusTrigger("myqueue-1", Connection = "ConnectionStringKey")] string myQueueItem, ILogger log)
        {
            log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");

            var myValuesRepository = new TableStorageService <MyValue>(log, TableStorageConnectionString, MyValuesTableName);
            var mySumRepository    = new TableStorageService <MyValue>(log, TableStorageConnectionString, MySumTableName);

            var myValue = JsonConvert.DeserializeObject <MyValue>(myQueueItem);

            myValuesRepository.InsertOrUpdateEntry(myValue);

            // this is not memory efficient
            var latestValues = myValuesRepository.GetAllEntries().OrderBy(v => v.Timestamp).TakeLast(10);
            var totalSum     = latestValues.Sum(v => v.Value);

            var myNewestSum = new MyValue()
            {
                Value = totalSum
            };

            mySumRepository.InsertOrUpdateEntry(myNewestSum);
        }
    static void Main()
    {
        // Create value
        MyValue myval = new MyValue();

        myval.x = 123;

        // box it
        object obj = myval;

        System.Console.WriteLine("{0}", obj.ToString());

        // modify the contents in the box.
        IModifyMyValue iface = (IModifyMyValue)obj;

        iface.X = 456;
        System.Console.WriteLine("{0}", obj.ToString());

        // unbox it and see what it is.
        MyValue newval = (MyValue)obj;

        System.Console.WriteLine("{0}", newval.ToString());
    }
Esempio n. 34
0
        void TestBoxing()
        {
            var myv = new MyValue();

            Console.Write(TestHelper1(myv));
            Console.Write(TestHelper2(myv));
            Console.Write(TestHelper3(myv));
            Console.Write(TestHelper4(myv));
            Console.Write(myv.a);
            Console.Write(";");

            var myv2 = new MyClass();

            Console.Write(TestHelper1(myv2));
            Console.Write(TestHelper2(myv2));
            Console.Write(TestHelper4(myv2));
            Console.Write(myv2.a);
            Console.WriteLine();

            string TestHelper1(IFormattable ifmt) => ifmt.ToString("N", null);
            string TestHelper2(object ifmt) => ((IFormattable)ifmt).ToString("N", null);
            string TestHelper3(MyValue ifmt) => ifmt.ToString("N", null);
            string TestHelper4 <T>(T ifmt) where T : IFormattable => ifmt.ToString("N", null);
        }
Esempio n. 35
0
        public void ObjectsOfDifferentTypeAreNotEqual_EvenIfSubclass()
        {
            var value1 = new MyValue();
            var value2 = new MyValue2();

            Assert.IsFalse(value1.Equals(value2));
        }
Esempio n. 36
0
 public MyStruct(MyValue a, MyValue b)
 { v1 = a; v2 = b; }