Пример #1
0
        protected void testLockList()
        {
            LockList<string> m_list = new LockList<string>("TestLockList", 4);
            m_list.Add("aaaaa");
            m_list.Add("bbbbb");
            m_list.Add("ccccc");

            m_list.RemoveAt(1);
        }
Пример #2
0
        public static Il2CppSystem.Collections.Generic.List <T> ToIl2CppList <T>(this LockList <T> lockList)
        {
            Il2CppSystem.Collections.Generic.List <T> il2CppList = new Il2CppSystem.Collections.Generic.List <T>();
            for (int i = 0; i < lockList.Count; i++)
            {
                il2CppList.Add(lockList[i]);
            }

            return(il2CppList);
        }
Пример #3
0
        /// <summary>
        /// Not Tested
        /// </summary>
        public static SizedList <T> ToSizedList <T>(this LockList <T> lockList)
        {
            SizedList <T> sizedList = new SizedList <T>();

            for (int i = 0; i < sizedList.Count; i++)
            {
                sizedList.Add(sizedList[i]);
            }

            return(sizedList);
        }
Пример #4
0
        /// <summary>
        /// (Cross-Game compatible) Return this with an additional Item added to it
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TCast">The Type of the Item to add</typeparam>
        /// <param name="lockList"></param>
        /// <param name="objectToAdd">Item to add</param>
        /// <returns></returns>
        public static LockList <TSource> AddTo <TSource, TCast>(this LockList <TSource> lockList, TCast objectToAdd)
            where TSource : Il2CppSystem.Object where TCast : Il2CppSystem.Object
        {
            if (lockList is null)
            {
                lockList = new LockList <TSource>();
            }

            lockList.Add(objectToAdd.TryCast <TSource>());
            return(lockList);
        }
Пример #5
0
 /// <summary>
 /// (Cross-Game compatible) Return the first element that matches the predicate, or return default
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source"></param>
 /// <param name="predicate"></param>
 /// <returns></returns>
 public static T FirstOrDefault <T>(this LockList <T> source, Func <T, bool> predicate) where T : Il2CppSystem.Object
 {
     for (int i = 0; i < source.Count; i++)
     {
         T item = source[i];
         if (predicate(item))
         {
             return(item);
         }
     }
     return(default);
        /// <summary>
        /// (Cross-Game compatible) Return as LockList
        /// </summary>
        public static LockList <Il2CppSystem.Object> ToLockList(this IEnumerator enumerator)
        {
            LockList <Il2CppSystem.Object> lockList = new LockList <Il2CppSystem.Object>();

            while (enumerator.MoveNext())
            {
                lockList.Add(enumerator.Current);
            }

            return(lockList);
        }
Пример #7
0
        /// <summary>
        /// (Cross-Game compatible) Return as LockList
        /// </summary>
        public static LockList <T> ToLockList <T>(this IEnumerable <T> enumerable)
        {
            LockList <T> lockList = new LockList <T>();

            for (int i = 0; i < enumerable.Count(); i++)
            {
                lockList.Add(enumerable.ElementAt(i));
            }

            return(lockList);
        }
Пример #8
0
        /// <summary>
        /// Not Tested
        /// </summary>
        public static LockList <T> ToLockList <T>(this Il2CppReferenceArray <T> referenceArray) where T : Il2CppSystem.Object
        {
            LockList <T> lockList = new LockList <T>();

            foreach (T item in referenceArray)
            {
                lockList.Add(item);
            }

            return(lockList);
        }
Пример #9
0
        /// <summary>
        /// (Cross-Game compatible) Return as System.List
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="lockList"></param>
        /// <returns></returns>
        public static List <T> ToList <T>(this LockList <T> lockList)
        {
            List <T> newList = new List <T>();

            for (int i = 0; i < lockList.Count; i++)
            {
                newList.Add(lockList[i]);
            }

            return(newList);
        }
Пример #10
0
        /// <summary>
        /// (Cross-Game compatible) Return a duplicate of this
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        public static LockList <T> Duplicate <T>(this LockList <T> list)
        {
            LockList <T> newList = new LockList <T>();

            for (int i = 0; i < list.Count; i++)
            {
                newList.Add(list[i]);
            }

            return(newList);
        }
Пример #11
0
        /// <summary>
        /// Not Tested
        /// </summary>
        public static LockList <T> ToLockList <T>(this List <T> list)
        {
            LockList <T> lockList = new LockList <T>();

            foreach (T item in list)
            {
                lockList.Add(item);
            }

            return(lockList);
        }
Пример #12
0
        /// <summary>
        /// (Cross-Game compatible) Return as Il2CppReferenceArray
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="lockList"></param>
        /// <returns></returns>
        public static Il2CppReferenceArray <T> ToIl2CppReferenceArray <T>(this LockList <T> lockList) where T : Il2CppSystem.Object
        {
            Il2CppReferenceArray <T> il2cppArray = new Il2CppReferenceArray <T>(lockList.Count);

            for (int i = 0; i < lockList.Count; i++)
            {
                il2cppArray[i] = lockList[i];
            }

            return(il2cppArray);
        }
Пример #13
0
        /// <summary>
        /// Not Tested
        /// </summary>
        public static LockList <T> ToLockList <T>(this SizedList <T> sizedList)
        {
            LockList <T> lockList = new LockList <T>();

            for (int i = 0; i < sizedList.count; i++)
            {
                lockList.Add(sizedList[i]);
            }

            return(lockList);
        }
        /// <summary>
        /// (Cross-Game compatible) Return as LockList
        /// </summary>
        public static LockList <T> ToLockList <T>(this IEnumerable <T> enumerable) where T : Il2CppSystem.Object
        {
            LockList <T> lockList   = new LockList <T>();
            var          enumerator = enumerable.GetEnumeratorCollections();

            while (enumerator.MoveNext())
            {
                lockList.Add(enumerator.Current.Cast <T>());
            }

            return(lockList);
        }
Пример #15
0
        /// <summary>
        /// (Cross-Game compatible) Return a duplicate of this as type TCast
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TCast"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        public static LockList <TCast> DuplicateAs <TSource, TCast>(this LockList <TSource> list)
            where TSource : Il2CppSystem.Object where TCast : Il2CppSystem.Object
        {
            LockList <TCast> newList = new LockList <TCast>();

            for (int i = 0; i < list.Count; i++)
            {
                newList.Add(list[i].TryCast <TCast>());
            }

            return(newList);
        }
Пример #16
0
        public void ClearRemovedAllItems()
        {
            var list = new LockList <int>();

            list.Add(150);
            list.Add(42);
            list.Add(978);
            list.Clear();

            list.Should().NotBeNull();
            list.Count.Should().Be(0);
        }
Пример #17
0
        /// <summary>
        /// (Cross-Game compatible) Return as System.Array
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="lockList"></param>
        /// <returns></returns>
        public static T[] ToArray <T>(this LockList <T> lockList)
        {
            T[] newArray = new T[] { };
            for (int i = 0; i < lockList.Count; i++)
            {
                T item = lockList[i];
                Array.Resize(ref newArray, newArray.Length + 1);
                newArray[newArray.Length - 1] = item;
            }

            return(newArray);
        }
Пример #18
0
        public void InsertWorks()
        {
            var list = new LockList <int>();

            list.Add(150);
            list.Add(42);
            list.Add(978);

            list.Insert(1, 99);
            list.Count.Should().Be(4);
            list[1].Should().Be(99);
            list[2].Should().Be(42);
        }
Пример #19
0
        public void AddMultileItemsToList()
        {
            var list = new LockList <int>();

            list.Add(150);
            list.Add(7);
            list.Add(978);
            list.Add(35);
            list.Add(42);

            list.Should().NotBeNull();
            list.Count.Should().Be(5);
        }
Пример #20
0
        /// <summary>
        /// (Cross-Game compatible) Return the first element that matches the predicate
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public static T First <T>(this LockList <T> source, Func <T, bool> predicate) where T : Il2CppSystem.Object
        {
            for (int i = 0; i < source.Count; i++)
            {
                T item = source[i];
                if (predicate(item))
                {
                    return(item);
                }
            }

            throw new NullReferenceException();
        }
Пример #21
0
        public void RemoveWorksForList()
        {
            var list = new LockList <int>();

            list.Add(150);
            list.Add(7);
            list.Add(978);
            list.Add(35);
            list.Add(42);

            list.Remove(978).Should().BeTrue();
            list.Count.Should().Be(4);
        }
Пример #22
0
        public void CopyToWorks()
        {
            var list = new LockList <int>();

            list.Add(150);
            list.Add(42);
            list.Add(978);

            var list2 = new int[3];

            list.CopyTo(list2, 0);

            list2.Length.Should().Be(3);
            list2[0].Should().Be(150);
            list2[1].Should().Be(42);
            list2[2].Should().Be(978);
        }
Пример #23
0
        /// <summary>
        /// (Cross-Game compatible) Check if this has any items of type TCast
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TCast">The Type you're checking for</typeparam>
        /// <param name="lockList"></param>
        /// <returns></returns>
        public static bool HasItemsOfType <TSource, TCast>(this LockList <TSource> lockList) where TSource : Il2CppSystem.Object
            where TCast : Il2CppSystem.Object
        {
            for (int i = 0; i < lockList.Count; i++)
            {
                TSource item = lockList[i];
                try
                {
                    if (item.IsType <TCast>())
                    {
                        return(true);
                    }
                }
                catch (Exception) { }
            }

            return(false);
        }
Пример #24
0
        public static TCast GetItemOfType <TSource, TCast>(this LockList <TSource> lockList) where TCast : Il2CppSystem.Object
            where TSource : Il2CppSystem.Object
        {
            if (!HasItemsOfType <TSource, TCast>(lockList))
            {
                return(null);
            }

            for (int i = 0; i < lockList.Count; i++)
            {
                TSource item = lockList[i];
                try
                {
                    if (item.TryCast <TCast>() != null)
                    {
                        return(item.TryCast <TCast>());
                    }
                }
                catch (Exception) { }
            }

            return(null);
        }
Пример #25
0
        /// <summary>
        /// (Cross-Game compatible) Return this with the first Item of type TCast removed
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TCast">The Type of the Item you want to remove</typeparam>
        /// <param name="lockList"></param>
        /// <param name="itemToRemove">The specific Item to remove</param>
        /// <returns></returns>
        public static LockList <TSource> RemoveItem <TSource, TCast>(this LockList <TSource> lockList, TCast itemToRemove)
            where TSource : Il2CppSystem.Object where TCast : Il2CppSystem.Object
        {
            if (!HasItemsOfType <TSource, TCast>(lockList))
            {
                return(lockList);
            }

            List <TSource> arrayList = lockList.ToList();

            for (int i = 0; i < lockList.Count; i++)
            {
                TSource item = lockList[i];
                if (item is null || !item.Equals(itemToRemove.TryCast <TCast>()))
                {
                    continue;
                }

                arrayList.RemoveAt(i);
                break;
            }

            return(arrayList.ToLockList());
        }
Пример #26
0
        public void ListInstantiation()
        {
            var list = new LockList <bool>();

            list.Should().NotBeNull();
        }
Пример #27
0
 public LockQueue(string name)
 {
     m_list = new LockList <T>("name");
 }
Пример #28
0
        public TupleSpaceXL(String path)
        {
            _view       = new View();
            _tupleSpace = new List <Tuple>();
            _lockList   = new LockList();
            MinDelay    = 0;
            MaxDelay    = 0;

            myPath = path;
            bool obtainedView = false;


            try
            {
                string[] file = File.ReadAllLines(Path.Combine(Directory.GetCurrentDirectory(), "../../../config/serverListXL.txt"));

                foreach (string i in file)
                {
                    if (i != path)
                    {
                        ServerList.Add(i);
                    }
                }
            }
            catch (FileNotFoundException)
            {
                System.Console.WriteLine("Server List not Found");
                System.Console.WriteLine("Aborting...");
                System.Environment.Exit(1);
            }

            List <List <Tuple> > allTupleSpaces = new List <List <Tuple> >();

            foreach (string s in ServerList)
            {
                try
                {
                    Console.WriteLine("Trying to get view acesss: " + s);
                    TupleSpaceXL otherServer = (TupleSpaceXL)Activator.GetObject(typeof(TupleSpaceXL), s);
                    View         currentView = otherServer.AddView(myPath);
                    allTupleSpaces.Add(otherServer.GetTupleSpace());
                    if (_view.Version < currentView.Version)
                    {
                        _view = currentView;
                    }

                    obtainedView = true;
                }
                catch (System.Net.Sockets.SocketException)
                {
                    Console.WriteLine(s + " is not alive");
                }
            }

            _tupleSpace = Intersection(allTupleSpaces).ToList();
            List <string> serversCopy = _view.Servers.ToList();

            foreach (string s in serversCopy)
            {
                if (s != myPath)
                {
                    try
                    {
                        TupleSpaceXL otherServer = (TupleSpaceXL)Activator.GetObject(typeof(TupleSpaceXL), s);
                        otherServer.SetTupleSpace(_tupleSpace);
                        otherServer.SetOnUpdate(false);
                    } catch (System.Net.Sockets.SocketException)
                    {
                        Console.WriteLine("** SETTING TS: Server at: " + s + " is dead but is in my view!");
                        _view.Remove(s);
                    }
                }
            }
            //Already have the new tuple space. Update process is now complete. Inform the clients of the new view.
            this.SetOnUpdate(false);

            //If no one replies to the view then i create my own view
            if (obtainedView == false)
            {
                _view = new View();
                _view.Add(myPath);
            }
        }