public static List<RedisInstance> Parse(string filePath) { List<RedisInstance> instances = new List<RedisInstance>(); try { XPathDocument csdef = new XPathDocument(filePath); XPathNavigator csdefNav = csdef.CreateNavigator(); XmlNamespaceManager nsm = new XmlNamespaceManager(csdefNav.NameTable); nsm.AddNamespace("ns", "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"); XPathNodeIterator roles = csdefNav.Select("/ns:ServiceDefinition/ns:WorkerRole", nsm); // first node must be master bool isMaster = true; int masterPort = 0; while (roles.MoveNext()) { int port = 0; string localPort = string.Empty; string extPort = string.Empty; string roleName = roles.Current.GetAttribute("name", string.Empty); XPathNodeIterator endpoint = roles.Current.Select("./ns:Endpoints/ns:InputEndpoint", nsm); if (endpoint.MoveNext()) { localPort = endpoint.Current.GetAttribute("localPort", string.Empty); extPort = endpoint.Current.GetAttribute("port", string.Empty); } if (roleName != string.Empty && localPort != string.Empty) { int.TryParse(localPort, out port); RedisInstance instance = new RedisInstance(); instance.IsMaster = isMaster; instance.LocalPort = port; instance.RoleName = roleName; if (isMaster) { if (int.TryParse(extPort, out port)) masterPort = port; } instance.MasterPort = masterPort; instances.Add(instance); isMaster = false; } } } catch (Exception ex) { Console.WriteLine("Parsing ServiceDefinition file failed: " + filePath); if (ex.InnerException != null) Console.WriteLine(ex.InnerException.Message); else Console.WriteLine(ex.Message); } return instances; }
/// <summary> /// Create the XmlConfig.xml file /// </summary> /// <param name="isEmul"></param> /// <param name="configPath"></param> /// <param name="redisConfPath"></param> /// <param name="workPath"></param> /// <param name="redisInstBinPath"></param> /// <param name="redisBinSubFolder"></param> /// <param name="domain"></param> /// <param name="subscription"></param> /// <param name="instances"></param> /// <returns></returns> public static bool CreateInstXml(bool isEmul, string configPath, string redisConfPath, string workPath, string redisInstBinPath, string redisBinSubFolder, string domain, string subscription, string pubSettingsFilePath, List <RedisInstance> instances) { RedisInstance masterInst = instances[0]; int masterIndex = 0; StringBuilder sbParams = new StringBuilder(); sbParams.AppendFormat(instXmlEmul, isEmul ? "true" : "false"); sbParams.AppendFormat(instXmlRoot, workPath, redisInstBinPath, redisBinSubFolder, configPath, redisConfPath); sbParams.AppendFormat(instXmlPubSettingsFile, pubSettingsFilePath == null ? "" : pubSettingsFilePath); sbParams.Append(instXmlSDK); if (!isEmul) { sbParams.AppendFormat(instXmlAzure, domain, subscription); } sbParams.AppendFormat(instXmlAzureCfg, isEmul ? "local" : "cloud"); int roleIndex = 0; foreach (RedisInstance inst in instances) { if (inst.IsMaster) { masterInst = inst; masterIndex = roleIndex; } sbParams.AppendFormat(instXmlRole, roleIndex, inst.RoleName, inst.LocalPort); roleIndex++; } sbParams.AppendFormat(instXmlMasterRole, masterInst.MasterPort, isEmul ? "localhost" : domain); StringBuilder sbSteps = new StringBuilder(); sbSteps.Append(instXmlStepPrep); if (!isEmul) { sbSteps.Append(instXmlStepPrepProd); } sbSteps.AppendFormat(instXmlMasterRoleStep, masterIndex); roleIndex = 0; foreach (RedisInstance inst in instances) { if (!inst.IsMaster) { sbSteps.AppendFormat(instXmlSlaveRoleStep, roleIndex); } roleIndex++; } if (isEmul) { sbSteps.Append(instXmlLaunchEmul); } else { sbSteps.Append(instXmlDeployAzure); } string xmlconfig = String.Format(instXmlSkeleton, sbParams.ToString(), sbSteps.ToString()); try { File.WriteAllText(Path.Combine(workPath, "XmlConfig.xml"), xmlconfig, Encoding.UTF8); } catch (Exception ex) { if (ex.InnerException != null) { Console.WriteLine(ex.InnerException.Message); } else { Console.WriteLine(ex.Message); } return(false); } Console.WriteLine("XmlConfig file for Inst4WA written as"); Console.WriteLine(Path.Combine(workPath, "XmlConfig.xml")); return(true); }
public static List <RedisInstance> Parse(string filePath) { List <RedisInstance> instances = new List <RedisInstance>(); try { XPathDocument csdef = new XPathDocument(filePath); XPathNavigator csdefNav = csdef.CreateNavigator(); XmlNamespaceManager nsm = new XmlNamespaceManager(csdefNav.NameTable); nsm.AddNamespace("ns", "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"); XPathNodeIterator roles = csdefNav.Select("/ns:ServiceDefinition/ns:WorkerRole", nsm); // first node must be master bool isMaster = true; int masterPort = 0; while (roles.MoveNext()) { int port = 0; string localPort = string.Empty; string extPort = string.Empty; string roleName = roles.Current.GetAttribute("name", string.Empty); XPathNodeIterator endpoint = roles.Current.Select("./ns:Endpoints/ns:InputEndpoint", nsm); if (endpoint.MoveNext()) { localPort = endpoint.Current.GetAttribute("localPort", string.Empty); extPort = endpoint.Current.GetAttribute("port", string.Empty); } if (roleName != string.Empty && localPort != string.Empty) { int.TryParse(localPort, out port); RedisInstance instance = new RedisInstance(); instance.IsMaster = isMaster; instance.LocalPort = port; instance.RoleName = roleName; if (isMaster) { if (int.TryParse(extPort, out port)) { masterPort = port; } } instance.MasterPort = masterPort; instances.Add(instance); isMaster = false; } } } catch (Exception ex) { Console.WriteLine("Parsing ServiceDefinition file failed: " + filePath); if (ex.InnerException != null) { Console.WriteLine(ex.InnerException.Message); } else { Console.WriteLine(ex.Message); } } return(instances); }