Exemplo n.º 1
0
        internal static void AddProject(ProjectItem projectItem, ICollection <string> projectList, string projectName)
        {
            ThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                foreach (var project in projectItem.DTE.Solution.AllProjects())
                {
                    try
                    {
                        if (project.Name == projectName)
                        {
                            AddProject(projectList, project);
                            return;
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Debug($"Cannot add project named '{projectName}' ({exception.Message})");
                    }
                }

                string message = $"Cannot find project named '{projectName}'";

                ErrorList.AddWarning(projectItem, message);
                Log.Warn(message);
            });
        }
Exemplo n.º 2
0
        public static Type Compile(ProjectItem projectItem, ShadowClass shadowClass)
        {
            if (Directory.Exists(Constants.TempDirectory) == false)
            {
                Directory.CreateDirectory(Constants.TempDirectory);
            }

            var filname = Path.GetRandomFileName();
            var path    = Path.Combine(Constants.TempDirectory, filname);

            var result = shadowClass.Compile(path);

            ErrorList.Clear();

            var errors = result.Diagnostics.Where(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error || diagnostic.Severity == DiagnosticSeverity.Warning);

            var hasErrors = false;

            foreach (var error in errors)
            {
                var message = error.GetMessage();

                message = message.Replace("__Typewriter.", string.Empty);
                //message = message.Replace("__Code.", string.Empty);
                message = message.Replace("publicstatic", string.Empty);

                Log.Warn("Template error: {0} {1}", error.Id, message);

                if (error.Severity == DiagnosticSeverity.Error || error.IsWarningAsError)
                {
                    ErrorList.AddError(projectItem, message);
                    hasErrors = true;
                }
                else
                {
                    ErrorList.AddWarning(projectItem, message);
                }
            }

            if (hasErrors)
            {
                ErrorList.Show();
            }

            if (result.Success)
            {
                var assembly = Assembly.LoadFrom(path);
                var type     = assembly.GetType("__Typewriter.Template");

                return(type);
            }

            throw new Exception("Failed to compile template.");
        }
Exemplo n.º 3
0
        internal static void AddProject(ProjectItem projectItem, ICollection <string> projectList, string projectName)
        {
            foreach (var project in projectItem.DTE.Solution.AllProjects())
            {
                try
                {
                    if (project.Name == projectName)
                    {
                        AddProject(projectList, project);
                        return;
                    }
                }
                catch (Exception exception)
                {
                    Log.Debug($"Cannot add project named '{projectName}' ({exception.Message})");
                }
            }

            string message = $"Cannot find project named '{projectName}'";

            ErrorList.AddWarning(projectItem, message);
            Log.Warn(message);
        }
Exemplo n.º 4
0
        public static Type Compile(ProjectItem projectItem, ShadowClass shadowClass)
        {
            if (Directory.Exists(Constants.TempDirectory) == false)
            {
                Directory.CreateDirectory(Constants.TempDirectory);
            }

            foreach (Assembly assembly in shadowClass.ReferencedAssemblies)
            {
                if (assembly.GlobalAssemblyCache)
                {
                    continue;
                }

                var asmSourcePath = assembly.Location;
                var asmDestPath   = Path.Combine(Constants.TempDirectory, Path.GetFileName(asmSourcePath));

                var          sourceAssemblerInfo = AssemblyName.GetAssemblyName(asmSourcePath);
                AssemblyName destAssemblerInfo   = null;

                // Ignores the Assembler if versions are equals.
                if (File.Exists(asmDestPath))
                {
                    destAssemblerInfo = AssemblyName.GetAssemblyName(asmDestPath);
                    if (sourceAssemblerInfo.Version.CompareTo(destAssemblerInfo.Version) == 0)
                    {
                        continue;
                    }
                }

                try
                {
                    //File may be in use
                    File.Copy(asmSourcePath, asmDestPath, true);
                }
                catch (Exception e)
                {
                    Log.Warn($"{e.ToString()} \r\n  Source Version {sourceAssemblerInfo.Version}, Target Verison  {destAssemblerInfo?.Version.ToString() ?? "None"} ");
                }
            }

            var filname = Path.GetRandomFileName();
            var path    = Path.Combine(Constants.TempDirectory, filname);

            var result = shadowClass.Compile(path);

            ErrorList.Clear();

            var errors = result.Diagnostics.Where(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error || diagnostic.Severity == DiagnosticSeverity.Warning);

            var hasErrors = false;

            foreach (var error in errors)
            {
                var message = error.GetMessage();

                message = message.Replace("__Typewriter.", string.Empty);
                //message = message.Replace("__Code.", string.Empty);
                message = message.Replace("publicstatic", string.Empty);

                Log.Warn("Template error: {0} {1}", error.Id, message);

                if (error.Severity == DiagnosticSeverity.Error || error.IsWarningAsError)
                {
                    ErrorList.AddError(projectItem, message);
                    hasErrors = true;
                }
                else
                {
                    ErrorList.AddWarning(projectItem, message);
                }
            }

            if (hasErrors)
            {
                ErrorList.Show();
            }

            if (result.Success)
            {
                var assembly = Assembly.LoadFrom(path);
                var type     = assembly.GetType("__Typewriter.Template");

                return(type);
            }

            throw new Exception("Failed to compile template.");
        }