Пример #1
0
        private static void ThreadLoop()
        {
            try
            {
                while (!logCancelSource.IsCancellationRequested)
                {
                    string str = logQueue.Take(logCancelSource.Token);

                    if (EnableDebugLog)
                    {
                        Debug.Write(str);
                    }

                    if (EnableConsole)
                    {
                        Console.Write(str);
                    }

                    try
                    {
                        File.AppendAllText(logFileName, str);
                    }
                    catch (Exception)
                    {
                    }

                    MessageOut?.Invoke(null, str);
                }
            }
            catch (OperationCanceledException)
            {
            }
        }
Пример #2
0
        private void CopyDirectory(DirectoryInfo source, DirectoryInfo target)
        {
            Directory.CreateDirectory(target.FullName);

            foreach (FileInfo fi in source.GetFiles("*.dll"))
            {
                MessageOut?.Invoke($@"Copying {target.FullName}\{fi.Name}");
                fi.CopyTo(Path.Combine(target.FullName, fi.Name), true);
            }

            foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
            {
                DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
                if (!_ignoredDirectories.Contains(diSourceSubDir.FullName))
                {
                    CopyDirectory(diSourceSubDir, nextTargetSubDir);
                }
            }
            foreach (FileInfo fi in source.GetFiles("*.cs"))
            {
                MessageOut?.Invoke($@"Copying {target.FullName}\{fi.Name}");
                fi.CopyTo(Path.Combine(target.FullName, fi.Name), true);
            }

            foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
            {
                DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
                if (!_ignoredDirectories.Contains(diSourceSubDir.FullName))
                {
                    CopyDirectory(diSourceSubDir, nextTargetSubDir);
                }
            }
        }
Пример #3
0
 public void CopyProjectFiles()
 {
     if (Directory.Exists(_scriptDirectory))
     {
         MessageOut?.Invoke("Cleaning Script Directory...");
         Directory.Delete(_scriptDirectory, true);
     }
     MessageOut?.Invoke("Copying Project Files...");
     CopyDirectory(new DirectoryInfo(_projectDirectory), new DirectoryInfo(_scriptDirectory));
 }
Пример #4
0
        private string[] GenerateReferences(string projectRoot)
        {
            MessageOut?.Invoke("Searching References...");

            var referenceList = new List <string>();

            foreach (var requiredReference in _requiredReferences)
            {
                MessageOut?.Invoke($"Added Required Reference: {requiredReference}");
                referenceList.Add(requiredReference);
            }

            foreach (var projectFile in GetProjectFiles(projectRoot, "cs"))
            {
                MessageOut?.Invoke($"Parsing File References: {projectFile}");
                foreach (var reference in ReadFileReferences(projectFile))
                {
                    if (!referenceList.Contains(reference))
                    {
                        MessageOut?.Invoke($"Found New Reference: {reference}");
                        referenceList.Add(reference);
                    }
                }
                referenceList.Sort();
            }

            foreach (var reference in referenceList.ToArray())
            {
                MessageOut?.Invoke($"Verifying Reference: {reference}");
                if (Assembly.LoadWithPartialName($"{reference}") == null)
                {
                    MessageOut?.Invoke($"Ignoring Reference: {reference}");
                    referenceList.Remove(reference);
                }
                else
                {
                    MessageOut?.Invoke($"Added Reference: {reference}");
                }
            }

            var referenceHeaders = new List <string>();

            foreach (var reference in referenceList)
            {
                referenceHeaders.Add($@"//     <reference>{reference.Replace(_projectDirectory, "")}</reference>");
            }

            foreach (var projectFile in GetProjectFiles(projectRoot, "dll"))
            {
                referenceHeaders.Add($@"//     <reference>{projectFile.Replace($"{_projectDirectory}\\", "")}</reference>");
            }

            return(WrapHeaderContents("references", referenceHeaders.ToArray()));
        }
Пример #5
0
        private string[] GenerateFiles(string projectRoot)
        {
            var list = new List <string>();

            foreach (var projectFile in GetProjectFiles(projectRoot, "cs"))
            {
                MessageOut?.Invoke($"Added Project File: {projectFile}");
                list.Add($@"//     <file>{projectFile.Replace($"{_projectDirectory}\\", "")}</file>");
            }

            return(WrapHeaderContents("files", list.ToArray()));
        }
Пример #6
0
        public SharpScriptGenerator(string projectDirectory)
        {
            MessageOut?.Invoke("Initializing...");
            _projectDirectory = projectDirectory;
            MessageOut?.Invoke($"Project Directory: {projectDirectory}");
            _scriptDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SharpScript");
            MessageOut?.Invoke($"Output Directory: {_scriptDirectory}");
            _projectScriptFile = Path.Combine(_scriptDirectory, "SharpScript.ps1");
            MessageOut?.Invoke($"Script File: {_scriptDirectory}");
            _projectConfigFile = Path.Combine(_scriptDirectory, "SharpScript.config");
            MessageOut?.Invoke($"Configuration File: {_scriptDirectory}");
            if (!Directory.Exists(_scriptDirectory))
            {
                MessageOut?.Invoke("Creating Script Directory...");
                Directory.CreateDirectory(_scriptDirectory);
            }

            _ignoredFiles = new[]
            {
                Path.Combine(_projectDirectory, "Program.cs")
            };
            _ignoredDirectories = new[]
            {
                Path.Combine(_projectDirectory, "obj"),
                Path.Combine(_projectDirectory, "bin"),
                Path.Combine(_projectDirectory, "Properties")
            };
            _requiredReferences = new[]
            {
                "System.Core",
            };

            MessageOut?.Invoke($"Ignored Files: {_scriptDirectory}");
            MessageOut?.Invoke($"Ignored Directories: {_scriptDirectory}");
            MessageOut?.Invoke($"Required References: {_scriptDirectory}");
        }