/// <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);
        }
        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);
        }
Esempio n. 4
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);
 }
Esempio n. 5
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;
 }