private ICarouselUser LoadFromPath(string path)
        {
            DataContractSerializer serializer = new DataContractSerializer(typeof(CarouselUserDTO));

            using (FileStream fs = File.Open(path, FileMode.Open))
            {
                CarouselUserDTO userDTO = (CarouselUserDTO)serializer.ReadObject(fs);
                CarouselUser    user    = new CarouselUser();
                user.Name = userDTO.Name;
                foreach (CarouselCopyPasteItemDTO carouselCopyPasteItemDTO in userDTO.CopyPasteItems)
                {
                    CarouselCopyPasteItem carouselCopyPasteItem = new CarouselCopyPasteItem(this.clipboardService, this.carouselColorSettings);
                    carouselCopyPasteItem.Content         = carouselCopyPasteItemDTO.Content;
                    carouselCopyPasteItem.DisplayName     = carouselCopyPasteItemDTO.DisplayName;
                    carouselCopyPasteItem.DisplayOrder    = carouselCopyPasteItemDTO.DisplayOrder;
                    carouselCopyPasteItem.ColorType       = carouselCopyPasteItemDTO.ColorType;
                    carouselCopyPasteItem.ColorHue        = carouselCopyPasteItemDTO.ColorHue;
                    carouselCopyPasteItem.ColorLuminosity = carouselCopyPasteItemDTO.ColorLuminosity;
                    user.CopyPasteItems.Add(carouselCopyPasteItem);
                }
                foreach (CarouselFileDropItemDTO carouselFileDropItemDTO in userDTO.FileDropItems)
                {
                    CarouselFileDropItem carouselFileDropItem = new CarouselFileDropItem(this.carouselColorSettings);
                    carouselFileDropItem.DropProcessorName = carouselFileDropItemDTO.DropProcessorName;
                    carouselFileDropItem.DisplayName       = carouselFileDropItemDTO.DisplayName;
                    carouselFileDropItem.DisplayOrder      = carouselFileDropItemDTO.DisplayOrder;
                    carouselFileDropItem.ColorType         = carouselFileDropItemDTO.ColorType;
                    carouselFileDropItem.ColorHue          = carouselFileDropItemDTO.ColorHue;
                    carouselFileDropItem.ColorLuminosity   = carouselFileDropItemDTO.ColorLuminosity;
                    user.FileDropItems.Add(carouselFileDropItem);
                }
                return(user);
            }
        }
 public CarouselUser Load(string osuser)
 {
     try
     {
         using (var stream = File.OpenRead(this.CreateFileName(osuser)))
         {
             XmlSerializer serializer = XmlSerializer.FromTypes(new[] { typeof(CarouselUser) })[0];
             //var serializer = new XmlSerializer(typeof(CarouselUser));
             CarouselUser user = serializer.Deserialize(stream) as CarouselUser;
             return(user);
         }
     }
     catch (Exception ex)
     {
         log.Error(string.Format(@"Load(string osuser = {0}) has thrown an exception: ", osuser), ex);
         throw ex;
     }
 }
        public void Save(CarouselUser user)
        {
            try
            {
                // first serialize the object to memory stream,
                // in case of exception, the original file is not corrupted
                using (MemoryStream ms = new MemoryStream())
                {
                    var           writer     = new StreamWriter(ms);
                    XmlSerializer serializer = XmlSerializer.FromTypes(new[] { typeof(CarouselUser) })[0];
                    //var serializer = new System.Xml.Serialization.XmlSerializer(typeof(ShortcutCarousel.Model.CarouselUser));
                    serializer.Serialize(writer, user);
                    writer.Flush();

                    // if the serialization succeed, rewrite the file.
                    File.WriteAllBytes(this.CreateFileName(user.OSUser), ms.ToArray());
                }
            }
            catch (Exception ex)
            {
                log.Error(string.Format(@"Save(CarouselUser user = {0}) has thrown an exception: ", user), ex);
                throw ex;
            }
        }