Example #1
0
        /// <summary>
        /// Starts synchronizing time.
        /// </summary>
        public void SyncTime()
        {
            RunInBackground(() =>
            {
                SystemDateTime dt = Client.GetSystemDateAndTime();

                System.DateTime now = System.DateTime.Now.ToUniversalTime();
                DateTime deviceTime = new DateTime();
                deviceTime.Date     = new Date();
                deviceTime.Time     = new Time();

                deviceTime.Date.Year   = now.Year;
                deviceTime.Date.Month  = now.Month;
                deviceTime.Date.Day    = now.Day;
                deviceTime.Time.Hour   = now.Hour;
                deviceTime.Time.Minute = now.Minute;
                deviceTime.Time.Second = now.Second;

                Client.SetSystemDateAndTime(SetDateTimeType.Manual, dt.DaylightSavings,
                                            null, deviceTime);
            });
        }
        public void SetSystemDateTimeTest()
        {
            RunTest(() =>
            {
                SystemDateTime testDateTimeValue         = new SystemDateTime();
                TestTool.Proxies.Onvif.DateTime dateTime = new TestTool.Proxies.Onvif.DateTime();

                dateTime.Date = new Date();
                dateTime.Time = new Time();

                System.DateTime nowUtc = System.DateTime.Now.ToUniversalTime();

                dateTime.Time.Hour   = nowUtc.Hour;
                dateTime.Time.Minute = nowUtc.Minute;
                dateTime.Time.Second = nowUtc.Second;

                dateTime.Date.Day   = nowUtc.Day;
                dateTime.Date.Month = nowUtc.Month;
                dateTime.Date.Year  = nowUtc.Year;

                testDateTimeValue.DateTimeType    = SetDateTimeType.Manual;
                testDateTimeValue.DaylightSavings = false;
                testDateTimeValue.UTCDateTime     = dateTime;

                SetSystemDateAndTime(testDateTimeValue);

                SystemDateTime actualDateTime = GetSystemDateAndTime();

                Assert(actualDateTime != null, "Date and time settings not found",
                       "Check that DUT returned date and time settings");

                Assert(actualDateTime.DateTimeType == testDateTimeValue.DateTimeType,
                       "DateTimeType has not been set",
                       "Check that DateTimeType has been set. ",
                       string.Format("Expected: {0}, actual: {1}",
                                     testDateTimeValue.DateTimeType, actualDateTime.DateTimeType));

                Assert(actualDateTime.DaylightSavings == testDateTimeValue.DaylightSavings,
                       "DaylightSavings not set",
                       "Check that DaylightSavings has been set. ",
                       string.Format("Expected: {0}, actual: {1}",
                                     testDateTimeValue.DaylightSavings, actualDateTime.DaylightSavings));

                //Assert((actualDateTime.TimeZone != null), "The DUT did not return TimeZone settings",
                //       "Check that DUT returned TimeZone settings");

                //ValidateTimeZone(testDateTimeValue.TimeZone.TZ, actualDateTime.TimeZone.TZ);

                bool bCorrect = true;
                string dump   = null;
                if (actualDateTime.DateTimeType == SetDateTimeType.Manual)
                {
                    bCorrect = (actualDateTime.UTCDateTime != null);
                    dump     = string.Format("DateTimeType: Manual; LocalDateTime: {0}; UTCDateTime: {1}",
                                             actualDateTime.LocalDateTime == null ? "NOT PRESENT" : "PRESENT",
                                             actualDateTime.UTCDateTime == null ? "NOT PRESENT" : "PRESENT");
                }
                else
                {
                    dump = "DateTimeType: NTP";
                }

                Assert(bCorrect, "DateTimeType is Manual but UTCDateTime is not set", "Check if settings are self-consistent", dump);

                if (actualDateTime.LocalDateTime != null)
                {
                    string errorMessage;
                    bool bDateTimeValid = actualDateTime.LocalDateTime.IsValidDateTime("LocalDateTime", out errorMessage);
                    Assert(bDateTimeValid, errorMessage, "Validate LocalDateTime");
                }
                else
                {
                    WriteStep("Validate LocalDateTime", "LocalDateTime is NULL");
                }

                if (actualDateTime.UTCDateTime != null)
                {
                    string errorMessage;
                    bool bDateTimeValid = actualDateTime.UTCDateTime.IsValidDateTime("UTCDateTime", out errorMessage);
                    Assert(bDateTimeValid, errorMessage, "Validate UTCDateTime");
                }
                else
                {
                    WriteStep("Validate UTCDateTime", "UTCDateTime is NULL");
                }
            });
        }