Exemplo n.º 1
0
        static int _m_CopyTo(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


            System.Collections.Generic.List <xc.Task> __cl_gen_to_be_invoked = (System.Collections.Generic.List <xc.Task>)translator.FastGetCSObj(L, 1);


            int __gen_param_count = LuaAPI.lua_gettop(L);

            try {
                if (__gen_param_count == 2 && translator.Assignable <xc.Task[]>(L, 2))
                {
                    xc.Task[] array = (xc.Task[])translator.GetObject(L, 2, typeof(xc.Task[]));

                    __cl_gen_to_be_invoked.CopyTo(array);



                    return(0);
                }
                if (__gen_param_count == 3 && translator.Assignable <xc.Task[]>(L, 2) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3))
                {
                    xc.Task[] array      = (xc.Task[])translator.GetObject(L, 2, typeof(xc.Task[]));
                    int       arrayIndex = LuaAPI.xlua_tointeger(L, 3);

                    __cl_gen_to_be_invoked.CopyTo(array, arrayIndex);



                    return(0);
                }
                if (__gen_param_count == 5 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) && translator.Assignable <xc.Task[]>(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5))
                {
                    int       index      = LuaAPI.xlua_tointeger(L, 2);
                    xc.Task[] array      = (xc.Task[])translator.GetObject(L, 3, typeof(xc.Task[]));
                    int       arrayIndex = LuaAPI.xlua_tointeger(L, 4);
                    int       count      = LuaAPI.xlua_tointeger(L, 5);

                    __cl_gen_to_be_invoked.CopyTo(index, array, arrayIndex, count);



                    return(0);
                }
            } catch (System.Exception __gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to System.Collections.Generic.List<xc.Task>.CopyTo!"));
        }
        static int _m_CopyTo(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                System.Collections.Generic.List <XLua.LuaTable> gen_to_be_invoked = (System.Collections.Generic.List <XLua.LuaTable>)translator.FastGetCSObj(L, 1);


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 2 && translator.Assignable <XLua.LuaTable[]>(L, 2))
                {
                    XLua.LuaTable[] _array = (XLua.LuaTable[])translator.GetObject(L, 2, typeof(XLua.LuaTable[]));

                    gen_to_be_invoked.CopyTo(_array);



                    return(0);
                }
                if (gen_param_count == 3 && translator.Assignable <XLua.LuaTable[]>(L, 2) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3))
                {
                    XLua.LuaTable[] _array      = (XLua.LuaTable[])translator.GetObject(L, 2, typeof(XLua.LuaTable[]));
                    int             _arrayIndex = LuaAPI.xlua_tointeger(L, 3);

                    gen_to_be_invoked.CopyTo(_array, _arrayIndex);



                    return(0);
                }
                if (gen_param_count == 5 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) && translator.Assignable <XLua.LuaTable[]>(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5))
                {
                    int             _index      = LuaAPI.xlua_tointeger(L, 2);
                    XLua.LuaTable[] _array      = (XLua.LuaTable[])translator.GetObject(L, 3, typeof(XLua.LuaTable[]));
                    int             _arrayIndex = LuaAPI.xlua_tointeger(L, 4);
                    int             _count      = LuaAPI.xlua_tointeger(L, 5);

                    gen_to_be_invoked.CopyTo(_index, _array, _arrayIndex, _count);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to System.Collections.Generic.List<XLua.LuaTable>.CopyTo!"));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets an array containing the session IDs of the currently logged-on users for the
        /// server pointed to by the specified handle.
        /// </summary>
        /// <returns>
        /// Returns an array of integers, which contains the sessions IDs of currently logged-on users.
        /// Returns null if no users are logged on or the list of session IDs cannot be retrieved.
        /// </returns>
        private static int[] GetLoggedOnUserSessionIds(IntPtr serverHandle)
        {
            int[]  returnArray        = null;
            IntPtr sessionInfoPointer = IntPtr.Zero;
            int    sessionCount       = 0;

            // Get a list of the sessions on a server.
            int returnValue = NativeMethods.WTSEnumerateSessions(serverHandle, 0, 1, ref sessionInfoPointer, ref sessionCount);

            long current         = sessionInfoPointer.ToInt64();
            int  sessionInfoSize = Marshal.SizeOf(typeof(WTS_SESSION_INFO));

            if (returnValue != 0)
            {
                System.Collections.Generic.List <int> sessionIds = new System.Collections.Generic.List <int>(sessionCount);

                // Retrieve the session ID for each session.
                for (int i = 0; i < sessionCount; i++)
                {
                    WTS_SESSION_INFO si = (WTS_SESSION_INFO)Marshal.PtrToStructure((System.IntPtr)current, typeof(WTS_SESSION_INFO));
                    current += sessionInfoSize;
                    sessionIds.Add(si.SessionID);
                }

                NativeMethods.WTSFreeMemory(sessionInfoPointer);

                // Copy session IDs into the return array.
                sessionIds.TrimExcess();
                returnArray = new int[sessionIds.Count];
                sessionIds.CopyTo(returnArray);
            }

            return(returnArray);
        }
Exemplo n.º 4
0
        /// <summary>
        /// invoke a post request
        /// </summary>
        /// <param name="path">ex: /user/register</param>
        /// <param name="hosts">ex: https://example.com,http://192.168.1.100, http://example.com:8080, http://192.168.1.100:8080</param>
        /// <param name="data"></param>
        /// <param name="contentType"></param>
        /// <returns></returns>
        private byte[] TryPost(string[] hosts, string path, byte[] data, string contentType)
        {
            var i = 0;

            byte[] result  = null;
            var    url     = "";
            var    host    = "";
            var    success = false;

            //
            for (; i < hosts.Length; i++)
            {
                host = hosts[i];
                url  = host + path;
                try
                {
                    result  = this.Post(url, data, contentType);
                    success = true;
                    break;
                }
                catch (System.Net.WebException exception)
                {
                    if (exception.Status == WebExceptionStatus.ConnectFailure)
                    {
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            //
            if (success == false)
            {
                throw new WebException("no active host in hosts");
            }
            //
            lock (hosts)
            {
                var list = new System.Collections.Generic.List <string>(hosts);
                //
                list.Remove(host);
                list.Insert(0, host);
                //
                list.CopyTo(hosts);
            }
            return(result);
        }
Exemplo n.º 5
0
        public override bool FireEvent(XRL.World.Event E)
        {
            // bail out if not the event we want
            if (E.ID != EVENT_NAME)
            {
                return(base.FireEvent(E));
            }

            // get list of known location categories
            System.Collections.Generic.List <string> categories = Qud.API.JournalAPI.GetMapNoteCategories();
            // if no locations known, pop up an informational message and abort
            if (categories.Count <= 0)
            {
                XRL.UI.Popup.ShowSpace("No location categories known yet. Go forth and explore!");
                return(base.FireEvent(E));
            }
            // build list of category choices
            string[] catArray = new string[categories.Count + 1];
            catArray[0] = "All Known Categories";
            categories.CopyTo(catArray, 1);
            // query the user for category choice
            int catChoice = XRL.UI.Popup.ShowOptionList(
                Title:       "Map Pin Toggle - Location",
                Options:     catArray,
                Intro:       "Which location category's map pins would you like to toggle?\n",
                AllowEscape: true
                );

            // abort if player escaped out
            if (catChoice < 0)
            {
                return(base.FireEvent(E));
            }
            // query the user for toggle action choice
            int actChoice = XRL.UI.Popup.ShowOptionList(
                Title:       "Map Pin Toggle - Action",
                Options:     TOGGLE_ACTIONS,
                Intro:       "What action would you like to perform for " +
                (catChoice == 0 ?
                 " all known categories" :
                 catArray[catChoice]) +
                "?\n",
                AllowEscape: true
                );

            // abort if player escaped out
            if (actChoice < 0)
            {
                return(base.FireEvent(E));
            }
            // player has committed to a change
            // derive action flags from player choice
            //  -1 => disable
            //   0 => no change
            //   1 => enable
            ActE actUnv = ActE.NA;
            ActE actVis = ActE.NA;

            switch (actChoice)
            {
            case 0: { actUnv = ActE.OF; actVis = ActE.OF; } break;

            case 1: { actUnv = ActE.OF; actVis = ActE.NA; } break;

            case 2: { actUnv = ActE.OF; actVis = ActE.ON; } break;

            case 3: { actUnv = ActE.NA; actVis = ActE.OF; } break;

            case 4: { actUnv = ActE.NA; actVis = ActE.ON; } break;

            case 5: { actUnv = ActE.ON; actVis = ActE.OF; } break;

            case 6: { actUnv = ActE.ON; actVis = ActE.NA; } break;

            case 7: { actUnv = ActE.ON; actVis = ActE.ON; } break;
            }
            // iterate over all revealed map notes
            foreach (Qud.API.JournalMapNote mapNote in
                     Qud.API.JournalAPI.GetMapNotes(
                         (Qud.API.JournalMapNote item) =>
                         item.revealed &&
                         (catChoice == 0 ||
                          item.category == catArray[catChoice])
                         )
                     )
            {
                // apply chosen action(s)
                switch (VisitedNote(mapNote) ? actVis : actUnv)
                {
                case ActE.OF: mapNote.tracked = false; break;

                case ActE.NA: /* do nothing */ break;

                case ActE.ON: mapNote.tracked = true;  break;
                }
            }

            XRL.World.Zone z = XRL.Core.XRLCore.Core?.Game?.Player?.Body?.CurrentCell?.ParentZone;
            if (z != null && z.IsWorldMap())
            {
                z.Activated();
            }

            // toggle categories per configured behavior
            switch (GetCategoryBehavior())
            {
            case CatE.ALL:
            {
                // enable all categories since we're managing individual entries
                // otherwise disabled categories may override visibility
                foreach (string catString in categories)
                {
                    Qud.API.JournalAPI.SetCategoryMapNoteToggle(catString, true);
                }
            }
            break;

            case CatE.NONE:
            {
                // do nothing
            }
            break;

            case CatE.SYNC:
            {
                // add categories with tracked notes to hash set
                System.Collections.Generic.HashSet <string> catSet = new System.Collections.Generic.HashSet <string>();
                foreach (Qud.API.JournalMapNote mapNote in Qud.API.JournalAPI.GetMapNotes(
                             (Qud.API.JournalMapNote item) => item.revealed && item.tracked))
                {
                    catSet.Add(mapNote.category);
                }
                // now iterate over all categories and toggle based on set presence
                foreach (string catString in categories)
                {
                    Qud.API.JournalAPI.SetCategoryMapNoteToggle(catString, catSet.Contains(catString));
                }
            }
            break;
            }

            return(base.FireEvent(E));
        }
Exemplo n.º 6
0
        private void ReadCallback(IAsyncResult iar)
        {
            byte[] input = null;
            try {
                input = (byte[])iar.AsyncState;
                usb_fs.EndRead(iar);
            } catch (Exception ex) {
                System.Console.WriteLine("EndRead exception:");
                System.Console.WriteLine(ex);
            }

            try {
                /* Data received, as bytes
                 */
                if (this.verbose_mode > 0)
                {
                    System.Console.WriteLine("");
                    System.Console.WriteLine("IN BYTES:");
                    for (int i = 0; i < input.Length; i++)
                    {
                        if (i > 0 && i % 16 == 0)
                        {
                            System.Console.WriteLine("");
                        }
                        System.Console.Write("{0:x} ", input[i]);
                    }
                    System.Console.WriteLine("");
                    System.Console.WriteLine("");
                }
                if (input.Length > 3 && input[2] == 0x6) // ACK 0x1 0x1 0x6
                {
                    last_message = null;
                    System.Console.WriteLine("ACK : DEVICE");
                }
                else if (input.Length > 3 && input[2] == 0x15) // NACK 0x1 0x1 0x15
                {
                    System.Console.WriteLine("NACK : DEVICE");
                    // resend message?
                }
                else if (read_continues && input.Length > 0)
                {
                    for (int i = 2; i < input[1] + 2; i++)
                    {
                        long_buffer.Add(input[i]);
                    }
                    if (long_buffer[long_buffer.Count - 2] == 0x3)
                    {
                        read_continues = false;
                        SendAck();
                        byte[] sliced = new byte[long_buffer.Count];
                        long_buffer.CopyTo(sliced);
                        long_buffer.Clear();
                        HandleMessageFromDevice(sliced);
                    }
                }
                else if (input.Length > 3 && input[1] + 2 <= usb_report_size && input[input[1]] == 0x3 && input[2] == 0x2)
                {
                    // single report message
                    // 0x1 {message_length_byte} {message_data_bytes}
                    System.Console.WriteLine("ACK : POS");
                    SendAck();
                    byte[] sliced = new byte[input.Length - 2];
                    Array.Copy(input, 2, sliced, 0, sliced.Length);
                    HandleMessageFromDevice(sliced);
                }
                else if (input.Length > 3 && input[1] == 30)
                {
                    // long message begins
                    read_continues = true;
                    long_buffer.Clear();
                    for (int i = 2; i < input[1] + 2; i++)
                    {
                        long_buffer.Add(input[i]);
                    }
                }
                else
                {
                    SendNack();
                    System.Console.WriteLine("unknown message");
                }
            } catch (Exception ex) {
                System.Console.WriteLine("Message data exception:");
                System.Console.WriteLine(ex);
            }

            AsyncRead();
        }
Exemplo n.º 7
0
        public override bool FireEvent(XRL.World.Event E)
        {
            // bail out if not the event we want
            if (E.ID != EVENT_NAME)
            {
                return(base.FireEvent(E));
            }

            // get list of known location categories
            System.Collections.Generic.List <string> categories = Qud.API.JournalAPI.GetMapNoteCategories();
            // if no locations known, pop up an informational message and abort
            if (categories.Count <= 0)
            {
                XRL.UI.Popup.ShowSpace("No location categories known yet. Go forth and explore!");
                return(base.FireEvent(E));
            }
            // build list of category choices
            string[] catArray = new string[categories.Count + 1];
            catArray[0] = "All Known Categories";
            categories.CopyTo(catArray, 1);
            // query the user for category choice
            int catChoice = XRL.UI.Popup.ShowOptionList(
                Title:       "Map Pin Toggle - Location",
                Options:     catArray,
                Intro:       "Which location category's map pins would you like to toggle?\n",
                AllowEscape: true
                );

            // abort if player escaped out
            if (catChoice < 0)
            {
                return(base.FireEvent(E));
            }
            // query the user for toggle action choice
            int actChoice = XRL.UI.Popup.ShowOptionList(
                Title:       "Map Pin Toggle - Action",
                Options:     TOGGLE_ACTIONS,
                Intro:       "What action would you like to perform for " +
                (catChoice == 0 ?
                 " all known categories" :
                 categories[catChoice - 1]) +
                "?\n",
                AllowEscape: true
                );

            // abort if player escaped out
            if (actChoice < 0)
            {
                return(base.FireEvent(E));
            }
            // derive action flags from player choice
            //  -1 => disable
            //   0 => no change
            //   1 => enable
            ActE actUnv = ActE.NA;
            ActE actVis = ActE.NA;

            switch (actChoice)
            {
            case 0: { actUnv = ActE.OF; actVis = ActE.OF; } break;

            case 1: { actUnv = ActE.OF; actVis = ActE.NA; } break;

            case 2: { actUnv = ActE.OF; actVis = ActE.ON; } break;

            case 3: { actUnv = ActE.NA; actVis = ActE.OF; } break;

            case 4: { actUnv = ActE.NA; actVis = ActE.ON; } break;

            case 5: { actUnv = ActE.ON; actVis = ActE.OF; } break;

            case 6: { actUnv = ActE.ON; actVis = ActE.NA; } break;

            case 7: { actUnv = ActE.ON; actVis = ActE.ON; } break;
            }
            // iterate over all revealed map notes
            foreach (Qud.API.JournalMapNote mapNote in
                     Qud.API.JournalAPI.GetMapNotes(
                         (Qud.API.JournalMapNote item) =>
                         item.revealed &&
                         (catChoice == 0 ||
                          item.category == categories[catChoice - 1])
                         )
                     )
            {
                // apply chosen action(s)
                switch (VisitedNote(mapNote) ? actVis : actUnv)
                {
                case ActE.OF: mapNote.tracked = false; break;

                case ActE.NA: /* do nothing */ break;

                case ActE.ON: mapNote.tracked = true;  break;
                }
            }

            XRL.World.Zone z = XRL.Core.XRLCore.Core?.Game?.Player?.Body?.CurrentCell?.ParentZone;
            if (z != null && z.IsWorldMap())
            {
                z.Activated();
            }

            return(base.FireEvent(E));
        }
Exemplo n.º 8
0
		private string[] GetSelectedRolesForNewUser()
		{
			//// Step 2: Add roles to user.
			System.Collections.Generic.List<string> selectedRoleNames = new System.Collections.Generic.List<string>();
			foreach (ListItem roleItem in cblAvailableRolesForNewUser.Items)
			{
				if (roleItem.Selected)
				{
					selectedRoleNames.Add(roleItem.Value);
				}
			}

			if (selectedRoleNames.Count == 0)
				throw new WebException(Resources.GalleryServerPro.Admin_Manage_Users_Create_User_No_Role_Selected_Msg);

			string[] roleNames = new string[selectedRoleNames.Count];
			selectedRoleNames.CopyTo(roleNames);

			return roleNames;
		}
Exemplo n.º 9
0
		private void AddUser()
		{
			string newUserName = txtNewUserUserName.Text;
			string newUserPassword1 = txtNewUserPassword1.Text;
			string newUserPassword2 = txtNewUserPassword2.Text;

			if (newUserPassword1 != newUserPassword2)
				throw new WebException(Resources.GalleryServerPro.Admin_Manage_Users_Passwords_Not_Matching_Error);

			// Step 1: Create the user account.

			string email = txtNewUserEmail.Text;
			if ((String.IsNullOrEmpty(email)) && (HelperFunctions.IsValidEmail(newUserName)))
			{
				// No email address was specified, but the user name happens to be in the form of an email address,
				// so let's set the email property to the user name
				email = newUserName;
			}

			// Create the user. Any number of exceptions may occur; we'll deal with them in a catch block in the calling method.
			Membership.CreateUser(newUserName, newUserPassword1, email);

			// Step 2: Add roles to user.
			System.Collections.Generic.List<string> selectedRoleNames = new System.Collections.Generic.List<string>();
			foreach (ListItem roleItem in cblAvailableRolesForNewUser.Items)
			{
				if (roleItem.Selected)
				{
					selectedRoleNames.Add(roleItem.Value);
				}
			}

			if (selectedRoleNames.Count == 0)
				throw new WebException(Resources.GalleryServerPro.Admin_Manage_Users_Create_User_No_Role_Selected_Msg);

			string[] roleNames = new string[selectedRoleNames.Count];
			selectedRoleNames.CopyTo(roleNames);
			Roles.AddUserToRoles(newUserName, roleNames);
		}
Exemplo n.º 10
0
 public void CopyTo(JsonValue [] array, int arrayIndex)
 {
     list.CopyTo(array, arrayIndex);
 }
Exemplo n.º 11
0
 /// <summary>
 /// 复制成员到数组中
 /// </summary>
 /// <param name="array">目标数组</param>
 /// <param name="arrayIndex">从0开始的索引</param>
 public void CopyTo(Condition[] array, int arrayIndex)
 {
     _list.CopyTo(array, arrayIndex);
 }
Exemplo n.º 12
0
        public void ListRNDTest()
        {
            System.Collections.Generic.IList <int> testList = new List <int>();
            var controlList = new System.Collections.Generic.List <int>();
            var r           = new System.Random();

            for (int i = 0; i < 1000; i++)
            {
                var next = r.Next();
                controlList.Add(next);
                testList.Add(next);
                Assert.Equal(controlList.Count, testList.Count);
            }
            for (int i = 0; i < 1000; i++)
            {
                Assert.True(testList.IndexOf(controlList[i]) == i);
            }
            for (int i = 0; i < controlList.Count; i++)
            {
                if (r.Next() < int.MaxValue / 2)
                {
                    testList.RemoveAt(i);
                    controlList.RemoveAt(i);
                }
                else
                {
                    var newItem = r.Next();
                    testList.Insert(i, newItem);
                    controlList.Insert(i, newItem);
                }
            }
            Assert.Equal(controlList.Count, testList.Count);


            foreach (var itm in controlList)
            {
                Assert.True(testList.Contains(itm));
            }
            for (int i = 0; i < controlList.Count / 2; i++)
            {
                var e = controlList[i];
                controlList.Remove(e);
                testList.Remove(e);
            }
            Assert.Equal(controlList.Count, testList.Count);

            int[] controllarray = new int[controlList.Count + 1];
            int[] testArray     = new int[testList.Count + 1];
            controllarray[0] = r.Next();
            testArray[0]     = controllarray[0];
            controlList.CopyTo(controllarray, 1);
            testList.CopyTo(testArray, 1);

            var q = from a in testArray
                    join b in controllarray on a equals b
                    select a;


            Assert.True(testArray.Length == controllarray.Length && q.Count() == controllarray.Length);
            controlList.Clear();
            testList.Clear();
            Assert.Equal(controlList.Count, testList.Count);
        }
 public void CopyTo(Fiber[] array, int arrayIndex)
 {
     _lst.CopyTo(array, arrayIndex);
 }
Exemplo n.º 14
0
        public void ListRNDTest()
        {
            var controlList = new System.Collections.Generic.List<int>();
            var testList = new MyList<int>();

            var r = new System.Random();
            for (int i = 0; i < 1000; i++)
            {
                var next = r.Next();
                controlList.Add(next);
                testList.Add(next);
                Assert.AreEqual(controlList.Count, testList.Count);
            }
            for (int i = 0; i < 1000; i++)
            {
                Assert.IsTrue(testList.IndexOf(controlList[i]) == i);
            }
            for (int i = 0; i < controlList.Count; i++)
            {
                if (r.Next() < int.MaxValue / 2)
                {
                    testList.RemoveAt(i);
                    controlList.RemoveAt(i);
                }
                else
                {
                    var newItem = r.Next();
                    testList.Insert(i, newItem);
                    controlList.Insert(i, newItem);
                }
            }
            Assert.AreEqual(controlList.Count, testList.Count);

            foreach (var itm in controlList){
                Assert.IsTrue(testList.Contains(itm));
            }
            for (int i = 0; i < controlList.Count / 2; i++ )
            {
                var e = controlList[i];
                controlList.Remove(e);
                testList.Remove(e);
            }
            int[] controllarray = new int[controlList.Count+1];
            int[] testArray = new int[testList.Count+1];
            controllarray[0] = r.Next();
            testArray[0] = controllarray[0];
            controlList.CopyTo(controllarray, 1);
            testList.CopyTo(testArray, 1);

            var q = from a in testArray
                    join b in controllarray on a equals b
                    select a;

            Assert.IsTrue(testArray.Length == controllarray.Length && q.Count() == controllarray.Length);
            controlList.Clear();
            testList.Clear();
            Assert.AreEqual(controlList.Count,testList.Count);
        }