/*
 * AssemblyDateTimeAttribute.cs --
 *
 * Copyright (c) 2007-2012 by Joe Mistachkin.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: $
 */

using System;
using Eagle._Components.Private;

namespace Eagle._Attributes
{
    [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
    [ObjectId("e1272060-51a5-4393-b276-c3018a4da739")]
    public sealed class AssemblyDateTimeAttribute : Attribute
    {
        public AssemblyDateTimeAttribute()
        {
            //
            // NOTE: This should be reliable.
            //
            uint timeStamp = 0;

            if (!FileOps.GetPeFileTimeStamp(
                    GlobalState.GetAssemblyLocation(), ref timeStamp) ||
                !TimeOps.SecondsToDateTime(
                    timeStamp, ref dateTime, TimeOps.PeEpoch))
            {
                dateTime = DateTime.MinValue;
            }
        }

        ///////////////////////////////////////////////////////////////////////

        public AssemblyDateTimeAttribute(DateTime dateTime)
            : this()
        {
            this.dateTime = dateTime;
        }

        ///////////////////////////////////////////////////////////////////////

        public AssemblyDateTimeAttribute(string value)
            : this()
        {
            if (!String.IsNullOrEmpty(value))
                dateTime = DateTime.Parse(value); /* throw */
        }

        ///////////////////////////////////////////////////////////////////////

        private DateTime dateTime;
        public DateTime DateTime
        {
            get { return dateTime; }
        }
    }
}
