DateTime/Unix datetime converter
 public void ToStringTest()
 {
     DateTime timestamp = new DateTime(2012, 10, 15, 8, 20, 55);
     UnixDateTime target = new UnixDateTime(timestamp);
     string expected = timestamp.ToString();
     string actual;
     actual = target.ToString();
     Assert.AreEqual(expected, actual, "String conversion from datetime are not the same");
 }
 public void UnixDateTimeConstructorTest1()
 {
     UnixDateTime target = new UnixDateTime(1350289255);
     Assert.AreEqual(target.DateTime.Year, 2012, "Year not ok");
     Assert.AreEqual(target.DateTime.Month, 10, "Month not ok");
     Assert.AreEqual(target.DateTime.Day, 15, "Day not ok");
     Assert.AreEqual(target.DateTime.Hour, 8, "Hour not ok");
     Assert.AreEqual(target.DateTime.Minute, 20, "Minute not ok");
     Assert.AreEqual(target.DateTime.Second, 55, "Seconds not ok");
 }
Exemple #3
0
        /// <summary>
        /// Updates the TTL, Mapping Flag, Look-up Time out, Cache Time out and Result Domain to the values specified as the input parameters of this method. If a new value for a parameter is not specified, then the current value for the parameter is not changed. The method returns a reference to the modified object as an output parameter. 
        /// </summary>
        /// <param name="ttl">Optional - Time, in seconds, that the RR can be cached by a DNS resolver.</param>
        /// <param name="algorithm">Algorithm used with the key specified in the resource record. </param>
        /// <param name="keyTag">Method used to choose a key that verifies an SIG. See RFC 2535, Appendix C for the method used to calculate a KeyTag.</param>
        /// <param name="labels">Unsigned count of labels in the original SIG RR owner name. The count does not include the NULL label for the root, nor any initial wildcards.</param>
        /// <param name="originalTTL">TTL of the RR set signed by the SIG.</param>
        /// <param name="signature">Signature, represented in base 64, formatted as defined in RFC 2535, Appendix A.</param>
        /// <param name="signatureExpiration">Signature expiration date, expressed in seconds since the beginning of January 1, 1970, Greenwich Mean Time (GMT), excluding leap seconds.</param>
        /// <param name="signatureInception">Date and time at which the Signature becomes valid, expressed in seconds since the beginning of January 1, 1970, Greenwich Mean Time (GMT), excluding leap seconds.</param>
        /// <param name="signerName">Domain name of the signer that generated the SIG RR.</param>
        /// <param name="typeCovered">Type of RR covered by this SIG.</param>
        /// <returns>the modified object.</returns>
        public SIGType Modify(TimeSpan? ttl, UInt16 typeCovered,
             AlgorithmEnum algorithm,
             UInt16 labels,
             TimeSpan originalTTL,
             UnixDateTime signatureExpiration,
             UnixDateTime signatureInception,
             UInt16 keyTag,
             string signerName,
             string signature)
        {
            ManagementBaseObject inParams = m_mo.GetMethodParameters("Modify");
            if ((ttl != null) && (ttl != this.TTL))
                inParams["TTL"] = ttl.Value.TotalSeconds;

            //these are not optional, need to check if record is deleted if the same
            inParams["Algorithm"] = (UInt16)algorithm;
            inParams["Labels"] = labels;
            inParams["OriginalTTL"] = originalTTL.TotalSeconds;
            inParams["SignatureExpiration"] = signatureExpiration.Unix;
            inParams["SignatureInception"] = signatureInception.Unix;
            inParams["KeyTag"] = keyTag;
            inParams["SignerName"] = signerName;
            inParams["Signature"] = signature;

            //return new SIGType((ManagementObject)m_mo.InvokeMethod("Modify", inParams, null));
            try
            {

                return new SIGType(new ManagementObject(m_mo.Scope, new ManagementPath(m_mo.InvokeMethod("Modify", inParams, null)["RR"].ToString()), null));
            }
            catch (ManagementException me)
            {
                throw new WMIException(me);
            }
        }
Exemple #4
0
        /// <summary>
        /// Instantiates an SIG RR based on the data in the method's input parameters: the record's DNS Server Name, Container Name, Owner Name, class (default = IN), time-to-live value, and WINS mapping flag, reverse look-up time out, WINS cache time out and domain name to append. It returns a reference to the new object as an output parameter. 
        /// </summary>
        /// <param name="server">Server object</param>
        /// <param name="dnsServerName">Fully Qualified Domain Name (FQDN) or IP address of the DNS Server that contains this RR.</param>
        /// <param name="containerName">Name of the Container for the Zone, Cache, or RootHints instance which contains this RR.</param>
        /// <param name="ownerName">Owner FQDN for the RR.</param>
        /// <param name="recordClass">Class of the RR.</param>
        /// <param name="ttl">Time, in seconds, that the RR can be cached by a DNS resolver.</param>
        /// <param name="algorithm">Algorithm used with the key specified in the resource record. </param>
        /// <param name="keyTag">Method used to choose a key that verifies an SIG. See RFC 2535, Appendix C for the method used to calculate a KeyTag.</param>
        /// <param name="labels">Unsigned count of labels in the original SIG RR owner name. The count does not include the NULL label for the root, nor any initial wildcards.</param>
        /// <param name="originalTTL">TTL of the RR set signed by the SIG.</param>
        /// <param name="signature">Signature, represented in base 64, formatted as defined in RFC 2535, Appendix A.</param>
        /// <param name="signatureExpiration">Signature expiration date, expressed in seconds since the beginning of January 1, 1970, Greenwich Mean Time (GMT), excluding leap seconds.</param>
        /// <param name="signatureInception">Date and time at which the Signature becomes valid, expressed in seconds since the beginning of January 1, 1970, Greenwich Mean Time (GMT), excluding leap seconds.</param>
        /// <param name="signerName">Domain name of the signer that generated the SIG RR.</param>
        /// <param name="typeCovered">Type of RR covered by this SIG.</param>
        /// <returns>the new object.</returns>
        public static SIGType CreateInstanceFromPropertyData(
            Server server,
            string dnsServerName,
            string containerName,
            string ownerName,
            RecordClassEnum? recordClass,
            TimeSpan? ttl,
             UInt16 typeCovered,
             AlgorithmEnum algorithm,
             UInt16 labels,
             TimeSpan originalTTL,
             UnixDateTime signatureExpiration,
             UnixDateTime signatureInception,
             UInt16 keyTag,
             string signerName,
             string signature)
        {
            if (server == null)
                throw new ArgumentNullException("server is required");

            ManagementClass dnsClass = new ManagementClass(server.m_scope, new ManagementPath("MicrosoftDNS_SIGType"), null);
            ManagementBaseObject inParams = dnsClass.GetMethodParameters("CreateInstanceFromPropertyData");
            inParams["DnsServerName"] = dnsServerName;
            inParams["ContainerName"] = containerName;
            inParams["OwnerName"] = ownerName;
            if (recordClass != null)
                inParams["RecordClass"] = (UInt32)recordClass.Value;
            if (ttl != null)
                inParams["TTL"] = ttl.Value.TotalSeconds;
            inParams["Algorithm"] = (UInt16)algorithm;
            inParams["Labels"] = labels;
            inParams["OriginalTTL"] = originalTTL.TotalSeconds;
            inParams["SignatureExpiration"] = signatureExpiration.Unix;
            inParams["SignatureInception"] = signatureInception.Unix;
            inParams["KeyTag"] = keyTag;
            inParams["SignerName"] = signerName;
            inParams["Signature"] = signature;

            //return new SIGType((ManagementObject)dnsClass.InvokeMethod("CreateInstanceFromPropertyData", inParams, null));
            try
            {
                return new SIGType(new ManagementObject(server.m_scope, new ManagementPath(dnsClass.InvokeMethod("CreateInstanceFromPropertyData", inParams, null)["RR"].ToString()), null));
            }
            catch (ManagementException me)
            {
                throw new WMIException(me);
            }
        }
 public void UnixDateTimeConstructorTest()
 {
     DateTime timestamp = new DateTime(2012,10,15,8,20,55, DateTimeKind.Utc);
     UnixDateTime target = new UnixDateTime(timestamp);
     Assert.AreEqual(target.Unix, 1350289255, "Error converting DateTime to unix datetime");
 }