Example #1
0
        public override void Write(RecordType type, TlsVersion version, byte[] data)
        {
            var cipher = GetCipher().Cipher;

            // TODO parametrised from CipherSpec
            var explicitNonceLength = 8;
            var nonce = RandomGenerator.RandomBytes(explicitNonceLength);

            var aad = new byte[13];
            Array.Copy(EndianBitConverter.Big.GetBytes(State.WriteSeqNum++), 0, aad, 0, 8);
            Array.Copy(new[] { (byte)type, version.Major, version.Major }, 0, aad, 8, 3);
            Array.Copy(EndianBitConverter.Big.GetBytes((ushort)data.Length), 0, aad, 11, 2);

            var payload = new byte[explicitNonceLength + data.Length + cipher.TagLength];
            Array.Copy(nonce, payload, explicitNonceLength);

            cipher.Init(State.GetAEADParameters(false, aad, nonce));

            var payloadLength = explicitNonceLength;
            payloadLength += cipher.Encrypt(data, 0, payload, payloadLength, data.Length);
            payloadLength += cipher.EncryptFinal(payload, payloadLength);

            Writer.Write(type);
            Writer.Write(version);
            Writer.Write((ushort)payloadLength);
            Writer.Write(payload, 0, payloadLength);
        }
        public void AssertMxRecordAncestorIsObsolete(RecordType recordType)
        {
            var expectedMessage = "Obsolete - use an MX record.";
            var attribute = recordType.Attribute<ObsoleteAttribute>();

            Assert.That(attribute.Message, Is.EqualTo(expectedMessage));
        }
Example #3
0
        public override Record Read(RecordType type, TlsVersion version, ushort length)
        {
            var cipher = GetCipher().Cipher;

            // TODO parametrised from CipherSpec
            var explicitNonceLength = 8;

            var nonce = Reader.ReadBytes(explicitNonceLength);
            var payload = Reader.ReadBytes(length - explicitNonceLength);

            var aad = new byte[13];
            Array.Copy(EndianBitConverter.Big.GetBytes(State.ReadSeqNum++), 0, aad, 0, 8);
            Array.Copy(new[] { (byte)type, version.Major, version.Major }, 0, aad, 8, 3);
            Array.Copy(EndianBitConverter.Big.GetBytes((ushort)(length - explicitNonceLength - cipher.TagLength)), 0, aad, 11, 2);

            cipher.Init(State.GetAEADParameters(true, aad, nonce));

            var plaintext = new byte[payload.Length - cipher.TagLength];
            var plaintextLength = cipher.Decrypt(payload, 0, plaintext, 0, payload.Length - cipher.TagLength);
            plaintextLength += cipher.DecryptFinal(payload, plaintextLength, plaintext, plaintextLength);

            Array.Resize(ref plaintext, plaintextLength);

            return new Record(type, version, plaintext);
        }
Example #4
0
		protected DnsRecordBase(string name, RecordType recordType, RecordClass recordClass, int timeToLive)
		{
			Name = name ?? String.Empty;
			RecordType = recordType;
			RecordClass = recordClass;
			TimeToLive = timeToLive;
		}
        public static RecordData RecordDataFor(RecordType recordType)
        {
            switch (recordType)
            {
                case RecordType.A:
                    return new AddressData(recordType);
                case RecordType.AAAA:
                    return new IPv6AddressData(recordType);
                case RecordType.CNAME:
                case RecordType.MB: // Experimental
                case RecordType.MD: // Obsolete.. Should throw exception instead? Or use MX?
                case RecordType.MF: // Obsolete.. Should throw exception instead? Or use MX?
                case RecordType.MG: // Experimental
                case RecordType.MR: // Experimental
                case RecordType.NS:
                case RecordType.PTR:
                    return new DomainNameData(recordType);
                case RecordType.HINFO:
                    return new HostInformationData(recordType);
                case RecordType.MINFO:
                    return new MailInformationData(recordType);
                case RecordType.MX:
                    return new MailExchangeData(recordType);
                case RecordType.SOA:
                    return new StartOfAuthorityData(recordType);
                case RecordType.TXT:
                    return new TextData(recordType);
                case RecordType.WKS:
                    return new WellKnownServiceData(recordType);
                case RecordType.NULL: // Experimental
                    return new NullData(recordType);

            }
            return new NullData(recordType);
        }
Example #6
0
 public void WriteQuestion(Name name, RecordType qtype, RecordClass qclass = RecordClass.Internet)
 {
     WriteName(name);
     WriteUInt16((ushort)qtype);
     WriteUInt16((ushort)qclass);
     _questionCount++;
 }
Example #7
0
 public void Add(string controllerId, int count, string reason, RecordType type=RecordType.Permanent)
 {
     if (!Records.ContainsKey(controllerId))
         Records[controllerId] = new List<ScoreRecord>();
     Records[controllerId].Add(new ScoreRecord(count, reason, world.Clocks.CurrentTime, type));
     if (ScoresChanged != null) ScoresChanged();
 }
Example #8
0
 private Record(List<DateTime> records, int minutes, DateTime day, RecordType type)
 {
     mRecordsOfDay = records;
     mMinutes = minutes;
     mDay = day;
     mType = type;
 }
		protected ResourceRecordBase(string name, int timeToLive, RecordType recordType, string recordClass = "IN")
		{
			Name = name;
			TimeToLive = timeToLive;
			_recordType = recordType;
			RecordClass = recordClass;
		}
Example #10
0
        public Record(Socket socket, Buffers receive_buffer)
            : this()
        {
            if (socket == null)
                throw new ArgumentNullException ("socket");

            CompatArraySegment<byte> header_buffer = receive_buffer.EnforceHeaderLength (HeaderSize);

            // Read the 8 byte record header.
            ReceiveAll (socket, header_buffer, HeaderSize);

            // Read the values from the data.
            version        = header_buffer [0];
            type           = (RecordType) header_buffer [1];
            request_id     = ReadUInt16 (header_buffer, 2);
            BodyLength     = ReadUInt16 (header_buffer, 4);
            byte padding_length = header_buffer [6];

            CompatArraySegment<byte> body_buffer  = receive_buffer.EnforceBodyLength (BodyLength);

            // Read the record data, and throw an exception if the
            // complete data cannot be read.
            if (BodyLength > 0)
                ReceiveAll (socket, body_buffer, BodyLength);

            CompatArraySegment<byte> padding_buffer = receive_buffer.EnforcePaddingLength (padding_length);

            if(padding_length > 0)
                ReceiveAll(socket, padding_buffer, padding_length);

            buffers = receive_buffer;

            Logger.Write (LogLevel.Debug, Strings.Record_Received, Type, RequestID, BodyLength);
        }
Example #11
0
		public Record (byte version, RecordType type, ushort requestID,
		               byte[] bodyData, int bodyIndex, int bodyLength)
		{
			if (bodyData == null)
				throw new ArgumentNullException ("bodyData");

			if (bodyIndex < 0 || bodyIndex > bodyData.Length)
				throw new ArgumentOutOfRangeException (
					"bodyIndex");

			if (bodyLength < 0)
				bodyLength = bodyData.Length - bodyIndex;

			if (bodyLength > MaxBodySize)
				throw new ArgumentException (
					Strings.Record_DataTooBig,
					"data");


			this.Version = version;
			this.Type = type;
			this.RequestId = requestID;
			this.Body = bodyData;
			this.BodyOffset = bodyIndex;
			this.BodyLength = (ushort)bodyLength;
			this.PaddingLength = 0;
		}
Example #12
0
 public AudioParameters(RecordType recordType, int durationLimit, int sizeLimit, params string[] supportedExtensions)
 {
     DurationLimit = durationLimit;
     SizeLimit = sizeLimit;
     SupportedExtensions = supportedExtensions;
     AudioRecordType = recordType;
 }
 internal ResourceRecord(string name, RecordType type, RecordClass rClass, DateTime expiry)
 {
     _name = name;
     _type = type;
     _class = rClass;
     _expiry = expiry;
 }
 private DnsResponse(ushort messageId, DnsName queryName, RecordType queryType, RecordClass queryClass)
 {
     this.MessageId = messageId;
     this.QueryName = queryName;
     this.QueryType = queryType;
     this.QueryClass = queryClass;
 }
Example #15
0
        public ResourceRecord(DnsReader br)
        {
            _domain = br.ReadDomain();
            _qtype = (RecordType)br.ReadInt16();
            _qclass = (RecordClass)br.ReadInt16();
            _ttl = br.ReadInt32();

            int recordLength = br.ReadInt16();
            if (recordLength != 0)
            {
                switch (_qtype)
                {
                    case RecordType.A:     _record = new ARecord(br);      break;
                    case RecordType.CNAME: _record = new CNAMERecord(br);  break;
                    case RecordType.MX:    _record = new MXRecord(br);     break;
                    case RecordType.NS:    _record = new NSRecord(br);     break;
                    case RecordType.SOA:   _record = new SOARecord(br);    break;
                    case RecordType.TXT:   _record = new TXTRecord(br);    break;
                    case RecordType.PTR:   _record = new PTRERecord(br);	break;

                    // NetBIOS related records
                    case RecordType.NB:    _record = new NBRecord(br);     break;

                    default:
                        br += recordLength;
                        break;
                }
            }
        }
 public WellKnownServiceData(RecordType recordType)
 {
     _address = new AddressData(recordType);
     _protocol = 0;
     _bitMap = new byte[0];
     _recordType = recordType;
 }
Example #17
0
        /// <summary>
        /// Retrieves whois information
        /// </summary>
        /// <param name="domainName">The registrar or domain or name server whose whois information to be retrieved</param>
        /// <param name="recordType">The type of record i.e a domain, nameserver or a registrar</param>
        /// <returns></returns>
        public static string Lookup(string domainName, RecordType recordType)
        {
            string whoisServerName = WhoisServerResolver.GetWhoisServerName(domainName);
            using (TcpClient whoisClient = new TcpClient())
            {
                whoisClient.Connect(whoisServerName, Whois_Server_Default_PortNumber);

                string domainQuery = recordType.ToString() + " " + domainName + "\r\n";
                byte[] domainQueryBytes = Encoding.ASCII.GetBytes(domainQuery.ToCharArray());

                Stream whoisStream = whoisClient.GetStream();
                whoisStream.Write(domainQueryBytes, 0, domainQueryBytes.Length);

                StreamReader whoisStreamReader = new StreamReader(whoisClient.GetStream(), Encoding.ASCII);

                string streamOutputContent = "";
                List<string> whoisData = new List<string>();
                while (null != (streamOutputContent = whoisStreamReader.ReadLine()))
                {
                    whoisData.Add(streamOutputContent);
                }

                whoisClient.Close();

                return String.Join(Environment.NewLine, whoisData);
            }
        }
Example #18
0
        public override Record Read(RecordType type, TlsVersion version, ushort length)
        {
            SecurityAssert.SAssert(length <= 0x4000);

            var data = Reader.ReadBytes(length);

            return new Record(type, version, data);
        }
 /// <summary>
 /// Creates a RecordSet within a DNS zone.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Dns.IRecordSetOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='zoneName'>
 /// Required. The name of the zone without a terminating dot.
 /// </param>
 /// <param name='relativeRecordSetName'>
 /// Required. The name of the RecordSet, relative to the name of the
 /// zone.
 /// </param>
 /// <param name='recordType'>
 /// Required. The type of DNS record.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the CreateOrUpdate operation.
 /// </param>
 /// <returns>
 /// The response to a RecordSet CreateOrUpdate operation.
 /// </returns>
 public static RecordSetCreateOrUpdateResponse CreateOrUpdate(this IRecordSetOperations operations, string resourceGroupName, string zoneName, string relativeRecordSetName, RecordType recordType, RecordSetCreateOrUpdateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IRecordSetOperations)s).CreateOrUpdateAsync(resourceGroupName, zoneName, relativeRecordSetName, recordType, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Example #20
0
 public ScoreRecord(int count, string reason, double time, 
     RecordType type=RecordType.Permanent)
 {
     Count = count;
     Reason = reason;
     Time = time;
     Type = type;
 }
Example #21
0
        public Record(RecordType type, TlsVersion version, byte[] data)
        {
            Type = type;
            Version = version;

            SecurityAssert.NotNull(data);
            Data = data;
        }
Example #22
0
		public Record (byte version, RecordType type, ushort requestID, int bodyLength, Buffers buffers) : this()
		{
			Version = version;
			Type = type;
			RequestID  = requestID;
			BodyLength = (ushort) bodyLength;
			Content = buffers;
		}
Example #23
0
        public override void Write(RecordType type, TlsVersion version, byte[] data)
        {
            Writer.Write(type);
            Writer.Write(version);
            Writer.Write((ushort)data.Length);
            Writer.Write(data, 0, data.Length);

        }
Example #24
0
        protected virtual Record Read(RecordType recordType, string text)
        {
            var reader = readers.Resolve(recordType);
            if (reader != null)
                return reader.Read(text);

            return new Record(recordType, text);
        }
Example #25
0
 public Recorder(ISimulation hostsimulator, RecordType recordtype, string recordfile)
 {
     this.hostsimulator = hostsimulator;
     this.recordtype = recordtype;
     this.recordfile = recordfile;
     potentialfile = spikefile = null;
     potentialwriter = spikewriter = null;
 }
 protected DnsMessageBase(ushort messageId, DnsName queryName, RecordType queryType, RecordClass queryClass)
     : this()
 {
     this.MessageId = messageId;
     this.QueryCount = 1;
     this.QueryName = queryName;
     this.QueryType = queryType;
     this.QueryClass = queryClass;
 }
 public ResourceRecord(Domain domain, byte[] data, RecordType type,
         RecordClass klass = RecordClass.IN, TimeSpan ttl = default(TimeSpan))
 {
     this.domain = domain;
     this.type = type;
     this.klass = klass;
     this.ttl = ttl;
     this.data = data;
 }
Example #28
0
        public static void DoSystemEventRecord(Device device, string systemEvent, RecordType recordType = RecordType.Event)
        {
            RecordManager.WriteDataToLog(device, systemEvent, recordType);

            if (analysisToolOpen)
            {
                SendToAnalysisWindow(systemEvent);
            }
        }
		/// <summary>
		///   Queries for specified records.
		/// </summary>
		/// <param name="name"> Name, that should be queried </param>
		/// <param name="recordType"> Type the should be queried </param>
		/// <returns> All available responses on the local network </returns>
		public List<LlmnrMessage> Resolve(DomainName name, RecordType recordType = RecordType.A)
		{
			if (name == null)
				throw new ArgumentNullException(nameof(name), "Name must be provided");

			LlmnrMessage message = new LlmnrMessage { IsQuery = true, OperationCode = OperationCode.Query };
			message.Questions.Add(new DnsQuestion(name, recordType, RecordClass.INet));

			return SendMessageParallel(message);
		}
Example #30
0
        internal IP4AddressRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader)
            : base(name, type, rClass, expiry)
        {
            ushort dataLen = reader.ReadUShort();
            int pos = reader.Position;

            _address = new IPAddress(reader.ReadBytes(dataLen));

            reader.Position = pos + dataLen;
        }
 public BulkCopyFieldValueRequest(RecordType recordType, IEnumerable <IRecord> recordsToUpdate)
     : this()
 {
     RecordType       = recordType;
     _recordsToUpdate = recordsToUpdate;
 }
 /// <summary>
 /// Removes a RecordSet from a DNS zone.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='zoneName'>
 /// The name of the zone without a terminating dot.
 /// </param>
 /// <param name='relativeRecordSetName'>
 /// The name of the RecordSet, relative to the name of the zone.
 /// </param>
 /// <param name='recordType'>
 /// The type of DNS record. Possible values include: 'A', 'AAAA', 'CNAME',
 /// 'MX', 'NS', 'PTR', 'SOA', 'SRV', 'TXT'
 /// </param>
 /// <param name='ifMatch'>
 /// Defines the If-Match condition. The delete operation will be performed
 /// only if the ETag of the zone on the server matches this value.
 /// </param>
 /// <param name='ifNoneMatch'>
 /// Defines the If-None-Match condition. The delete operation will be
 /// performed only if the ETag of the zone on the server does not match this
 /// value.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task DeleteAsync(this IRecordSetsOperations operations, string resourceGroupName, string zoneName, string relativeRecordSetName, RecordType recordType, string ifMatch = default(string), string ifNoneMatch = default(string), CancellationToken cancellationToken = default(CancellationToken))
 {
     await operations.DeleteWithHttpMessagesAsync(resourceGroupName, zoneName, relativeRecordSetName, recordType, ifMatch, ifNoneMatch, null, cancellationToken).ConfigureAwait(false);
 }
 /// <summary>
 /// Gets a RecordSet.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='zoneName'>
 /// The name of the zone without a terminating dot.
 /// </param>
 /// <param name='relativeRecordSetName'>
 /// The name of the RecordSet, relative to the name of the zone.
 /// </param>
 /// <param name='recordType'>
 /// The type of DNS record. Possible values include: 'A', 'AAAA', 'CNAME',
 /// 'MX', 'NS', 'PTR', 'SOA', 'SRV', 'TXT'
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <RecordSet> GetAsync(this IRecordSetsOperations operations, string resourceGroupName, string zoneName, string relativeRecordSetName, RecordType recordType, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.GetWithHttpMessagesAsync(resourceGroupName, zoneName, relativeRecordSetName, recordType, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Lists the RecordSets of a specified type in a DNS zone.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group that contains the zone.
 /// </param>
 /// <param name='zoneName'>
 /// The name of the zone from which to enumerate RecordsSets.
 /// </param>
 /// <param name='recordType'>
 /// The type of record sets to enumerate. Possible values include: 'A',
 /// 'AAAA', 'CNAME', 'MX', 'NS', 'PTR', 'SOA', 'SRV', 'TXT'
 /// </param>
 /// <param name='top'>
 /// Query parameters. If null is passed returns the default number of zones.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <IPage <RecordSet> > ListByTypeAsync(this IRecordSetsOperations operations, string resourceGroupName, string zoneName, RecordType recordType, string top = default(string), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.ListByTypeWithHttpMessagesAsync(resourceGroupName, zoneName, recordType, top, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Updates a RecordSet within a DNS zone.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='zoneName'>
 /// The name of the zone without a terminating dot.
 /// </param>
 /// <param name='relativeRecordSetName'>
 /// The name of the RecordSet, relative to the name of the zone.
 /// </param>
 /// <param name='recordType'>
 /// The type of DNS record. Possible values include: 'A', 'AAAA', 'CNAME',
 /// 'MX', 'NS', 'PTR', 'SOA', 'SRV', 'TXT'
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Update operation.
 /// </param>
 /// <param name='ifMatch'>
 /// The etag of Zone.
 /// </param>
 /// <param name='ifNoneMatch'>
 /// Defines the If-None-Match condition. Set to '*' to force
 /// Create-If-Not-Exist. Other values will be ignored.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <RecordSet> UpdateAsync(this IRecordSetsOperations operations, string resourceGroupName, string zoneName, string relativeRecordSetName, RecordType recordType, RecordSet parameters, string ifMatch = default(string), string ifNoneMatch = default(string), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, zoneName, relativeRecordSetName, recordType, parameters, ifMatch, ifNoneMatch, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Example #36
0
 public bool Equals(A x, A y) =>
 RecordType <A> .EqualityTyped(x, y);
Example #37
0
 /// <summary>
 ///    Sends a record to the client.
 /// </summary>
 /// <param name="type">
 ///    A <see cref="RecordType" /> specifying the type of record
 ///    to send.
 /// </param>
 /// <param name="requestID">
 ///    A <see cref="ushort" /> containing the ID of the request
 ///    the record is associated with.
 /// </param>
 /// <param name="bodyData">
 ///    A <see cref="byte[]" /> containing the body data for the
 ///    request.
 /// </param>
 /// <remarks>
 ///    If the socket is not connected, the record will not be
 ///    sent.
 /// </remarks>
 /// <exception cref="ArgumentNullException">
 ///    <paramref name="bodyData" /> is <see langword="null" />.
 /// </exception>
 public void SendRecord(RecordType type, ushort requestID,
                        byte [] bodyData)
 {
     SendRecord(type, requestID, bodyData, 0, -1);
 }
Example #38
0
 /// <summary>
 /// 加载存档,如果存档不存在则创建新存档
 /// </summary>
 /// <param name="recordType">存档类型,注意需要与文件名相同</param>
 public static void InitOrCreateRecord(RecordType recordType)
 {
     InitOrCreateRecord(recordType.ToString());
 }
 public static async Task <RecordSet> GetOrDefaultAsync(this IRecordSetsOperations operations, string resourceGroupName, string zoneName, string relativeRecordSetName, RecordType recordType)
 {
     try
     {
         return(await operations.GetAsync(resourceGroupName, zoneName, relativeRecordSetName, RecordType.TXT));
     }
     catch
     {
         return(null);
     }
 }
        public override void Validate(object state)
        {
            base.Validate(state);

            //if (XPath.IsNull())
            //    throw new ChoRecordConfigurationException("XPath can't be null or whitespace.");

            if (XPath.IsNullOrWhiteSpace())
            {
                if (!IsDynamicObject && (RecordType.IsGenericType && RecordType.GetGenericTypeDefinition() == typeof(KeyValuePair <,>)))
                {
                    NodeName = NodeName.IsNullOrWhiteSpace() ? "KeyValuePair" : NodeName;
                    RootName = RootName.IsNullOrWhiteSpace() ? "KeyValuePairs" : RootName;
                }
                else if (!IsDynamicObject && !typeof(IChoScalarObject).IsAssignableFrom(RecordType))
                {
                    NodeName = NodeName.IsNullOrWhiteSpace() ? RecordType.Name : NodeName;
                    RootName = RootName.IsNullOrWhiteSpace() ? NodeName.ToPlural() : RootName;
                }
            }
            else
            {
                RootName = RootName.IsNullOrWhiteSpace() ? XPath.SplitNTrim("/").Where(t => !t.IsNullOrWhiteSpace() && t.NTrim() != "." && t.NTrim() != ".." && t.NTrim() != "*").FirstOrDefault() : RootName;
                NodeName = NodeName.IsNullOrWhiteSpace() ? XPath.SplitNTrim("/").Where(t => !t.IsNullOrWhiteSpace() && t.NTrim() != "." && t.NTrim() != ".." && t.NTrim() != "*").Skip(1).FirstOrDefault() : NodeName;
            }

            string rootName = null;
            string nodeName = null;
            ChoXmlDocumentRootAttribute da = TypeDescriptor.GetAttributes(RecordType).OfType <ChoXmlDocumentRootAttribute>().FirstOrDefault();

            if (da != null)
            {
                rootName = da.Name;
            }
            else
            {
                XmlRootAttribute ra = TypeDescriptor.GetAttributes(RecordType).OfType <XmlRootAttribute>().FirstOrDefault();
                if (ra != null)
                {
                    nodeName = ra.ElementName;
                }
            }

            RootName = RootName.IsNullOrWhiteSpace() && !rootName.IsNullOrWhiteSpace() ? rootName : RootName;
            NodeName = NodeName.IsNullOrWhiteSpace() && !nodeName.IsNullOrWhiteSpace() ? nodeName : NodeName;

            RootName = RootName.IsNullOrWhiteSpace() && !NodeName.IsNullOrWhiteSpace() ? NodeName.ToPlural() : RootName;
            if (!RootName.IsNullOrWhiteSpace() && RootName.ToSingular() != RootName)
            {
                NodeName = NodeName.IsNullOrWhiteSpace() && !RootName.IsNullOrWhiteSpace() ? RootName.ToSingular() : NodeName;
            }

            if (RootName.IsNullOrWhiteSpace())
            {
                RootName = "Root";
            }
            if (NodeName.IsNullOrWhiteSpace())
            {
                NodeName = "XElement";
            }

            //Encode Root and node names
            RootName = System.Net.WebUtility.HtmlEncode(RootName);
            NodeName = System.Net.WebUtility.HtmlEncode(NodeName);

            string[] fieldNames = null;
            XElement xpr        = null;

            if (state is Tuple <long, XElement> )
            {
                xpr = ((Tuple <long, XElement>)state).Item2;
            }
            else
            {
                fieldNames = state as string[];
            }

            if (AutoDiscoverColumns &&
                XmlRecordFieldConfigurations.Count == 0)
            {
                if (RecordType != null && !IsDynamicObject &&
                    ChoTypeDescriptor.GetProperties(RecordType).Where(pd => pd.Attributes.OfType <ChoXmlNodeRecordFieldAttribute>().Any()).Any())
                {
                    DiscoverRecordFields(RecordType);
                }
                else if (xpr != null)
                {
                    XmlRecordFieldConfigurations.AddRange(DiscoverRecordFieldsFromXElement(xpr));
                }
                else if (!fieldNames.IsNullOrEmpty())
                {
                    foreach (string fn in fieldNames)
                    {
                        if (IgnoredFields.Contains(fn))
                        {
                            continue;
                        }

                        if (fn.StartsWith("_"))
                        {
                            string fn1 = fn.Substring(1);
                            var    obj = new ChoXmlRecordFieldConfiguration(fn, xPath: $"./{fn1}");
                            obj.FieldName      = fn1;
                            obj.IsXmlAttribute = true;
                            XmlRecordFieldConfigurations.Add(obj);
                        }
                        else if (fn.EndsWith("_"))
                        {
                            string fn1 = fn.Substring(0, fn.Length - 1);
                            var    obj = new ChoXmlRecordFieldConfiguration(fn, xPath: $"./{fn1}");
                            obj.FieldName  = fn1;
                            obj.IsXmlCDATA = true;
                            XmlRecordFieldConfigurations.Add(obj);
                        }
                        else
                        {
                            var obj = new ChoXmlRecordFieldConfiguration(fn, xPath: $"./{fn}");
                            XmlRecordFieldConfigurations.Add(obj);
                        }
                    }
                }
            }
            else
            {
                IsComplexXPathUsed = false;

                foreach (var fc in XmlRecordFieldConfigurations)
                {
                    if (fc.IsArray == null)
                    {
                        fc.IsArray = typeof(ICollection).IsAssignableFrom(fc.FieldType);
                    }

                    if (fc.FieldName.IsNullOrWhiteSpace())
                    {
                        fc.FieldName = fc.Name;
                    }

                    if (fc.XPath.IsNullOrWhiteSpace())
                    {
                        fc.XPath = $"/{fc.FieldName}|/@{fc.FieldName}";
                    }
                    else
                    {
                        if (fc.XPath == fc.FieldName ||
                            fc.XPath == $"/{fc.FieldName}" || fc.XPath == $"/{fc.FieldName}" || fc.XPath == $"/{fc.FieldName}" ||
                            fc.XPath == $"/@{fc.FieldName}" || fc.XPath == $"/@{fc.FieldName}" || fc.XPath == $"/@{fc.FieldName}"
                            )
                        {
                        }
                        else
                        {
                            IsComplexXPathUsed = true;
                            fc.UseCache        = false;
                        }
                    }
                }
            }

            if (XmlRecordFieldConfigurations.Count <= 0)
            {
                throw new ChoRecordConfigurationException("No record fields specified.");
            }

            //Validate each record field
            foreach (var fieldConfig in XmlRecordFieldConfigurations)
            {
                fieldConfig.Validate(this);
            }

            //Check field position for duplicate
            string[] dupFields = XmlRecordFieldConfigurations.GroupBy(i => i.Name)
                                 .Where(g => g.Count() > 1)
                                 .Select(g => g.Key).ToArray();

            if (dupFields.Length > 0)
            {
                throw new ChoRecordConfigurationException("Duplicate field(s) [Name(s): {0}] found.".FormatString(String.Join(",", dupFields)));
            }

            PIDict = new Dictionary <string, System.Reflection.PropertyInfo>();
            PDDict = new Dictionary <string, PropertyDescriptor>();
            foreach (var fc in XmlRecordFieldConfigurations)
            {
                if (fc.PropertyDescriptor == null)
                {
                    fc.PropertyDescriptor = ChoTypeDescriptor.GetProperties(RecordType).Where(pd => pd.Name == fc.Name).FirstOrDefault();
                }
                if (fc.PropertyDescriptor == null)
                {
                    continue;
                }

                PIDict.Add(fc.Name, fc.PropertyDescriptor.ComponentType.GetProperty(fc.PropertyDescriptor.Name));
                PDDict.Add(fc.Name, fc.PropertyDescriptor);
            }

            RecordFieldConfigurationsDict = XmlRecordFieldConfigurations.OrderBy(c => c.IsXmlAttribute).Where(i => !i.Name.IsNullOrWhiteSpace()).ToDictionary(i => i.Name);

            if (XmlRecordFieldConfigurations.Where(e => e.IsNullable).Any() ||
                NullValueHandling == ChoNullValueHandling.Default)
            {
                if (NamespaceManager != null)
                {
                    if (!NamespaceManager.HasNamespace("xsi"))
                    {
                        NamespaceManager.AddNamespace("xsi", ChoXmlSettings.XmlSchemaInstanceNamespace);
                    }
                    if (!NamespaceManager.HasNamespace("xsd"))
                    {
                        NamespaceManager.AddNamespace("xsd", ChoXmlSettings.XmlSchemaNamespace);
                    }
                }
            }

            LoadNCacheMembers(XmlRecordFieldConfigurations);
        }
Example #41
0
 /// <summary>
 ///    Constructs and initializes a new instance of <see
 ///    cref="Record" /> populating it with a specified version,
 ///    type, ID, and body.
 /// </summary>
 /// <param name="version">
 ///    A <see cref="byte" /> containing the FastCGI version the
 ///    record is structured for.
 /// </param>
 /// <param name="type">
 ///    A <see cref="RecordType" /> containing the type of
 ///    record to create.
 /// </param>
 /// <param name="requestID">
 ///    A <see cref="ushort" /> containing the ID of the request
 ///    associated with the new record.
 /// </param>
 /// <param name="bodyData">
 ///    A <see cref="byte[]" /> containing the contents to use
 ///    in the new record.
 /// </param>
 /// <remarks>
 ///    <note type="caution">
 ///       The new instance will store a reference to <paramref
 ///       name="bodyData" /> and as such be invalid when the
 ///       value changes externally.
 ///    </note>
 /// </remarks>
 /// <exception cref="ArgumentNullException">
 ///    <paramref name="bodyData" /> is <see langword="null" />.
 /// </exception>
 /// <exception cref="ArgumentException">
 ///    <paramref name="bodyData" /> contains more than 65535
 ///    bytes and cannot be sent.
 /// </exception>
 public Record(byte version, RecordType type, ushort requestID,
               byte [] bodyData) : this(version, type,
                                        requestID, bodyData,
                                        0, -1)
 {
 }
        protected async Task <DnsResolveResult <TRecord> > ResolveDnsAsync <TRecord>(DomainName domain, RecordType recordType, CancellationToken token)
            where TRecord : DnsRecordBase
        {
            try
            {
                var records = await DnsResolver.ResolveAsync <TRecord>(domain, recordType, token : token);

                return(new DnsResolveResult <TRecord>(ReturnCode.NoError, records));
            }
            catch
            {
                return(new DnsResolveResult <TRecord>(ReturnCode.ServerFailure, null));
            }
        }
        private async Task <bool?> IsIpMatchAsync <TRecord>(DomainName domain, IPAddress ipAddress, int?prefix, RecordType recordType, CancellationToken token)
            where TRecord : DnsRecordBase, IAddressRecord
        {
            DnsResolveResult <TRecord> dnsResult = await ResolveDnsAsync <TRecord>(domain, recordType, token);

            if ((dnsResult == null) || ((dnsResult.ReturnCode != ReturnCode.NoError) && (dnsResult.ReturnCode != ReturnCode.NxDomain)))
            {
                return(null);
            }

            foreach (var dnsRecord in dnsResult.Records)
            {
                if (prefix.HasValue)
                {
                    if (ipAddress.Equals(dnsRecord.Address.GetNetworkAddress(prefix.Value)))
                    {
                        return(true);
                    }
                }
                else
                {
                    if (ipAddress.Equals(dnsRecord.Address))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #44
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "VersionManager&lt;T&gt;" /> class.
 /// </summary>
 /// <param name = "recType">Type of the record.</param>
 public VersionManager(RecordType recType)
 {
     RecordType = recType;
 }
 /// <summary>
 ///   Creates a new instance of the RecordExistsPrequisite class
 /// </summary>
 /// <param name="name"> Name of record that should be checked </param>
 /// <param name="recordType"> Type of record that should be checked </param>
 public RecordExistsPrequisite(DomainName name, RecordType recordType)
     : base(name, recordType, RecordClass.Any, 0)
 {
 }
Example #46
0
 /// <summary>
 /// 删除存档
 /// </summary>
 public static void DeleteRecord(RecordType recordType)
 {
     EZSave.Instance.DeletRecord(recordType.ToString());
 }
Example #47
0
 public int GetHashCode(A x) =>
 RecordType <A> .Hash(x);
Example #48
0
 private void RecordTypePage_TimeSeriesNextClick(object sender, RoutedEventArgs e)
 {
     RecordTypePage.Visibility = Visibility.Collapsed;
     DatePage.Visibility       = Visibility.Visible;
     RecordType = RecordType.RegularTimeSeries;
 }
Example #49
0
 public int Compare(A x, A y) =>
 RecordType <A> .Compare(x, y);
Example #50
0
 private void RecordTypePage_PairedDataNextClick(object sender, RoutedEventArgs e)
 {
     RecordTypePage.Visibility = Visibility.Collapsed;
     OrdinatePage.Visibility   = Visibility.Visible;
     RecordType = RecordType.PairedData;
 }
 /// <summary>
 /// Updates a RecordSet within a DNS zone.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='zoneName'>
 /// The name of the zone without a terminating dot.
 /// </param>
 /// <param name='relativeRecordSetName'>
 /// The name of the RecordSet, relative to the name of the zone.
 /// </param>
 /// <param name='recordType'>
 /// The type of DNS record. Possible values include: 'A', 'AAAA', 'CNAME',
 /// 'MX', 'NS', 'PTR', 'SOA', 'SRV', 'TXT'
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Update operation.
 /// </param>
 /// <param name='ifMatch'>
 /// The etag of Zone.
 /// </param>
 /// <param name='ifNoneMatch'>
 /// Defines the If-None-Match condition. Set to '*' to force
 /// Create-If-Not-Exist. Other values will be ignored.
 /// </param>
 public static RecordSet Update(this IRecordSetsOperations operations, string resourceGroupName, string zoneName, string relativeRecordSetName, RecordType recordType, RecordSet parameters, string ifMatch = default(string), string ifNoneMatch = default(string))
 {
     return(Task.Factory.StartNew(s => ((IRecordSetsOperations)s).UpdateAsync(resourceGroupName, zoneName, relativeRecordSetName, recordType, parameters, ifMatch, ifNoneMatch), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Example #52
0
 private IList <IResourceRecord> Get(Domain domain, RecordType type)
 {
     return(entries.Where(e => Matches(domain, e.Name) && e.Type == type).ToList());
 }
 /// <summary>
 /// Lists the RecordSets of a specified type in a DNS zone.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group that contains the zone.
 /// </param>
 /// <param name='zoneName'>
 /// The name of the zone from which to enumerate RecordsSets.
 /// </param>
 /// <param name='recordType'>
 /// The type of record sets to enumerate. Possible values include: 'A',
 /// 'AAAA', 'CNAME', 'MX', 'NS', 'PTR', 'SOA', 'SRV', 'TXT'
 /// </param>
 /// <param name='top'>
 /// Query parameters. If null is passed returns the default number of zones.
 /// </param>
 public static IPage <RecordSet> ListByType(this IRecordSetsOperations operations, string resourceGroupName, string zoneName, RecordType recordType, string top = default(string))
 {
     return(Task.Factory.StartNew(s => ((IRecordSetsOperations)s).ListByTypeAsync(resourceGroupName, zoneName, recordType, top), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Example #54
0
 private void WriteRecord(RecordType rt, int value)
 {
     s_stream !.WriteByte((byte)rt);
     WriteInt32(value);
 }
 /// <summary>
 /// Gets a RecordSet.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='zoneName'>
 /// The name of the zone without a terminating dot.
 /// </param>
 /// <param name='relativeRecordSetName'>
 /// The name of the RecordSet, relative to the name of the zone.
 /// </param>
 /// <param name='recordType'>
 /// The type of DNS record. Possible values include: 'A', 'AAAA', 'CNAME',
 /// 'MX', 'NS', 'PTR', 'SOA', 'SRV', 'TXT'
 /// </param>
 public static RecordSet Get(this IRecordSetsOperations operations, string resourceGroupName, string zoneName, string relativeRecordSetName, RecordType recordType)
 {
     return(Task.Factory.StartNew(s => ((IRecordSetsOperations)s).GetAsync(resourceGroupName, zoneName, relativeRecordSetName, recordType), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Example #56
0
 public ConfigureAutonumberRequest(RecordType recordType)
 {
     RecordType = recordType;
 }
Example #57
0
 public BulkReplaceRequest(RecordType recordType, IEnumerable <IRecord> recordsToUpdate)
 {
     RecordType       = recordType;
     _recordsToUpdate = recordsToUpdate;
 }
Example #58
0
 public RecordBase(RecordType type, ushort requestId)
     : this()
 {
     RecordType = type;
     RequestId  = requestId;
 }
Example #59
0
 partial void ConditionsCustomParse(OverlayStream stream, long finalPos, int offset, RecordType type, PreviousParse lastParsed)
 {
     Conditions = ConditionBinaryOverlay.ConstructBinayOverlayList(stream, _package);
 }
Example #60
0
 public Record(string message = "", RecordType recordType = RecordType.Output)
 {
     Message    = message;
     Written    = DateTime.Now;
     RecordType = recordType;
 }