public virtual int Resolve(string[] args) { Options resolveOption = new Options(); CommandLineParser parser = new GnuParser(); try { CommandLine line = parser.Parse(resolveOption, args); IList <string> argsList = line.GetArgList(); if (argsList.Count != 2) { return(UsageError("resolve requires exactly one path argument", ResolveUsage)); } if (!ValidatePath(argsList[1])) { return(-1); } try { ServiceRecord record = registry.Resolve(argsList[1]); foreach (Endpoint endpoint in record.external) { sysout.WriteLine(" Endpoint(ProtocolType=" + endpoint.protocolType + ", Api=" + endpoint .api + ");" + " Addresses(AddressType=" + endpoint.addressType + ") are: "); foreach (IDictionary <string, string> address in endpoint.addresses) { sysout.WriteLine("[ "); foreach (KeyValuePair <string, string> entry in address) { sysout.Write("\t" + entry.Key + ":" + entry.Value); } sysout.WriteLine("\n]"); } sysout.WriteLine(); } return(0); } catch (Exception e) { syserr.WriteLine(AnalyzeException("resolve", e, argsList)); } return(-1); } catch (ParseException exp) { return(UsageError("Invalid syntax " + exp, ResolveUsage)); } }
/// <summary> /// Extract all service records under a list of stat operations...this /// skips entries that are too short or simply not matching /// </summary> /// <param name="operations">operation support for fetches</param> /// <param name="parentpath">path of the parent of all the entries</param> /// <param name="stats">Collection of stat results</param> /// <returns>a possibly empty map of fullpath:record.</returns> /// <exception cref="System.IO.IOException">for any IO Operation that wasn't ignored. /// </exception> public static IDictionary <string, ServiceRecord> ExtractServiceRecords(RegistryOperations operations, string parentpath, ICollection <RegistryPathStatus> stats) { IDictionary <string, ServiceRecord> results = new Dictionary <string, ServiceRecord >(stats.Count); foreach (RegistryPathStatus stat in stats) { if (stat.size > ServiceRecord.RecordType.Length) { // maybe has data string path = RegistryPathUtils.Join(parentpath, stat.path); try { ServiceRecord serviceRecord = operations.Resolve(path); results[path] = serviceRecord; } catch (EOFException) { if (Log.IsDebugEnabled()) { Log.Debug("data too short for {}", path); } } catch (InvalidRecordException) { if (Log.IsDebugEnabled()) { Log.Debug("Invalid record at {}", path); } } catch (NoRecordException) { if (Log.IsDebugEnabled()) { Log.Debug("No record at {}", path); } } } } return(results); }
/// <summary>Assert that a path resolves to a service record</summary> /// <param name="path">path in the registry</param> /// <exception cref="System.IO.IOException"/> public virtual void AssertResolves(string path) { operations.Resolve(path); }