예제 #1
0
        private void WriteHeader(DnsHeader header)
        {
            bool printedWarning = false;

            WriteLine("HEADER:");
            WriteLine();
            WriteLine("Opcode: {0}, Rcode: {1}, Id: {2}, Flags: {3}",
                      DnsUtility.ToString(header.OpCode),
                      header.ResponseCode.ToString().ToUpperInvariant(), header.Id,
                      GetHeaderFlags(header));
            WriteLine("Question: {0}, Answer: {1}, Authority: {2}, Additional: {3}",
                      header.QuestionCount, header.AnswerCount, header.AuthorityCount,
                      header.AdditionalCount);
            WriteLine();
            if (header.IsTruncated)
            {
                WriteLine("WARNING: answer was truncated");
                printedWarning = true;
            }
            if (header.IsRecursionDesired && !header.IsRecursionAllowed && !header.IsAuthorative)
            {
                WriteLine("WARNING: recursion was requested but disallowed");
                printedWarning = true;
            }
            if (printedWarning)
            {
                WriteLine();
            }
        }
예제 #2
0
        /// <summary>
        /// 记录文档
        /// </summary>
        /// <param name="taskIds">任务 Id</param>
        /// <param name="status">状态</param>
        /// <param name="errorMessage">错误消息</param>
        public void Log(IEnumerable <Guid> taskIds, bool status, string errorMessage)
        {
            if (taskIds == null || !taskIds.Any())
            {
                return;
            }

            var hostName    = DnsUtility.GetLocalHostName();
            var jobEndTime  = DateTime.Now;
            var taskRecords = (from taskId in taskIds
                               select new TaskRecordDto
            {
                TopicTaskId = taskId,
                ExecuteStartTime = jobStartTime,
                ExecuteEndTime = jobEndTime,
                HostName = hostName,
                ExecutedResult = status,
                ErrorMessage = errorMessage
            });

            using (var service = ServiceLocator.Instance.Resolve <ITopicService>())
            {
                foreach (var taskRecord in taskRecords)
                {
                    service.LogTaskRecord(taskRecord);
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Writes a formatted usage message to the output.
 /// </summary>
 /// <param name="format">The format specification.</param>
 /// <param name="args">The format arguments.</param>
 protected override void WriteUsage(string format, params object[] args)
 {
     if (!string.IsNullOrEmpty(format))
     {
         WriteLine(format, args);
         WriteLine();
     }
     WriteLine("[@server] [qtype] [qclass] qname");
     WriteLine("  - retrieve info about qname");
     WriteLine("      server:      query server name or forward server index");
     WriteLine("      qtype:       query type (A,CNAME,MX,NS,PTR,SOA,TXT,...)");
     WriteLine("      qclass:      query class (IN,CH,HS,ANY)");
     WriteLine("      qname:       query target name");
     WriteLine("set opt [value]");
     WriteLine("  - set specified option, where opt is one of:");
     WriteLine("      qtype:       default qtype (current:{0})", DnsUtility.ToString(this.DefaultQueryType));
     WriteLine("      qclass:      default qclass (current:{0})", DnsUtility.ToString(this.DefaultQueryClass));
     WriteLine("      suffix:      appends name to each query (current:{0})", this.NameSuffix);
     WriteLine("      reverse:     reverse ips before display (state:{0})", GetOptionOnOff(NDigOptions.ReverseAddrs));
     WriteLine("      sort:        sort section before display (state:{0})", GetOptionOnOff(NDigOptions.SortRecords));
     WriteLine("      header:      header display mode (state:{0})", GetOptionOnOff(NDigOptions.WriteHeader));
     WriteLine("      answer:      answer section display mode (state:{0})", GetOptionOnOff(NDigOptions.WriteAnswer));
     WriteLine("      question:    question section display mode (state:{0})", GetOptionOnOff(NDigOptions.WriteQuestion));
     WriteLine("      authority:   authority section display mode (state:{0})", GetOptionOnOff(NDigOptions.WriteAuthority));
     WriteLine("      additional:  additional section display mode (state:{0})", GetOptionOnOff(NDigOptions.WriteAdditional));
     WriteLine("      stats:       query stats display mode (state:{0})", GetOptionOnOff(NDigOptions.WriteStats));
     WriteLine("      noempty:     suppress empty section display (state:{0})", GetOptionOnOff(NDigOptions.SuppressEmptySections));
     WriteLine("      nologo:      suppress program logo (state:{0})", GetOptionOnOff(NDigOptions.SuppressLogo));
     WriteLine("config");
     WriteLine("  - print resolver configuration");
     WriteLine("servers");
     WriteLine("  - print forward server list");
     WriteLine("version");
     WriteLine("  - print version and copyright header");
     WriteLine("help, ?");
     WriteLine("  - print help");
     WriteLine("exit [save]");
     WriteLine("  - exit program");
     WriteLine("      save:        save configuration (default:yes)");
 }
예제 #4
0
 /// <summary>
 /// Returns a <see cref="System.String"/> representation of this instance.
 /// </summary>
 /// <returns>A <see cref="System.String"/> representation of this instance.</returns>
 public override string ToString()
 {
     return(DnsUtility.Format("{0} {1}", base.ToString(), this.Domain));
 }
예제 #5
0
 /// <summary>
 /// Returns a <see cref="System.String"/> representation of this instance.
 /// </summary>
 /// <returns>A <see cref="System.String"/> representation of this instance.</returns>
 public override string ToString()
 {
     return(DnsUtility.Format("{0} \"{1}\" \"{2}\"", base.ToString(), this.Cpu, this.Os));
 }
예제 #6
0
 /// <summary>
 /// Returns a <see cref="System.String"/> representation of this instance.
 /// </summary>
 /// <returns>A <see cref="System.String"/> representation of this instance.</returns>
 public override string ToString()
 {
     return(DnsUtility.Format("{0} {1}", base.ToString(), DnsUtility.ToString(this.Data)));
 }
예제 #7
0
 /// <summary>
 /// Returns a <see cref="System.String"/> representation of this instance.
 /// </summary>
 /// <returns>A <see cref="System.String"/> representation of this instance.</returns>
 public override string ToString()
 {
     return(DnsUtility.Format("{0} {1} {2}", base.ToString(), this.RMbox, this.EMbox));
 }
예제 #8
0
 /// <summary>
 /// Returns a <see cref="System.String"/> representation of this instance.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(DnsUtility.Format("{0} {1}", base.ToString(), this.Canonical));
 }
예제 #9
0
 /// <summary>
 /// Returns a <see cref="System.String"/> representation of this instance.
 /// </summary>
 /// <returns>A <see cref="System.String"/> representation of this instance.</returns>
 public override string ToString()
 {
     return(DnsUtility.Format("{0} {1} {2} {3} {4} {5} {6} {7}",
                              base.ToString(), this.Master, this.RMbox, this.Serial, DnsUtility.ToString(this.Refresh),
                              DnsUtility.ToString(this.Retry), DnsUtility.ToString(this.Expire), DnsUtility.ToString(this.Minimum)));
 }
예제 #10
0
 /// <summary>
 /// Returns a <see cref="System.String"/> representation of this instance.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(DnsUtility.Format("{0} {1}", base.ToString(), this.NewMailbox));
 }
예제 #11
0
 /// <summary>
 /// Returns a <see cref="System.String"/> representation of this instance.
 /// </summary>
 /// <returns>A <see cref="System.String"/> representation of this instance.</returns>
 public override string ToString()
 {
     return(DnsUtility.Format("{0} \"{1}\"", base.ToString(), this.Text));
 }
예제 #12
0
 /// <summary>
 /// Returns a <see cref="System.String"/> representation of this instance.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return(DnsUtility.Format("{0} {1,-2} {2,-2} {3,-2} {4,-2}", base.ToString(),
                              this.Priority, this.Weight, this.Port, this.Target));
 }
예제 #13
0
        private void DoSetCommand(string[] args)
        {
            switch (args[0].ToLowerInvariant())
            {
            case "suffix":
                DnsName suffix = null;

                if (args.Length == 2 && !DnsName.TryParse(args[1], out suffix))
                {
                    WriteUsage("value: '{0}' is not a valid name", args[1]);
                    return;
                }
                this.NameSuffix = suffix;
                WriteLine("suffix set: {0}", this.NameSuffix);
                break;

            case "qclass":
                DnsQueryClass qclass = DnsQueryClass.IN;

                if (args.Length == 2 && !TryParseEnum(args[1], out qclass))
                {
                    WriteUsage("value: '{0}' is not a valid qclass", args[1]);
                    return;
                }
                this.DefaultQueryClass = qclass;
                WriteLine("qclass set: {0}", DnsUtility.ToString(this.DefaultQueryClass));
                break;

            case "qtype":
                DnsQueryType qtype = DnsQueryType.A;

                if (args.Length == 2 && !TryParseEnum(args[1], out qtype))
                {
                    WriteUsage("value: '{0}' is not a valid qtype", args[1]);
                    return;
                }
                this.DefaultQueryType = qtype;
                WriteLine("qtype set: {0}", DnsUtility.ToString(this.DefaultQueryType));
                break;

            case "reverse":
                ParseBooleanOption(NDigOptions.ReverseAddrs, "reverse", args);
                break;

            case "sort":
                ParseBooleanOption(NDigOptions.SortRecords, "sort", args);
                break;

            case "header":
                ParseBooleanOption(NDigOptions.WriteHeader, "header", args);
                break;

            case "question":
                ParseBooleanOption(NDigOptions.WriteQuestion, "question", args);
                break;

            case "answer":
                ParseBooleanOption(NDigOptions.WriteAnswer, "answer", args);
                break;

            case "authority":
                ParseBooleanOption(NDigOptions.WriteAuthority, "authority", args);
                break;

            case "additional":
                ParseBooleanOption(NDigOptions.WriteAdditional, "additional", args);
                break;

            case "stats":
                ParseBooleanOption(NDigOptions.WriteStats, "stats", args);
                break;

            case "noempty":
                ParseBooleanOption(NDigOptions.SuppressEmptySections, "noempty", args);
                break;

            case "nologo":
                ParseBooleanOption(NDigOptions.SuppressLogo, "nologo", args);
                break;

            default:
                WriteUsage("opt: '{0}' is not a valid option", args[0]);
                return;
            }
        }
예제 #14
0
 /// <summary>
 /// Returns a <see cref="System.String"/> representation of this instance.
 /// </summary>
 /// <returns>A <see cref="System.String"/> representation of this instance.</returns>
 public override string ToString()
 {
     return(DnsUtility.Format("{0} \"{1}\"", base.ToString(), this.Specification));
 }
예제 #15
0
 /// <summary>
 /// Returns a <see cref="System.String"/> representation of this instance.
 /// </summary>
 /// <returns>A <see cref="System.String"/> representation of this instance.</returns>
 public override string ToString()
 {
     return(DnsUtility.Format("{0} {1,-2} {2}", base.ToString(), this.Preference,
                              this.Exchange));
 }