GetWebProjectDirectory() public method

public GetWebProjectDirectory ( ) : string
return string
Exemplo n.º 1
0
        private static int GetEpiserverVersion(WebsiteContext context)
        {
            if (context.ExitAtNextCheck)
                return -1;

            if (context.EpiserverVersion > 0)
                return context.EpiserverVersion;

            // try to find an episerver .dll
            var episerverDllFilePath = Directory.EnumerateFiles(context.CurrentDirectory, "EPiServer.dll", SearchOption.AllDirectories).FirstOrDefault();
            var packagesConfigPath = Path.Combine(context.GetWebProjectDirectory(), "packages.config");

            if (episerverDllFilePath != null) {
                var version = FileVersionInfo.GetVersionInfo(episerverDllFilePath);
                return version.FileMajorPart;
            }

            // look in the package.config file for episerver
            if (File.Exists(packagesConfigPath)) {
                var doc = XDocument.Load(packagesConfigPath);
                var episerverPackage = doc.Descendants("package").FirstOrDefault(x => x.Attribute("id").Value == "EPiServer.CMS.Core");

                if (episerverPackage != null) {
                    var versionString = episerverPackage.Attribute("version").Value;
                    var version = Version.Parse(versionString);
                    return version.Major;
                }
            }

            return -1;
        }
Exemplo n.º 2
0
        private void UpdateEpiserverFrameworkFile(WebsiteContext context, long siteId)
        {
            var episerverFrameworkFile = Directory.EnumerateFiles(context.GetWebProjectDirectory(), "EPiServerFramework.config", SearchOption.AllDirectories).FirstOrDefault();

            if (episerverFrameworkFile == null) {
                Logger.Error("Could not find an EPiServerFramework.config file.");
                return;
            }

            var doc = XDocument.Load(episerverFrameworkFile);
            var key = string.Format("/LM/W3SVC/{0}/ROOT:{1}", siteId, Environment.MachineName);
            var automaticSiteMappingElement = doc.Descendants("automaticSiteMapping").FirstOrDefault();

            if (automaticSiteMappingElement == null)
            {
                Logger.Warn("AutomaticSiteMapping element could not be found in EPiServerFramework.config");
                return;
            }

            var alreadyUpdated = automaticSiteMappingElement.Descendants().Any(element => element.Attribute("key").Value.Equals(key));

            if (alreadyUpdated) {
                Logger.Warn("No change needed.");
                return;
            }

            var fileAttributes = File.GetAttributes(episerverFrameworkFile);
            var hadReadOnly = false;
            var epiSiteId = doc.Descendants("siteHosts").FirstOrDefault().Attribute("siteId").Value;

            if (IsReadOnly(fileAttributes)) {
                fileAttributes = RemoveAttribute(fileAttributes, FileAttributes.ReadOnly);
                File.SetAttributes(episerverFrameworkFile, fileAttributes);
                hadReadOnly = true;
            }

            // add new site mapping
            automaticSiteMappingElement.Add(new XElement("add", new XAttribute("key", key), new XAttribute("siteId", epiSiteId)));
            doc.Save(episerverFrameworkFile);

            if (hadReadOnly) {
                fileAttributes = SetAttribute(fileAttributes, FileAttributes.ReadOnly);
                File.SetAttributes(episerverFrameworkFile, fileAttributes);
            }

            Logger.Success("EPiServerFramework.config has been updated.");
            Logger.Success("Do not forget to update the file in source control.");
        }
Exemplo n.º 3
0
        public void Execute(WebsiteContext context)
        {
            // EPiServerFramework.config came with CMS 6
            if (context.EpiserverVersion < 6) {
                Logger.Warn("No change needed.");
                return;
            }

            using (ServerManager manager = new ServerManager()) {
                var webProjectDirectory = context.GetWebProjectDirectory();
                var site = manager.Sites.SingleOrDefault(s => s.Applications.Any(app => app.VirtualDirectories.Any(dir => dir.PhysicalPath == webProjectDirectory)));

                if (site == null) {
                    Logger.Warn("Could not find a matching site in IIS.");
                    return;
                }

                UpdateEpiserverFrameworkFile(context, site.Id);
            }
        }
Exemplo n.º 4
0
        private static double GetFrameworkVersion(WebsiteContext context)
        {
            if (context.ExitAtNextCheck)
                return -1;

            if (context.FrameworkVersion > 0)
                return context.FrameworkVersion;

            var webProjectFilePath = Directory.EnumerateFiles(context.GetWebProjectDirectory(), "*.csproj").FirstOrDefault();

            if (string.IsNullOrEmpty(webProjectFilePath) || !File.Exists(webProjectFilePath)) {
                context.ExitAtNextCheck = true;
                Console.WriteLine("The .csproj file for the \"{1}\" (web) project could not be found. Looked at: {0}",
                                  webProjectFilePath, context.WebProjectName);
                return -1;
            }

            var doc = XDocument.Load(webProjectFilePath);
            var targetFrameworkVersion = doc.Descendants().FirstOrDefault(x => x.Name.LocalName == "TargetFrameworkVersion");

            if (targetFrameworkVersion == null) {
                context.ExitAtNextCheck = true;
                Console.WriteLine("Could not find TargetFrameworkVersion in Web project.");
                return -1;
            }

            var versionString = targetFrameworkVersion.Value.Replace("v", string.Empty);

            double version;

            if (!Double.TryParse(versionString, out version)) {
                context.ExitAtNextCheck = true;
                Console.WriteLine("Could not parse Framework Version from {0}.", versionString);
                return -1;
            }

            return version;
        }
Exemplo n.º 5
0
        public void Execute(WebsiteContext context)
        {
            var licenseDirectory = Config.Instance.EpiserverLicensePath;
            var webProjectPath = context.GetWebProjectDirectory();
            var licensePath = Path.Combine(webProjectPath, LICENSE_FILENAME);

            if (File.Exists(licensePath)) {
                Logger.Warn("License file already exists.");
                return;
            }

            if (licenseDirectory.IsNullOrEmpty()) {
                Logger.Warn("Skipping because config is missing for EPiServer license directory.");
                Logger.Log(@"To update run command:");
                Logger.TabIndention += 1;
                Logger.Log(@"wia config license.directory c:\path\to\directory");
                Logger.TabIndention -= 1;
                return;
            }

            try {
                string licenseFileNeeded = Path.Combine(licenseDirectory, "CMS" + context.EpiserverVersion, LICENSE_FILENAME);

                if (!File.Exists(licenseFileNeeded)) {
                    Logger.Error("Required license file could not be found.");
                    Logger.Error("Path: " + licenseFileNeeded);
                    return;
                }

                File.Copy(licenseFileNeeded, licensePath);
            }
            catch (Exception ex) {
                Logger.Error("Failed to copy license file to website: " + ex.Message);
                return;
            }

            Logger.Success("Copied license file for EPiServer CMS {0} to website.", context.EpiserverVersion);
        }
Exemplo n.º 6
0
        public void Execute(WebsiteContext context)
        {
            if (!context.HasAdministratorPrivileges()) {
                Logger.Error("Could not execute Webserver task without administrator rights.");
                return;
            }

            using (ServerManager manager = new ServerManager()) {
                var webProjectDirectory = context.GetWebProjectDirectory();
                var siteAlreadyExists = manager.Sites.Any(s => s.Applications.Any(app => app.VirtualDirectories.Any(dir => dir.PhysicalPath == webProjectDirectory)));

                if (siteAlreadyExists) {
                    Logger.Warn("Site already exists in IIS.");
                    return;
                }

                var name = context.ProjectName;
                var host = new Uri(context.ProjectUrl).Host;

                // Create appool with project name
                var appPool = manager.ApplicationPools.Add(name);
                appPool.ManagedRuntimeVersion = GetFrameworkVersion(context);

                appPool.ProcessModel.PingingEnabled = false;
                appPool.Enable32BitAppOnWin64 = context.Enable32Bit;
                appPool.ManagedPipelineMode = context.AppPoolMode == AppPoolMode.Integrated
                                                  ? ManagedPipelineMode.Integrated
                                                  : ManagedPipelineMode.Classic;

                if (!string.IsNullOrEmpty(Config.Instance.AppPoolUsername)) {
                    Logger.Log("Setting AppPool identity...");

                    var password = Config.Instance.AppPoolPassword;

                    if (string.IsNullOrEmpty(password)) {
                        Logger.Warn("Please fill in password for AppPool identity user!");
                        Console.WriteLine("\tUsername: "******"\tPassword: "******"Created a new AppPool with .NET {0} named {1}", appPool.ManagedRuntimeVersion, name);

                // Create site with appool.
                Site site = manager.Sites.Add(name, webProjectDirectory, 80);
                site.ServerAutoStart = true;
                site.Applications[0].ApplicationPoolName = name;
                Logger.Log("Created a new site named " + name);

                site.Bindings.Clear();
                site.Bindings.Add("*:80:" + host, "http");
                Logger.Log("Added binding for " + host);

                try {
                    manager.CommitChanges();
                    Logger.Success("Site and AppPool has been created in IIS.");
                }
                catch (Exception ex) {
                    Logger.Error(ex.ToString());
                    context.ExitAtNextCheck = true;
                }
            }
        }
Exemplo n.º 7
0
        private static string GetProjectUrl(WebsiteContext context)
        {
            if (context.ExitAtNextCheck)
                return null;

            var projectUrl = context.ProjectUrl;

            if (!string.IsNullOrWhiteSpace(projectUrl)) {
                if (!projectUrl.StartsWith("http://"))
                    projectUrl = "http://" + projectUrl;

                return projectUrl;
            }

            var webProjectFolderPath = context.GetWebProjectDirectory();
            var episerverConfigPath = Directory.GetFiles(webProjectFolderPath, "episerver.config", SearchOption.AllDirectories)
                                               .FirstOrDefault();

            if (!File.Exists(episerverConfigPath)) {
                // the episerver config section might be in web.config
                var webConfigPath = Path.Combine(webProjectFolderPath, "web.config");

                if (!File.Exists(webConfigPath)) {
                    // serious trouble if this file can not be found.
                    context.ExitAtNextCheck = true;
                    Console.WriteLine("The web.config file could not be found in " + webProjectFolderPath);
                    return null;
                }

                episerverConfigPath = webConfigPath;
            }

            var doc = XDocument.Load(episerverConfigPath);
            var siteSettings = doc.Descendants().FirstOrDefault(x => x.Name.LocalName == "siteSettings");

            if (siteSettings == null) {
                context.ExitAtNextCheck = true;
                Console.WriteLine("Could not find the EPiServer configuration section in neither episerver.config or web.config.");
                return null;
            }

            projectUrl = siteSettings.Attribute("siteUrl").Value;
            return projectUrl;
        }