示例#1
0
        /// <summary>
        /// Deserializes the most recently used information from a string.
        /// </summary>
        /// <param name="culture">The serialization culture.</param>
        /// <param name="mru">The string containing the serialized most recently used information.</param>
        /// <returns>The most recently used information.</returns>
        internal static MostRecentlyUsed Deserialize(CultureInfo culture, string mru)
        {
            string[] parts  = mru.Split(new char[] { '|' });
            var      result = new MostRecentlyUsed(parts[0], DateTimeOffset.ParseExact(parts[1], "o", culture));

            return(result);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MostRecentlyUsedModel"/> class.
        /// </summary>
        /// <param name="context">The context that is used to execute actions on the UI thread.</param>
        /// <param name="mostRecentlyUsed">The object that stores information about a most recently used file.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="context"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="mostRecentlyUsed"/> is <see langword="null" />.
        /// </exception>
        public MostRecentlyUsedModel(IContextAware context, MostRecentlyUsed mostRecentlyUsed)
            : base(context)
        {
            {
                Lokad.Enforce.Argument(() => mostRecentlyUsed);
            }

            m_Mru = mostRecentlyUsed;
        }
        public void Create()
        {
            var context = new Mock<IContextAware>();
            var mru = new MostRecentlyUsed(@"c:\temp\a.txt", DateTimeOffset.Now);
            var model = new MostRecentlyUsedModel(context.Object, mru);

            Assert.AreEqual(Path.GetFileNameWithoutExtension(mru.FilePath), model.FileName);
            Assert.AreEqual(mru.FilePath, model.FilePath);
            Assert.AreEqual(mru.LastTimeOpened, model.LastTimeOpened);
        }
        /// <summary>
        /// Converts the given value object to the specified type, using the specified
        /// context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context.</param>
        /// <param name="culture">The current culture.</param>
        /// <param name="value">The object to convert.</param>
        /// <param name="destinationType">The <see cref="Type"/> to convert the value parameter to.</param>
        /// <returns>The converted object.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="destinationType"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="NotSupportedException">The conversion cannot be performed.</exception>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType != typeof(string))
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }

            var mru = value as MostRecentlyUsed;

            return(MostRecentlyUsed.Serialize(culture, mru));
        }
        /// <summary>
        /// Converts the given object to the type of this converter, using the specified
        /// context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context.</param>
        /// <param name="culture">The current culture.</param>
        /// <param name="value">The object to convert.</param>
        /// <returns>An object that represents the converted value.</returns>
        /// <exception cref="NotSupportedException">The conversion cannot be performed.</exception>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var text = value as string;

            if (text == null)
            {
                return(base.ConvertFrom(context, culture, value));
            }

            return(MostRecentlyUsed.Deserialize(culture, text));
        }
示例#6
0
        public void SerializeAndDeserialize()
        {
            var path = @"c:\temp\myfile.txt";
            var date = DateTimeOffset.Now;
            var mru  = new MostRecentlyUsed(path, date);

            var converter       = new MostRecentlyUsedConverter();
            var serializedMru   = converter.ConvertTo(null, CultureInfo.InvariantCulture, mru, typeof(string));
            var deserializedMru = converter.ConvertFrom(null, CultureInfo.InvariantCulture, serializedMru) as MostRecentlyUsed;

            Assert.IsNotNull(deserializedMru);
            Assert.AreEqual(mru.FilePath, deserializedMru.FilePath);
            Assert.AreEqual(mru.LastTimeOpened, deserializedMru.LastTimeOpened);
        }
        public void SerializeAndDeserialize()
        {
            var path = @"c:\temp\myfile.txt";
            var date = DateTimeOffset.Now;
            var mru = new MostRecentlyUsed(path, date);

            var converter = new MostRecentlyUsedConverter();
            var serializedMru = converter.ConvertTo(null, CultureInfo.InvariantCulture, mru, typeof(string));
            var deserializedMru = converter.ConvertFrom(null, CultureInfo.InvariantCulture, serializedMru) as MostRecentlyUsed;

            Assert.IsNotNull(deserializedMru);
            Assert.AreEqual(mru.FilePath, deserializedMru.FilePath);
            Assert.AreEqual(mru.LastTimeOpened, deserializedMru.LastTimeOpened);
        }
示例#8
0
 /// <summary>
 /// Serializes the most recently used information to a string.
 /// </summary>
 /// <param name="culture">The serialization culture.</param>
 /// <param name="mru">The most recently used item.</param>
 /// <returns>A string containing the most recently used information.</returns>
 internal static string Serialize(CultureInfo culture, MostRecentlyUsed mru)
 {
     return string.Format(culture, "{0}|{1:o}", mru.FilePath, mru.LastTimeOpened);
 }
示例#9
0
 /// <summary>
 /// Deserializes the most recently used information from a string.
 /// </summary>
 /// <param name="culture">The serialization culture.</param>
 /// <param name="mru">The string containing the serialized most recently used information.</param>
 /// <returns>The most recently used information.</returns>
 internal static MostRecentlyUsed Deserialize(CultureInfo culture, string mru)
 {
     string[] parts = mru.Split(new char[] { '|' });
     var result = new MostRecentlyUsed(parts[0], DateTimeOffset.ParseExact(parts[1], "o", culture));
     return result;
 }
示例#10
0
 /// <summary>
 /// Serializes the most recently used information to a string.
 /// </summary>
 /// <param name="culture">The serialization culture.</param>
 /// <param name="mru">The most recently used item.</param>
 /// <returns>A string containing the most recently used information.</returns>
 internal static string Serialize(CultureInfo culture, MostRecentlyUsed mru)
 {
     return(string.Format(culture, "{0}|{1:o}", mru.FilePath, mru.LastTimeOpened));
 }