Пример #1
0
        /// <summary>
        /// Copies to.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public void CopyTo(ICopy target, CopyToProgress progressDelegate)
        {
            CopyBase.Copy(this, target, typeof(ICard), progressDelegate);

            //copy media objects
            ICard targetCard = target as ICard;

            if (targetCard != null)
            {
                foreach (IMedia media in QuestionMedia)
                {
                    targetCard.AddMedia(media, Side.Question);
                }
                foreach (IMedia media in AnswerMedia)
                {
                    targetCard.AddMedia(media, Side.Answer);
                }
                try
                {
                    if (targetCard is MLifter.DAL.XML.XmlCard)
                    {
                        (targetCard as MLifter.DAL.XML.XmlCard).Id = Id;
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Tried to set the card id for XML but failed: " + ex.ToString());
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Copies the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        public static void Copy(ICards source, ICards target, CopyToProgress progressDelegate)
        {
            source.Parent.GetParentDictionary().Chapters.CopyTo(target.Parent.GetParentDictionary().Chapters, progressDelegate);

            CopyBase.Copy(source, target, typeof(ICards), progressDelegate);
            int counter = 0;
            int count   = source.Cards.Count - (CardIdsNotToCopy != null ? CardIdsNotToCopy.Count : 0);
            Dictionary <int, int> chapterMappings = target.Parent.GetParentDictionary().Parent.Properties[ParentProperty.ChapterMappings] as Dictionary <int, int>;

            foreach (ICard card in source.Cards)
            {
                if (CardIdsNotToCopy != null && CardIdsNotToCopy.Contains(card.Id))
                {
                    continue;
                }

                ++counter;
                if (progressDelegate != null && counter % 5 == 0)
                {
                    progressDelegate.Invoke(String.Format(Properties.Resources.CARDS_COPYTO_STATUS, counter, count), counter * 1.0 / count * 100);
                }

                ICard newCard = target.AddNew();
                card.CopyTo(newCard, progressDelegate);
                newCard.Chapter = chapterMappings[card.Chapter];
            }
        }
Пример #3
0
 private void FillSource(CopyBase c)
 {
     c.Id        = 1;
     c.Email     = "user@email";
     c.FirstName = "test";
     c.LastName  = "user";
     c.Phone     = "800-555-1212";
 }
Пример #4
0
        /// <summary>
        /// Copies to.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        /// <remarks>Documented by Dev03, 2009-01-13</remarks>
        public void CopyTo(ICopy target, CopyToProgress progressDelegate)
        {
            CopyBase.Copy(this, target, typeof(IDictionary), progressDelegate);

            //copy extensions
            foreach (IExtension extension in Extensions)
            {
                IExtension newExtension = ((IDictionary)target).ExtensionFactory(extension.Id);
                extension.CopyTo(newExtension, progressDelegate);
            }
        }
Пример #5
0
        /// <summary>
        /// Copies this instance to the specified target.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
        {
            IChapter targetChapter = target as IChapter;

            if (targetChapter != null && targetChapter.Settings == null && this.Settings != null)
            {
                targetChapter.Settings = targetChapter.Parent.GetParentDictionary().CreateSettings();
            }

            CopyBase.Copy(this, target, typeof(IChapter), progressDelegate);
        }
Пример #6
0
 /// <summary>
 /// Copies to.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="progressDelegate">The progress delegate.</param>
 /// <remarks>Documented by Dev03, 2009-01-13</remarks>
 public void CopyTo(ICopy target, CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this, target, typeof(ICardStyle), progressDelegate);
     if (target is DbCardStyle)
     {
         CopyMediaTo((DbCardStyle)target);
     }
     if (target is DbCardStyle)
     {
         ((DbCardStyle)target).FlushToDB();
     }
 }
Пример #7
0
        public void CopyExtraReverse()
        {
            CopyDestinationExtra s = new CopyDestinationExtra();
            FillSource(s);
            CopyBase d = new CopyBase();

            ObjectCopier.Copy(s, d);

            Assert.AreEqual(s.Id, d.Id);
            Assert.AreEqual(s.Email, d.Email);
            Assert.AreEqual(s.FirstName, d.FirstName);
            Assert.AreEqual(s.LastName, d.LastName);
            Assert.AreEqual(s.Phone, d.Phone);
        }
Пример #8
0
        public void CopyExtraReverse()
        {
            CopyDestinationExtra s = new CopyDestinationExtra();

            FillSource(s);
            CopyBase d = new CopyBase();

            ObjectCopier.Copy(s, d);

            Assert.AreEqual(s.Id, d.Id);
            Assert.AreEqual(s.Email, d.Email);
            Assert.AreEqual(s.FirstName, d.FirstName);
            Assert.AreEqual(s.LastName, d.LastName);
            Assert.AreEqual(s.Phone, d.Phone);
        }
Пример #9
0
        public void CopyToDictionary()
        {
            CopyBase s = new CopyBase();

            FillSource(s);
            Dictionary <string, object> d = new Dictionary <string, object>();

            ObjectCopier.Copy(s, d);

            Assert.Greater(d.Count, 0);

            Assert.AreEqual(s.Id, d["Id"]);
            Assert.AreEqual(s.Email, d["Email"]);
            Assert.AreEqual(s.FirstName, d["FirstName"]);
            Assert.AreEqual(s.LastName, d["LastName"]);
            Assert.AreEqual(s.Phone, d["Phone"]);
        }
Пример #10
0
        /// <summary>
        /// Copies to.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        /// <remarks>Documented by Dev03, 2009-03-23</remarks>
        public void CopyTo(ICopy target, CopyToProgress progressDelegate)
        {
            CopyBase.Copy(this, target, typeof(ICard), progressDelegate);

            //copy media objects
            ICard targetCard = target as ICard;

            if (targetCard != null)
            {
                foreach (IMedia media in QuestionMedia)
                {
                    targetCard.AddMedia(media, Side.Question);
                }
                foreach (IMedia media in AnswerMedia)
                {
                    targetCard.AddMedia(media, Side.Answer);
                }
            }
        }
Пример #11
0
        public static void Copy(ISettings source, ISettings target, CopyToProgress progressDelegate)
        {
            try
            {
                if (!(source is XmlAllowedSettings) && source.Style != null && target.Style == null)
                {
                    target.Style = target.Parent.GetParentDictionary().CreateCardStyle();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }

            CopyBase.Copy(source, target, typeof(ISettings), progressDelegate);

            try
            {
                if (source is XmlChapterSettings || source is XmlCardSettings || source is XmlAllowedSettings || source.Logo == null)
                {
                    target.Logo = null;
                }
                else
                {
                    target.Logo = GetNewMedia(source.Logo, target);
                }
            }
            catch { }

            try
            {
                if (!(source is XmlChapterSettings || source is XmlCardSettings || source is XmlAllowedSettings))
                {
                    Dictionary <CommentarySoundIdentifier, IMedia> cSounds = new Dictionary <CommentarySoundIdentifier, IMedia>();
                    foreach (KeyValuePair <CommentarySoundIdentifier, IMedia> pair in source.CommentarySounds)
                    {
                        cSounds.Add(pair.Key, GetNewMedia(pair.Value, target));
                    }
                    target.CommentarySounds = cSounds;
                }
            }
            catch { }
        }
Пример #12
0
        public void CopyFromDictionary()
        {
            Dictionary <string, object> s = new Dictionary <string, object>();

            s.Add("Id", 1);
            s.Add("Email", "user@email");
            s.Add("FirstName", "test");
            s.Add("LastName", "user");
            s.Add("Phone", "800-555-1212");

            CopyBase d = new CopyBase();

            ObjectCopier.Copy(s, d);

            Assert.AreEqual(s["Id"], d.Id);
            Assert.AreEqual(s["Email"], d.Email);
            Assert.AreEqual(s["FirstName"], d.FirstName);
            Assert.AreEqual(s["LastName"], d.LastName);
            Assert.AreEqual(s["Phone"], d.Phone);
        }
Пример #13
0
        /// <summary>
        /// Copies this instance to the specified target.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        public void CopyTo(ICopy target, CopyToProgress progressDelegate)
        {
            CopyBase.Copy(this, target, typeof(IExtension), progressDelegate);

            //copy data stream
            using (Stream data = this.Data)
            {
                if (data != null)
                {
                    ((IExtension)target).Data = data;
                }
            }

            //copy actions
            IList <ExtensionAction> actions = ((IExtension)target).Actions;

            actions.Clear();
            foreach (ExtensionAction action in this.Actions)
            {
                actions.Add(action);
            }
        }
Пример #14
0
        public void CopyToDictionary()
        {
            CopyBase s = new CopyBase();
            FillSource(s);
            Dictionary<string, object> d = new Dictionary<string, object>();

            ObjectCopier.Copy(s, d);

            Assert.Greater(d.Count, 0);

            Assert.AreEqual(s.Id, d["Id"]);
            Assert.AreEqual(s.Email, d["Email"]);
            Assert.AreEqual(s.FirstName, d["FirstName"]);
            Assert.AreEqual(s.LastName, d["LastName"]);
            Assert.AreEqual(s.Phone, d["Phone"]);
        }
Пример #15
0
 public void CopyTo(MLifter.DAL.Tools.ICopy target, MLifter.DAL.Tools.CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this as ISettings, target, typeof(ISettings), progressDelegate);
 }
Пример #16
0
 /// <summary>
 /// Copies this instance to the specified target.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="progressDelegate">The progress delegate.</param>
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this, target, typeof(ISnoozeOptions), progressDelegate);
 }
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this, target, typeof(IQueryMultipleChoiceOptions), progressDelegate);
 }
Пример #18
0
 /// <summary>
 /// Copies this instance to the specified target.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="progressDelegate">The progress delegate.</param>
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this, target, typeof(IQueryType), progressDelegate);
 }
Пример #19
0
 private void FillSource(CopyBase c)
 {
     c.Id = 1;
     c.Email = "user@email";
     c.FirstName = "test";
     c.LastName = "user";
     c.Phone = "800-555-1212";
 }
Пример #20
0
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this, target, typeof(IGradeSynonyms), progressDelegate);
 }
Пример #21
0
        public void CopyFromDictionary()
        {
            Dictionary<string, object> s = new Dictionary<string, object>();
            s.Add("Id", 1);
            s.Add("Email", "user@email");
            s.Add("FirstName", "test");
            s.Add("LastName", "user");
            s.Add("Phone", "800-555-1212");

            CopyBase d = new CopyBase();

            ObjectCopier.Copy(s, d);

            Assert.AreEqual(s["Id"], d.Id);
            Assert.AreEqual(s["Email"], d.Email);
            Assert.AreEqual(s["FirstName"], d.FirstName);
            Assert.AreEqual(s["LastName"], d.LastName);
            Assert.AreEqual(s["Phone"], d.Phone);

        }