Ejemplo n.º 1
0
        private void GetBoolSetting(IDictionary dict, string setting, ref bool val)
        {
            string temp = (string)dict[setting];

            if (!String.IsNullOrEmpty(temp))
            {
                if (!TryParseTrueFalse(temp, ref val))
                {
                    Output.Warning(ScaffoldResources.UnableToParseValueInEnvironment(temp, setting));
                }
            }
        }
Ejemplo n.º 2
0
        private void DeleteDirectory(string dirName)
        {
            try
            {
                Directory.Delete(dirName, true);

                if (this.Verbose)
                {
                    Output.Message(MessageImportance.Low, ScaffoldResources.SubDirDeleted(dirName));
                }
            }
            catch (SystemException)
            {
                Output.Warning(ScaffoldResources.SubDirNotDeleted(dirName));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Process th e
        /// </summary>
        /// <param name="userLevel"></param>
        /// <returns></returns>
        bool IProcessConfiguration.ProcessConfiguration(System.Configuration.ConfigurationUserLevel userLevel)
        {
            try
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(userLevel);

                if (!config.HasFile)
                {
                    return(true);
                }

                ConfigurationSection tempSection = null;
                ScaffoldSection      section     = null;

                try
                {
                    tempSection = config.GetSection("scaffold");
                    section     = tempSection as ScaffoldSection;
                }
                catch (ConfigurationException e)
                {
                    Output.Error(ScaffoldResources.ProblemLoadingExeConfiguration(e.Message));
                }

                if (section == null)
                {
                    if (tempSection != null)
                    {
                        Output.Warning(ScaffoldResources.ScaffoldSectionPresentButWrongType);
                    }

                    // Otherwise the section just isn't there
                    return(true);
                }

                GetBoolSetting(section, "Verbose", ref verbose);
                GetBoolSetting(section, "NoRemoting", ref noRemoting);
            }
            catch (ConfigurationErrorsException)
            {
                Output.Warning(ScaffoldResources.ApplicationConfigurationCouldNotBeLoaded);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        private void CreateFile(string fileName, string content)
        {
            if (File.Exists(fileName))
            {
                Output.Warning(ScaffoldResources.AlreadyExists(fileName));
                return;
            }

            using (StreamWriter sw = new StreamWriter(fileName, false, System.Text.Encoding.ASCII))
            {
                sw.Write(content);
            }

            if (this.Verbose)
            {
                Output.Message(MessageImportance.Low, ScaffoldResources.Created(fileName));
            }
        }
Ejemplo n.º 5
0
        private void GetBoolSetting(ScaffoldSection section, string setting, ref bool val)
        {
            try
            {
                for (int i = 0; i < section.Settings.Count; i++)
                {
                    TypeElement element = section.Settings[i];

                    if (String.Compare(element.Key, setting, true) == 0)
                    {
                        if (!TryParseTrueFalse(element.Value, ref val))
                        {
                            Output.Warning(ScaffoldResources.UnableToParseValueInConfig(element.Value, element.Key));
                        }

                        return;
                    }
                }
            }
            catch (ConfigurationException e)
            {
                Output.Warning(e.Message);
            }
        }
Ejemplo n.º 6
0
        private void RealExecute()
        {
            // At this point, we need a program (the default argument)
            if (this.ScriptPath == null)
            {
                Output.Error(ScaffoldResources.NoSourceSpecified);
                return;
            }

            // Fully qualify the program
            this.ScriptPath = this.ScriptPath.MakeFullPath();

            if (this.ScriptPath.File == String.Empty)
            {
                Output.Error(ScaffoldResources.NoEmptyFilename);
                return;
            }
            else if (this.ScriptPath.HasWildcards)
            {
                Output.Error(ScaffoldResources.NoSourceWildcards);
                return;
            }
            else if (this._Language == ScriptLanguage.Unknown)
            {
                Output.Error(ScaffoldResources.FileNameMustEndIn);
                return;
            }

            // TODO-johnls-12/15/2007: More project types coming soon...?
            if (this._Language != ScriptLanguage.CSharp)
            {
                Output.Error(ScaffoldResources.OnlyCSharpSourcesSupported);
                return;
            }

            // Look for installed VS versions get information about them
            IList <VisualStudioInfo> vsInfos = VisualStudioInfo.GetInstalledVisualStudios();

            if (vsInfos.Count == 0)
            {
                // Must have at least one supported version of Visual Studio installed
                Output.Error(ScaffoldResources.VSNotInstalled(StringUtility.Join(", ", ScriptInfo.ValidVisualStudioVersions)));
                return;
            }

            // Get list of installed runtimes.
            IList <RuntimeInfo> runtimeInfos = RuntimeInfo.GetInstalledRuntimes();

            // If VS is installed we have at least one runtime...
            if (runtimeInfos.Count == 0)
            {
                Output.Error(ScaffoldResources.RuntimeNotInstalled(StringUtility.Join(", ", ScriptInfo.ValidRuntimeVersions)));
                return;
            }

            ScriptInfo       scriptInfo = null;
            VisualStudioInfo vsInfo;
            RuntimeInfo      runtimeInfo;

            if (File.Exists(this.ScriptPath))
            {
                try
                {
                    // Grab script information from script
                    scriptInfo = ScriptInfo.GetScriptInfo(this.ScriptPath);
                }
                catch (ScriptInfoException e)
                {
                    Output.Error(e.Message);
                    return;
                }

                // Validate that VS/CLR/FX versions installed
                runtimeInfo = ((List <RuntimeInfo>)runtimeInfos).Find(
                    v => (scriptInfo.ClrVersion == v.ClrVersion && scriptInfo.FxVersion == v.FxVersion));
                vsInfo = ((List <VisualStudioInfo>)vsInfos).Find(
                    v => (scriptInfo.VsVersion == v.VsVersion));

                if (runtimeInfo == null || vsInfo == null)
                {
                    Output.Error(ScaffoldResources.ScriptsRequiredClrFxAndVsNotInstalled(scriptInfo.ClrVersion, scriptInfo.FxVersion, scriptInfo.VsVersion));
                    return;
                }
            }
            else
            {
                vsInfo      = vsInfos[0];
                runtimeInfo = runtimeInfos[0];

                scriptInfo = new ScriptInfo(vsInfo.VsVersion, runtimeInfo.ClrVersion, runtimeInfo.FxVersion, new List <string>());

                // Go grab references from the csc.rsp file and add CodeRunner.dll and ToolBelt.dll
                // in the same directory as Scaffold.exe.
                scriptInfo.References.AddRange(GrabSystemRspFileReferences(runtimeInfo.FxInstallPath.Append("csc.rsp", PathType.File), runtimeInfo));
                scriptInfo.References.Add(@"$(CodeRunnerPath)CodeRunner.dll");
                scriptInfo.References.Add(@"$(CodeRunnerPath)ToolBelt.dll");
            }

            ParsedPath projectDir = CreateTempDirectory();

            if (!CreateProjectFiles(scriptInfo, vsInfo, runtimeInfo, projectDir))
            {
                return;
            }

            StartDevenvAndWait(vsInfos[0], new ParsedPath(
                                   projectDir.VolumeAndDirectory + this.ScriptPath.File + ".sln", PathType.File));

            DeleteDirectory(projectDir);
        }
Ejemplo n.º 7
0
        private bool StartScaffoldAndRemote()
        {
            Process process = null;
            string  programName;

            if (runningFromCommandLine)
            {
                programName = Assembly.GetEntryAssembly().Location;
            }
            else
            {
                // Look for scaffold.exe in the same directory as this assembly
                ParsedPath path = new ParsedPath(Assembly.GetExecutingAssembly().Location, PathType.File);

                programName = path.VolumeAndDirectory + scaffoldExe;
            }

            using (RemoteOutputter remoteOutputter = new RemoteOutputter(this.Output.Outputter))
            {
                try
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo(programName, Parser.Arguments);

                    startInfo.UseShellExecute = false;
                    startInfo.EnvironmentVariables[scaffoldEnvironmentVar] = "RemotingUrl=" + remoteOutputter.RemotingUrl;

                    process = Process.Start(startInfo);

                    if (process == null)
                    {
                        Output.Error(ScaffoldResources.ScaffoldDidNotStart);
                        return(false);
                    }

                    if (this.Wait)
                    {
                        // We pass the wait flag into the remote process so that it will display the wait message.
                        // It will wait on VS to exit, and we will wait on it.
                        process.WaitForExit();
                    }
                    else
                    {
                        // Wait for Scaffold to reach blocking point then continue
                        WaitHandle[] waitHandles = new WaitHandle[]
                        {
                            new ProcessWaitHandle(process),
                            remoteOutputter.BlockingEvent
                        };

                        int n = WaitHandle.WaitAny(waitHandles);

                        if (n == 0)
                        {
                            // The process exited unexpectedly; leave the scene of the crime
                            return(false);
                        }
                    }

                    process.Close();
                }
                catch (Win32Exception e)
                {
                    Output.Error(ScaffoldResources.UnableToStartScaffold(e.Message));
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 8
0
        private bool CreateProjectFiles(ScriptInfo scriptInfo, VisualStudioInfo vsInfo, RuntimeInfo runtimeInfo, ParsedPath projectDir)
        {
            if (!Directory.Exists(this.ScriptPath.VolumeAndDirectory))
            {
                Output.Error(ScaffoldResources.DirectoryDoesNotExist(this.ScriptPath.VolumeAndDirectory));
                return(false);
            }

            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("AssemblyName", this.ScriptPath.File);
            dict.Add("SourceDirectory", this.ScriptPath.VolumeAndDirectory);
            dict.Add("SourceName", this.ScriptPath.FileAndExtension);
            dict.Add("ProjectGuid", Guid.NewGuid().ToString().ToUpper());
            dict.Add("ProjectTypeExt", ScriptEnvironment.GetExtensionFromScaffoldLanguage(this.language));
            dict.Add("ProductVersion", String.Format("{0}.{1}", vsInfo.VsVersion, vsInfo.VsBuild));
            dict.Add("ToolsVersion", String.Format(" ToolsVersion=\"{0}\" ", scriptInfo.FxVersion));
            dict.Add("TargetFrameworkVersion", "v" + scriptInfo.FxVersion);
            dict.Add("ScriptVsVersion", scriptInfo.VsVersion);
            dict.Add("ScriptClrVersion", scriptInfo.ClrVersion);
            dict.Add("ScriptFxVersion", scriptInfo.FxVersion);

            switch (scriptInfo.VsVersion)
            {
            case "10.0":
                dict.Add("SolutionFileVersion", "11.00");
                dict.Add("VSName", "2010");
                break;

            case "9.0":
                dict.Add("SolutionFileVersion", "10.00");
                dict.Add("VSName", "2008");
                break;

            case "8.0":
                dict.Add("ToolsVersion", "");
                dict.Add("SolutionFileVersion", "9.00");
                dict.Add("VSName", "2005");
                break;
            }

            dict.Add("ScriptReferencesComment", CreateCommentSnippetFromReferences(scriptInfo.References));
            dict.Add("ReferenceXmlSnippet", CreateXmlSnippetFromReferences(ScriptInfo.GetFullScriptReferencesPaths(scriptPath, scriptInfo, runtimeInfo)));

            string tagProgramFile = this.ScriptTemplate;

            if (tagProgramFile == null || !File.Exists(tagProgramFile))
            {
                tagProgramFile = GetResource("CodeRunner.Templates.Template.cs");
            }

            string sourceFile = StringUtility.ReplaceTags(tagProgramFile, "%", "%", dict);

            string tagCsProjFile = GetResource("CodeRunner.Templates.Template.csproj");
            string csProjFile    = StringUtility.ReplaceTags(tagCsProjFile, "%", "%", dict);

            string tagCsProjUserFile = GetResource("CodeRunner.Templates.Template.csproj.user");
            string csProjUserFile    = StringUtility.ReplaceTags(tagCsProjUserFile, "%", "%", dict);

            string tagSlnFile = GetResource("CodeRunner.Templates.Template.sln");
            string slnFile    = StringUtility.ReplaceTags(tagSlnFile, "%", "%", dict);

            try
            {
                if (!File.Exists(this.ScriptPath))
                {
                    CreateFile(this.ScriptPath, sourceFile);
                }

                CreateFile(projectDir.VolumeAndDirectory + this.ScriptPath.File + ".csproj", csProjFile);
                CreateFile(projectDir.VolumeAndDirectory + this.ScriptPath.File + ".csproj.user", csProjUserFile);
                CreateFile(projectDir.VolumeAndDirectory + this.ScriptPath.File + ".sln", slnFile);
            }
            catch (IOException exp)
            {
                Output.Error("{0}", exp.Message);
                return(false);
            }

            return(true);
        }