コード例 #1
0
 internal virtual void CloneToImpl(CollectionEx coll)
 {
     foreach (DocumentSerializable serializable in base.InnerList)
     {
         coll.InnerList.Add(serializable.method_4());
     }
 }
コード例 #2
0
ファイル: ModularCar.cs プロジェクト: Ailtop/RustDocuments
    public void SpawnPreassignedModules()
    {
        if (!spawnSettings.useSpawnSettings || CollectionEx.IsNullOrEmpty(spawnSettings.configurationOptions))
        {
            return;
        }
        ModularCarPresetConfig modularCarPresetConfig = spawnSettings.configurationOptions[UnityEngine.Random.Range(0, spawnSettings.configurationOptions.Length)];

        if (Interface.CallHook("OnVehicleModulesAssign", this, modularCarPresetConfig.socketItemDefs) != null)
        {
            return;
        }
        for (int i = 0; i < modularCarPresetConfig.socketItemDefs.Length; i++)
        {
            ItemModVehicleModule itemModVehicleModule = modularCarPresetConfig.socketItemDefs[i];
            if (itemModVehicleModule != null && base.Inventory.SocketsAreFree(i, itemModVehicleModule.socketsTaken))
            {
                itemModVehicleModule.doNonUserSpawn = true;
                Item  item = ItemManager.Create(itemModVehicleModule.GetComponent <ItemDefinition>(), 1, 0uL);
                float num  = UnityEngine.Random.Range(spawnSettings.minStartHealthPercent, spawnSettings.maxStartHealthPercent);
                item.condition = item.maxCondition * num;
                if (!TryAddModule(item))
                {
                    item.Remove();
                }
            }
        }
        Interface.CallHook("OnVehicleModulesAssigned", this, modularCarPresetConfig.socketItemDefs);
    }
コード例 #3
0
        public void BulkUpdate__IndividualOperationsDoNotTriggerVersionChanged__EndingBulkUpdateTriggersVersionChanged()
        {
            var c = new CollectionEx<int>();

            var eventCalled = false;
            var lastVersion = c.Version;

            c.VersionChanged += (s, e) =>
                {
                    eventCalled = true;
                };

            using (var bulkUpdate = c.BeginBulkUpdate())
            {
                c.Add(13);
                c.AddRange(new int[] { 1, 2, 3, 4, 5 });
                c.Move(1, 0);
                c.Remove(1);
                c.RemoveAt(0);
                c.RemoveRange(0, 2);
                c.Replace(5, 6);
                c.Reset(new int[] { 11, 12, 13 });

                c[0] = 5;

                Assert.IsFalse(eventCalled);
                Assert.AreEqual(lastVersion, c.Version);
            }

            // event and version should be updated now as bulkUpdate finished

            Assert.IsTrue(eventCalled);
            Assert.AreNotEqual(lastVersion, c.Version);
        }
コード例 #4
0
        /// <summary>
        /// 指定された時間のLabels.Valuesのインデックスを返します。
        /// </summary>
        /// <param title="time">指定する時間</param>
        /// <returns>インデックス</returns>
        public int GetLabelIndexAt(decimal time)
        {
            int ret = CollectionEx.GetLastIndexBeforeKey <decimal, string>(_labelBorders, time, _prevIndex, 1);

            _prevIndex = ret;
            return(ret);
        }
コード例 #5
0
ファイル: Global.cs プロジェクト: vscode1111/DataToSQL
 /// <summary>
 /// Заполнение данных реальных объектов с БД.
 /// </summary>
 public void FillData <T, TReal>(XPCollection xpCollection, CollectionEx <TReal> realCollection)
 {
     realCollection.Clear();
     foreach (T server in xpCollection)
     {
         realCollection.Add((TReal)Activator.CreateInstance(typeof(TReal), server, ItemRealCollection));
     }
 }
コード例 #6
0
 /// <summary>
 /// 指定された値以下の最も近い境界のインデックスを取得します。存在しない場合は-1を返します。
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public int GetIndexFromValue(decimal value)
 {
     _rwLock.EnterReadLock();
     try {
         int ret = CollectionEx.GetLastIndexBeforeKey <decimal, string>(__borders, value, _prevIndex, 1);
         _prevIndex = ret;
         return(ret);
     } finally { _rwLock.ExitReadLock(); }
 }
コード例 #7
0
        public void CanRemoveRange()
        {
            var c = new CollectionEx<int>();

            c.AddRange(new int[] { 1, 2 });
            c.RemoveRange(0, 2);

            Assert.AreEqual(0, c.Count);
        }
コード例 #8
0
 /// <summary>
 /// 指定された時間におけるインデックスを返します.
 /// </summary>
 /// <param name="time"></param>
 /// <param name="firstIndex"></param>
 /// <returns></returns>
 public int GetIndexAt(decimal time, int firstIndex)
 {
     _rwLock.EnterReadLock();
     try {
         int ret = CollectionEx.GetLastIndexBeforeKey <decimal, decimal?[]>(_sequence, time, firstIndex, 1);
         _prevIndex = ret;
         return(ret);
     } finally { _rwLock.ExitReadLock(); }
 }
コード例 #9
0
        public void CanAddRange()
        {
            var c = new CollectionEx<int>();

            c.AddRange(new int[] { 1, 2 });

            Assert.IsTrue(c[0] == 1);
            Assert.IsTrue(c[1] == 2);
            Assert.AreEqual(2, c.Count);
        }
コード例 #10
0
        public void CanClearItems()
        {
            var c = new CollectionEx<int>();

            c.Add(1);
            c.Add(2);

            c.Clear();

            Assert.AreEqual(0, c.Count);
        }
コード例 #11
0
        public void CanAddItem()
        {
            var c = new CollectionEx<int>();

            c.Add(1);
            c.Add(2);
            
            Assert.IsTrue(c[0] == 1);
            Assert.IsTrue(c[1] == 2);
            Assert.AreEqual(2, c.Count);
        }
コード例 #12
0
        public void BUG__001__CountAmbiguity()
        {
            // when casted to ICollectionEx<>, using Count fails build due to
            // Error	Ambiguity between 'ICollection<>.Count' and 'IReadOnlyCollection<>.Count'

            var col = new CollectionEx<int>();

            var icol = col as ICollectionEx<int>;

            Assert.AreEqual(icol.Count, 0);
        }
コード例 #13
0
        /// <summary>
        /// Заполнение данных реальных объектов с БД.
        /// </summary>
        public static DataSourceReal FindSource <TReal>(Item item, CollectionEx <TReal> realCollection)
        {
            foreach (TReal server in realCollection)
            {
                if (item.DataSource != null &&
                    (server as DataSourceReal).Oid == item.DataSource.Oid)
                {
                    return(server as DataSourceReal);
                }
            }

            return(null);
        }
コード例 #14
0
        public void CanReplaceItems()
        {
            var c = new CollectionEx<int>();

            c.Add(1);
            c.Add(2);

            c.Replace(1, 3);

            Assert.IsTrue(c[0] == 3);
            Assert.IsTrue(c[1] == 2);
            Assert.AreEqual(2, c.Count);
        }
コード例 #15
0
ファイル: Global.cs プロジェクト: vscode1111/DataToSQL
 /// <summary>
 /// Асинхронное чтение данных.
 /// </summary>
 static void ReadDataAsync(CollectionEx <DataSourceReal> realCollection)
 {
     realCollection.ConnectedCount = 0;
     foreach (DataSourceReal opcServer in realCollection)
     {
         opcServer.ReadDataAsync();
         opcServer.SendDataToXPObject();
         if (opcServer.IsConnected)
         {
             realCollection.ConnectedCount++;
         }
     }
 }
コード例 #16
0
ファイル: EFCoreRepository.cs プロジェクト: SeaLee02/Sea.Core
        public override IQueryable <TEntity> GetAllIncluding(params Expression <Func <TEntity, object> >[] propertySelectors)
        {
            IQueryable <TEntity> queryable = ((IEnumerable <TEntity>)Table).AsQueryable();

            if (!CollectionEx.IsNullOrEmpty <Expression <Func <TEntity, object> > >(propertySelectors))
            {
                foreach (Expression <Func <TEntity, object> > expression in propertySelectors)
                {
                    queryable = queryable.Include <TEntity, object>(expression);
                }
            }
            return(queryable);
        }
コード例 #17
0
        public void VersionChanged__CanCallGetSnapshot()
        {
            var c = new CollectionEx<int>();

            c.VersionChanged += (s, e) =>
                {
                    var _c = (CollectionEx<int>)s;

                    _c.GetSnapshot();
                };

            c.Add(1);
        }
コード例 #18
0
ファイル: Global.cs プロジェクト: vscode1111/DataToSQL
        /// <summary>
        /// Инициализация переменных.
        /// </summary>
        public void Init()
        {
            Version = "v1.21.14";

            InitTime = DateTime.Now;

            varXml = new VarXml("Config.xml");
            varXml.LoadFromXML();

            CollectionWithUnits = new XPCollectionWithUnits();

            DataSourceCollection         = (CollectionWithUnits.Add(typeof(DataSource))).Collection;
            StatisticsCollection         = (CollectionWithUnits.Add(typeof(Statistics))).Collection;
            OPCServerCollection          = (CollectionWithUnits.Add(typeof(OPCServer))).Collection;
            VzljotCollection             = (CollectionWithUnits.Add(typeof(Vzljot))).Collection;
            DDEServerCollection          = (CollectionWithUnits.Add(typeof(DDEServer))).Collection;
            TechnographCollection        = (CollectionWithUnits.Add(typeof(Technograph))).Collection;
            PingServerCollection         = (CollectionWithUnits.Add(typeof(PingServer))).Collection;
            KMAZSServerCollection        = (CollectionWithUnits.Add(typeof(KMAZSServer))).Collection;
            ItemCollection               = (CollectionWithUnits.Add(typeof(Item))).Collection;
            SQLServerCollection          = (CollectionWithUnits.Add(typeof(SQLServer))).Collection;
            SQLServerItemForceCollection = (CollectionWithUnits.Add(typeof(SQLServerItemForceCollection))).Collection;

            DataSourceRealCollection  = new CollectionEx <DataSourceReal>();
            StatisticsRealCollection  = new CollectionEx <StatisticsReal>();
            OPCServerRealCollection   = new CollectionEx <OPCServerReal>();
            VzljotRealCollection      = new CollectionEx <VzljotReal>();
            DDEServerRealCollection   = new CollectionEx <DDEServerReal>();
            TechnographRealCollection = new CollectionEx <TechnographReal>();
            PingServerRealCollection  = new CollectionEx <PingServerReal>();
            KMAZSServerRealCollection = new CollectionEx <KMAZSServerReal>();
            ItemRealCollection        = new Collection <ItemReal>();
            SQLServerRealCollection   = new CollectionEx <SQLServerReal>();

            CopyDataToReal();

            ThreadMainFautCount = 0;

            ThreadMain = new ThreadTimer()
            {
                Period = varXml.ThreadMainPeriod
            };
            ThreadMain.WorkChanged += ThreadMain_WorkChanged;
            ThreadMain.Run();

            ThreadMainDelay = varXml.ThreadMainDelay;
            AppName         = varXml.AppName;

            WorkerReboot         = new BackgroundWorker();
            WorkerReboot.DoWork += WorkerReboot_DoWork;
        }
コード例 #19
0
ファイル: Class47.cs プロジェクト: pengxinglove/PersonalSpire
 void DocumentSerializableCollection.CloneToImpl(CollectionEx A_0)
 {
     foreach (DocumentSerializable serializable in base.InnerList)
     {
         A_0.InnerList.Add(serializable.method_4());
         OverrideLevelFormat format = A_0.InnerList[A_0.Count - 1] as OverrideLevelFormat;
         format.method_0((A_0 as Class47).OwnerBase);
         format.OverrideListLevel.method_0(format);
     }
     foreach (KeyValuePair <int, int> pair in this.method_7())
     {
         (A_0 as Class47).method_7().Add(pair.Key, pair.Value);
     }
 }
コード例 #20
0
        public void TryRemoveTest()
        {
            CollectionEx.TryRemove <int>(null, 10).ShouldBe(false);

            var list1 = new List <int>()
            {
                10, 20, 30
            };

            list1.TryRemove(20).ShouldBe(true);
            list1.TryRemove(20).ShouldBe(true);
            list1.TryRemove(10).ShouldBe(true);
            list1.TryRemove(30).ShouldBe(true);
            list1.TryRemove(30, true).ShouldBe(false);
        }
コード例 #21
0
        public void Add__TriggersVersionChanged()
        {
            var c = new CollectionEx<int>();

            var eventCalled = false;
            var lastVersion = c.Version;

            c.VersionChanged += (s, e) =>
                {
                    eventCalled = true;
                };

            c.Add(13);

            Assert.IsTrue(eventCalled);
            Assert.AreNotEqual(lastVersion, c.Version);
        }
コード例 #22
0
        public void TryGetValueAtIndexTest()
        {
            CollectionEx.TryGetValueAtIndex <int>(null, 0, out var ok).ShouldBe(false);

            var list1 = new int[] { 10, 20, 30 };

            list1.TryGetValueAtIndex(0, out var item0).ShouldBe(true);
            item0.ShouldBe(10);

            list1.TryGetValueAtIndex(1, out var item1).ShouldBe(true);
            item1.ShouldBe(20);

            list1.TryGetValueAtIndex(2, out var item2).ShouldBe(true);
            item2.ShouldBe(30);

            list1.TryGetValueAtIndex(3, out var item3).ShouldBe(false);
            item3.ShouldBe(0);
        }
コード例 #23
0
        public void TryGetValueAtIndexObjTest()
        {
            CollectionEx.TryGetValueAtIndex <int>(null, (object)0, out var ok).ShouldBe(false);

            var list1 = new int[] { 10, 20, 30 };

            list1.TryGetValueAtIndex(0f, out var item0).ShouldBe(true);
            item0.ShouldBe(10);

            list1.TryGetValueAtIndex(1.0d, out var item1).ShouldBe(true);
            item1.ShouldBe(20);

            list1.TryGetValueAtIndex((object)2, out var item2).ShouldBe(true);
            item2.ShouldBe(30);

            list1.TryGetValueAtIndex((object)3, out var item3).ShouldBe(false);
            item3.ShouldBe(0);

            list1.TryGetValueAtIndex(new object(), out var item4).ShouldBe(false);
            item3.ShouldBe(0);
        }
コード例 #24
0
        public void Move__TriggersVersionChangedEvent()
        {
            var c = new CollectionEx<int>();

            c.Add(13);
            c.Add(7);

            var eventCalled = false;
            var lastVersion = c.Version;

            c.VersionChanged += (s, e) =>
            {
                eventCalled = true;
            };

            c.Move(1, 0);

            Assert.IsTrue(eventCalled);
            Assert.AreNotEqual(lastVersion, c.Version);
            Assert.AreEqual(7, c[0]);
            Assert.AreEqual(13, c[1]);
        }
コード例 #25
0
        public void IOEx_BlobIO()
        {
            string[] map = new string[] { "Int", "Int", "NVarChar", "VarBinary" };
            object[] val = new object[] { 1234, IOEx.SafeIO <int>(null), "初めまして", Encoding.UTF8.GetBytes("This is a binary string") };
            BlobIO   b   = new BlobIO(map, val);

            byte[] m = b.Map;
            Assert.Equal(b.GetN <int>(0), val[0]); // Failed to get value");
            b.Set(0, 9876);
            Assert.Equal(b.GetN <int>(0), 9876);   // Failed to set value");
            b.Set(0, 9876.0);
            Assert.Equal(b.GetN <int>(0), 9876);   // Failed to set value");
            b.Clear(0);
            Assert.Equal(b.GetN <int>(0), null);   // Failed to clear value");
            b = BlobIO.Data(NumberEx.Numeric(Math.PI, out decimal? v) ? v : null);
            Assert.Equal((decimal)Math.PI, b.GetDecimal(0));
            b = BlobIO.Data(val);
            Assert.Equal(b.GetN <int>(0), val[0]);         // Failed to get value");
            Assert.Equal(b.GetN <int>(1), val[1] as int?); // Failed to get value");
            Assert.Equal(b.Get <string>(2), val[2]);       // Failed to get value");
            Assert.True(CollectionEx.ArrayEquals(b.Get <byte[]>(3), val[3] as byte[]), "Failed to get value");
            Assert.True(CollectionEx.ArrayEquals(m, b.Map), "Failed to get value");
            byte[] io;
            Assert.True(NumberEx.TryFromServerHex("0x0000000308080C001111111100111111110000000000", out io), "Failed to parse IO");
            b = new BlobIO(io);
            Assert.Null(b.PK);
            string str = b.Str;

            b.PK = 0;
            Assert.True(NumberEx.TryFromServerHex("0x000100030808000000000C001111111100111111110000000000", out io), "Failed to parse IO with PK");
            Assert.NotEqual(str, b.Str);
            Assert.Equal(0, b.PK);
            b.PK = null;
            Assert.True(NumberEx.TryFromServerHex("0x0000000308080C001111111100111111110000000000", out io), "Failed to parse IO with PK");
            Assert.Equal(str, b.Str);
            Assert.Null(b.PK);
            b.PK = -1;
            Assert.True(NumberEx.TryFromServerHex("0x0001000308080FFFFFFFFC001111111100111111110000000000", out io), "Failed to parse IO with PK");
            Assert.NotEqual(str, b.Str);
            Assert.Equal(-1, b.PK);

            b  = null;
            b += 1;
            b += (short)1;
            b += "初めまして";
            b += Math.PI;
            b += Math.PI.DoubleToFloat();
            b += IOEx.SafeIO <long>(null);
            b += (bool?)null;
            b += TestGuid;
            b += io;
            b += DateTimeEx.s_Epoch;
            string friendly = "1, 1, '初めまして', 3.142, 3.142, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 'AAEAAwgID/////wAEREREQARERERAAAAAAA=', '01/01/1970 00:00:00'";
            string bstr     = "AAMACggQDAYNAAIOFSEAAAAAAQAAAQAAAAAP5Yid44KB44G+44GX44GmAEAJIftURC0YAEBJD9sBAQD/////////////////////AAAAABoAAQADCAgP/////AARERERABEREREAAAAAAAAIn3/197WAAAD/AAAABQAAAMD/";

            Assert.Null(b.PK);
            Assert.Equal(bstr, b.Str);                                                                                                                                                                            // Failed to get value");
            Assert.Equal("Int, SmallInt, NVarChar, Float, Real, BigInt, Bit, UniqueIdentifier, VarBinary, DateTime2", b.StrMap);                                                                                  // Failed to get value");
            Assert.Equal("1, 1, '初めまして', 3.1415927, 3.141593, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 0x0001000308080ffffffffc001111111100111111110000000000, '1970-01-01T00:00:00.000'", b.StrData); // Failed to get value");
            Assert.Equal(friendly, b.Friendly);                                                                                                                                                                   // Failed to get value");
            b.Name = "V";
            b.Cols = "a,b,c,d,e,f,g,h,i,j".Split(',');
            Assert.Equal("a, b, c, d, e, f, g, h, i, j", b.StrCols);                                                                                                                                                                                                                                             // Failed to get value");
            Assert.Equal("\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"", b.Select);                                                                                                                                                                                                      //, "Failed to get value");
            Assert.Equal("\"a\" = 1, \"b\" = 1, \"c\" = 0x1d5281307e3057306630, \"d\" = 3.1415927, \"e\" = 3.141593, \"f\" = NULL, \"g\" = NULL, \"h\" = 'ffffffff-ffff-ffff-ffff-ffffffffffff', \"i\" = 0x0001000308080ffffffffc001111111100111111110000000000, \"j\" = '1970-01-01T00:00:00.000'", b.Update);  //, "Failed to get value");
            Assert.Equal("\"a\" = V.GetInt32(0), \"b\" = V.GetInt16(1), \"c\" = V.GetString(2), \"d\" = V.GetDouble(3), \"e\" = V.GetSingle(4), \"f\" = V.GetInt64(5), \"g\" = V.GetBool(6), \"h\" = V.GetGuid(7), \"i\" = V.GetBytes(8), \"j\" = V.GetDateTime(9)", b.UpdateVar);                               //, "Failed to get value");
            Assert.Equal(" (\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\") VALUES (1, 1, 0x1d5281307e3057306630, 3.1415927, 3.141593, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 0x0001000308080ffffffffc001111111100111111110000000000, '1970-01-01T00:00:00.000')", b.Insert); //, "Failed to get value");
            Assert.Equal(" (\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\") VALUES (V.GetInt32(0), V.GetInt16(1), V.GetString(2), V.GetDouble(3), V.GetSingle(4), V.GetInt64(5), V.GetBool(6), V.GetGuid(7), V.GetBytes(8), V.GetDateTime(9))", b.InsertVar);                              //, "Failed to get value");
            Assert.Equal("V", b.Name);                                                                                                                                                                                                                                                                           // Failed to get value");

            byte[] bio = BlobIO.ExportBlobList(b);

            b = BlobIO.Data(1, (short)1, "初めまして", Math.PI, Math.PI.DoubleToFloat(), IOEx.SafeIO <long>(null), (bool?)null, TestGuid, io, DateTimeEx.s_Epoch);
            Assert.Equal(friendly, b.Friendly);                                                                                                    // Failed to get value");
            Assert.True(b.Concat(b));
            Assert.Equal(string.Join(", ", friendly, friendly), b.Friendly);                                                                       // Failed to get value");
            b = new BlobIO(bio);
            Assert.Equal(friendly, b.Friendly);                                                                                                    // Failed to get value");
            Assert.True(b.Set(4, BlobIO.Data(float.NaN, 0L, false, Guid.Empty, (byte[])null)));
            Assert.Equal("1, 1, '初めまして', 3.142, NULL, 0, False, '00000000-0000-0000-0000-000000000000', NULL, '01/01/1970 00:00:00'", b.Friendly); // Failed to get value");

            b  = new BlobIO(bio);
            io = b.IO;
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList();
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            int ix = 0;

            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io.Take(pair.Value.Length)));
            }
            byte[] dataio, prefixio, suffixio, ixsio, sbioio;
            string data = "0000000001000001000000000fe5889de38281e381bee38197e381a600400921fb54442d180040490fdb010100ffffffffffffffffffffffffffffffff000000001a0001000308080ffffffffc00111111110011111111000000000000089f7ff5f7b5800000";

            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + data, out dataio) ? dataio : null, b.DataIO));
            string prefix = "0x0003000a08100c060d00020e1521";

            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(prefix, out prefixio) ? prefixio : null, b.PrefixIO));
            string presuffix = "ff000a016101620163016401650166016701680169016a00";
            string suffix    = presuffix + "05000000c0ff";

            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));
            string ixs = "0002" + "00000066" + "000000cc";

            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            string sio  = prefix + data + suffix;
            string sbio = sio + ixs + data + data + data;

            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");

            b = new BlobIO(bstr);
            Assert.Equal(friendly, b.Friendly); // Failed to get value");

            b.PK = 0;
            Assert.Equal(0, b.PK);
            Assert.Equal("AQMAAAAAAAoIEAwGDQACDhUhAAAAAAEAAAEAAAAAD+WIneOCgeOBvuOBl+OBpgBACSH7VEQtGABASQ/bAQEA/////////////////////wAAAAAaAAEAAwgID/////wAEREREQARERERAAAAAAAACJ9/9fe1gAAA/wAAAAUAAADA/w==", b.Str); // Failed to get value");
            Assert.Equal("Int, SmallInt, NVarChar, Float, Real, BigInt, Bit, UniqueIdentifier, VarBinary, DateTime2", b.StrMap);                                                                                     // Failed to get value");
            Assert.Equal("1, 1, '初めまして', 3.1415927, 3.141593, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 0x0001000308080ffffffffc001111111100111111110000000000, '1970-01-01T00:00:00.000'", b.StrData);    // Failed to get value");
            Assert.Equal(friendly, b.Friendly);                                                                                                                                                                      // Failed to get value");
            b.Name = "V";
            b.Cols = "a,b,c,d,e,f,g,h,i,j".Split(',');
            Assert.Equal("a, b, c, d, e, f, g, h, i, j", b.StrCols);                                                                                                                                                                                                                                             // Failed to get value");
            Assert.Equal("\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"", b.Select);                                                                                                                                                                                                      //, "Failed to get value");
            Assert.Equal("\"a\" = 1, \"b\" = 1, \"c\" = 0x1d5281307e3057306630, \"d\" = 3.1415927, \"e\" = 3.141593, \"f\" = NULL, \"g\" = NULL, \"h\" = 'ffffffff-ffff-ffff-ffff-ffffffffffff', \"i\" = 0x0001000308080ffffffffc001111111100111111110000000000, \"j\" = '1970-01-01T00:00:00.000'", b.Update);  //, "Failed to get value");
            Assert.Equal("\"a\" = V.GetInt32(0), \"b\" = V.GetInt16(1), \"c\" = V.GetString(2), \"d\" = V.GetDouble(3), \"e\" = V.GetSingle(4), \"f\" = V.GetInt64(5), \"g\" = V.GetBool(6), \"h\" = V.GetGuid(7), \"i\" = V.GetBytes(8), \"j\" = V.GetDateTime(9)", b.UpdateVar);                               //, "Failed to get value");
            Assert.Equal(" (\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\") VALUES (1, 1, 0x1d5281307e3057306630, 3.1415927, 3.141593, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 0x0001000308080ffffffffc001111111100111111110000000000, '1970-01-01T00:00:00.000')", b.Insert); //, "Failed to get value");
            Assert.Equal(" (\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\") VALUES (V.GetInt32(0), V.GetInt16(1), V.GetString(2), V.GetDouble(3), V.GetSingle(4), V.GetInt64(5), V.GetBool(6), V.GetGuid(7), V.GetBytes(8), V.GetDateTime(9))", b.InsertVar);                              //, "Failed to get value");
            Assert.Equal("V", b.Name);                                                                                                                                                                                                                                                                           // Failed to get value");

            int seed = 0;

            io  = b.Export(false, ref seed);
            bio = BlobIO.ExportBlobList(false, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(false);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(false, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            ix = 0;
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io.Take(pair.Value.Length)));
            }
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + data, out dataio) ? dataio : null, b.DataIO));
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(prefix, out prefixio) ? prefixio : null, b.PrefixIO));
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");


            Assert.Equal(io.Length + sizeof(int), b.IO.Length);
            io  = b.IO;
            bio = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(0, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "00000000" + "000a08100c060d00020e1521";
            sio    = prefix + data + suffix;
            sbio   = sio + ixs + "00000000" + data + "00000000" + data + "00000000" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");


            b    = new BlobIO(bstr);
            b.PK = -1;
            Assert.Equal(-1, b.PK);

            io  = b.IO;
            bio = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(-1, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "FFFFFFFF" + "000a08100c060d00020e1521";
            sio    = prefix + data + "ff00000005000000c0ff";
            sbio   = sio + ixs + "FFFFFFFF" + data + "FFFFFFFF" + data + "FFFFFFFF" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");


            b.Name = "V";
            b.Cols = "a,b,c,d,e,f,g,h,i,j".Split(',');
            io     = b.IO;
            bio    = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(-1, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "FFFFFFFF" + "000a08100c060d00020e1521";
            sio    = prefix + data + suffix;
            sbio   = sio + ixs + "FFFFFFFF" + data + "FFFFFFFF" + data + "FFFFFFFF" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");



            b.PK = null;
            Assert.Null(b.PK);

            seed = 0;
            io   = b.Export(true, ref seed);
            bio  = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            ix = 0;
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "FFFFFFFF" + "000a08100c060d00020e1521";
            sio    = prefix + data + suffix;
            sbio   = sio + ixs + "FFFFFFFE" + data + "FFFFFFFD" + data + "FFFFFFFC" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");



            b.PK = null;
            Assert.Null(b.PK);
            b.Indexes = new int[] { 1, 3, 5 };
            Assert.Equal("1,3,5", b.StrIxs); // Failed to get indexes");
            Assert.Null(b.StrNulls);         // Failed to get null oks");
            Assert.Null(b.StrOuts);          // Failed to get outputs");

            seed = 0;
            io   = b.Export(true, ref seed);
            bio  = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            ix = 0;
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "FFFFFFFF" + "000a08100c060d00020e1521";
            suffix = presuffix + "052a0000c0ff";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));
            sio  = prefix + data + suffix;
            sbio = sio + ixs + "FFFFFFFE" + data + "FFFFFFFD" + data + "FFFFFFFC" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");

            b.Indexes = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrIxs); // Failed to get indexes");
            Assert.Null(b.StrNulls);                       // Failed to get null oks");
            Assert.Null(b.StrOuts);                        // Failed to get outputs");
            suffix = presuffix + "05ff0300c0ff";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Indexes = new int[] { 0, 24 };
            Assert.Equal("0", b.StrIxs); // Failed to get indexes");
            Assert.Null(b.StrNulls);     // Failed to get null oks");
            Assert.Null(b.StrOuts);      // Failed to get outputs");
            suffix = presuffix + "05010000c0ff";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Indexes = new int[] { 0 };
            Assert.Equal("0", b.StrIxs); // Failed to get indexes");
            Assert.Null(b.StrNulls);     // Failed to get null oks");
            Assert.Null(b.StrOuts);      // Failed to get outputs");
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Indexes = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Nulls   = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Outs    = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Ins     = new int[] { 6 };
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrIxs);   // Failed to get indexes");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrNulls); // Failed to get null oks");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrOuts);  // Failed to get outputs");
            suffix = presuffix + "05ffffff3f10";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Indexes = null;
            b.Nulls   = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Outs    = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            Assert.Null(b.StrIxs);                           // Failed to get indexes");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrNulls); // Failed to get null oks");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrOuts);  // Failed to get outputs");
            suffix = presuffix + "0500fcff3f10";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Nulls = null;
            b.Outs  = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            Assert.Null(b.StrIxs);                          // Failed to get indexes");
            Assert.Null(b.StrNulls);                        // Failed to get null oks");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrOuts); // Failed to get outputs");
            suffix = presuffix + "050000f03f10";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Nulls = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Outs  = null;
            Assert.Null(b.StrIxs);                           // Failed to get indexes");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrNulls); // Failed to get null oks");
            Assert.Null(b.StrOuts);                          // Failed to get outputs");
            suffix = presuffix + "0500fc0f0010";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            Assert.True(NumberEx.TryFromServerHex("0x0100" + "FFFFFFFF" + "000a08100c060d00020e1521" + data +
                                                  presuffix +
                                                  ixs + "FFFFFFFE" + data + "FFFFFFFD" + data + "FFFFFFFC" + data, out bio));
            ix = 0;
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
            }
        }
コード例 #26
0
        public void Clear__TriggersVersionChangedEvent()
        {
            var c = new CollectionEx<int>();

            c.Add(13);
            c.Add(7);

            var eventCalled = false;
            var lastVersion = c.Version;

            c.VersionChanged += (s, e) =>
            {
                if (eventCalled)
                    Assert.Fail("VersionChanged should be triggered only once during bulk updates");

                eventCalled = true;
            };

            c.Clear();

            Assert.IsTrue(eventCalled);
            Assert.AreNotEqual(lastVersion, c.Version);
            Assert.AreEqual(0, c.Count);
        }
コード例 #27
0
        public void Constructor__DoesNotTriggerVersionChangedEvent()
        {
            var c = new CollectionEx<int>(new int[] { 1, 2, 3, 4 });

            Assert.AreEqual(0, c.Version);
            Assert.AreEqual(4, c.Count);
        }
コード例 #28
0
        public void IndexerGet__DoesNotTriggerVersionChangedEvent()
        {
            var c = new CollectionEx<int>();

            c.Add(13);

            var eventCalled = false;
            var lastVersion = c.Version;

            c.VersionChanged += (s, e) =>
            {
                eventCalled = true;
            };

            var x = c[0];

            Assert.IsFalse(eventCalled);
            Assert.AreEqual(lastVersion, c.Version);
        }
コード例 #29
0
        public void IndexerSet__TriggersVersionChangedEvent()
        {
            var c = new CollectionEx<int>();

            c.Add(13);

            var eventCalled = false;
            var lastVersion = c.Version;

            c.VersionChanged += (s, e) =>
            {
                eventCalled = true;
            };

            c[0] = 7;

            Assert.IsTrue(eventCalled);
            Assert.AreNotEqual(lastVersion, c.Version);
            Assert.AreEqual(7, c[0]);
            Assert.AreEqual(1, c.Count);
        }
コード例 #30
0
        public void Replace__TriggersVersionChangedEvent()
        {
            var c = new CollectionEx<int>();

            c.Add(13);
            c.Add(7);

            var eventCalled = false;
            var lastVersion = c.Version;

            c.VersionChanged += (s, e) =>
            {
                eventCalled = true;
            };

            c.Replace(13, 99);

            Assert.IsTrue(eventCalled);
            Assert.AreNotEqual(lastVersion, c.Version);
            Assert.AreEqual(2, c.Count);
        }
コード例 #31
0
        public void IsReadonly_Add_ThrowsException()
        {
            var c = new CollectionEx<int>(new int[] { 1, 2 });

            c.Add(3);
        }
コード例 #32
0
        public void IsReadonly_Remove_ThrowsException()
        {
            var c = new CollectionEx<int>(new int[] { 1, 2 });

            c.Remove(1);
        }
コード例 #33
0
        public void IsReadonly_Clear_ThrowsException()
        {
            var c = new CollectionEx<int>(new int[] { 1, 2 });

            c.Clear();
        }
コード例 #34
0
        public IEnumerable <string> Transform(ForNode item)
        {
            _EncounteredOutputStyleBlock = true;
            if (!(ShouldRender && _EncounteredOutputStyleBlock))
            {
                yield break;
            }

            object?evalObj;

            if (item.Expression != null)
            {
                evalObj = Environment.Evaluation.EvaluateDynamic(item.Expression.Expression, Scopes);
            }
            else
            {
                evalObj = item.AlreadyEvaluatedObject;
            }

            Func <object?[], object?> loopFunction = args =>
            {
                if (args?.Length != 1)
                {
                    throw new NotImplementedException();
                }
                return(new ForNode(item.PrimaryBlock, item.ElseBlock, item.VariableNames,
                                   args[0], item.Filter, item.Recursive,
                                   item.EndParsingNode, item.WhiteSpaceControl));
            };

            var arr = CollectionEx.ToArray(evalObj) ?? Array.Empty <object>();

            if (item.Filter != null)
            {
                var filtered = new List <object?>();
                foreach (var arrItem in arr)
                {
                    var unpacked = ReflectionHelpers.Unpack(arrItem, item.VariableNames.Length);
                    Scopes.Push($"ForNode | Filter: {item.Filter} Item: {arrItem}");
                    for (var i = 0; i < unpacked.Length; ++i)
                    {
                        Scopes.Current.DefineAndSetVariable(item.VariableNames[i], unpacked[i]);
                    }
                    var result = Environment.Evaluation.EvaluateDynamic(item.Filter.Expression, Scopes);
                    Scopes.Pop($"ForNode | Filter: {item.Filter} Item: {arrItem}");
                    if (TypeCoercion.GetTruthy(result))
                    {
                        filtered.Add(arrItem);
                    }
                }
                arr = filtered.ToArray();
            }

            if (arr.Length == 0 && item.ElseBlock != null)
            {
                foreach (var output in item.ElseBlock.Transform(this))
                {
                    yield return(output);
                }
                yield break;
            }


            var depth = 0;

            if (Scopes.Current.TryGetVariable <LoopInfo>("loop", out var previousLoopInfo) && previousLoopInfo != null)
            {
                depth = previousLoopInfo.depth0 + 1;
            }

            var loopInfo = new LoopInfo(arr, loopFunction, depth);

            for (var index = 0; index < arr.Length; ++index)
            {
                loopInfo.index0 = index;
                var arrItem  = arr[index];
                var unpacked = ReflectionHelpers.Unpack(arrItem, item.VariableNames.Length);

                Scopes.Push($"ForNode: {item.Expression} Item: {arrItem}");
                for (var i = 0; i < unpacked.Length; ++i)
                {
                    Scopes.Current.DefineAndSetVariable(item.VariableNames[i], unpacked[i]);
                }
                Scopes.Current.DefineAndSetVariable("loop", loopInfo);
                foreach (var output in item.PrimaryBlock.Transform(this))
                {
                    yield return(output);
                }
                Scopes.Pop($"ForNode: {item.Expression} Item: {arrItem}");
            }
            yield break;
        }