private static void ValidDirectory()
        {
            Console.Write("> Your current directory is ");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write("valid ");
            Console.ResetColor();
            Console.WriteLine("for generating code.");

            if (!ValidPaths.ContainsKey(Program.CurrentDirectory))
            {
                ValidPaths.Add(Program.CurrentDirectory, true);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     This is the main method to call to resolve all dependencies. This MUST be the first method called, which is
        ///     automatically called by the V8Engine's static constructor. You can also call this directly in a "main" or "startup"
        ///     file before touching any V8.Net type.
        /// </summary>
        public static void ResolveDependencies()
        {
            _CheckLocalPathUpdated();

            // ... force load the required assemblies now (this is assuming the method is called from the calling type's static constructor or main startup) ...

            //if (!IsLoaded("V8.Net.SharedTypes"))
            //    Assembly.Load("V8.Net.SharedTypes");

            //if (Environment.Is64BitProcess)
            //{
            //    if (!IsLoaded("V8.Net.Proxy.Interface.x64"))
            //        Assembly.Load("V8.Net.Proxy.Interface.x64");
            //}
            //else
            //{
            //    if (!IsLoaded("V8.Net.Proxy.Interface.x86"))
            //        Assembly.Load("V8.Net.Proxy.Interface.x86");
            //}

            //if (!IsLoaded("V8.Net"))
            //    Assembly.Load("V8.Net");

            var paths = ValidPaths.ToArray();

            foreach (var path in paths)
                if (TryLoad(path))
                    return;

            var bitStr = Environment.Is64BitProcess ? "x64" : "x86";
            var msg = $"Could not locate the required V8 native libraries.  V8.NET is running in the '" + bitStr + "' mode.  Some areas to check: " + Environment.NewLine
                + "1. Did you download the DLLs from a ZIP file? If so you may have to unblock the file. On Windows, you must open the file properties of the zip file and 'Unblock' it BEFORE extracting the files." + Environment.NewLine
                + "2. Review the searched paths in the nested errors below and make sure the desired path is accessible to the application ";

            if (!string.IsNullOrWhiteSpace(_WebHostPath))
                msg += "pool identity (usually Read & Execute for 'IIS_IUSRS', or a similar user/group)" + Environment.NewLine;
            else
                msg += "for loading the required libraries under the current program's security context." + Environment.NewLine;

            msg += " Paths searched: " + Environment.NewLine + " * " + string.Join(Environment.NewLine + " * ", paths);

            System.Diagnostics.Debug.WriteLine(msg, "WARNING");

            if (Environment.UserInteractive)
                Console.WriteLine(msg);

            if (System.Diagnostics.Debugger.IsAttached)
                throw new DllNotFoundException(msg + Environment.NewLine + "This exception is thrown as a notice since a debugger is attached. You can always use a try..catch block to ignore it.");
        }
        public static void NotValidDirectory()
        {
            Console.Write("> Your current directory is ");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write("not valid ");
            Console.ResetColor();
            Console.WriteLine("for generating code.");

            if (!ValidPaths.ContainsKey(Program.CurrentDirectory))
            {
                ValidPaths.Add(Program.CurrentDirectory, false);
            }

            Program.EmptyLine();
        }
Ejemplo n.º 4
0
        static void _CheckLocalPathUpdated()
        {
            if (!_LocalPathEnvUpdated)
            {
                try
                {
                    // ... add the search location to the path so "Assembly.LoadFrom()" can find other dependant assemblies if needed ...
                    // ... attempt to update environment variable automatically for the native DLLs ...
                    // (see: http://stackoverflow.com/questions/7996263/how-do-i-get-iis-to-load-a-native-dll-referenced-by-my-wcf-service
                    //   and http://stackoverflow.com/questions/344608/unmanaged-dlls-fail-to-load-on-asp-net-server)

                    var path     = System.Environment.GetEnvironmentVariable("PATH"); // TODO: Detect other systems if necessary.
                    var newPaths = string.Join(";", ValidPaths.ToArray()) + ";";
                    System.Environment.SetEnvironmentVariable("PATH", newPaths + path);
                    _LocalPathEnvUpdated = true;
                }
                catch { }
            }
        }
        public static void CheckIfDirectoryIsValid()
        {
            if (ValidPaths.ContainsKey(Program.CurrentDirectory))
            {
                var valid = ValidPaths.First(m => m.Key.Equals(Program.CurrentDirectory)).Value;

                if (valid)
                {
                    ValidDirectory();
                    return;
                }

                NotValidDirectory();
                return;
            }

            var solutions = Directory.GetFiles(Program.CurrentDirectory, "*.sln");

            if (!solutions.Any())
            {
                NotValidDirectory();
                return;
            }

            var directories = Directory.GetDirectories(Program.CurrentDirectory);

            if (!directories.Any(directory => directory.Contains(".DAL", StringComparison.InvariantCultureIgnoreCase)) ||
                !directories.Any(directory => directory.Contains(".Providers", StringComparison.InvariantCultureIgnoreCase)) ||
                !directories.Any(directory => directory.Contains(".Services", StringComparison.InvariantCultureIgnoreCase)))
            {
                NotValidDirectory();
                return;
            }

            var directoryDAL       = directories.First(directory => directory.Contains(".DAL", StringComparison.InvariantCultureIgnoreCase));
            var directoryProviders = directories.First(directory => directory.Contains(".Providers", StringComparison.InvariantCultureIgnoreCase));
            var directoryServices  = directories.First(directory => directory.Contains(".Services", StringComparison.InvariantCultureIgnoreCase));

            ValidProjectDirectory(directoryDAL);
            ValidProjectDirectory(directoryProviders);
            ValidProjectDirectory(directoryServices);
            ValidDirectory();
        }
Ejemplo n.º 6
0
        private void FindValidPaths(int i, int j, IList <int> currentPath)
        {
            currentPath.Add(_data[i][j]);

            // if bottom is reached, add currentPath to ValidPaths
            if (currentPath.Count == _data.Length)
            {
                ValidPaths.Add(currentPath);
            }

            // save currentPath length in order to know how many items to copy to possible alternative path
            var currentPathLength    = currentPath.Count;
            var needsAlternativePath = false;

            var nextValidItemsQueue = GetNextValidItems(i, j);

            while (nextValidItemsQueue.TryDequeue(out (int i, int j)item))
            {
                FindValidPaths(item.i, item.j, needsAlternativePath ? currentPath.Take(currentPathLength).ToList() : currentPath);
                needsAlternativePath = true;
            }
        }
        public static void Actions(List <string> actions)
        {
            if (actions.Count <= 1)
            {
                Help();
                return;
            }

            var action = actions[1];

            switch (action.ToLower())
            {
            case "help":
                Help();
                return;

            case "providers":
                ProviderGenerator.GenerateProviders();
                Program.EmptyLine();
                return;

            case "services":
                ServiceGenerator.GenerateServices();
                Program.EmptyLine();
                return;

            case "valid":
                CheckIfDirectoryIsValid();
                Program.EmptyLine();
                return;

            case "viewmodel":
                var model = string.Empty;

                SetModules();

                if (actions.Count < 3)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    var modelname = Models.Any() ? Models.First().Value : "Model1";
                    Console.WriteLine($"You forget to give a model (example: generate viewmodel {modelname})");
                    Console.ResetColor();
                    Program.EmptyLine();
                    return;
                }

                if (Models.Any(m => m.Value.Equals(
                                   actions[2].Trim(),
                                   StringComparison.InvariantCultureIgnoreCase)))
                {
                    model = Models.First(m => m.Value.Equals(
                                             actions[2].Trim(),
                                             StringComparison.InvariantCultureIgnoreCase)).Value;

                    Console.WriteLine($"Model {model} geselecteerd");

                    Program.EmptyLine();
                    return;
                }

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("We could not found your specified model");
                Console.ResetColor();

                Program.EmptyLine();
                return;

            case "models":
                CheckIfDirectoryIsValid();

                if (!ValidPaths.ContainsKey(Program.CurrentDirectory) ||
                    !ValidPaths.First(x => x.Key.Equals(Program.CurrentDirectory, StringComparison.InvariantCultureIgnoreCase)).Value)
                {
                    Program.EmptyLine();
                    return;
                }

                SetModules();
                PrintModules();
                Program.EmptyLine();
                return;

            default:
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("> The module 'generate' does not recognize your specified command, use 'generate help' to find your command.");
                Console.ResetColor();
                Program.EmptyLine();
                return;
            }
        }