예제 #1
0
        internal override void Process(ProcessorArgs args)
        {
            var dataFolder = args.Server.MapPath("/App_Config/Include/zzz/DataFolder.config");

            if (File.Exists(dataFolder))
            {
                return;
            }

            var dir = Path.GetDirectoryName(dataFolder);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            var dataFolderPath = "/App_Data";
            var contents       = $@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration xmlns:set=""http://www.sitecore.net/xmlconfig/set/"">
  <sitecore>
    <sc.variable name=""dataFolder"" set:value=""{dataFolderPath}"" />
  </sitecore>
</configuration>";

            File.WriteAllText(dataFolder, contents);
        }
        protected void ExtractNuGetPackage([NotNull] ProcessorArgs args, [NotNull] string package)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(package, "package");

            using (var zip = new ZipFile(package))
            {
                foreach (var zipEntry in zip.Entries ?? new ZipEntry[0])
                {
                    if (zipEntry == null || zipEntry.FileName == null || !zipEntry.FileName.StartsWith("lib/"))
                    {
                        continue;
                    }

                    var filePath = args.Server.MapPath("/bin/" + zipEntry.FileName.Substring("lib/".Length));
                    if (File.Exists(filePath))
                    {
                        continue;
                    }

                    var dir = Path.GetDirectoryName(filePath);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    using (var file = File.OpenWrite(filePath))
                    {
                        zipEntry.Extract(file);
                    }
                }
            }
        }
예제 #3
0
        private void ProcessMasterDatabase([NotNull] ProcessorArgs args, [NotNull] string[] defaultDatabasesNames, [NotNull] IDictionary <string, Database> defaultDatabases)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(defaultDatabasesNames, "defaultDatabasesNames");
            Assert.ArgumentNotNull(defaultDatabases, "defaultDatabases");

            var connectionStrings = args.ConnectionStringsConfig;

            if (!defaultDatabasesNames.Contains("web"))
            {
                return;
            }

            var webDatabasePath    = args.Server.MapPath(string.Format("/App_Data/Databases/{0}", this.GetDefaultDatabase(defaultDatabases, "web").FileName));
            var masterDatabasePath = args.Server.MapPath(string.Format("/App_Data/Databases/{0}", this.GetDefaultDatabase(defaultDatabases, "master").FileName));

            if (File.Exists(webDatabasePath) || !File.Exists(masterDatabasePath))
            {
                return;
            }

            args.WriteLine("Copying master database as web...");

            File.Copy(masterDatabasePath, webDatabasePath);

            var cstr = new SqlConnectionStringBuilder
            {
                IntegratedSecurity = true,
                UserInstance       = true,
                DataSource         = ".\\SQLEXPRESS",
                AttachDBFilename   = webDatabasePath
            };

            this.AddConnectionString(connectionStrings, "web", cstr.ToString());
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              var addedConnectionStrings = args.AddedConnectionStrings;
              var connectionStringsPath = args.Server.MapPath("/App_Config/ConnectionStrings.config");

              var connectionStringsConfig = args.ConnectionStringsConfig;
              if (File.Exists(connectionStringsPath))
              {
            connectionStringsConfig.Load(connectionStringsPath);

            var documentElement = connectionStringsConfig.DocumentElement;
            Assert.IsNotNull(documentElement, "documentElement is null");

            foreach (var addNode in documentElement.ChildNodes.OfType<XmlElement>())
            {
              if (addNode == null)
              {
            continue;
              }

              var name = addNode.GetAttribute("name");
              if (!string.IsNullOrEmpty(name))
              {
            addedConnectionStrings.Add(name);
              }
            }
              }
              else
              {
            connectionStringsConfig.LoadXml("<connectionStrings />");
              }
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var addedConnectionStrings = args.AddedConnectionStrings;
            var connectionStringsPath  = args.Server.MapPath("/App_Config/ConnectionStrings.config");

            var connectionStringsConfig = args.ConnectionStringsConfig;

            if (File.Exists(connectionStringsPath))
            {
                connectionStringsConfig.Load(connectionStringsPath);

                var documentElement = connectionStringsConfig.DocumentElement;
                Assert.IsNotNull(documentElement, "documentElement is null");

                foreach (var addNode in documentElement.ChildNodes.OfType <XmlElement>())
                {
                    if (addNode == null)
                    {
                        continue;
                    }

                    var name = addNode.GetAttribute("name");
                    if (!string.IsNullOrEmpty(name))
                    {
                        addedConnectionStrings.Add(name);
                    }
                }
            }
            else
            {
                connectionStringsConfig.LoadXml("<connectionStrings />");
            }
        }
 internal override void Process(ProcessorArgs args)
 {
     var roslyn = args.Server.MapPath("/bin/roslyn");
       if (Directory.Exists(roslyn))
       {
     Directory.Delete(roslyn, true);
       }
 }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              using (var zip = this.GetFileSetZip(args, "default"))
              {
            this.ExtractFileSet(args, zip, "default");
              }
        }
예제 #8
0
        internal override void Process(ProcessorArgs args)
        {
            var roslyn = args.Server.MapPath("/bin/roslyn");

            if (Directory.Exists(roslyn))
            {
                Directory.Delete(roslyn, true);
            }
        }
예제 #9
0
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            using (var zip = this.GetFileSetZip(args, "default"))
            {
                this.ExtractFileSet(args, zip, "default");
            }
        }
예제 #10
0
        internal static IRelease GetRelease(ProcessorArgs args)
        {
            args.WriteLine("Downloading metadata...");

              var kernelVersion = args.SitecoreVersion;
              var versionName = GetVersionName(kernelVersion);
              var version = GetVersion(versionName);
              var releaseName = GetReleaseName(kernelVersion);
              var release = GetRelease(version, releaseName);

              return release;
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              var release = args.Release;
              Assert.IsNotNull(release, "release");

              var programDataNuget = this.GetNuGet(release);
              if (File.Exists(programDataNuget))
              {
            this.ExtractNuGetPackage(args, programDataNuget);
              }
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              if (args.Mode != BootcampMode.Everything)
              {
            return;
              }

              using (var zip = this.GetFileSetZip(args, "client"))
              {
            this.ExtractFileSet(args, zip, "client");
              }
        }
예제 #13
0
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            if (args.Mode != BootcampMode.Everything)
            {
                return;
            }

            using (var zip = this.GetFileSetZip(args, "client"))
            {
                this.ExtractFileSet(args, zip, "client");
            }
        }
예제 #14
0
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            args.WriteLine("Extracting assemblies bundled in *.nupkg files...");

            var nugetPackages = Directory.GetFiles(args.Server.MapPath("/"), "*.nupkg", SearchOption.AllDirectories);

            foreach (var package in nugetPackages)
            {
                this.ExtractNuGetPackage(args, package);

                File.Delete(package);
            }
        }
예제 #15
0
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var release = args.Release;

            Assert.IsNotNull(release, "release");

            var programDataNuget = this.GetNuGet(release);

            if (File.Exists(programDataNuget))
            {
                this.ExtractNuGetPackage(args, programDataNuget);
            }
        }
        internal override void Process(ProcessorArgs args)
        {
            args.WriteLine("Merging web.config include files...");

              var webConfigPath = args.Server.MapPath("/web.config");
              Assert.IsTrue(File.Exists(webConfigPath), "The /web.config file does not exist");

              var result = this.Process(webConfigPath);
              if (result == null)
              {
            return;
              }

              result.Save(webConfigPath);
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              args.WriteLine("Extracting assemblies bundled in *.nupkg files...");

              var nugetPackages = Directory.GetFiles(args.Server.MapPath("/"), "*.nupkg", SearchOption.AllDirectories);

              foreach (var package in nugetPackages)
              {
            this.ExtractNuGetPackage(args, package);

            File.Delete(package);
              }
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              var release = args.Release;
              Assert.IsNotNull(release, "release");

              var defaultFiles = release.Defaults.Files;
              var defaultDatabases = release.Defaults.Databases;
              var defaultDatabasesNames = defaultDatabases.Keys.Select(x => x == "analytics" ? "reporting" : x).ToArray();

              this.ProcessDatabases(args, defaultDatabasesNames, defaultDatabases, defaultFiles);

              this.ProcessMasterDatabase(args, defaultDatabasesNames, defaultDatabases);
        }
        internal override void Process(ProcessorArgs args)
        {
            var root = args.Server.MapPath("/");
            var bin  = Path.Combine(root, "bin");

            if (!Directory.Exists(bin))
            {
                Directory.CreateDirectory(bin);
            }

            var appBin = Path.Combine(root, "App_Bin");

            if (!Directory.Exists(appBin))
            {
                return;
            }

            var files = Directory.GetFiles(appBin, "*", SearchOption.AllDirectories);

            foreach (var sourcePath in files)
            {
                if (sourcePath == null)
                {
                    continue;
                }

                var virtualPath = sourcePath.Substring(appBin.Length).TrimStart("/\\".ToCharArray());
                var targetPath  = Path.Combine(bin, virtualPath);
                var dir         = Path.GetDirectoryName(targetPath);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                else
                {
                    var sourceFile = new FileInfo(sourcePath);
                    var targetFile = new FileInfo(targetPath);
                    if (targetFile.Exists && targetFile.Length == sourceFile.Length)
                    {
                        // to speed up bootcamp we do not overwrite the assemblies with the same size
                        continue;
                    }
                }

                // to avoid re-deploying during next web deploy we copy instead of moving
                File.Copy(sourcePath, targetPath);
            }
        }
예제 #20
0
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var release = args.Release;

            Assert.IsNotNull(release, "release");

            var defaultFiles          = release.Defaults.Files;
            var defaultDatabases      = release.Defaults.Databases;
            var defaultDatabasesNames = defaultDatabases.Keys.Select(x => x == "analytics" ? "reporting" : x).ToArray();

            this.ProcessDatabases(args, defaultDatabasesNames, defaultDatabases, defaultFiles);

            this.ProcessMasterDatabase(args, defaultDatabasesNames, defaultDatabases);
        }
        internal override void Process(ProcessorArgs args)
        {
            args.WriteLine("Merging web.config include files...");

            var webConfigPath = args.Server.MapPath("/web.config");

            Assert.IsTrue(File.Exists(webConfigPath), "The /web.config file does not exist");

            var result = this.Process(webConfigPath);

            if (result == null)
            {
                return;
            }

            result.Save(webConfigPath);
        }
        internal override void Process(ProcessorArgs args)
        {
            var root = args.Server.MapPath("/");
              var bin = Path.Combine(root, "bin");
              if (!Directory.Exists(bin))
              {
            Directory.CreateDirectory(bin);
              }

              var appBin = Path.Combine(root, "App_Bin");
              if (!Directory.Exists(appBin))
              {
            return;
              }

              var files = Directory.GetFiles(appBin, "*", SearchOption.AllDirectories);
              foreach (var sourcePath in files)
              {
            if (sourcePath == null)
            {
              continue;
            }

            var virtualPath = sourcePath.Substring(appBin.Length).TrimStart("/\\".ToCharArray());
            var targetPath = Path.Combine(bin, virtualPath);
            var dir = Path.GetDirectoryName(targetPath);
            if (!Directory.Exists(dir))
            {
              Directory.CreateDirectory(dir);
            }
            else
            {
              var sourceFile = new FileInfo(sourcePath);
              var targetFile = new FileInfo(targetPath);
              if (targetFile.Exists && targetFile.Length == sourceFile.Length)
              {
            // to speed up bootcamp we do not overwrite the assemblies with the same size
            continue;
              }
            }

            // to avoid re-deploying during next web deploy we copy instead of moving
            File.Copy(sourcePath, targetPath);
              }
        }
예제 #23
0
        internal override void Process(ProcessorArgs args)
        {
            var filePath = args.Server.MapPath("/App_Data/bootcamp.lastrun.txt");

            if (File.Exists(filePath))
            {
                try
                {
                    File.Delete(filePath);
                }
                catch
                {
                    // we don't care if we cannot delete the file - the feature is optional
                    return;
                }
            }

            using (var writter = new StreamWriter(File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)))
            {
                foreach (var directory in new DirectoryInfo(args.Server.MapPath("/")).GetDirectories())
                {
                    if (IgnoreDirectories.Contains(directory.Name))
                    {
                        continue;
                    }

                    foreach (var file in directory.GetFiles("*", SearchOption.AllDirectories))
                    {
                        writter.Write(file.FullName);
                        writter.Write("|");
                        writter.Write(file.Length);
                        writter.Write("|");
                        writter.Write(file.LastWriteTimeUtc);

                        writter.WriteLine();
                    }
                }
            }

            var clientFilePath = args.Server.MapPath("/App_Data/bootcamp.client.lastrun.txt");

            File.WriteAllText(clientFilePath, Directory.GetFiles(args.Server.MapPath("/"), "*", SearchOption.AllDirectories).Length.ToString());
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var appData        = args.Server.MapPath("/App_Data");
            var appDataFolders = new[]
            {
                "debug", "diagnostics", "indexes", "logs", "packages", "serialization", "submit queue", "tools", "viewstate"
            };

            foreach (var name in appDataFolders)
            {
                var dir = Path.Combine(appData, name);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              var appData = args.Server.MapPath("/App_Data");
              var appDataFolders = new[]
              {
            "debug", "diagnostics", "indexes", "logs", "packages", "serialization", "submit queue", "tools", "viewstate"
              };

              foreach (var name in appDataFolders)
              {
            var dir = Path.Combine(appData, name);
            if (!Directory.Exists(dir))
            {
              Directory.CreateDirectory(dir);
            }
              }
        }
예제 #26
0
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var root          = args.Server.MapPath("/");
            var webConfigPath = Path.Combine(root, "web.config");

            if (!File.Exists(webConfigPath))
            {
                return;
            }

            var webConfig = new XmlDocument();

            webConfig.Load(webConfigPath);
            if (webConfig.SelectSingleNode("/configuration/sitecore") != null)
            {
                // to speed up bootcamp we consider web.config read-to-use if it contains <sitecore> element
                return;
            }

            var httpModule = webConfig.SelectNodes("/configuration/system.web/httpModules/add")
                             .OfType <XmlElement>()
                             .FirstOrDefault(x => x.GetAttribute("type").Contains(typeof(HttpModule).FullName));

            if (httpModule != null)
            {
                httpModule.ParentNode.RemoveChild(httpModule);
            }

            args.WriteLine("Moving /web.config to /Web_Config/Include/!root_web_config.config");
            var targetFolder    = Path.Combine(root, "Web_Config/Include");
            var targetWebConfig = Path.Combine(targetFolder, "!root_web_config.config");

            if (File.Exists(targetWebConfig))
            {
                File.Delete(targetWebConfig);
            }

            webConfig.Save(targetWebConfig);
            File.Delete(webConfigPath);
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              var connectionStringsPath = args.Server.MapPath("/App_Config/ConnectionStrings.config");
              var dir = Path.GetDirectoryName(connectionStringsPath);
              if (!Directory.Exists(dir))
              {
            Directory.CreateDirectory(dir);
              }

              if (File.Exists(connectionStringsPath) &&
              File.ReadAllText(connectionStringsPath) == args.ConnectionStringsConfig.OuterXml)
              {
            // speed up and prevent Sitecore from recycling
            return;
              }

              args.ConnectionStringsConfig.Save(connectionStringsPath);
        }
예제 #28
0
        internal override void Process(ProcessorArgs args)
        {
            var filePath = args.Server.MapPath("/App_Data/bootcamp.lastrun.txt");
              if (File.Exists(filePath))
              {
            try
            {
              File.Delete(filePath);
            }
            catch
            {
              // we don't care if we cannot delete the file - the feature is optional
              return;
            }
              }

              using (var writter = new StreamWriter(File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)))
              {
            foreach (var directory in new DirectoryInfo(args.Server.MapPath("/")).GetDirectories())
            {
              if (IgnoreDirectories.Contains(directory.Name))
              {
            continue;
              }

              foreach (var file in directory.GetFiles("*", SearchOption.AllDirectories))
              {
            writter.Write(file.FullName);
            writter.Write("|");
            writter.Write(file.Length);
            writter.Write("|");
            writter.Write(file.LastWriteTimeUtc);

            writter.WriteLine();
              }
            }
              }

              var clientFilePath = args.Server.MapPath("/App_Data/bootcamp.client.lastrun.txt");
              File.WriteAllText(clientFilePath, Directory.GetFiles(args.Server.MapPath("/"), "*", SearchOption.AllDirectories).Length.ToString());
        }
        protected ZipFile GetFileSetZip([NotNull] ProcessorArgs args, [NotNull] string type)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(type, "type");

            var release = args.Release;

            Assert.IsNotNull(release, "release");

            Assert.ArgumentNotNull(release, "release");

            args.WriteLine("Downloading " + type + " files...");

            var fileInfo = release.Defaults.Files[type].Download();

            var zipFilePath = fileInfo.FullName;

            args.WriteLine("Downloaded to " + zipFilePath);

            ZipFile zip;

            try
            {
                zip = new ZipFile(zipFilePath);
            }
            catch
            {
                args.WriteLine("Cached " + type + " files are corrupted. Re-downloading...");

                File.Delete(zipFilePath);

                fileInfo = release.Defaults.Files[type].Download();

                zipFilePath = fileInfo.FullName;
                args.WriteLine("Downloaded to " + zipFilePath);

                zip = new ZipFile(zipFilePath);
            }

            return(zip);
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var connectionStringsPath = args.Server.MapPath("/App_Config/ConnectionStrings.config");
            var dir = Path.GetDirectoryName(connectionStringsPath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            if (File.Exists(connectionStringsPath) &&
                File.ReadAllText(connectionStringsPath) == args.ConnectionStringsConfig.OuterXml)
            {
                // speed up and prevent Sitecore from recycling
                return;
            }

            args.ConnectionStringsConfig.Save(connectionStringsPath);
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              var sourceNinject = args.Server.MapPath("/bin/Ninject.dll");
              if (!File.Exists(sourceNinject))
              {
            return;
              }

              var targetNinject = args.Server.MapPath("/bin/Social/Ninject.dll");
              if (!File.Exists(targetNinject))
              {
            var dir = Path.GetDirectoryName(targetNinject);
            if (!Directory.Exists(dir))
            {
              Directory.CreateDirectory(dir);
            }

            File.Copy(sourceNinject, targetNinject);
              }
        }
예제 #32
0
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              var root = args.Server.MapPath("/");
              var webConfigPath = Path.Combine(root, "web.config");
              if (!File.Exists(webConfigPath))
              {
            return;
              }

              var webConfig = new XmlDocument();
              webConfig.Load(webConfigPath);
              if (webConfig.SelectSingleNode("/configuration/sitecore") != null)
              {
            // to speed up bootcamp we consider web.config read-to-use if it contains <sitecore> element
            return;
              }

              var httpModule = webConfig.SelectNodes("/configuration/system.web/httpModules/add")
            .OfType<XmlElement>()
            .FirstOrDefault(x => x.GetAttribute("type").Contains(typeof(HttpModule).FullName));
              if (httpModule != null)
              {
            httpModule.ParentNode.RemoveChild(httpModule);
              }

              args.WriteLine("Moving /web.config to /Web_Config/Include/!root_web_config.config");
              var targetFolder = Path.Combine(root, "Web_Config/Include");
              var targetWebConfig = Path.Combine(targetFolder, "!root_web_config.config");
              if(File.Exists(targetWebConfig))
              {
            File.Delete(targetWebConfig);
              }

              webConfig.Save(targetWebConfig);
              File.Delete(webConfigPath);
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
              var connectionStrings = args.ConnectionStringsConfig;

              var mongoConnectionStrings = new[]
              {
            "analytics",
            "tracking.live",
            "tracking.history",
            "tracking.contact",
              };

              foreach (var name in mongoConnectionStrings)
              {
            if (args.AddedConnectionStrings.Contains(name))
            {
              continue;
            }

            if (ConfigurationManager.ConnectionStrings[name] != null)
            {
              continue;
            }

            var addNode = connectionStrings.CreateElement("add");
            addNode.SetAttribute("name", name);

            var db = Path.Combine(args.Server.MapPath("/").TrimEnd('\\'), name);
            db = db.Replace("\\\\", "\\").Replace("\\", "_").Replace(":", "").Replace(".", "_");
            db = db.Length > 64 ? db.Substring(db.Length - 64) : db; // mongo db limit is 64 chars for db name
            addNode.SetAttribute("connectionString", string.Format("mongodb://localhost:27017/{0}", db));
            connectionStrings.DocumentElement.AppendChild(addNode);
            args.AddedConnectionStrings.Add(name);
              }
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var sourceNinject = args.Server.MapPath("/bin/Ninject.dll");

            if (!File.Exists(sourceNinject))
            {
                return;
            }

            var targetNinject = args.Server.MapPath("/bin/Social/Ninject.dll");

            if (!File.Exists(targetNinject))
            {
                var dir = Path.GetDirectoryName(targetNinject);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                File.Copy(sourceNinject, targetNinject);
            }
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            var connectionStrings = args.ConnectionStringsConfig;

            var mongoConnectionStrings = new[]
            {
                "analytics",
                "tracking.live",
                "tracking.history",
                "tracking.contact",
            };

            foreach (var name in mongoConnectionStrings)
            {
                if (args.AddedConnectionStrings.Contains(name))
                {
                    continue;
                }

                if (ConfigurationManager.ConnectionStrings[name] != null)
                {
                    continue;
                }

                var addNode = connectionStrings.CreateElement("add");
                addNode.SetAttribute("name", name);

                var db = Path.Combine(args.Server.MapPath("/").TrimEnd('\\'), name);
                db = db.Replace("\\\\", "\\").Replace("\\", "_").Replace(":", "").Replace(".", "_");
                db = db.Length > 64 ? db.Substring(db.Length - 64) : db; // mongo db limit is 64 chars for db name
                addNode.SetAttribute("connectionString", string.Format("mongodb://localhost:27017/{0}", db));
                connectionStrings.DocumentElement.AppendChild(addNode);
                args.AddedConnectionStrings.Add(name);
            }
        }
예제 #36
0
        internal override void Process(ProcessorArgs args)
        {
            var filePath = args.Server.MapPath("/App_Data/bootcamp.lastrun.txt");

            if (!File.Exists(filePath))
            {
                return;
            }

            try
            {
                var oldFiles =
                    File.ReadAllLines(filePath)
                    .Select(x => x.Split('|'))
                    .Select(x => new { FilePath = x[0], FileSize = x[1], LastModifiedUtc = x[2] })
                    .GetEnumerator();

                foreach (var directory in new DirectoryInfo(args.Server.MapPath("/")).GetDirectories())
                {
                    if (IgnoreDirectories.Contains(directory.Name))
                    {
                        continue;
                    }

                    foreach (var file in directory.GetFiles("*", SearchOption.AllDirectories))
                    {
                        if (oldFiles.MoveNext())
                        {
                            return;
                        }

                        if (!file.FullName.Equals(oldFiles.Current))
                        {
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                args.WriteLine("Error happened during checking for changes: " + ex.GetType() + ", Message: " + ex.Message + ", StackTrace: " + ex.StackTrace);
                try
                {
                    File.Delete(filePath);
                }
                catch
                {
                    // we don't care if we cannot delete file
                }
            }

            var fileClientPath = args.Server.MapPath("/App_Data/bootcamp.client.lastrun.txt");

            if (!File.Exists(fileClientPath))
            {
                if (args.Mode == BootcampMode.NoClient)
                {
                    throw new AbortPipelineException();
                }

                return;
            }

            try
            {
                if (int.Parse(File.ReadAllText(fileClientPath)) == Directory.GetFiles(args.Server.MapPath("/sitecore")).Length)
                {
                }
            }
            catch (Exception ex)
            {
                args.WriteLine("Error happened during checking client for changes: " + ex.GetType() + ", Message: " + ex.Message + ", StackTrace: " + ex.StackTrace);
                try
                {
                    File.Delete(fileClientPath);
                }
                catch
                {
                    // we don't care if we cannot delete file
                }

                return;
            }

            throw new AbortPipelineException();
        }
예제 #37
0
        internal override void Process(ProcessorArgs args)
        {
            var filePath = args.Server.MapPath("/App_Data/bootcamp.lastrun.txt");
              if (!File.Exists(filePath))
              {
            return;
              }

              try
              {
            var oldFiles =
              File.ReadAllLines(filePath)
            .Select(x => x.Split('|'))
            .Select(x => new { FilePath = x[0], FileSize = x[1], LastModifiedUtc = x[2] })
            .GetEnumerator();

            foreach (var directory in new DirectoryInfo(args.Server.MapPath("/")).GetDirectories())
            {
              if (IgnoreDirectories.Contains(directory.Name))
              {
            continue;
              }

              foreach (var file in directory.GetFiles("*", SearchOption.AllDirectories))
              {
            if (oldFiles.MoveNext())
            {
              return;
            }

            if (!file.FullName.Equals(oldFiles.Current))
            {
              return;
            }
              }
            }
              }
              catch (Exception ex)
              {
            args.WriteLine("Error happened during checking for changes: " + ex.GetType() + ", Message: " + ex.Message + ", StackTrace: " + ex.StackTrace);
            try
            {
              File.Delete(filePath);
            }
            catch
            {
              // we don't care if we cannot delete file
            }
              }

              var fileClientPath = args.Server.MapPath("/App_Data/bootcamp.client.lastrun.txt");
              if (!File.Exists(fileClientPath))
              {
            if (args.Mode == BootcampMode.NoClient)
            {
              throw new AbortPipelineException();
            }

            return;
              }

              try
              {
            if (int.Parse(File.ReadAllText(fileClientPath)) == Directory.GetFiles(args.Server.MapPath("/sitecore")).Length)
            {

            }
              }
              catch (Exception ex)
              {
            args.WriteLine("Error happened during checking client for changes: " + ex.GetType() + ", Message: " + ex.Message + ", StackTrace: " + ex.StackTrace);
            try
            {
              File.Delete(fileClientPath);
            }
            catch
            {
              // we don't care if we cannot delete file
            }

            return;
              }

              throw new AbortPipelineException();
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var webConfig  = args.Server.MapPath("/web.config");
            var mimeTypes  = args.Server.MapPath("/App_Config/MimeTypes.config");
            var globalAsax = args.Server.MapPath("/global.asax");
            {
                var webConfigNeeded  = !File.Exists(webConfig);
                var appConfigNeeded  = !File.Exists(mimeTypes); // if there is no MimeTypes then no other app_config files
                var globalAsaxNeeded = !File.Exists(globalAsax);

                if (!webConfigNeeded && !appConfigNeeded && !globalAsaxNeeded)
                {
                    return;
                }

                args.WriteLine("Extracting config files...");

                var release = args.Release;
                Assert.IsNotNull(release, "release");

                var confiFilesUrl  = release.Defaults.Configs.FilesUrl;
                var configFilesZip = new ConfigFiles(confiFilesUrl).Download();
                using (var zip = new ZipFile(configFilesZip.FullName))
                {
                    foreach (var zipEntry in zip.Entries ?? new ZipEntry[0])
                    {
                        if (zipEntry == null)
                        {
                            continue;
                        }

                        var virtualPath = zipEntry.FileName ?? string.Empty;
                        if (webConfigNeeded && virtualPath.Equals("web.config", StringComparison.OrdinalIgnoreCase))
                        {
                            using (var stream = File.OpenWrite(webConfig))
                            {
                                zipEntry.Extract(stream);
                            }

                            continue;
                        }

                        if (globalAsaxNeeded && virtualPath.Equals("global.asax", StringComparison.OrdinalIgnoreCase))
                        {
                            using (var stream = File.OpenWrite(globalAsax))
                            {
                                zipEntry.Extract(stream);
                            }

                            continue;
                        }

                        if (appConfigNeeded && virtualPath.StartsWith("App_Config", StringComparison.OrdinalIgnoreCase))
                        {
                            var filePath = args.Server.MapPath("/" + virtualPath.TrimStart('/'));
                            if (!File.Exists(filePath))
                            {
                                var dir = Path.GetDirectoryName(filePath);
                                if (!Directory.Exists(dir))
                                {
                                    Directory.CreateDirectory(dir);
                                }

                                using (var stream = File.OpenWrite(filePath))
                                {
                                    zipEntry.Extract(stream);
                                }
                            }
                        }
                    }
                }
            }
        }
        protected void ExtractFileSet([NotNull] ProcessorArgs args, [NotNull] ZipFile zip, [NotNull] string type)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(zip, "zip");
            Assert.ArgumentNotNull(type, "type");

            args.WriteLine("Extracting " + type + " files...");

            using (zip)
            {
                foreach (var entry in zip.SelectEntries("*") ?? new ZipEntry[0])
                {
                    if (entry == null)
                    {
                        continue;
                    }

                    var fileName = entry.FileName;
                    var prefix   = "Website/";
                    var pos      = fileName.IndexOf(prefix);
                    if (pos < 0)
                    {
                        continue;
                    }

                    var virtualPath = fileName.Substring(pos + prefix.Length);
                    var filePath    = args.Server.MapPath(virtualPath);
                    if (entry.IsDirectory)
                    {
                        if (!Directory.Exists(filePath))
                        {
                            Directory.CreateDirectory(filePath);
                        }
                    }
                    else
                    {
                        if (File.Exists(filePath))
                        {
                            continue;
                        }

                        try
                        {
                            var directoryPath = Path.GetDirectoryName(filePath);
                            if (!Directory.Exists(directoryPath))
                            {
                                Directory.CreateDirectory(directoryPath);
                            }

                            using (var file = File.OpenWrite(filePath))
                            {
                                entry.Extract(file);
                            }
                        }
                        catch (Exception ex)
                        {
                            args.WriteLine("Failed.");
                            args.WriteLine("- Exception: " + ex.GetType().FullName);
                            args.WriteLine("- Message: " + ex.Message);
                            args.WriteLine("- StackTrace: " + ex.StackTrace.Replace("\n", "<br />"));
                        }
                    }
                }
            }
        }
        internal override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              var webConfig = args.Server.MapPath("/web.config");
              var mimeTypes = args.Server.MapPath("/App_Config/MimeTypes.config");
              var globalAsax = args.Server.MapPath("/global.asax");
              {
            var webConfigNeeded = !File.Exists(webConfig);
            var appConfigNeeded = !File.Exists(mimeTypes); // if there is no MimeTypes then no other app_config files
            var globalAsaxNeeded = !File.Exists(globalAsax);

            if (!webConfigNeeded && !appConfigNeeded && !globalAsaxNeeded)
            {
              return;
            }

            args.WriteLine("Extracting config files...");

            var release = args.Release;
            Assert.IsNotNull(release, "release");

            var confiFilesUrl = release.Defaults.Configs.FilesUrl;
            var configFilesZip = new ConfigFiles(confiFilesUrl).Download();
            using (var zip = new ZipFile(configFilesZip.FullName))
            {
              foreach (var zipEntry in zip.Entries ?? new ZipEntry[0])
              {
            if (zipEntry == null)
            {
              continue;
            }

            var virtualPath = zipEntry.FileName ?? string.Empty;
            if (webConfigNeeded && virtualPath.Equals("web.config", StringComparison.OrdinalIgnoreCase))
            {
              using (var stream = File.OpenWrite(webConfig))
              {
                zipEntry.Extract(stream);
              }

              continue;
            }

            if (globalAsaxNeeded && virtualPath.Equals("global.asax", StringComparison.OrdinalIgnoreCase))
            {
              using (var stream = File.OpenWrite(globalAsax))
              {
                zipEntry.Extract(stream);
              }

              continue;
            }

            if (appConfigNeeded && virtualPath.StartsWith("App_Config", StringComparison.OrdinalIgnoreCase))
            {
              var filePath = args.Server.MapPath("/" + virtualPath.TrimStart('/'));
              if (!File.Exists(filePath))
              {
                var dir = Path.GetDirectoryName(filePath);
                if (!Directory.Exists(dir))
                {
                  Directory.CreateDirectory(dir);
                }

                using (var stream = File.OpenWrite(filePath))
                {
                  zipEntry.Extract(stream);
                }
              }
            }
              }
            }
              }
        }
예제 #41
0
        private void ProcessDatabases([NotNull] ProcessorArgs args, [NotNull] string[] defaultDatabasesNames, [NotNull] IDictionary <string, Database> defaultDatabases, [NotNull] IDictionary <string, FileSet> defaultFiles)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(defaultDatabasesNames, "defaultDatabasesNames");
            Assert.ArgumentNotNull(defaultDatabases, "defaultDatabases");
            Assert.ArgumentNotNull(defaultFiles, "defaultFiles");

            var connectionStrings = args.ConnectionStringsConfig;

            foreach (var connectionStringName in defaultDatabasesNames)
            {
                var name = connectionStringName;
                if (name == null)
                {
                    continue;
                }

                if (args.AddedConnectionStrings.Contains(name))
                {
                    continue;
                }

                if (ConfigurationManager.ConnectionStrings[name] != null)
                {
                    continue;
                }

                var defaultDatabase = this.GetDefaultDatabase(defaultDatabases, name);
                var fileName        = defaultDatabase.FileName;
                var filePath        = args.Server.MapPath(string.Format("/App_Data/Databases/{0}", fileName));
                var dir             = Path.GetDirectoryName(filePath);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                // web database is processed separately
                if (name == "web")
                {
                    continue;
                }

                if (!File.Exists(filePath))
                {
                    args.WriteLine(string.Format("Downloading {0} database...", name));

                    var tmp = Path.GetTempFileName() + ".dir";

                    try
                    {
                        var file = this.GetDefaultFile(defaultFiles, name);

                        var downloadedFile = file.Download().FullName;

                        args.WriteLine("Downloaded to " + downloadedFile);

                        args.WriteLine("Extracting " + name + " database files...");

                        using (var zip = new ZipFile(downloadedFile))
                        {
                            zip.ExtractAll(tmp);
                        }

                        var extractedFile = Directory.GetFiles(tmp, fileName, SearchOption.AllDirectories).First();
                        File.Move(extractedFile, filePath);
                    }
                    finally
                    {
                        if (Directory.Exists(tmp))
                        {
                            Directory.Delete(tmp, true);
                        }
                    }
                }

                var cstr = new SqlConnectionStringBuilder
                {
                    IntegratedSecurity = true,
                    UserInstance       = true,
                    DataSource         = ".\\SQLEXPRESS",
                    AttachDBFilename   = filePath
                };

                this.AddConnectionString(connectionStrings, name, cstr.ToString());
            }
        }
예제 #42
0
 internal abstract void Process([NotNull] ProcessorArgs args);