예제 #1
0
        public void RunScript_Issue53_WillNotFail()
        {
            const string name            = "TEST_NAME_ISSUE53";
            const string scriptLines     = ":log info (\"start\") \r\n/ system identity print \r\n/ system identity print\r\n:log info (\"end\") ";
            const int    commandRowsCnt  = 2; // 2x call of / system identity print
            ITikCommand  scriptCreateCmd = Connection.CreateCommandAndParameters("/system/script/add",
                                                                                 "name", name,
                                                                                 "source", scriptLines);
            var id = scriptCreateCmd.ExecuteScalar();

            try
            {
                //run via ID
                ITikCommand scriptRunCmd = Connection.CreateCommand("/system/script/run",
                                                                    Connection.CreateParameter(TikSpecialProperties.Id, id, TikCommandParameterFormat.NameValue));
                var responseRows = scriptRunCmd.ExecuteList();
                Assert.IsTrue(responseRows.Count() == commandRowsCnt); //one empty !re row per script line command

                ////run via number
                //ITikCommand scriptRunCmd1 = Connection.CreateCommand("/system/script/run",
                //    Connection.CreateParameter("number", "0", TikCommandParameterFormat.NameValue));
                //var responseRows1 = scriptRunCmd1.ExecuteList();
                //Assert.IsTrue(responseRows1.Count() == commandRowsCnt); //one empty !re row per script line command
            }
            finally
            {
                Connection.CreateCommandAndParameters("/system/script/remove", TikSpecialProperties.Id, id).ExecuteNonQuery();
            }
        }
예제 #2
0
        private static IEnumerable <TEntity> LoadList <TEntity>(ITikCommand command)
            where TEntity : new()
        {
            var responseSentences = command.ExecuteList();

            return(responseSentences.Select(sentence => CreateObject <TEntity>(sentence)).ToList());
        }
예제 #3
0
        internal static List <MikrotikUserList> GetUserListFromMikrotik(ITikConnection connection, Mikrotik mikrotik)
        {
            List <MikrotikUserList> lstMikrotikUserList = new List <MikrotikUserList>();
            ITikCommand             userCmd             = connection.CreateCommand("/ppp/secret/print");
            var lstUserFromMikrotik = userCmd.ExecuteList();

            foreach (var user in lstUserFromMikrotik)
            {
                var name     = user.Words["name"];
                var password = user.Words["password"];
                var package  = user.Words["profile"];
                var active   = user.Words["disabled"];
                var profile  = user.Words["profile"];
                lstMikrotikUserList.Add(new MikrotikUserList()
                {
                    UserName     = name,
                    Password     = password,
                    MikrotikID   = mikrotik.MikrotikID,
                    MikrotikName = mikrotik.MikName,
                    ProfileName  = profile,
                    active       = active
                });
            }
            return(lstMikrotikUserList);
        }
예제 #4
0
        /// <summary>
        /// Loads entity list from given command.
        /// </summary>
        /// <typeparam name="TEntity">Loaded entities type.</typeparam>
        /// <returns>List (or empty list) of loaded entities.</returns>
        /// <seealso cref="LoadSingle{TEntity}(ITikCommand)"/>
        public static IEnumerable <TEntity> LoadList <TEntity>(this ITikCommand command)
            where TEntity : new()
        {
            Guard.ArgumentNotNull(command, "command");

            var responseSentences = command.ExecuteList();

            return(responseSentences.Select(sentence => CreateObject <TEntity>(sentence)).ToList());
        }
예제 #5
0
        internal static List <MikrotikUserList> GetActiveUserListFromMikrotik(ITikConnection connection, Mikrotik mikrotik)
        {
            List <MikrotikUserList> lstMikrotikUserList = new List <MikrotikUserList>();
            ITikCommand             userCmd             = connection.CreateCommand("/ppp/active/print");
            var lstUserFromMikrotik = userCmd.ExecuteList();

            foreach (var user in lstUserFromMikrotik)
            {
                var name = user.Words["name"];
                lstMikrotikUserList.Add(new MikrotikUserList()
                {
                    UserName = name
                });
            }
            return(lstMikrotikUserList);
        }
예제 #6
0
        internal static IEnumerable <ITikReSentence> GetPackageListFromMikrotik(ITikConnection connection)
        {
            ITikCommand PackageCmd = connection.CreateCommand("/ppp/profile/print");

            return(PackageCmd.ExecuteList());
        }