Exemplo n.º 1
0
 public FindSolutionCmd(ILogger logger, string folderPath, CancellationToken token,
                        string searchFilter = null, SearchOption?searchOption = null) : base("FindVsSolution", logger, token)
 {
     _folderPath   = folderPath;
     _searchFilter = searchFilter;
     _searchOption = searchOption;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Create UserGame object from path.
        /// </summary>
        /// <param name="fileName">File name to check.</param>
        /// <param name="searchOption">If not specified then check specified file only.</param>
        /// <returns></returns>
        public UserGame FromDisk(string fileName, SearchOption?searchOption = null)
        {
            var        item         = new UserGame();
            var        fi           = new FileInfo(fileName);
            var        vi           = System.Diagnostics.FileVersionInfo.GetVersionInfo(fi.FullName);
            var        architecture = JocysCom.ClassLibrary.Win32.PEReader.GetProcessorArchitecture(fi.FullName);
            var        is64bit      = architecture == System.Reflection.ProcessorArchitecture.Amd64;
            XInputMask mask         = Engine.XInputMask.None;

            if (searchOption.HasValue)
            {
                // Get XInput files used inside game folder.
                var list = GetMasks(fi.DirectoryName, searchOption.Value, is64bit);
                // Combine masks.
                foreach (var value in list.Values)
                {
                    mask |= value;
                }
                // var mask = GetMask(fi.FullName);
                if (mask == Engine.XInputMask.None)
                {
                    mask   = (is64bit)
                    ? mask = Engine.XInputMask.XInput13_x64
                    : mask = Engine.XInputMask.XInput13_x86;
                }
            }
            else
            {
                mask = GetMask(fileName);
            }
            item.Timeout               = -1;
            item.Comment               = vi.Comments ?? "";
            item.DateCreated           = DateTime.Now;
            item.DateUpdated           = item.DateCreated;
            item.FileName              = fi.Name ?? "";
            item.FileProductName       = EngineHelper.FixName(vi.ProductName, item.FileName);
            item.FileVersion           = vi.FileVersion ?? "";
            item.CompanyName           = vi.CompanyName ?? "";
            item.ComputerId            = BoardInfo.GetHashedDiskId(BoardInfo.GetDiskId());
            item.FileVersion           = new Version(vi.FileMajorPart, vi.FileMinorPart, vi.FileBuildPart, vi.FilePrivatePart).ToString();
            item.FullPath              = fi.FullName ?? "";
            item.GameId                = Guid.NewGuid();
            item.HookMask              = 0;
            item.XInputMask            = (int)mask;
            item.XInputPath            = "";
            item.DInputMask            = 0;
            item.DInputFile            = "";
            item.FakeVID               = 0;
            item.FakePID               = 0;
            item.Timeout               = -1;
            item.Weight                = 1;
            item.IsEnabled             = true;
            item.ProcessorArchitecture = (int)architecture;
            return(item);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Enumerate all of the MSBuild solution files in a given folder.
        /// </summary>
        /// <param name="folderPath">The top level path to search.</param>
        /// <param name="searchFilter">Optional. A wildcard filter in the form of "*.sln".</param>
        /// <param name="searchOption">Optional. Specifies whether to recurse sub-directories or not.</param>
        /// <returns>If any solutions are found, will return an enumerable list of them in order in which they are discovered.</returns>
        public static IEnumerable <string> GetSolutions(string folderPath, string searchFilter = null,
                                                        SearchOption?searchOption = null)
        {
            if (string.IsNullOrEmpty(searchFilter))
            {
                return(Directory.EnumerateFileSystemEntries(folderPath, DefaultSolutionFilter,
                                                            searchOption ?? SearchOption.AllDirectories));
            }

            return(Directory.EnumerateFileSystemEntries(folderPath, searchFilter,
                                                        searchOption ?? SearchOption.AllDirectories));
        }
        public FileSystemService(string targetFolder, string[]?searchPattern, SearchOption?options, EnumerationOptions?enumerationOptions)
        {
            if (targetFolder.Equals(string.Empty) || targetFolder.Count() < 2)
            {
                throw new ArgumentException("The filesystem path provided is in an invalid state!");
            }
            TargetPath = targetFolder;

            DirInfo = new DirectoryInfo(TargetPath);

            //check the state of the array of search patterns to know what to do.
            if (searchPattern is null)
            {
                SearchPattern = new string[] { "*.mp4", "*.mkv", "*.flv", "*.avi", "*.mpg" };
            }
            else
            {
                SearchPattern = searchPattern;
            }

            //check the state of SearchOptions
            if (options is null)
            {
                this.SearchOption = System.IO.SearchOption.TopDirectoryOnly;
            }
            this.SearchOption = options;

            if (enumerationOptions is null)
            {
                this.EnumerationOptions = new System.IO.EnumerationOptions {
                    MatchCasing = MatchCasing.CaseInsensitive, RecurseSubdirectories = true
                };
            }
            else
            {
                this.EnumerationOptions = enumerationOptions;
            }
        }
Exemplo n.º 5
0
 public ADObjectSearcher(ADSessionInfo sessionInfo, ADObject obj)
 {
     this._searchScope              = ADSearchScope.Subtree;
     this._filter                   = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*");
     this._propertyList             = new List <string>(ADObject.DefaultProperties);
     this._timeLimit                = TimeSpan.Zero;
     this._schemaTranslationEnabled = true;
     this._pageSize                 = 0x100;
     this._searchOption             = null;
     this._autoRangeRetrieve        = true;
     this._sdFlags                  = SecurityMasks.Owner | SecurityMasks.Group | SecurityMasks.Dacl;
     if (sessionInfo == null)
     {
         if (obj == null)
         {
             this._adSession = ADSession.ConstructSession(null);
         }
         else
         {
             this._adSession = ADSession.ConstructSession(obj.SessionInfo);
         }
     }
     else
     {
         this._adSession = ADSession.ConstructSession(sessionInfo);
     }
     if (obj != null)
     {
         this._adObject   = obj;
         this._searchRoot = this._adObject.DistinguishedName;
         foreach (string propertyName in this._adObject.PropertyNames)
         {
             this._propertyList.Add(propertyName);
         }
     }
 }
Exemplo n.º 6
0
        static int Main(string[] args)
        {
            try
            {
                string        outPath     = null;                // -o{FILE}, --descriptor_set_out={FILE}
                bool          version     = false;               // --version
                bool          help        = false;               // -h, --help
                var           importPaths = new List <string>(); // -I{PATH}, --proto_path={PATH}
                var           inputFiles  = new List <string>(); // {PROTO_FILES} (everything not `-`)
                bool          exec        = false;
                string        package     = null;                // --package=foo
                CodeGenerator codegen     = null;

                Dictionary <string, string> options = null;
                foreach (string arg in args)
                {
                    string lhs = arg, rhs = "";
                    int    index = arg.IndexOf('=');
                    if (index > 0)
                    {
                        lhs = arg.Substring(0, index);
                        rhs = arg.Substring(index + 1);
                    }
                    else if (arg.StartsWith("-o"))
                    {
                        lhs = "--descriptor_set_out";
                        rhs = arg.Substring(2);
                    }
                    else if (arg.StartsWith("-I"))
                    {
                        lhs = "--proto_path";
                        rhs = arg.Substring(2);
                    }


                    if (lhs.StartsWith("+"))
                    {
                        if (options == null)
                        {
                            options = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                        }
                        options[lhs.Substring(1)] = rhs;
                        continue;
                    }

                    switch (lhs)
                    {
                    case "":
                        break;

                    case "--version":
                        version = true;
                        break;

                    case "--package":
                        package = rhs;
                        break;

                    case "-h":
                    case "--help":
                        help = true;
                        break;

                    case "--csharp_out":
                        outPath = rhs;
                        codegen = CSharpCodeGenerator.Default;
                        exec    = true;
                        break;

                    case "--vb_out":
                        outPath = rhs;
#pragma warning disable CS0618
                        codegen = VBCodeGenerator.Default;
#pragma warning restore CS0618
                        exec = true;
                        break;

                    case "--descriptor_set_out":
                        outPath = rhs;
                        codegen = null;
                        exec    = true;
                        break;

                    case "--proto_path":
                        importPaths.Add(rhs);
                        break;

                    default:
                        if (lhs.StartsWith("-") || !string.IsNullOrWhiteSpace(rhs))
                        {
                            help = true;
                            break;
                        }
                        else
                        {
                            inputFiles.Add(lhs);
                        }
                        break;
                    }
                }

                if (help)
                {
                    ShowHelp();
                    return(0);
                }
                else if (version)
                {
                    Console.WriteLine($"protogen {GetVersion<Program>()}");
                    Console.WriteLine($"protobuf-net {GetVersion<ProtoReader>()}");
                    Console.WriteLine($"protobuf-net.Reflection {GetVersion<FileDescriptorSet>()}");
                    return(0);
                }
                else if (inputFiles.Count == 0)
                {
                    Console.Error.WriteLine("Missing input file.");
                    return(-1);
                }
                else if (!exec)
                {
                    Console.Error.WriteLine("Missing output directives.");
                    return(-1);
                }
                else
                {
                    int exitCode = 0;
                    var set      = new FileDescriptorSet
                    {
                        DefaultPackage = package
                    };
                    if (importPaths.Count == 0)
                    {
                        set.AddImportPath(Directory.GetCurrentDirectory());
                    }
                    else
                    {
                        foreach (var dir in importPaths)
                        {
                            if (Directory.Exists(dir))
                            {
                                set.AddImportPath(dir);
                            }
                            else
                            {
                                Console.Error.WriteLine($"Directory not found: {dir}");
                                exitCode = 1;
                            }
                        }
                    }

                    if (inputFiles.Count == 1 && importPaths.Count == 1)
                    {
                        SearchOption?searchOption = null;
                        if (inputFiles[0] == "**/*.proto" ||
                            inputFiles[0] == "**\\*.proto")
                        {
                            searchOption            = SearchOption.AllDirectories;
                            set.AllowNameOnlyImport = true;
                        }
                        else if (inputFiles[0] == "*.proto")
                        {
                            searchOption = SearchOption.TopDirectoryOnly;
                        }

                        if (searchOption != null)
                        {
                            inputFiles.Clear();
                            var searchRoot = importPaths[0];
                            foreach (var path in Directory.EnumerateFiles(importPaths[0], "*.proto", searchOption.Value))
                            {
                                inputFiles.Add(MakeRelativePath(searchRoot, path));
                            }
                        }
                    }

                    foreach (var input in inputFiles)
                    {
                        if (!set.Add(input, true))
                        {
                            Console.Error.WriteLine($"File not found: {input}");
                            exitCode = 1;
                        }
                    }

                    if (exitCode != 0)
                    {
                        return(exitCode);
                    }
                    set.Process();
                    var errors = set.GetErrors();
                    foreach (var err in errors)
                    {
                        if (err.IsError)
                        {
                            exitCode++;
                        }
                        Console.Error.WriteLine(err.ToString());
                    }
                    if (exitCode != 0)
                    {
                        return(exitCode);
                    }

                    if (codegen == null)
                    {
                        using (var fds = File.Create(outPath))
                        {
                            Serializer.Serialize(fds, set);
                        }
                    }


                    var files = codegen.Generate(set, options: options);
                    foreach (var file in files)
                    {
                        var path = Path.Combine(outPath, file.Name);

                        var dir = Path.GetDirectoryName(path);
                        if (!Directory.Exists(dir))
                        {
                            Console.Error.WriteLine($"Output directory does not exist, creating... {dir}");
                            Directory.CreateDirectory(dir);
                        }

                        File.WriteAllText(path, file.Text);
                        Console.WriteLine($"generated: {path}");
                    }

                    return(0);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
                return(-1);
            }
        }
Exemplo n.º 7
0
 internal static void RenameDirectories(string path, Func <string, string> rename, string?pattern = null, SearchOption?searchOption = null, Func <string, bool>?predicate = null, Action <string>?log = null)
 {
     log ??= TraceLog;
     Directory.GetDirectories(path, pattern ?? PathHelper.AllSearchPattern, searchOption ?? SearchOption.AllDirectories)
     .Where(directory => predicate?.Invoke(directory) ?? true)
     .ForEach(directory =>
     {
         string newDirectory = rename(directory);
         if (!string.Equals(directory, newDirectory))
         {
             log(directory);
             Directory.Move(directory, newDirectory);
             log(newDirectory);
         }
     });
 }
Exemplo n.º 8
0
 internal static void RenameFiles(string path, Func <string, int, string> rename, string?pattern = null, SearchOption?searchOption = null, Func <string, bool>?predicate = null, bool overwrite = false, bool isDryRun = false, Action <string>?log = null)
 {
     log ??= TraceLog;
     Directory.EnumerateFiles(path, pattern ?? PathHelper.AllSearchPattern, searchOption ?? SearchOption.AllDirectories)
     .Where(file => predicate?.Invoke(file) ?? true)
     .OrderBy(file => file)
     .ToArray()
     .ForEach((file, index) =>
     {
         string newFile = rename(file, index);
         if (!string.Equals(file, newFile))
         {
             log(file);
             if (!isDryRun)
             {
                 FileHelper.Move(file, newFile, overwrite);
             }
             log(newFile);
         }
     });
 }
Exemplo n.º 9
0
        private static async Task <int> Main(string[] args)
        {
            try
            {
                string        outPath = null;                    // -o{FILE}, --descriptor_set_out={FILE}
                bool          version = false;                   // --version
                bool          help = false;                      // -h, --help
                var           importPaths = new List <string>(); // -I{PATH}, --proto_path={PATH}
                var           inputFiles = new List <string>();  // {PROTO_FILES} (everything not `-`)
                bool          exec = false;
                string        package = null;                    // --package=foo
                string        grpcMode = null, grpcUrl = null, grpcService = null;
                CodeGenerator codegen = null;

                Dictionary <string, string> options = null;
                for (int i = 0; i < args.Length; i++)
                {
                    var    arg = args[i];
                    string lhs = arg, rhs = "";
                    int    index = arg.IndexOf('=');
                    if (index > 0)
                    {
                        lhs = arg.Substring(0, index);
                        rhs = arg.Substring(index + 1);
                    }
                    else if (arg.StartsWith("-o"))
                    {
                        lhs = "--descriptor_set_out";
                        rhs = arg.Substring(2);
                    }
                    else if (arg.StartsWith("-I"))
                    {
                        lhs = "--proto_path";
                        rhs = arg.Substring(2);
                    }

                    if (lhs.StartsWith("+"))
                    {
                        if (options == null)
                        {
                            options = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                        }
                        options[lhs.Substring(1)] = rhs;
                        continue;
                    }

                    switch (lhs)
                    {
                    case "":
                        break;

                    case "--version":
                        version = true;
                        break;

                    case "--package":
                        package = rhs;
                        break;

                    case "-h":
                    case "--help":
                        help = true;
                        break;

                    case "--csharp_out":
                        outPath = rhs;
                        codegen = CSharpCodeGenerator.Default;
                        exec    = true;
                        break;

                    case "--vb_out":
                        outPath = rhs;
#pragma warning disable CS0618
                        codegen = VBCodeGenerator.Default;
#pragma warning restore CS0618
                        exec = true;
                        break;

                    case "--descriptor_set_out":
                        outPath = rhs;
                        codegen = null;
                        exec    = true;
                        break;

                    case "--proto_path":
                        importPaths.Add(rhs);
                        break;

                    case "--pwd":
                        Console.WriteLine($"Current Directory: {Directory.GetCurrentDirectory()}");
#if NETCOREAPP2_1 || NETSTANDARD2_0
                        Console.WriteLine($"Program: {typeof(Program).Assembly.Location}");
                        Console.WriteLine($"CodeGenerator: {typeof(CodeGenerator).Assembly.Location}");
#endif
                        break;

                    case "--grpc":
                        if (++i < args.Length)
                        {
                            grpcMode = args[i];
                            if (++i < args.Length)
                            {
                                grpcUrl = args[i];

                                if (string.Equals(grpcMode, "get", StringComparison.OrdinalIgnoreCase) && ++i < args.Length)
                                {
                                    grpcService = args[i];
                                }
                            }
                        }
                        break;

                    default:
                        if (lhs.StartsWith("-") || !string.IsNullOrWhiteSpace(rhs))
                        {
                            help = true;
                            break;
                        }
                        else
                        {
                            inputFiles.Add(lhs);
                        }
                        break;
                    }
                }

                if (help)
                {
                    ShowHelp();
                    return(0);
                }
                else if (version)
                {
                    var ver = GetVersion(typeof(Program));
                    Console.WriteLine($"protogen {ver}");
                    var tmp = GetVersion <ProtoReader>();
                    if (tmp != ver)
                    {
                        Console.WriteLine($"protobuf-net {tmp}");
                    }
                    tmp = GetVersion <FileDescriptorSet>();
                    if (tmp != ver)
                    {
                        Console.WriteLine($"protobuf-net.Reflection {tmp}");
                    }
                    return(0);
                }
                else if (grpcMode is object)
                {
#if GRPC_TOOLS
                    return(await GrpcTools.ExecuteAsync(grpcMode, grpcUrl, grpcService, codegen, outPath, options));
#else
                    Console.Error.Write("gRPC tools are not available on this platform");
                    await Task.Yield(); // this is just to make the compiler happy, and doesn't really matter

                    return(1);
#endif
                }
                else if (inputFiles.Count == 0)
                {
                    Console.Error.WriteLine("Missing input file.");
                    return(-1);
                }
                else if (!exec)
                {
                    Console.Error.WriteLine("Missing output directives.");
                    return(-1);
                }
                else
                {
                    int exitCode = 0;
                    var set      = new FileDescriptorSet
                    {
                        DefaultPackage = package
                    };
                    if (importPaths.Count == 0)
                    {
                        set.AddImportPath(Directory.GetCurrentDirectory());
                    }
                    else
                    {
                        foreach (var dir in importPaths)
                        {
                            if (Directory.Exists(dir))
                            {
                                set.AddImportPath(dir);
                            }
                            else
                            {
                                Console.Error.WriteLine($"Directory not found: {dir}");
                                exitCode = 1;
                            }
                        }
                    }

                    // add the library area for auto-imports (library inbuilts)
                    set.AddImportPath(Path.GetDirectoryName(typeof(Program).Assembly.Location));

                    if (inputFiles.Count == 1 && importPaths.Count == 1)
                    {
                        SearchOption?searchOption = null;
                        if (inputFiles[0] == "**/*.proto" ||
                            inputFiles[0] == "**\\*.proto")
                        {
                            searchOption            = SearchOption.AllDirectories;
                            set.AllowNameOnlyImport = true;
                        }
                        else if (inputFiles[0] == "*.proto")
                        {
                            searchOption = SearchOption.TopDirectoryOnly;
                        }

                        if (searchOption != null)
                        {
                            inputFiles.Clear();
                            var searchRoot = importPaths[0];
                            foreach (var path in Directory.EnumerateFiles(importPaths[0], "*.proto", searchOption.Value))
                            {
                                inputFiles.Add(MakeRelativePath(searchRoot, path));
                            }
                        }
                    }

                    foreach (var input in inputFiles)
                    {
                        if (!set.Add(input, true))
                        {
                            Console.Error.WriteLine($"File not found: {input}");
                            exitCode = 1;
                        }
                    }

                    if (exitCode != 0)
                    {
                        return(exitCode);
                    }
                    set.Process();
                    var errors = set.GetErrors();
                    foreach (var err in errors)
                    {
                        if (err.IsError)
                        {
                            exitCode++;
                        }
                        Console.Error.WriteLine(err.ToString());
                    }
                    if (exitCode != 0)
                    {
                        return(exitCode);
                    }

                    if (codegen == null)
                    {
                        using (var fds = File.Create(outPath))
                        {
                            Serializer.Serialize(fds, set);
                        }

                        return(0);
                    }

                    var files = codegen.Generate(set, options: options);
                    WriteFiles(files, outPath);

                    return(0);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
                return(-1);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Get files related to the following format:
        ///
        /// path query (-r | -d) [ (-inPath | -exPath | -inName | -exName) limiter ]*
        ///
        /// or
        ///
        /// path file0 [ file1 [file2 ...]].
        ///
        /// path: path of directory
        ///
        /// query: limiter, often a file format, ie *.jnt, *.xml ...
        ///
        /// -r: recursive
        /// -d: top
        ///
        ///
        /// Example:
        ///
        /// ./data *.jnt -r -exPath devin
        ///
        /// ./files *.xml -d
        ///
        /// c:/cool/mix *.xml -r -inPath rectangle -exName square
        ///
        /// ./smith file1.xml file2.jnt file3.txt file4.yay
        ///
        /// </summary>
        /// <param name="args"></param>
        public Files(string[] args)
        {
            int i, len = args.Length;

            if (len > 1)
            {
                //Get directory
                string directory = args[0];
                if (!Directory.Exists(directory))
                {
                    return;
                }

                //Get file extension (*.jnt, *.xml, *.etc...)
                string ext = args[1];
                if (!ext.StartsWith("*"))
                {
                    List <string> files = new List <string>(len - 1);
                    for (i = 1; i < len; ++i)
                    {
                        if (Directory.Exists(directory + args[i]))
                        {
                            files.Add(directory + args[i]);
                        }
                    }
                    m_files = files;
                }
                else if (len > 2)
                {
                    //Get the search type
                    SearchOption?option = null;
                    switch (args[2])
                    {
                    //Only the top directory
                    case "-d":
                        option = SearchOption.TopDirectoryOnly;
                        break;

                    //Recursive from directory
                    case "-r":
                        option = SearchOption.AllDirectories;
                        break;

                    default:
                        throw new System.ArgumentException("Missing -d or -r");
                    }
                    if (!option.HasValue)
                    {
                        return;
                    }

                    m_files = new List <string>(Directory.GetFiles(directory, ext, option.Value));
                    if (m_files.Count > 0)
                    {
                        //Process limiters
                        string type, limiter;
                        for (i = 3; i < len; ++i)
                        {
                            type = args[i];
                            ++i;
                            limiter = args[i];

                            switch (type)
                            {
                            case "-inPath":
                                m_files = includeInPath(m_files, limiter);
                                break;

                            case "-exPath":
                                m_files = excludeInPath(m_files, limiter);
                                break;

                            case "-inName":
                                m_files = includeInName(m_files, limiter);
                                break;

                            case "-exName":
                                m_files = excludeInName(m_files, limiter);
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                else
                {
                    throw new System.ArgumentException("Wrong number of arguments");
                }
            }
        }
Exemplo n.º 11
0
		public ADObjectSearcher(ADSessionInfo sessionInfo, ADObject obj)
		{
			this._searchScope = ADSearchScope.Subtree;
			this._filter = ADOPathUtil.CreateFilterClause(ADOperator.Like, "objectClass", "*");
			this._propertyList = new List<string>(ADObject.DefaultProperties);
			this._timeLimit = TimeSpan.Zero;
			this._schemaTranslationEnabled = true;
			this._pageSize = 0x100;
			this._searchOption = null;
			this._autoRangeRetrieve = true;
			this._sdFlags = SecurityMasks.Owner | SecurityMasks.Group | SecurityMasks.Dacl;
			if (sessionInfo == null)
			{
				if (obj == null)
				{
					this._adSession = ADSession.ConstructSession(null);
				}
				else
				{
					this._adSession = ADSession.ConstructSession(obj.SessionInfo);
				}
			}
			else
			{
				this._adSession = ADSession.ConstructSession(sessionInfo);
			}
			if (obj != null)
			{
				this._adObject = obj;
				this._searchRoot = this._adObject.DistinguishedName;
				foreach (string propertyName in this._adObject.PropertyNames)
				{
					this._propertyList.Add(propertyName);
				}
			}
		}
Exemplo n.º 12
0
        ///// <summary>
        ///// Loads the items.
        ///// </summary>
        public static IEnumerable <IPathInfo> Enumerate(IEnumerable <IPathInfo> paths, string searchPattern, SearchOption?searchOption
#if NETCORE
                                                        , EnumerationOptions enumerationOptions
#endif
#if DEBUG
                                                        , FileSystemEntryEnumeratorProcessSimulation simulationParameters
#endif
                                                        ) => new Enumerable <IPathInfo>(() => new PathInfoFileSystemEntryEnumerator(paths, searchPattern, searchOption
#if NETCORE
                                                                                                                                    , enumerationOptions
#endif
#if DEBUG
                                                                                                                                    , simulationParameters
#endif
                                                                                                                                    )
                                                                                        );
Exemplo n.º 13
0
 /// <summary>
 /// Instantiates a <see cref="SearchPattern"/> instance using the supplied parameters.
 /// </summary>
 /// <param name="pattern">
 /// The filter string for this pattern.
 /// </param>
 /// <param name="option">
 /// The depth which searches associated with this pattern should be performed for.
 /// </param>
 public SearchPattern(string pattern, SearchOption?option = null)
 {
     this.Pattern = pattern ?? throw new ArgumentNullException(nameof(pattern));
     this.Option  = option;
 }
Exemplo n.º 14
0
        /// <summary>
        /// Default IncludeXmlComments
        /// </summary>
        public static SwaggerGenOptions IncludeXmlComments(this SwaggerGenOptions options, string?direcotoryPath = default, SearchOption?searchOption = default)
        {
            var xmlFiles = Directory.GetFiles(string.IsNullOrEmpty(direcotoryPath) ? AppContext.BaseDirectory : direcotoryPath, "*.xml", searchOption ?? SearchOption.TopDirectoryOnly);

            Array.ForEach(xmlFiles, xml =>
            {
                options.IncludeXmlComments(xml, true);
            });
            return(options);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 3层 Dictionary namespace => class => member
        /// </summary>
        // private static Dictionary<string, Dictionary<string, Dictionary<string, string>>> classValue = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();
        static void Main(string[] args)
        {
            string        outPath               = null;                // -o{FILE}, --descriptor_set_out={FILE}
            bool          version               = false;               // --version
            bool          help                  = false;               // -h, --help
            var           importPaths           = new List <string>(); // -I{PATH}, --proto_path={PATH}
            var           inputFiles            = new List <string>(); // {PROTO_FILES} (everything not `-`)
            bool          exec                  = false;
            string        package               = null;                // --package=foo
            List <string> filesPath             = new List <string>();
            Dictionary <string, string> options = null;

            foreach (string arg in args)
            {
                string lhs = arg, rhs = "";
                int    index = arg.IndexOf('=');
                if (index > 0)
                {
                    lhs = arg.Substring(0, index);
                    rhs = arg.Substring(index + 1);
                }
                else if (arg.StartsWith("-o"))
                {
                    lhs = "--descriptor_set_out";
                    rhs = arg.Substring(2);
                }
                else if (arg.StartsWith("-I"))
                {
                    lhs = "--json_path";
                    rhs = arg.Substring(2);
                }

                if (lhs.StartsWith("+"))
                {
                    if (options == null)
                    {
                        options = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                    }
                    options[lhs.Substring(1)] = rhs;
                    continue;
                }

                switch (lhs)
                {
                case "":
                    break;

                case "--version":
                    Console.WriteLine("1.0.0");
                    break;

                case "--package":
                    package = rhs;
                    break;

                case "-h":
                case "--help":
                    help = true;
                    break;

                case "--csharp_out":
                    outPath = rhs;
                    exec    = true;
                    break;

                case "--descriptor_set_out":
                    outPath = rhs;
                    exec    = true;
                    break;

                case "--json_path":
                    importPaths.Add(rhs);
                    break;

                default:
                    if (lhs.StartsWith("-") || !string.IsNullOrWhiteSpace(rhs))
                    {
                        help = true;
                        break;
                    }
                    else
                    {
                        inputFiles.Add(lhs);
                    }
                    break;
                }
            }

            if (help)
            {
                return;
            }
            else if (version)
            {
                Console.WriteLine("1.0.0");
                return;
            }
            else if (inputFiles.Count == 0)
            {
                Console.Error.WriteLine("Missing input file.");
                return;
            }
            else if (!exec)
            {
                Console.Error.WriteLine("Missing output directives.");
                return;
            }
            else
            {
                if (importPaths.Count == 0)
                {
                    Console.WriteLine("import path empty");
                }
                else
                {
                    foreach (var dir in importPaths)
                    {
                        if (!Directory.Exists(dir))
                        {
                            Console.Error.WriteLine($"Directory not found: {dir}");
                            return;
                        }
                    }
                }

                if (inputFiles.Count == 1 && importPaths.Count == 1)
                {
                    SearchOption?searchOption = SearchOption.AllDirectories;

                    if (searchOption != null)
                    {
                        //inputFiles.Clear();
                        var searchRoot = importPaths[0];
                        foreach (var path in Directory.EnumerateFiles(importPaths[0], inputFiles[0], searchOption.Value))
                        {
                            filesPath.Add(path);
                        }
                    }
                }
            }
            foreach (var path in filesPath)
            {
                string text     = File.ReadAllText(path);
                var    fileName = "\\" + path.Split('\\').Last().Split('.').First() + ".cs";
                try
                {
                    DynamicJsonObject dy = ConvertJson(text);
                    CodeGenerate.CSharpCode(outPath + fileName, dy);
                    Console.WriteLine("JsonConvert2Net " + path + " => " + outPath + fileName + " Success");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
            Console.ReadKey();
        }
 public EnumerateFilesOperation(TxDirectory directory, string path, string searchPattern,
                                SearchOption searchOption)
     : this(directory, path, searchPattern)
 {
     _searchOption = searchOption;
 }
Exemplo n.º 17
0
 public ContentsKey(string path, string pattern, SearchOption?searchOption)
 {
     Path         = path;
     Pattern      = pattern;
     SearchOption = searchOption;
 }
Exemplo n.º 18
0
        public static object[][] getParameters(string dirName, List <string> excludes, SearchOption?searchOption)
        {
            searchOption ??= SearchOption.AllDirectories;

            var root  = "C:\\Users\\David Whitney\\OneDrive\\Desktop\\coffee-gb-netcore\\CoreBoy.Test.Integration\\roms";
            var dir   = Path.Combine(root, dirName);
            var paths = Directory.EnumerateFiles(dir, "*.gb", searchOption.Value).ToList();

            paths.RemoveAll(path => excludes.Any(path.Contains));

            var returnVal = paths.Select(path => new List <object> {
                path
            }.ToArray()).ToArray();

            return(returnVal);
        }