예제 #1
0
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder
        .HasDefaultSchema("Identity")
        .Ignore <DomainEvent>()
        .ApplyConfiguration(new EventPublishedConfiguration())
        .ApplyConfiguration(new EventSubscribedConfiguration())
        .ApplyConfiguration(new UserConfiguration())
        .ApplyConfiguration(new RoleConfiguration())
        .ApplyConfiguration(new PermissionConfiguration())
        .ApplyConfiguration(new UserRoleConfiguration())
        .ApplyConfiguration(new UserRefreshTokenConfiguration())
        .ApplyConfiguration(new RolePermissionConfiguration());

        var utcDateTimeConverter = new UtcDateTimeConverter();
        var dateTimeProperties   = modelBuilder.Model
                                   .GetEntityTypes()
                                   .SelectMany(x => x.GetProperties())
                                   .Where(x => x.ClrType == typeof(DateTime));

        foreach (var property in dateTimeProperties)
        {
            property.SetValueConverter(utcDateTimeConverter);
        }
    }
예제 #2
0
        public async Task UpdateOwner(Owner dbOwner, Owner owner)
        {
            dbOwner.Map(owner);
            UtcDateTimeConverter.Convert(owner);
            var sql = "UPDATE [dbo].[Owner] SET Address=@Address, DateOfBirth=@DateOfBirth, Name=@Name WHERE OwnerId = @OwnerId";

            await Execute(sql, new { OwnerId = dbOwner.Id, dbOwner.Name, dbOwner.DateOfBirth, dbOwner.Address }, CommandType.Text);
        }
예제 #3
0
        public async Task CreateOwner(Owner owner)
        {
            owner.Id = Guid.NewGuid();
            UtcDateTimeConverter.Convert(owner);
            var sql = "INSERT INTO [dbo].[Owner] VALUES (@OwnerId, @Name, @DateOfBirth, @Address)";

            await Execute(sql, new { OwnerId = owner.Id, owner.Name, owner.DateOfBirth, owner.Address }, CommandType.Text);
        }
예제 #4
0
        /// <summary>
        /// Converts the local date time into a UTC time
        /// </summary>
        /// <param name="dateTime">The current instance of the date time</param>
        /// <param name="timeZone">The time zone to convert from</param>
        /// <returns>The same date time but expressed in UTC time</returns>
        public static DateTime?ToUtc(this DateTime?dateTime, string timeZone = null)
        {
            if (dateTime == null)
            {
                return(null);
            }

            IDateTimeConverter converter = new UtcDateTimeConverter(timeZone);

            return(converter.Convert((DateTime)dateTime));
        }
예제 #5
0
        protected void WriteGenerator(XmlWriter xw, bool forReadability)
        {
            xw.WriteStartElement("Generator");
            Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();

            string product = GetAttribute <AssemblyProductAttribute>(assembly).Product;
            string version = assembly.GetName().Version.ToString(4);

            xw.WriteAttributeString("name", typeof(MSBuildLogger).FullName);
            xw.WriteAttributeString("product", product);
            xw.WriteAttributeString("version", version);
            xw.WriteAttributeString("date", UtcDateTimeConverter.ToString(DateTime.UtcNow));

            xw.WriteEndElement();
        }
예제 #6
0
        public void UtcDateTimeConverter_ConvertToUtc_DateTime_UseCustomTimezone_Success()
        {
            const string inputValue  = "2016-12-31 15:00";
            string       outputValue = "";
            const string timeZone    = "Europe/Brussels";

            UtcDateTimeConverter converter = new UtcDateTimeConverter(timeZone);

            const string exactFormat = "yyyy-MM-dd HH:mm";

            if (DateTime.TryParseExact(inputValue, exactFormat, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime output))
            {
                DateTime convertedDate = converter.Convert(DateTime.SpecifyKind(output, DateTimeKind.Utc));
                outputValue = convertedDate.ToString(exactFormat);
            }

            Assert.True(outputValue == "2016-12-31 14:00");
        }
예제 #7
0
        public void UtcDateTimeConverter_ConvertToUtc_DateTime_UseCurrentTimezone_Success()
        {
            Thread.CurrentThread.CurrentCulture   = new CultureInfo("nl-BE");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl-BE");

            const string inputValue  = "2016-12-31 15:00";
            string       outputValue = "";

            UtcDateTimeConverter converter   = new UtcDateTimeConverter();
            const string         exactFormat = "yyyy-MM-dd HH:mm";

            if (DateTime.TryParseExact(inputValue, exactFormat, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime output))
            {
                DateTime convertedDate = converter.Convert(DateTime.SpecifyKind(output, DateTimeKind.Utc));
                outputValue = convertedDate.ToString(exactFormat);
            }

            Assert.True(outputValue == "2016-12-31 16:00");
        }
예제 #8
0
        /// <summary>
        /// Converts the local date time into a UTC time
        /// </summary>
        /// <param name="dateTime">The current instance of the date time</param>
        /// <param name="timeZone">The time zone to convert from</param>
        /// <returns>The same date time but expressed in UTC time</returns>
        public static DateTime ToUtc(this DateTime dateTime, string timeZone = null)
        {
            IDateTimeConverter converter = new UtcDateTimeConverter(timeZone);

            return(converter.Convert(dateTime));
        }