示例#1
0
        public void CreateCollectionClass()
        {
            var actual      = _faker.Create <CollectionClass>();
            var notExpected = new CollectionClass(new List <double>());

            CollectionAssert.AreNotEqual(notExpected.ints, actual.ints);
            CollectionAssert.AreNotEqual(notExpected.times, actual.times);
        }
示例#2
0
    public static void Main()
    {
        CollectionClass Arr = new CollectionClass();

        foreach (double d in Arr)
        {
            Console.WriteLine(d);
        }
    }
        public ActionResult Index()
        {
            CollectionClass cs = new CollectionClass();

            cs.tbl_HAKKIMDA = db.TBL_HAKKIMDA.ToList();
            cs.tbl_ILETISIM = db.TBL_ILETISIM.ToList();
            cs.tbl_MESAJ    = db.TBL_MESSAGE.ToList();
            return(View(cs));
        }
        public void CollectionClassContainingDifferentCollectionsShouldCompareUsingKeys()
        {
            // Arrange
            var c1 = new CollectionClass
            {
                Users = UserCollection1
            };

            var c2 = new CollectionClass
            {
                Users = UserCollection2
            };

            // Act
            List <ObjectVariance> variances = ObjectComparer.GetObjectVariances(c1, c2).ToList();

            // Assert
            Assert.Empty(variances);
        }
示例#5
0
        public void ClassWithOneEmptyListShouldReturnVariance()
        {
            // Arrange
            var list1 = new List <int> {
                1, 2, 3
            };
            var list2 = Enumerable.Empty <int>();
            var c1    = new CollectionClass
            {
                Ints = list1
            };

            var c2 = new CollectionClass
            {
                Ints = list2
            };

            // Act
            List <ObjectVariance> variances = ObjectComparer.GetObjectVariances(c1, c2).ToList();

            // Assert
            Assert.NotEmpty(variances);
            Assert.Equal(1, variances.Count);
            Assert.Equal("Ints.Count()", variances[0].PropertyName);
            Assert.Equal(3, variances[0].PropertyValue1);
            Assert.Equal(0, variances[0].PropertyValue2);

            // Parent
            Assert.NotNull(variances[0].ParentVariance);
            Assert.Equal(list1, variances[0].ParentVariance.PropertyValue1);
            Assert.Equal(list2, variances[0].ParentVariance.PropertyValue2);
            Assert.Equal("Ints", variances[0].ParentVariance.PropertyName);

            // Parent's parent
            Assert.NotNull(variances[0].ParentVariance.ParentVariance);
            Assert.Null(variances[0].ParentVariance.ParentVariance.PropertyName);
            Assert.Equal(c1, variances[0].ParentVariance.ParentVariance.PropertyValue1);
            Assert.Equal(c2, variances[0].ParentVariance.ParentVariance.PropertyValue2);
            Assert.Null(variances[0].ParentVariance.ParentVariance.ParentVariance);
        }
示例#6
0
        public void ClassWithSameListContentsShouldReturnNoVariance()
        {
            // Arrange
            var c1 = new CollectionClass
            {
                Ints = new List <int> {
                    1, 2, 3
                }
            };

            var c2 = new CollectionClass
            {
                Ints = new List <int> {
                    1, 2, 3
                }
            };

            // Act
            List <ObjectVariance> variances = ObjectComparer.GetObjectVariances(c1, c2).ToList();

            // Assert
            Assert.Empty(variances);
        }
    public static void Main()
    {
        var c     = new CollectionClass();
        var watch = System.Diagnostics.Stopwatch.StartNew();

        for (var i = 0; i < 10000; i++)
        {
            c.Test1();
        }
        watch.Stop();
        Console.WriteLine("Test1:" + watch.ElapsedMilliseconds);

        watch = System.Diagnostics.Stopwatch.StartNew();
        for (var i = 0; i < 10000; i++)
        {
            c.Test2();
        }
        watch.Stop();
        Console.WriteLine("Test2:" + watch.ElapsedMilliseconds);

        watch = System.Diagnostics.Stopwatch.StartNew();
        for (var i = 0; i < 10000; i++)
        {
            c.Test3();
        }
        watch.Stop();
        Console.WriteLine("Test3:" + watch.ElapsedMilliseconds);

        watch = System.Diagnostics.Stopwatch.StartNew();
        for (var i = 0; i < 10000; i++)
        {
            c.Test4();
        }
        watch.Stop();
        Console.WriteLine("Test4:" + watch.ElapsedMilliseconds);
    }
示例#8
0
        public List<Image> StartScan()
        {
            //return null;
            wiaManager = new WiaClass();

            wiaDevs = wiaManager.Devices as CollectionClass;

            //if (string.IsNullOrEmpty(DefaultScaner))
            //{

                object selectUsingUI = System.Reflection.Missing.Value;			// = Nothing
                wiaRoot = (ItemClass)wiaManager.Create(ref selectUsingUI);	// let user select device

                if (wiaRoot != null)
                {
                    string selectId = wiaRoot.GetPropById((WiaItemPropertyId)WiaDeviceInfoPropertyId.DeviceInfoDevId) as string;
                    XmlHelper.UpdateConfig("DefaultScan", selectId);
                }
            //}
            else
            {
                foreach (object info in (wiaManager.Devices as CollectionClass))
                {
                    //string selectId = wiaRoot.GetPropById((WiaItemPropertyId)WiaDeviceInfoPropertyId.DeviceInfoDevId) as string;
                    //if (selectId == DefaultScaner)
                    //{

                    //    wiaRoot = (ItemClass)info.Create();
                    //    break;
                    //}
                }
            }

            try
            {
                //wiaManager = new WiaClass();		// create COM instance of WIA manager

                //wiaDevs = wiaManager.Devices as CollectionClass;			// call Wia.Devices to get all devices

                // this call shows the common WIA dialog to let the user select a picture:
                //wiaPics = wiaRoot.GetItemsFromUI(WiaFlag.SingleImage, WiaIntent.ImageTypeColor) as CollectionClass;
                //if (wiaPics == null)
                //{
                //    return null;
                //}

                //string imageFileName = string.Empty;
                //bool takeFirst = true;						// this sample uses only one single picture
                //foreach (object wiaObj in wiaPics)			// enumerate all the pictures the user selected
                //{
                //if (takeFirst)
                //{
                string imageFileName = string.Empty;
                ItemClass wiaObj =(ItemClass) wiaRoot.TakePicture();

                //wiaItem = (ItemClass)Marshal.CreateWrapperOfType(wiaObj, typeof(ItemClass));
                imageFileName = Path.GetTempFileName();				// create temporary file for image
                Cursor.Current = Cursors.WaitCursor;				// could take some time
                //this.Refresh();
                //wiaRoot.TakePicture();
                wiaObj.Transfer(imageFileName, false);			// transfer picture to our temporary file
                Image img = Image.FromFile(imageFileName);	// create Image instance from file
                //takeFirst = false;									// first and only one done.
                imgs.Add(img);

                //}
                //    Marshal.ReleaseComObject(wiaObj);					// release enumerated COM object
                //}
            }
            catch (Exception ee)
            {
                //MessageBox.Show(this, "Acquire from WIA Imaging failed\r\n" + ee.Message, "WIA", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //Application.Exit();
            }
            finally
            {
                if (wiaItem != null)
                    Marshal.ReleaseComObject(wiaItem);		// release WIA image COM object
                if (wiaPics != null)
                    Marshal.ReleaseComObject(wiaPics);		// release WIA collection COM object
                if (wiaRoot != null)
                    Marshal.ReleaseComObject(wiaRoot);		// release WIA root device COM object
                if (wiaDevs != null)
                    Marshal.ReleaseComObject(wiaDevs);		// release WIA devices collection COM object
                if (wiaManager != null)
                    Marshal.ReleaseComObject(wiaManager);		// release WIA manager COM object
                Cursor.Current = Cursors.Default;				// restore cursor
            }

            return imgs;
            //    ImageFile imageFile;
            //    DeviceManagerClass manager = new DeviceManagerClass();
            //    Device WiaDev = null;
            //    CommonDialogClass devCdc = new WIA.CommonDialogClass();
            //    if (string.IsNullOrEmpty(DefaultScaner))
            //    {
            //        WiaDev = devCdc.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
            //        if (WiaDev != null)
            //        {
            //            XmlHelper.UpdateConfig("DefaultScan", WiaDev.DeviceID);
            //        }
            //    }
            //    else
            //    {
            //        foreach (DeviceInfo info in manager.DeviceInfos)
            //        {
            //            if (info.Type != WiaDeviceType.ScannerDeviceType) continue;
            //            if (info.DeviceID == DefaultScaner)
            //            {

            //                WiaDev = info.Connect();
            //                break;
            //            }
            //        }
            //    }

            //    if (WiaDev == null)
            //    {
            //        WiaDev = devCdc.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
            //        if (WiaDev != null)
            //        {
            //            XmlHelper.UpdateConfig("DefaultScan", WiaDev.DeviceID); ;
            //        }
            //        else
            //        {
            //            throw new Exception("请确认扫描仪是否正常连接!");
            //        }

            //    }

            //    Property documentHandlingSelect1 = null;

            //    foreach (Property prop in WiaDev.Properties)
            //    {
            //        if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_SELECT)
            //        {
            //            documentHandlingSelect1 = prop;
            //            object obj = new object();
            //            obj = (WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER);
            //            documentHandlingSelect1.set_Value(ref obj);

            //        }
            //        else if (prop.PropertyID == 3013)
            //        {
            //            object val = 1;
            //            prop.set_Value(ref val);
            //        }
            //        //Pages
            //        else if (prop.PropertyID == 3096)
            //        {
            //            object val = 1;
            //            prop.set_Value(ref val);
            //        }
            //        else if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_STATUS)
            //        {
            //            documentHandlingSelect1 = prop;

            //        }
            //    }

            //    Item item = WiaDev.Items[1];
            //    foreach (WIA.Property itemProperty in item.Properties)
            //    {
            //        //IProperty tempProperty;
            //        Object tempNewProperty;

            //        if (itemProperty.Name.Equals("Horizontal Resolution"))
            //        {
            //            tempNewProperty = 100;
            //            ((IProperty)itemProperty).set_Value(ref tempNewProperty);
            //        }
            //        else if (itemProperty.Name.Equals("Vertical Resolution"))
            //        {
            //            tempNewProperty = 100;
            //            ((IProperty)itemProperty).set_Value(ref tempNewProperty);
            //        }
            //        //else if (itemProperty.Name.Equals("Horizontal Extent"))
            //        //{
            //        //    //tempNewProperty = 619;
            //        //    //((IProperty)itemProperty).set_Value(ref tempNewProperty);
            //        //}
            //        //else if (itemProperty.Name.Equals("Vertical Extent"))
            //        //{
            //        //    //tempNewProperty = 876;
            //        //    //((IProperty)itemProperty).set_Value(ref tempNewProperty);
            //        //}
            //    }

            //    CommonDialogClass cdc = new WIA.CommonDialogClass();
            //    try
            //    {
            //        imageFile = cdc.ShowTransfer(item, wiaFormatJPEG, false) as ImageFile;
            //    }
            //    catch (System.Runtime.InteropServices.COMException ex)
            //    {
            //        imageFile = null;

            //    }

            //    while (imageFile != null)
            //    {
            //        var buffer = imageFile.FileData.get_BinaryData() as byte[];
            //        imageFile.SaveFile(Path.Combine(LocalSavePath, DateTime.Now.Millisecond + ".jpg"));
            //        using (MemoryStream ms = new MemoryStream())
            //        {
            //            ms.Write(buffer, 0, buffer.Length);
            //            imgs.Add(System.Drawing.Image.FromStream(ms));

            //        }
            //        imageFile = null;

            //        try
            //        {
            //            imageFile = cdc.ShowTransfer(item, wiaFormatJPEG, false) as ImageFile;
            //        }
            //        catch (Exception ex)
            //        {
            //            return imgs;
            //            throw new Exception(ex.Message);
            //        }
            //    }
            //    return imgs;
            //}
        }
示例#9
0
 public EnumeratorClass(CollectionClass Kolekcija)
 {
     this.Kolekcija = Kolekcija;
 }
示例#10
0
 public void LoadBuiltinClasses()
 {
     classes["Int"]               = new IntClass();
     classes["Float"]             = new FloatClass();
     classes["Boolean"]           = new BooleanClass();
     classes["String"]            = new StringClass();
     classes["Char"]              = new CharClass();
     classes["Byte"]              = new ByteClass();
     classes["Message"]           = new MessageClass();
     classes["Unassigned"]        = new UnassignedClass();
     classes["Tuple"]             = new TupleClass();
     classes["NameValue"]         = new NameValueClass();
     classes["Lambda"]            = new LambdaClass();
     classes["Void"]              = new VoidClass();
     classes["Some"]              = new SomeClass();
     classes["None"]              = new NoneClass();
     classes["Array"]             = new ArrayClass();
     classes["Iterator"]          = new IteratorClass();
     classes["LazyIterator"]      = new LazyIteratorClass();
     classes["StreamIterator"]    = new StreamIteratorClass();
     classes["Any"]               = new AnyClass();
     classes["Placeholder"]       = new PlaceholderClass();
     classes["Range"]             = new RangeClass();
     classes["Dictionary"]        = new DictionaryClass();
     classes["Container"]         = new ContainerClass();
     classes["Unmatched"]         = new UnmatchedClass();
     classes["Complex"]           = new ComplexClass();
     classes["Rational"]          = new RationalClass();
     classes["Long"]              = new LongClass();
     classes["Lazy"]              = new LazyClass();
     classes["YieldingInvokable"] = new YieldingInvokableClass();
     classes["Del"]               = new DelClass();
     classes["Slice"]             = new SliceClass();
     classes["End"]               = new EndClass();
     classes["List"]              = new ListClass();
     classes["Arguments"]         = new ArgumentsClass();
     classes["Symbol"]            = new SymbolClass();
     classes["Infinity"]          = new InfinityClass();
     classes["OpenRange"]         = new OpenRangeClass();
     classes["KeyValue"]          = new KeyValueClass();
     classes["Regex"]             = new RegexClass();
     classes["Pattern"]           = new PatternClass();
     classes["PackageFunction"]   = new PackageFunctionClass();
     classes["Sys"]               = new SysClass();
     classes["Math"]              = new MathClass();
     classes["RuntimeFunction"]   = new RuntimeFunctionClass();
     classes["Reference"]         = new ReferenceClass();
     classes["Group"]             = new RegexGroupClass();
     classes["Match"]             = new RegexMatchClass();
     classes["Date"]              = new DateClass();
     classes["Interval"]          = new IntervalClass();
     classes["TypeConstraint"]    = new TypeConstraintClass();
     classes["ByteArray"]         = new ByteArrayClass();
     classes["Selector"]          = new SelectorClass();
     classes["Number"]            = new NumberClass();
     classes["Collection"]        = new CollectionClass();
     classes["TextFinding"]       = new TextFindingClass();
     classes["SkipTake"]          = new SkipTakeClass();
     classes["Constructor"]       = new ConstructorClass();
     classes["MutString"]         = new MutStringClass();
     classes["Error"]             = new ErrorClass();
     classes["Success"]           = new SuccessClass();
     classes["Failure"]           = new FailureClass();
     classes["Optional"]          = new OptionalClass();
     classes["Result"]            = new ResultClass();
     classes["Monad"]             = new MonadClass();
     classes["Unit"]              = new UnitClass();
     classes["YieldReturn"]       = new YieldReturnClass();
     classes["Index"]             = new IndexClass();
     classes["Cycle"]             = new CycleClass();
     classes["Set"]               = new SetClass();
 }
示例#11
0
        public HTMLParser(byte[] source)
        {
            if (source == null || source.Length <= 0) return;
              _Source = source;

              _Items = new CollectionClass();
              // преобразуем данные в текст
              string sourceString = GetSourceAsString();

              // при запросе
              // первая строка содержит метод запроса, путь и версию HTTP протокола
              string httpInfo = sourceString.Substring(0, sourceString.IndexOf("\r\n"));
              Regex myReg = new Regex(@"(?<method>.+)\s+(?<path>.+)\s+HTTP/(?<version>[\d\.]+)", RegexOptions.Multiline);
              if (myReg.IsMatch(httpInfo))
              {
            Match m = myReg.Match(httpInfo);
            if (m.Groups["method"].Value.ToUpper() == "POST")
            {
              _Method = MethodsList.POST;
            }
            else if (m.Groups["method"].Value.ToUpper() == "CONNECT")
            {
              _Method = MethodsList.CONNECT;
            }
            else
            {
              _Method = MethodsList.GET;
            }

            _Path = m.Groups["path"].Value;
            _HTTPVersion = m.Groups["version"].Value;
              }
              else
              {
            // при ответе
            // первая строка содержит код состояния
            myReg = new Regex(@"HTTP/(?<version>[\d\.]+)\s+(?<status>\d+)\s*(?<msg>.*)", RegexOptions.Multiline);
            Match m = myReg.Match(httpInfo);
            int.TryParse(m.Groups["status"].Value, out _StatusCode);
            _StatusMessage = m.Groups["msg"].Value;
            _HTTPVersion = m.Groups["version"].Value;
              }

              // выделяем заголовки (до первых двух переводов строк)
              _HeadersTail = sourceString.IndexOf("\r\n\r\n");
              if (_HeadersTail != -1)
              { // хвост найден, отделяем заголовки
            sourceString = sourceString.Substring(sourceString.IndexOf("\r\n") + 2, _HeadersTail - sourceString.IndexOf("\r\n") - 2);
              }

              // парсим заголовки и заносим их в коллекцию
              myReg = new Regex(@"^(?<key>[^\x3A]+)\:\s{1}(?<value>.+)$", RegexOptions.Multiline);
              MatchCollection mc = myReg.Matches(sourceString);
              foreach (Match mm in mc)
              {
            string key = mm.Groups["key"].Value;
            if (!_Items.ContainsKey(key))
            {
              // если указанного заголовка нет в коллекции, добавляем его
              _Items.AddItem(key, mm.Groups["value"].Value.Trim("\r\n ".ToCharArray()));
            }
              }
        }
示例#12
0
 private NestedClass(CollectionClass pc)
 {
     this.pc = pc;
 }
示例#13
0
        public void CollectionClassWithTwoDifferencesShouldReturnTwoVariances()
        {
            // Arrange
            var inner1 = new ImmutableClass(1, "tast");
            var inner2 = new ImmutableClass(2, "test");
            var list1  = new List <ImmutableClass> {
                inner1
            };
            var list2 = new List <ImmutableClass> {
                inner2
            };
            var c1 = new CollectionClass
            {
                ImmutableClasses = list1
            };

            var c2 = new CollectionClass
            {
                ImmutableClasses = list2
            };

            // Act
            List <ObjectVariance> variances = ObjectComparer.GetObjectVariances(c1, c2).ToList();

            // Assert
            Assert.NotEmpty(variances);
            Assert.Equal(2, variances.Count); // List comparison is count-based, so should be 2 differences

            // First variance
            Assert.Equal("Int1", variances[0].PropertyName);
            Assert.Equal(1, variances[0].PropertyValue1);
            Assert.Equal(2, variances[0].PropertyValue2);

            // First variance's parent
            Assert.NotNull(variances[0].ParentVariance);
            Assert.Equal("this[0]", variances[0].ParentVariance.PropertyName);
            Assert.Equal(inner1, variances[0].ParentVariance.PropertyValue1);
            Assert.Equal(inner2, variances[0].ParentVariance.PropertyValue2);

            // First variance's parent's parent
            Assert.NotNull(variances[0].ParentVariance.ParentVariance);
            Assert.Equal("ImmutableClasses", variances[0].ParentVariance.ParentVariance.PropertyName);
            Assert.Equal(list1, variances[0].ParentVariance.ParentVariance.PropertyValue1);
            Assert.Equal(list2, variances[0].ParentVariance.ParentVariance.PropertyValue2);

            // First variance's parent's parent's parent
            Assert.NotNull(variances[0].ParentVariance.ParentVariance.ParentVariance);
            Assert.Null(variances[0].ParentVariance.ParentVariance.ParentVariance.PropertyName);
            Assert.Equal(c1, variances[0].ParentVariance.ParentVariance.ParentVariance.PropertyValue1);
            Assert.Equal(c2, variances[0].ParentVariance.ParentVariance.ParentVariance.PropertyValue2);

            // Second variance
            Assert.Equal("String1", variances[1].PropertyName);
            Assert.Equal("tast", variances[1].PropertyValue1);
            Assert.Equal("test", variances[1].PropertyValue2);

            // Second variance's parent
            Assert.NotNull(variances[1].ParentVariance);
            Assert.Equal("this[0]", variances[1].ParentVariance.PropertyName);
            Assert.Equal(inner1, variances[1].ParentVariance.PropertyValue1);
            Assert.Equal(inner2, variances[1].ParentVariance.PropertyValue2);

            // First variance's parent's parent
            Assert.NotNull(variances[1].ParentVariance.ParentVariance);
            Assert.Equal("ImmutableClasses", variances[1].ParentVariance.ParentVariance.PropertyName);
            Assert.Equal(list1, variances[1].ParentVariance.ParentVariance.PropertyValue1);
            Assert.Equal(list2, variances[1].ParentVariance.ParentVariance.PropertyValue2);

            // Second variance's parent's parent's parent
            Assert.NotNull(variances[1].ParentVariance.ParentVariance.ParentVariance);
            Assert.Null(variances[1].ParentVariance.ParentVariance.ParentVariance.PropertyName);
            Assert.Equal(c1, variances[1].ParentVariance.ParentVariance.ParentVariance.PropertyValue1);
            Assert.Equal(c2, variances[1].ParentVariance.ParentVariance.ParentVariance.PropertyValue2);
            Assert.Null(variances[1].ParentVariance.ParentVariance.ParentVariance.ParentVariance);
        }