private bool TryLoadXml(string pkgDir, out Dictionary <string, string> xml) { xml = new Dictionary <string, string>(); xml["ApplicationManifestDir"] = pkgDir; // first load ApplicationManifest string appFile = new FileInfo(Path.Combine(pkgDir, "ApplicationManifest.xml")).FullName; xml["ApplicationManifestFile"] = appFile; if (!File.Exists(appFile)) { log.Error("Cannot find ApplicationManifest at '" + appFile + "'"); return(false); } var appMan = Load.ApplicationManifest(appFile); if (appMan == null) { return(false); } xml[AppName] = appMan.ApplicationTypeName; xml[AppVersion] = appMan.ApplicationTypeVersion; if (appMan.Parameters != null && appMan.Parameters.Length > 0) { bool paramOnce = false; StringBuilder sb = new StringBuilder(); foreach (var p in appMan.Parameters) { if (paramOnce) { sb.Append(PackageSettings.ApplicationParameterSplitChar); } sb.Append(p.Name); sb.Append('='); sb.Append(p.DefaultValue); paramOnce = true; } xml[Defaults.ApplicationParameters] = sb.ToString(); } ServiceType svcTempl0 = null; // get servicetemplate info if (appMan.ServiceTemplates != null && appMan.ServiceTemplates.Length > 0) { svcTempl0 = appMan.ServiceTemplates[0]; if (svcTempl0 is StatefulServiceType) { StatefulServiceType sst = (StatefulServiceType)svcTempl0; xml["ServiceStateful"] = "true"; xml["ServiceType"] = sst.ServiceTypeName; xml["ServiceStatefulMinReplica"] = sst.MinReplicaSetSize.ToString(); xml["ServiceStatefulTargetReplica"] = sst.TargetReplicaSetSize.ToString(); this.UpdatePartitionInfo(xml, sst); } else if (svcTempl0 is StatelessServiceType) { StatelessServiceType sst = (StatelessServiceType)svcTempl0; xml["ServiceStateless"] = "true"; xml["ServiceType"] = sst.ServiceTypeName; xml["ServiceStatelessCount"] = sst.InstanceCount.ToString(); this.UpdatePartitionInfo(xml, sst); } } // next load ServiceManifest if (appMan.ServiceManifestImport.Length != 1) { log.Error("Can only verify 1 service manifest"); return(false); } ServiceManifestRefType manRef = appMan.ServiceManifestImport[0].ServiceManifestRef; xml["ServiceManifestName"] = manRef.ServiceManifestName; string svcDir = Path.Combine(pkgDir, manRef.ServiceManifestName); xml["ServiceManifestDir"] = svcDir; if (!Directory.Exists(svcDir)) { log.Error("Could not find service manifest folder at '{0}'", svcDir); return(false); } string svcFile = Path.Combine(svcDir, "ServiceManifest.xml"); xml["ServiceManifestFile"] = svcFile; if (!File.Exists(svcFile)) { log.Error("Cannot find ServiceManifest at '{0}'", svcFile); return(false); } var svcMan = Load.ServiceManifest(svcFile); if (svcMan == null) { log.Error("Service manifest was not able to be loaded"); return(false); } if (!manRef.ServiceManifestName.Equals(svcMan.Name)) { log.Error("Service names don't match, ApplicationManifest ref is '{0}' but ServiceManifest is '{1}'", manRef.ServiceManifestName, svcMan.Name); return(false); } xml[SvcName] = svcMan.Name; /* * if (svcMan.ServiceTypes.Count != 1) * { * log.Error("Only expected 1 service type in manifest, found={0}", svcMan.ServiceTypes.Count); * return false; * } */ object o = svcMan.ServiceTypes[0]; if (o is StatefulServiceTypeType) { StatefulServiceTypeType sstt = (StatefulServiceTypeType)o; if (sstt.HasPersistedState) { xml["ServiceStatefulPersisted"] = "true"; } } string svcManSvcType = GetServiceTypeName(o); if (svcTempl0 != null && !svcManSvcType.Equals(svcTempl0.ServiceTypeName)) { log.Error("Service type names don't match, Application ServiceTemplate name is '{0}' but ServiceManifest SerciveTypeName is '{1}'", svcTempl0.ServiceTypeName, svcManSvcType); return(false); } xml["ServiceVersion"] = svcMan.Version; StringBuilder exeSb = new StringBuilder(); StringBuilder folderSb = new StringBuilder(); bool once = false; foreach (CodePackageType cpt in svcMan.CodePackage) { EntryPointDescriptionType entDesc = cpt.EntryPoint; EntryPointDescriptionTypeExeHost exeHost = entDesc.Item as EntryPointDescriptionTypeExeHost; if (exeHost == null) { log.Error("Could not find ExeHost description"); return(false); } if (once) { exeSb.Append(','); folderSb.Append(','); } folderSb.Append(cpt.Name); exeSb.Append(exeHost.Program); once = true; } xml[Defaults.ServiceCodeFolder] = folderSb.ToString(); xml[Defaults.ServiceExeHost] = exeSb.ToString(); return(true); }