public static void Initialize(System.Fabric.ServiceContext context) { ApplicationName = context.CodePackageActivationContext.ApplicationName; string typeName = context.CodePackageActivationContext.ApplicationTypeName; typeName = typeName.Remove(typeName.Length - 4, 4); string unqualifiedApplicationName = $"{Constant.FabricScheme}/{typeName}"; string environmentName = ApplicationName.Replace(unqualifiedApplicationName, ""); if (environmentName.Length > 1) { // remove the . character to get the environment name extracted EnvironmentName = environmentName.Substring(1, environmentName.Length - 1); } }
public void Save(string foldername, String keyPassword = null) { if (!Directory.Exists(foldername)) { return; } String application = ApplicationName.Replace(".exe", String.Empty); String version = Version; String tempDir = String.Format(@"{2}\Application Files\{0}_{1}", application, version.Replace(".", "_"), foldername); if (Directory.Exists(tempDir)) { Directory.Delete(tempDir, true); } while (Directory.Exists(tempDir)) { } Directory.CreateDirectory(tempDir); File.Copy(DeploymentManifestFile.FullName, Path.Combine(foldername, DeploymentManifestFile.Name), true); foreach (var file in ApplicationConfigurationFile.Directory.GetFiles()) { if (file.Extension != ".application") { file.CopyTo(Path.Combine(tempDir, file.Name.Replace(".deploy", String.Empty)), true); } else { file.CopyTo(Path.Combine(foldername, file.Name.Replace(".deploy", String.Empty)), true); } } Process x = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "mage.exe"; if (ApplicationConfigurationDirty) { SaveApplicationConfigurationDetails(Path.Combine(tempDir, ApplicationConfigurationFile.Name.Replace(".deploy", String.Empty))); startInfo.Arguments = String.Format(@"-u ""{1}\{0}.exe.manifest"" -fd ""{1}""", application, tempDir); x.StartInfo = startInfo; x.Start(); x.WaitForExit(); } if (ApplicationManifestDirty) { SaveApplicationManifestDetails(String.Format(@"{1}\{0}.exe.manifest", application, tempDir)); if (keyPassword != null) { startInfo.Arguments = String.Format(@"-s ""{1}\{0}.exe.manifest"" -cf ""{2}"" -pwd {3}", application, tempDir, SigningKeyLocation, keyPassword); x.StartInfo = startInfo; x.Start(); x.WaitForExit(); } startInfo.Arguments = String.Format(@"-u ""{2}\{0}.application"" -appm ""{1}\{0}.exe.manifest""", application, tempDir, foldername); x.StartInfo = startInfo; x.Start(); x.WaitForExit(); } if (DeploymentManifestDirty) { SaveDeploymentManifestDetails(String.Format(@"{1}\{0}.application", application, foldername)); if (keyPassword != null) { startInfo.Arguments = String.Format(@"-s ""{1}\{0}.application"" -cf ""{2}"" -pwd {3}", application, foldername, SigningKeyLocation, keyPassword); x.StartInfo = startInfo; x.Start(); x.WaitForExit(); } } SigningInfoDirty = false; DirectoryInfo tempDirFI = new DirectoryInfo(tempDir); foreach (var file in tempDirFI.GetFiles()) { if (file.Extension != ".manifest") { file.MoveTo(String.Concat(file.FullName, ".deploy")); } } if (ApplicationConfigurationDirty) { SaveApplicationConfigurationDetails(); SaveApplicationManifestDetails(); SaveDeploymentManifestDetails(); } else if (ApplicationManifestDirty) { SaveApplicationManifestDetails(); } else if (DeploymentManifestDirty) { SaveDeploymentManifestDetails(); } }