Пример #1
0
        //public ActionResult GetIndex(int dropDownList = 0, string executeQuery = "")
        //{
        //    var executeItem = new ExecuteItem
        //    {
        //        DropDownList = dropDownList,
        //        ExecuteQuery = executeQuery
        //    };
        //    return View(executeItem);
        //}

        public ActionResult Index()
        {
            if (!SystemActionItem.IsAdmin)
            {
                return(View("Index"));
            }
            var executeItem = new ExecuteItem();

            UpdateModel(executeItem);
            var model = new ExecuteQueryItem {
                ExecuteItem = executeItem, Erros = false
            };

            try
            {
                if (executeItem.DropDownList == 1)
                {
                    model.DataTable = Gets(executeItem.ExecuteQuery);
                    model.Message   = "Câu lệnh đã được thực thi ...";
                }
                if (executeItem.DropDownList == 2)
                {
                    ExecuteQuerys(executeItem.ExecuteQuery);
                    model.DataTable = new DataTable();
                    model.Message   = "Câu lệnh đã được thực thi ...";
                }
            }
            catch (Exception ex)
            {
                model.Message = ex.Message;
                model.Erros   = true;
            }
            return(View(model));
        }
Пример #2
0
        public void Start(ExecuteItem item, string directory)
        {
            var process = new Process();

            if (string.IsNullOrEmpty(directory))
            {
                directory = Path.GetFullPath(item.Program);
            }

            try
            {
                _log.Debug("Executing: " + item.Program);
                _log.Debug("...parameters: " + item.Arguments);
                _log.Debug("...in directory: " + directory);

                process.StartInfo.FileName         = item.Program;
                process.StartInfo.Arguments        = item.Arguments;
                process.StartInfo.WorkingDirectory = directory;
                //process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                //process.StartInfo.CreateNoWindow = true;
                //process.StartInfo.RedirectStandardInput = true;
                //process.StartInfo.RedirectStandardOutput = RedirectAllOutput;
                //process.StartInfo.RedirectStandardError = RedirectErrors;
                //process.StartInfo.UseShellExecute = false;
                process.Start();
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
        }
Пример #3
0
        private static void ExecuteClass(ExecuteItem item, bool isStart, Action <Exception> errorHandler)
        {
            if (isStart && item.Instance != null && item.Instance is IStartup)
            {
                try
                {
                    ((IStartup)item.Instance).Start();
                }
                catch (Exception ex)
                {
                    if (errorHandler != null)
                    {
                        errorHandler(ex);
                    }
                }
            }

            if (item.MethodList != null && item.MethodList.Count > 0)
            {
                foreach (var method in item.MethodList)
                {
                    try
                    {
                        ExecuteMethod(item.ClassType, item.Instance, method.MethodName, method.IsStatic, method.MethodArgs);
                    }
                    catch (Exception ex)
                    {
                        if (errorHandler != null)
                        {
                            errorHandler(ex);
                        }
                    }
                }
            }

            if (!isStart && item.Instance != null && item.Instance is IShutdown)
            {
                try
                {
                    ((IShutdown)item.Instance).Shut();
                }
                catch (Exception ex)
                {
                    if (errorHandler != null)
                    {
                        errorHandler(ex);
                    }
                }
            }
        }
Пример #4
0
        private static List <ExecuteItem> GetModule(bool isStart, Action <Exception> errorHandler)
        {
            if (!File.Exists(s_XmlPath))
            {
                return(new List <ExecuteItem>(0));
            }
            string      xpath = isStart ? @"//autorun/startup" : @"//autorun/shutdown";
            XmlDocument x     = new XmlDocument();

            x.Load(s_XmlPath);
            XmlNode node = x.SelectSingleNode(xpath);

            if (node == null || node.ChildNodes == null || node.ChildNodes.Count <= 0)
            {
                return(new List <ExecuteItem>(0));
            }
            XmlNode[] mList = GetChildrenNodes(node, "module");
            if (mList == null || mList.Length <= 0)
            {
                return(new List <ExecuteItem>(0));
            }
            List <ExecuteItem> rstList = new List <ExecuteItem>(mList.Length * 2);

            foreach (var n in mList)
            {
                try
                {
                    string typeName = GetNodeAttribute(n, "type");
                    if (typeName == null || typeName.Trim().Length <= 0)
                    {
                        continue;
                    }
                    string[]    argments;
                    XmlNodeList args = n.SelectNodes("constructor/arg");
                    if (args == null || args.Count <= 0)
                    {
                        argments = new string[0];
                    }
                    else
                    {
                        argments = new string[args.Count];
                        for (int i = 0; i < args.Count; i++)
                        {
                            string t = args[i].InnerText;
                            argments[i] = t == null ? null : t.Trim();
                        }
                    }
                    Type        type = Type.GetType(typeName, true);
                    ExecuteItem item = new ExecuteItem();
                    rstList.Add(item);
                    item.ClassType = type;
                    if (type.IsAbstract)
                    {
                        item.Instance = null;
                    }
                    else
                    {
                        item.Instance = CreateInstance(type, argments);
                    }
                    XmlNode[] methodNodeList = GetChildrenNodes(n, "method");
                    if (methodNodeList == null || methodNodeList.Length <= 0)
                    {
                        item.MethodList = new List <ExecuteMethodItem>(0);
                    }
                    else
                    {
                        item.MethodList = new List <ExecuteMethodItem>(methodNodeList.Length);
                        foreach (XmlNode mn in methodNodeList)
                        {
                            try
                            {
                                string[]  aa;
                                XmlNode[] argList = GetChildrenNodes(mn, "arg");
                                if (argList == null || argList.Length <= 0)
                                {
                                    aa = new string[0];
                                }
                                else
                                {
                                    aa = new string[argList.Length];
                                    for (int i = 0; i < argList.Length; i++)
                                    {
                                        string t = argList[i].InnerText;
                                        aa[i] = t == null ? null : t.Trim();
                                    }
                                }
                                string mType = GetNodeAttribute(mn, "type");
                                item.MethodList.Add(new ExecuteMethodItem
                                {
                                    MethodName = GetNodeAttribute(mn, "name"),
                                    IsStatic   = (mType != null && mType.ToLower().Trim() == "static"),
                                    MethodArgs = aa
                                });
                            }
                            catch (Exception ex)
                            {
                                if (errorHandler != null)
                                {
                                    errorHandler(ex);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (errorHandler != null)
                    {
                        errorHandler(ex);
                    }
                }
            }
            return(rstList);
        }
Пример #5
0
        public static ExecuteItem Tokenize(string source)
        {
            var res        = new ExecuteItem();
            var whitespace = new[] { ' ', '\t', '\r', '\n' };

            if (source == null)
            {
                return(res);
            }

            var command = new StringBuilder();
            var max     = source.Length - 1;
            var inQuote = false;

            int i;

            for (i = 0; i <= max; i++)
            {
                var last = i == max;
                var c    = source[i];

                if (c == '"')
                {
                    if (!inQuote)
                    {
                        inQuote = true;
                    }
                    else
                    {
                        if (!last && source[i + 1] == '"')
                        {
                            i++;
                        }
                        else
                        {
                            inQuote = false;
                        }
                    }
                }

                else if (!inQuote && ((IList)whitespace).Contains(c))
                {
                    source        = source.SafeSubstring(i + 1);
                    res.Program   = command.ToString();
                    res.Arguments = source;
                    return(res);

                    ;
                }
                else if (!inQuote && ((IList)whitespace).Contains(c))
                {
                    break;
                }

                // Normal character, copy
                command.Append(c);
            }


            res.Program   = command.ToString();
            res.Arguments = source;
            return(res);
        }
Пример #6
0
 private static List<ExecuteItem> GetModule(bool isStart, Action<Exception> errorHandler)
 {
     if (!File.Exists(s_XmlPath))
     {
         return new List<ExecuteItem>(0);
     }
     string xpath = isStart ? @"//autorun/startup" : @"//autorun/shutdown";
     XmlDocument x = new XmlDocument();
     x.Load(s_XmlPath);
     XmlNode node = x.SelectSingleNode(xpath);
     if (node == null || node.ChildNodes == null || node.ChildNodes.Count <= 0)
     {
         return new List<ExecuteItem>(0);
     }
     XmlNode[] mList = GetChildrenNodes(node, "module");
     if (mList == null || mList.Length <= 0)
     {
         return new List<ExecuteItem>(0);
     }
     List<ExecuteItem> rstList = new List<ExecuteItem>(mList.Length * 2);
     foreach (var n in mList)
     {
         try
         {
             string typeName = GetNodeAttribute(n, "type");
             if (typeName == null || typeName.Trim().Length <= 0)
             {
                 continue;
             }
             string[] argments;
             XmlNodeList args = n.SelectNodes("constructor/arg");
             if (args == null || args.Count <= 0)
             {
                 argments = new string[0];
             }
             else
             {
                 argments = new string[args.Count];
                 for (int i = 0; i < args.Count; i++)
                 {
                     string t = args[i].InnerText;
                     argments[i] = t == null ? null : t.Trim();
                 }
             }
             Type type = Type.GetType(typeName, true);
             ExecuteItem item = new ExecuteItem();
             rstList.Add(item);
             item.ClassType = type;
             if (type.IsAbstract)
             {
                 item.Instance = null;
             }
             else
             {
                 item.Instance = CreateInstance(type, argments);
             }
             XmlNode[] methodNodeList = GetChildrenNodes(n, "method");
             if (methodNodeList == null || methodNodeList.Length <= 0)
             {
                 item.MethodList = new List<ExecuteMethodItem>(0);
             }
             else
             {
                 item.MethodList = new List<ExecuteMethodItem>(methodNodeList.Length);
                 foreach (XmlNode mn in methodNodeList)
                 {
                     try
                     {
                         string[] aa;
                         XmlNode[] argList = GetChildrenNodes(mn, "arg");
                         if (argList == null || argList.Length <= 0)
                         {
                             aa = new string[0];
                         }
                         else
                         {
                             aa = new string[argList.Length];
                             for (int i = 0; i < argList.Length; i++)
                             {
                                 string t = argList[i].InnerText;
                                 aa[i] = t == null ? null : t.Trim();
                             }
                         }
                         string mType = GetNodeAttribute(mn, "type");
                         item.MethodList.Add(new ExecuteMethodItem
                         {
                             MethodName = GetNodeAttribute(mn, "name"),
                             IsStatic = (mType != null && mType.ToLower().Trim() == "static"),
                             MethodArgs = aa
                         });
                     }
                     catch (Exception ex)
                     {
                         if (errorHandler != null)
                         {
                             errorHandler(ex);
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             if (errorHandler != null)
             {
                 errorHandler(ex);
             }
         }
     }
     return rstList;
 }
Пример #7
0
        private static void ExecuteClass(ExecuteItem item, bool isStart, Action<Exception> errorHandler)
        {
            if (isStart && item.Instance != null && item.Instance is IStartup)
            {
                try
                {
                    ((IStartup)item.Instance).Start();
                }
                catch (Exception ex)
                {
                    if (errorHandler != null)
                    {
                        errorHandler(ex);
                    }
                }
            }

            if (item.MethodList != null && item.MethodList.Count > 0)
            {
                foreach (var method in item.MethodList)
                {
                    try
                    {
                        ExecuteMethod(item.ClassType, item.Instance, method.MethodName, method.IsStatic, method.MethodArgs);
                    }
                    catch (Exception ex)
                    {
                        if (errorHandler != null)
                        {
                            errorHandler(ex);
                        }
                    }
                }
            }

            if (!isStart && item.Instance != null && item.Instance is IShutdown)
            {
                try
                {
                    ((IShutdown)item.Instance).Shut();
                }
                catch (Exception ex)
                {
                    if (errorHandler != null)
                    {
                        errorHandler(ex);
                    }
                }
            }
        }