示例#1
0
        public static void Main(params string[] args)
        {
            Console.WriteLine();
            Arguments inputArgs = new Arguments(args);

            if (!String.IsNullOrEmpty(inputArgs["map"]))
            {
                MapLoader loader = new MapLoader(inputArgs["map"]);

                if (loader.MapIsValid)
                {
                    MapArguments mapArgs = new MapArguments(inputArgs, loader);

                    if (mapArgs.ArgumentsAreValid)
                    {
                        DateTime start = DateTime.Now;
                        Packer = new Packer(loader, mapArgs);
                        Packer.Pack(Console.Out, Console.Error);
                        Console.WriteLine(TIME, DateTime.Now.Subtract(start).TotalSeconds, DateTime.Now);

                        if (!String.IsNullOrEmpty(inputArgs["watch"]) && Convert.ToBoolean(inputArgs["watch"]))
                        {
                            Console.WriteLine(WATCHING);
                            LastChange = DateTime.Now;

                            FileSystemWatcher watcher = new FileSystemWatcher(mapArgs.SourcePath);
                            watcher.IncludeSubdirectories = true;
                            watcher.Changed            += new FileSystemEventHandler(watcher_Changed);
                            watcher.EnableRaisingEvents = true;

                            while (true)
                            {
                                Console.ReadKey();
                            }
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine(mapArgs.ArgumentsInvalidReason);
                    }
                }
                else
                {
                    Console.Error.WriteLine(loader.MapIsInvalidReason);
                }
            }
            else
            {
                Console.Error.WriteLine(USAGE);
            }
        }
示例#2
0
        public static void Main(params string[] args)
        {
            Console.WriteLine();
            Arguments inputArgs = new Arguments(args);

            if (!String.IsNullOrEmpty(inputArgs["map"]))
            {
                MapLoader loader = new MapLoader(inputArgs["map"]);

                if (loader.MapIsValid)
                {
                    MapArguments mapArgs = new MapArguments(inputArgs, loader);

                    if (mapArgs.ArgumentsAreValid)
                    {
                        DateTime start = DateTime.Now;
                        Packer = new Packer(loader, mapArgs);
                        Packer.Pack(Console.Out, Console.Error);
                        Console.WriteLine(TIME, DateTime.Now.Subtract(start).TotalSeconds, DateTime.Now);

                        if (!String.IsNullOrEmpty(inputArgs["watch"]) && Convert.ToBoolean(inputArgs["watch"]))
                        {
                            Console.WriteLine(WATCHING);
                            LastChange = DateTime.Now;

                            FileSystemWatcher watcher = new FileSystemWatcher(mapArgs.SourcePath);
                            watcher.IncludeSubdirectories = true;
                            watcher.Changed += new FileSystemEventHandler(watcher_Changed);
                            watcher.EnableRaisingEvents = true;

                            while (true)
                            {
                                Console.ReadKey();
                            }
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine(mapArgs.ArgumentsInvalidReason);
                    }
                }
                else
                {
                    Console.Error.WriteLine(loader.MapIsInvalidReason);
                }
            }
            else
            {
                Console.Error.WriteLine(USAGE);
            }
        }
示例#3
0
        /// <summary>
        /// Resolves the output actions for the given output.
        /// </summary>
        /// <param name="loader">The loader containing the map file definition.</param>
        /// <param name="output">The output to resolve actions for.</param>
        /// <returns>An output's actions collection.</returns>
        private static IEnumerable <OutputAction> ResolveOutputActions(MapLoader loader, XmlElement output)
        {
            Dictionary <string, OutputAction> actions = new Dictionary <string, OutputAction>();

            foreach (XmlElement element in loader.Map.SelectNodes("jspack/outputAction[@global='true']"))
            {
                string name = element.Attributes["name"].Value;
                actions[name] = new OutputAction(name, element.Attributes["executable"].Value, element.Attributes["arguments"].Value);
            }

            foreach (XmlElement element in output.SelectNodes("action"))
            {
                string name = element.Attributes["name"].Value;
                string args = element.Attributes["arguments"].Value;

                if (actions.ContainsKey(name))
                {
                    if (!String.IsNullOrEmpty(args))
                    {
                        actions[name].Arguments = args;
                    }
                }
                else
                {
                    XmlElement action = loader.Map.SelectSingleNode("jspack/outputAction[@name='" + name + "']") as XmlElement;

                    if (action != null)
                    {
                        if (String.IsNullOrEmpty(args))
                        {
                            args = action.Attributes["arguments"].Value;
                        }

                        actions[name] = new OutputAction(name, action.Attributes["executable"].Value, args);
                    }
                }
            }

            return((from kvp in actions
                    select kvp.Value).ToArray());
        }
示例#4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="loader">The loader containing the map file to pack.</param>
 /// <param name="arguments">The arguments defining the packing behavior.</param>
 public Packer(MapLoader loader, MapArguments arguments)
 {
     Loader    = loader;
     Arguments = arguments;
 }
示例#5
0
        /// <summary>
        /// Resolves the output actions for the given output.
        /// </summary>
        /// <param name="loader">The loader containing the map file definition.</param>
        /// <param name="output">The output to resolve actions for.</param>
        /// <returns>An output's actions collection.</returns>
        private static IEnumerable<OutputAction> ResolveOutputActions(MapLoader loader, XmlElement output)
        {
            Dictionary<string, OutputAction> actions = new Dictionary<string, OutputAction>();

            foreach (XmlElement element in loader.Map.SelectNodes("jspack/outputAction[@global='true']"))
            {
                string name = element.Attributes["name"].Value;
                actions[name] = new OutputAction(name, element.Attributes["executable"].Value, element.Attributes["arguments"].Value);
            }

            foreach (XmlElement element in output.SelectNodes("action"))
            {
                string name = element.Attributes["name"].Value;
                string args = element.Attributes["arguments"].Value;

                if (actions.ContainsKey(name))
                {
                    if (!String.IsNullOrEmpty(args))
                    {
                        actions[name].Arguments = args;
                    }
                }
                else
                {
                    XmlElement action = loader.Map.SelectSingleNode("jspack/outputAction[@name='" + name + "']") as XmlElement;

                    if (action != null)
                    {
                        if (String.IsNullOrEmpty(args))
                        {
                            args = action.Attributes["arguments"].Value;
                        }

                        actions[name] = new OutputAction(name, action.Attributes["executable"].Value, args);
                    }
                }
            }

            return (from kvp in actions
                    select kvp.Value).ToArray();
        }
示例#6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="loader">The loader containing the map file to pack.</param>
 /// <param name="arguments">The arguments defining the packing behavior.</param>
 public Packer(MapLoader loader, MapArguments arguments)
 {
     Loader = loader;
     Arguments = arguments;
 }
示例#7
0
        /// <summary>
        /// Parses a map and arguments set.
        /// </summary>
        /// <param name="args">The command line arguments to use while parsing.</param>
        /// <param name="loader">The loader containing the map to use while parsing.</param>
        private void ParseMap(Arguments args, MapLoader loader)
        {
            ArgumentsAreValid      = true;
            ArgumentsInvalidReason = "The script map arguments are invalid.\n";

            string mapDir = Path.GetDirectoryName(loader.Path);

            SourcePath = args["src"] ?? String.Empty;

            if (String.IsNullOrEmpty(SourcePath) && loader.Map.DocumentElement.Attributes["src"] != null)
            {
                SourcePath = loader.Map.DocumentElement.Attributes["src"].Value;
            }

            if (String.IsNullOrEmpty(SourcePath))
            {
                SourcePath = @".\";
            }

            if (!Path.IsPathRooted(SourcePath))
            {
                SourcePath = Path.GetFullPath(Path.Combine(mapDir, SourcePath));
            }

            TargetPath = args["target"] ?? String.Empty;

            if (String.IsNullOrEmpty(TargetPath) && loader.Map.DocumentElement.Attributes["target"] != null)
            {
                TargetPath = loader.Map.DocumentElement.Attributes["target"].Value;
            }

            if (String.IsNullOrEmpty(TargetPath))
            {
                TargetPath = @".\";
            }

            if (!Path.IsPathRooted(TargetPath))
            {
                TargetPath = Path.GetFullPath(Path.Combine(mapDir, TargetPath));
            }

            Version = args["version"] ?? String.Empty;

            if (String.IsNullOrEmpty(Version))
            {
                Version = loader.Map.DocumentElement.Attributes["version"].Value;
            }

            string actions = args["actions"] ?? String.Empty;

            if (String.IsNullOrEmpty(actions))
            {
                actions = loader.Map.DocumentElement.Attributes["actions"].Value;
            }

            OutputActions = true;

            try
            {
                OutputActions = Convert.ToBoolean(actions);
            }
            catch
            {
                ArgumentsInvalidReason += "Output actions must be either \"true\" or \"false\".\n";
                ArgumentsAreValid       = false;
            }
        }
示例#8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="args">Command line arguments to use when parsing the arguments.</param>
 /// <param name="loader">The loader containing the map to use when parsing the arguments.</param>
 public MapArguments(Arguments args, MapLoader loader)
 {
     ParseMap(args, loader);
 }