Exemplo n.º 1
0
        public static void UncommitedXml(SetupInfo setupInfo)
        {
            var fsUncommitedXmlTemplate = Path.Combine(
                setupInfo.Props.SolutionPath,
                @"CerebelloWebRole\Uncommited.template.xml");

            var fsUncommitedXml = Path.Combine(
                setupInfo.Props.SolutionPath,
                @"CerebelloWebRole\Uncommited.xml");

            var newText = TemplateProcessor.ProcessTemplate(File.ReadAllText(fsUncommitedXmlTemplate), setupInfo.Props, true);
            File.WriteAllText(fsUncommitedXml, newText);
        }
Exemplo n.º 2
0
        public static void TestUncommitedConfig(SetupInfo setupInfo)
        {
            var testUncommitedConfigTemplate = Path.Combine(
                setupInfo.Props.SolutionPath,
                @"CerebelloWebRole.Tests\Uncommited.template.config");

            var testUncommitedConfig = Path.Combine(
                setupInfo.Props.SolutionPath,
                @"CerebelloWebRole.Tests\Uncommited.config");

            var newText = TemplateProcessor.ProcessTemplate(File.ReadAllText(testUncommitedConfigTemplate), setupInfo.Props, true);
            File.WriteAllText(testUncommitedConfig, newText);
        }
Exemplo n.º 3
0
        private static void RunSetup(SetupInfo setupInfo)
        {
            var listSteps = new List <Action <SetupInfo> >
            {
                SetupSteps.UncommitedXml,
                SetupSteps.FirestarterUncommitedConfig,
                SetupSteps.TestUncommitedConfig,
                SetupSteps.WindowsAzureTargets,
            };

            foreach (var step in listSteps)
            {
                try
                {
                    step(setupInfo);
                }
                // ReSharper disable EmptyGeneralCatchClause
                catch
                // ReSharper restore EmptyGeneralCatchClause
                {
                }
            }
        }
Exemplo n.º 4
0
        public static void WindowsAzureTargets(SetupInfo setupInfo)
        {
            var azureTargets = setupInfo.AzureTargets;

            foreach (var azureTarget in azureTargets)
            {
                var dllsToLetIn = new[]
                {
                    "System.EnterpriseServices.Wrapper.dll",
                };

                var neededAnds =
                    dllsToLetIn
                    .OrderBy(s => s)
                    .Select(s => String.Format("'%(WebFiles.Filename)%(WebFiles.Extension)' != '{0}'", s))
                    .ToArray();

                var  lines   = File.ReadAllLines(azureTarget.FullName);
                bool changed = false;
                for (int itLine = 0; itLine < lines.Length; itLine++)
                {
                    var curLine = lines[itLine];

                    if (curLine.Contains("<_AssembliesToValidate") &&
                        curLine.Contains("Include=\"@(WebFiles);@(WorkerFiles)\""))
                    {
                        var match        = Regex.Match(curLine, @"Condition\=""(?<CONDITION>(?:\\""|.)*?)""");
                        var oldCondition = match.Groups["CONDITION"].Value;

                        var oldAnds = oldCondition.Split(new[] { " AND ", " And ", " and " }, StringSplitOptions.None);

                        var itemsAnd = new List <string>();

                        foreach (var currentAnd in oldAnds)
                        {
                            if (!itemsAnd.Contains(currentAnd))
                            {
                                itemsAnd.Add(currentAnd.Trim());
                            }
                        }

                        var oldCount = itemsAnd.Count;

                        foreach (var neededAnd in neededAnds)
                        {
                            if (!itemsAnd.Contains(neededAnd))
                            {
                                itemsAnd.Add(neededAnd.Trim());
                            }
                        }

                        var newCount = itemsAnd.Count;

                        // if any needed AND item is missing, we must change the line
                        if (oldCount < newCount)
                        {
                            var newLine = Regex.Replace(
                                lines[itLine],
                                @"Condition\=""(?<CONDITION>(?:\\""|.)*?)""",
                                String.Format("Condition=\" {0} \"", String.Join(" And ", itemsAnd)));

                            lines[itLine] = newLine;

                            changed = true;
                        }
                    }
                }

                if (changed)
                {
                    File.WriteAllLines(azureTarget.FullName, lines);
                }
            }
        }
Exemplo n.º 5
0
        static int Main2(string[] args)
        {
            var joinArgs = string.Join(" ", args);

            var argsMatches = Regex.Matches(joinArgs, @"  (?<CHECK>\\c\w|\\check\w)  |  (?:\\d:""(?<DESKTOP>.*?)"")  |  (?<DEBUG>\\d\w|\\debug\w)  ", RegexOptions.IgnorePatternWhitespace);

            bool debug = argsMatches.Cast <Match>().Any(m => m.Groups["DEBUG"].Success);

            if (debug)
            {
                Debugger.Launch();
            }

            bool   check       = argsMatches.Cast <Match>().Any(m => m.Groups["CHECK"].Success);
            string desktopPath = argsMatches.Cast <Match>()
                                 .Select(m => m.Groups["DESKTOP"])
                                 .Where(m => m.Success)
                                 .Select(m => m.Value)
                                 .LastOrDefault();

            if (string.IsNullOrWhiteSpace(desktopPath))
            {
                desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            }

            var newArgs = new List <string>();

            if (check)
            {
                newArgs.Add(@"\c");
            }
            if (!string.IsNullOrWhiteSpace(desktopPath))
            {
                newArgs.Add(string.Format(@"\d:""{0}""", desktopPath));
            }

            SetupInfo setupInfo;
            var       ser = new XmlSerializer(typeof(SetupInfo));

            // Loading setup info file
            if (File.Exists("solution-setup-info.xml"))
            {
                using (var reader = XmlReader.Create("solution-setup-info.xml"))
                {
                    setupInfo = (SetupInfo)ser.Deserialize(reader);
                }
            }
            else
            {
                setupInfo = new SetupInfo();
            }

            // set values in the setup info
            {
                var dirInfo = new DirectoryInfo(Environment.CurrentDirectory);
                var sln     = dirInfo.GetFiles("Cerebello.sln");
                while (!sln.Any())
                {
                    dirInfo = dirInfo.Parent;
                    if (dirInfo == null)
                    {
                        MessageBox.Show("Cannot find 'Cerebello.sln' in the current directory or any parent directory.");
                        return(2);
                    }

                    sln = dirInfo.GetFiles("Cerebello.sln");
                }

                if (dirInfo != null)
                {
                    if (setupInfo.Props == null)
                    {
                        setupInfo.Props = new SetupInfo.Properties();
                    }

                    setupInfo.Props.SolutionPath = dirInfo.FullName;
                }

                setupInfo.Props.DesktopPath = desktopPath;
            }

            // check to see if setup is needed
            var  currentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            bool isSetupOk      = setupInfo.Version == currentVersion;

            if (check && isSetupOk)
            {
                return(0);
            }

            setupInfo.Version = currentVersion;

            // check to see if solution is already setup
            if (!AdminPrivileges.HasAdminPrivileges())
            {
                if (Debugger.IsAttached)
                {
                    newArgs.Add(@"\debug");
                }

                var proc = AdminPrivileges.TryRestartWithAdminPrivileges(newArgs.ToArray());
                if (proc == null)
                {
                    MessageBox.Show("Could not start solution setup with administrative privileges.");
                    return(3);
                }

                proc.WaitForExit();

                return(proc.ExitCode);
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var frm = new Form1(setupInfo);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                var dirVisualStudio = new DirectoryInfo(@"C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio");
                var azureTargets    = dirVisualStudio.GetFiles("Microsoft.WindowsAzure.targets", SearchOption.AllDirectories);
                setupInfo.AzureTargets = azureTargets;

                // applying the setup
                RunSetup(setupInfo);

                // saving setup info file
                var ws = new XmlWriterSettings {
                    NewLineHandling = NewLineHandling.Entitize
                };
                using (var reader = XmlWriter.Create("solution-setup-info.xml", ws))
                {
                    ser.Serialize(reader, setupInfo);
                }
            }
            else
            {
                return(1);
            }

            return(0);
        }
Exemplo n.º 6
0
 public Form1(SetupInfo setupInfo)
 {
     this.setupInfo = setupInfo;
     this.InitializeComponent();
     this.propertyGrid1.SelectedObject = this.setupInfo.Props;
 }
Exemplo n.º 7
0
        static int Main2(string[] args)
        {
            var joinArgs = string.Join(" ", args);

            var argsMatches = Regex.Matches(joinArgs, @"  (?<CHECK>\\c\w|\\check\w)  |  (?:\\d:""(?<DESKTOP>.*?)"")  |  (?<DEBUG>\\d\w|\\debug\w)  ", RegexOptions.IgnorePatternWhitespace);

            bool debug = argsMatches.Cast<Match>().Any(m => m.Groups["DEBUG"].Success);

            if (debug)
                Debugger.Launch();

            bool check = argsMatches.Cast<Match>().Any(m => m.Groups["CHECK"].Success);
            string desktopPath = argsMatches.Cast<Match>()
                .Select(m => m.Groups["DESKTOP"])
                .Where(m => m.Success)
                .Select(m => m.Value)
                .LastOrDefault();

            if (string.IsNullOrWhiteSpace(desktopPath))
                desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            var newArgs = new List<string>();
            if (check) newArgs.Add(@"\c");
            if (!string.IsNullOrWhiteSpace(desktopPath))
                newArgs.Add(string.Format(@"\d:""{0}""", desktopPath));

            SetupInfo setupInfo;
            var ser = new XmlSerializer(typeof(SetupInfo));

            // Loading setup info file
            if (File.Exists("solution-setup-info.xml"))
            {
                using (var reader = XmlReader.Create("solution-setup-info.xml"))
                {
                    setupInfo = (SetupInfo)ser.Deserialize(reader);
                }
            }
            else
            {
                setupInfo = new SetupInfo();
            }

            // set values in the setup info
            {
                var dirInfo = new DirectoryInfo(Environment.CurrentDirectory);
                var sln = dirInfo.GetFiles("Cerebello.sln");
                while (!sln.Any())
                {
                    dirInfo = dirInfo.Parent;
                    if (dirInfo == null)
                    {
                        MessageBox.Show("Cannot find 'Cerebello.sln' in the current directory or any parent directory.");
                        return 2;
                    }

                    sln = dirInfo.GetFiles("Cerebello.sln");
                }

                if (dirInfo != null)
                {
                    if (setupInfo.Props == null)
                        setupInfo.Props = new SetupInfo.Properties();

                    setupInfo.Props.SolutionPath = dirInfo.FullName;
                }

                setupInfo.Props.DesktopPath = desktopPath;
            }

            // check to see if setup is needed
            var currentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            bool isSetupOk = setupInfo.Version == currentVersion;

            if (check && isSetupOk)
                return 0;

            setupInfo.Version = currentVersion;

            // check to see if solution is already setup
            if (!AdminPrivileges.HasAdminPrivileges())
            {
                if (Debugger.IsAttached)
                    newArgs.Add(@"\debug");

                var proc = AdminPrivileges.TryRestartWithAdminPrivileges(newArgs.ToArray());
                if (proc == null)
                {
                    MessageBox.Show("Could not start solution setup with administrative privileges.");
                    return 3;
                }

                proc.WaitForExit();

                return proc.ExitCode;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var frm = new Form1(setupInfo);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                var dirVisualStudio = new DirectoryInfo(@"C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio");
                var azureTargets = dirVisualStudio.GetFiles("Microsoft.WindowsAzure.targets", SearchOption.AllDirectories);
                setupInfo.AzureTargets = azureTargets;

                // applying the setup
                RunSetup(setupInfo);

                // saving setup info file
                var ws = new XmlWriterSettings { NewLineHandling = NewLineHandling.Entitize };
                using (var reader = XmlWriter.Create("solution-setup-info.xml", ws))
                {
                    ser.Serialize(reader, setupInfo);
                }
            }
            else
            {
                return 1;
            }

            return 0;
        }
Exemplo n.º 8
0
        private static void RunSetup(SetupInfo setupInfo)
        {
            var listSteps = new List<Action<SetupInfo>>
                {
                    SetupSteps.UncommitedXml,
                    SetupSteps.FirestarterUncommitedConfig,
                    SetupSteps.TestUncommitedConfig,
                    SetupSteps.WindowsAzureTargets,
                };

            foreach (var step in listSteps)
            {
                try
                {
                    step(setupInfo);
                }
                // ReSharper disable EmptyGeneralCatchClause
                catch
                // ReSharper restore EmptyGeneralCatchClause
                {
                }
            }
        }
Exemplo n.º 9
0
 public Form1(SetupInfo setupInfo)
 {
     this.setupInfo = setupInfo;
     this.InitializeComponent();
     this.propertyGrid1.SelectedObject = this.setupInfo.Props;
 }
Exemplo n.º 10
0
        public static void WindowsAzureTargets(SetupInfo setupInfo)
        {
            var azureTargets = setupInfo.AzureTargets;

            foreach (var azureTarget in azureTargets)
            {
                var dllsToLetIn = new[]
                    {
                        "System.EnterpriseServices.Wrapper.dll",
                    };

                var neededAnds =
                    dllsToLetIn
                        .OrderBy(s => s)
                        .Select(s => String.Format("'%(WebFiles.Filename)%(WebFiles.Extension)' != '{0}'", s))
                        .ToArray();

                var lines = File.ReadAllLines(azureTarget.FullName);
                bool changed = false;
                for (int itLine = 0; itLine < lines.Length; itLine++)
                {
                    var curLine = lines[itLine];

                    if (curLine.Contains("<_AssembliesToValidate")
                        && curLine.Contains("Include=\"@(WebFiles);@(WorkerFiles)\""))
                    {
                        var match = Regex.Match(curLine, @"Condition\=""(?<CONDITION>(?:\\""|.)*?)""");
                        var oldCondition = match.Groups["CONDITION"].Value;

                        var oldAnds = oldCondition.Split(new[] { " AND ", " And ", " and " }, StringSplitOptions.None);

                        var itemsAnd = new List<string>();

                        foreach (var currentAnd in oldAnds)
                            if (!itemsAnd.Contains(currentAnd))
                                itemsAnd.Add(currentAnd.Trim());

                        var oldCount = itemsAnd.Count;

                        foreach (var neededAnd in neededAnds)
                            if (!itemsAnd.Contains(neededAnd))
                                itemsAnd.Add(neededAnd.Trim());

                        var newCount = itemsAnd.Count;

                        // if any needed AND item is missing, we must change the line
                        if (oldCount < newCount)
                        {
                            var newLine = Regex.Replace(
                                lines[itLine],
                                @"Condition\=""(?<CONDITION>(?:\\""|.)*?)""",
                                String.Format("Condition=\" {0} \"", String.Join(" And ", itemsAnd)));

                            lines[itLine] = newLine;

                            changed = true;
                        }
                    }
                }

                if (changed)
                    File.WriteAllLines(azureTarget.FullName, lines);
            }
        }