示例#1
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(IChapters source, IChapters target, CopyToProgress progressDelegate)
        {
            if (target.Parent.GetParentDictionary().Parent.Properties.ContainsKey(ParentProperty.ChapterMappings))
            {
                return;
            }

            Dictionary <int, int> chaperMappings = new Dictionary <int, int>();

            foreach (IChapter chapter in source.Chapters)
            {
                IChapter newChapter = target.AddNew();
                chapter.CopyTo(newChapter, progressDelegate);
                chaperMappings.Add(chapter.Id, newChapter.Id);

                if (source.Parent.GetParentDictionary().DefaultSettings.SelectedLearnChapters.Contains(chapter.Id))
                {
                    target.Parent.GetParentDictionary().DefaultSettings.SelectedLearnChapters.Add(newChapter.Id);
                }
                if (source.Parent.GetParentDictionary().UserSettings.SelectedLearnChapters.Contains(chapter.Id))
                {
                    target.Parent.GetParentDictionary().UserSettings.SelectedLearnChapters.Add(newChapter.Id);
                }
            }

            target.Parent.GetParentDictionary().Parent.Properties[ParentProperty.ChapterMappings] = chaperMappings;
        }
示例#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>
        /// <remarks>Documented by Dev05, 2012-01-11</remarks>
        public static void Copy(ICopy source, ICopy target, CopyToProgress progressDelegate)
        {
            if (source.GetType() != target.GetType())
                throw new ArgumentException("Source and Target must be the same type!");

            Copy(source, target, source.GetType(), progressDelegate);
        }
示例#3
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());
                }
            }
        }
示例#4
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];
            }
        }
示例#5
0
        /// <summary>
        /// Copies the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="type">The type the source and target should be interpreded as.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        public static void Copy(ICopy source, ICopy target, Type type, CopyToProgress progressDelegate)
        {
            if (!(type.IsAssignableFrom(source.GetType()) && type.IsAssignableFrom(target.GetType())))
            {
                throw new ArgumentException("Source and Target must implement " + type.ToString());
            }

            foreach (PropertyInfo info in type.GetProperties())
            {
                if (type.GetProperty(info.Name).IsDefined(typeof(IgnoreCopyAttribute), true) ||
                    source.GetType().GetProperty(info.Name).IsDefined(typeof(IgnoreCopyAttribute), true) ||
                    target.GetType().GetProperty(info.Name).IsDefined(typeof(IgnoreCopyAttribute), true))
                {
                    continue;
                }

                if (typeof(ICopy).IsAssignableFrom(info.PropertyType))
                {
                    ICopy copyObject = (info.GetValue(source, null) as ICopy);
                    if (copyObject != null)
                    {
                        copyObject.CopyTo(info.GetValue(target, null) as ICopy, progressDelegate);
                    }
                }

                if (info.IsDefined(typeof(ValueCopyAttribute), true))
                {
                    object value = info.GetValue(source, null);
                    if (value != null)
                    {
                        info.SetValue(target, value, null);
                    }
                }
            }
        }
示例#6
0
        /// <summary>
        /// Copies the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="type">The type the source and target should be interpreded as.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        public static void Copy(ICopy source, ICopy target, Type type, CopyToProgress progressDelegate)
        {
            if (!(type.IsAssignableFrom(source.GetType()) && type.IsAssignableFrom(target.GetType())))
                throw new ArgumentException("Source and Target must implement " + type.ToString());

            foreach (PropertyInfo info in type.GetProperties())
            {
                if (type.GetProperty(info.Name).IsDefined(typeof(IgnoreCopyAttribute), true) ||
                    source.GetType().GetProperty(info.Name).IsDefined(typeof(IgnoreCopyAttribute), true) ||
                    target.GetType().GetProperty(info.Name).IsDefined(typeof(IgnoreCopyAttribute), true))
                    continue;

                if (typeof(ICopy).IsAssignableFrom(info.PropertyType))
                {
                    ICopy copyObject = (info.GetValue(source, null) as ICopy);
                    if (copyObject != null)
                        copyObject.CopyTo(info.GetValue(target, null) as ICopy, progressDelegate);
                }

                if (info.IsDefined(typeof(ValueCopyAttribute), true))
                {
                    object value = info.GetValue(source, null);
                    if (value != null)
                        info.SetValue(target, value, null);
                }
            }
        }
示例#7
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)
        {
            IChapters targetChapters = target as IChapters;

            if (targetChapters != null)
            {
                ChaptersHelper.Copy(this, targetChapters, progressDelegate);
            }
        }
示例#8
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>
        /// <remarks>Documented by Dev05, 2012-01-11</remarks>
        public static void Copy(ICopy source, ICopy target, CopyToProgress progressDelegate)
        {
            if (source.GetType() != target.GetType())
            {
                throw new ArgumentException("Source and Target must be the same type!");
            }

            Copy(source, target, source.GetType(), progressDelegate);
        }
        public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
        {
            IStatistics targetStatistics = target as IStatistics;

            if (targetStatistics != null)
            {
                StatisticsHelper.Copy(this as IStatistics, targetStatistics, progressDelegate);
            }
        }
示例#10
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);
            }
        }
示例#11
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);
        }
示例#12
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();
     }
 }
示例#13
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>
 /// <remarks>Documented by Dev08, 2009-02-06</remarks>
 public static void Copy(IStatistics source, IStatistics target, CopyToProgress progressDelegate)
 {
     try
     {
         foreach (IStatistic statistic in source)
         {
             target.Add(statistic);
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.ToString(), "StatisticsHelper.Copy()");
     }
 }
示例#14
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);
                }
            }
        }
示例#15
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 { }
        }
示例#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(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);
            }
        }
示例#17
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(IChapters source, IChapters target, CopyToProgress progressDelegate)
        {
            if (target.Parent.GetParentDictionary().Parent.Properties.ContainsKey(ParentProperty.ChapterMappings))
                return;

            Dictionary<int, int> chaperMappings = new Dictionary<int, int>();
            foreach (IChapter chapter in source.Chapters)
            {
                IChapter newChapter = target.AddNew();
                chapter.CopyTo(newChapter, progressDelegate);
                chaperMappings.Add(chapter.Id, newChapter.Id);

                if (source.Parent.GetParentDictionary().DefaultSettings.SelectedLearnChapters.Contains(chapter.Id))
                    target.Parent.GetParentDictionary().DefaultSettings.SelectedLearnChapters.Add(newChapter.Id);
                if (source.Parent.GetParentDictionary().UserSettings.SelectedLearnChapters.Contains(chapter.Id))
                    target.Parent.GetParentDictionary().UserSettings.SelectedLearnChapters.Add(newChapter.Id);
            }

            target.Parent.GetParentDictionary().Parent.Properties[ParentProperty.ChapterMappings] = chaperMappings;
        }
示例#18
0
 /// <summary>
 /// Copies to.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="progressDelegate">The progress delegate.</param>
 /// <remarks>Documented by Dev03, 2008-12-03</remarks>
 public void CopyTo(ICopy target, CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this, target, typeof(IDictionary), progressDelegate);
 }
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this, target, typeof(IQueryMultipleChoiceOptions), progressDelegate);
 }
示例#20
0
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     SettingsHelper.Copy(this, target as ISettings, progressDelegate);
 }
示例#21
0
文件: DbSettings.cs 项目: hmehr/OSS
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     SettingsHelper.Copy(this, target as ISettings, progressDelegate);
 }
示例#22
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());
                }
            }
        }
示例#23
0
文件: DbWords.cs 项目: hmehr/OSS
 public void CopyTo(ICopy target, CopyToProgress progressDelegate)
 {
     WordsHelper.CopyWords(this, target as IWords);
 }
示例#24
0
文件: DbStatistics.cs 项目: hmehr/OSS
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     IStatistics targetStatistics = target as IStatistics;
     if (targetStatistics != null)
         StatisticsHelper.Copy(this as IStatistics, targetStatistics, progressDelegate);
 }
示例#25
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);
        }
示例#26
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)
 {
     CardsHelper.Copy(this, target as ICards, progressDelegate);
 }
示例#27
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();
 }
示例#28
0
文件: LearnLogic.cs 项目: hmehr/OSS
        /// <summary>
        /// Imports the learning module.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="source">The source.</param>
        /// <param name="getLogin">The get login.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        /// <param name="errorMessageDelegate">The error message delegate.</param>
        /// <param name="user">The user.</param>
        /// <param name="calCount">The cal count.</param>
        /// <remarks>Documented by Dev05, 2009-02-12</remarks>
        public static void ImportLearningModule(IConnectionString target, ConnectionStringStruct source,
			GetLoginInformation getLogin, CopyToProgress progressDelegate, DataAccessErrorDelegate errorMessageDelegate, User user, string licenseKey, bool contentProtected, int calCount)
        {
            IDictionary dic = LearningModulesIndex.ConnectionUsers[target].List().AddNew(1, string.Empty, licenseKey, contentProtected, calCount);
            ConnectionStringStruct targetConnection = new ConnectionStringStruct(target.ConnectionType, dic.Connection, dic.Id);
            CopyLearningModule(source, targetConnection, getLogin, progressDelegate, errorMessageDelegate, user, true, contentProtected);
        }
示例#29
0
        /// <summary>
        /// Copies to.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        /// <remarks>Documented by Dev03, 2009-04-19</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)
                    try
                    {
                        targetCard.AddMedia(media, Side.Question);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex, "DbCard.AddMedia() throws an exception.");
                    }
                foreach (IMedia media in AnswerMedia)
                    try
                    {
                        targetCard.AddMedia(media, Side.Answer);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex, "DbCard.AddMedia() throws an exception.");
                    }
            }
        }
示例#30
0
文件: DbExtension.cs 项目: hmehr/OSS
        /// <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);
        }
示例#31
0
文件: PreviewWords.cs 项目: hmehr/OSS
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     WordsHelper.CopyWords(this, target as IWords);
 }
示例#32
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);
            }
        }
示例#33
0
文件: XmlCardStyle.cs 项目: hmehr/OSS
 /// <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(ITextStyle), progressDelegate);
 }
示例#34
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)
 {
     CardsHelper.Copy(this, target as ICards, progressDelegate);
 }
示例#35
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);
            }
        }
示例#36
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)
 {
     throw new NotImplementedException();
 }
示例#37
0
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this, target, typeof(IGradeTyping), progressDelegate);
 }
示例#38
0
文件: LearnLogic.cs 项目: hmehr/OSS
        /// <summary>
        /// Copies the contents of a learning module to another one.
        /// </summary>
        /// <param name="connectionSource">The connection source.</param>
        /// <param name="connectionTarget">The connection target.</param>
        /// <param name="getLogin">The get login delegate.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        /// <param name="errorMessageDelegate">The error message delegate.</param>
        /// <param name="user">The currently logged in user.</param>
        /// <param name="resetAfterCopy">if set to <c>true</c> to reset after copy.</param>
        /// <remarks>Documented by Dev02, 2008-09-24</remarks>
        /// <exception cref="DictionaryContentProtectedException"></exception>
        public static void CopyLearningModule(ConnectionStringStruct connectionSource, ConnectionStringStruct connectionTarget,
			GetLoginInformation getLogin, CopyToProgress progressDelegate, DataAccessErrorDelegate errorMessageDelegate, User user, bool resetAfterCopy)
        {
            CopyLearningModule(connectionSource, connectionTarget, getLogin, progressDelegate, errorMessageDelegate, user, resetAfterCopy, false);
        }
 /// <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)
 {
     throw new NotImplementedException();
 }
示例#40
0
文件: LearnLogic.cs 项目: hmehr/OSS
        /// <summary>
        /// Copies the contents of a learning module to another one.
        /// </summary>
        /// <param name="connectionSource">The connection source.</param>
        /// <param name="connectionTarget">The connection target.</param>
        /// <param name="getLogin">The get login delegate.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        /// <param name="errorMessageDelegate">The error message delegate.</param>
        /// <param name="user">The currently logged in user.</param>
        /// <param name="resetAfterCopy">if set to <c>true</c> to reset after copy.</param>
        /// <remarks>Documented by Dev02, 2008-09-24</remarks>
        /// <exception cref="DictionaryContentProtectedException"></exception>
        private static void CopyLearningModule(ConnectionStringStruct connectionSource, ConnectionStringStruct connectionTarget,
			GetLoginInformation getLogin, CopyToProgress progressDelegate, DataAccessErrorDelegate errorMessageDelegate, User user, bool resetAfterCopy, bool ignoreProtected)
        {
            bool CurrentUserTryed;
            UserStruct? CurrentUser = null;
            try
            {
                if (user != null)
                {
                    UserStruct cUser = user.BaseUser.AuthenticationStruct;
                    cUser.CloseOpenSessions = true;
                    cUser.UserName = cUser.UserName ?? string.Empty;
                    cUser.AuthenticationType = cUser.AuthenticationType ?? UserAuthenticationTyp.ListAuthentication;
                    CurrentUser = cUser;
                }
            }
            catch { }

            User userSource = new User(null);
            User userTarget = new User(null);

            try
            {
                CurrentUserTryed = false;
                if (connectionSource.Typ == DatabaseType.Xml)   //XML needs to be in read-only mode otherwise the file would be locked
                    connectionSource.ReadOnly = true;
                userSource.SetBaseUser(UserFactory.Create((GetLoginInformation)delegate(UserStruct u, ConnectionStringStruct c)
                    {
                        if (!CurrentUserTryed && CurrentUser.HasValue)
                        {
                            CurrentUserTryed = true;
                            return CurrentUser;
                        }

                        return getLogin.Invoke(u, c);
                    }, connectionSource, errorMessageDelegate, userSource, true));

                if (!userSource.OpenLearningModule())
                    return;

                //don't allow import of protected LMs
                if (!ignoreProtected && userSource.Dictionary.DictionaryContentProtected)
                    throw new DictionaryContentProtectedException();

                CurrentUserTryed = false;
                userTarget.SetBaseUser(UserFactory.Create((GetLoginInformation)delegate(UserStruct u, ConnectionStringStruct c)
                    {
                        if (!CurrentUserTryed && CurrentUser.HasValue)
                        {
                            CurrentUserTryed = true;
                            return CurrentUser;
                        }

                        return getLogin.Invoke(u, c);
                    }, connectionTarget, errorMessageDelegate, userTarget, true));

                if (!userTarget.OpenLearningModule())
                    return;

                userSource.Dictionary.PreloadCardCache();

                //do copying
                userSource.Dictionary.CopyToFinished += new Dictionary.CopyToFinishedEventHandler(Dictionary_CopyToFinished);
                userSource.Dictionary.BeginCopyTo(userTarget.Dictionary, progressDelegate, userSource, userTarget, resetAfterCopy);
            }
            catch (Exception exp)
            {
                //clean up
                if (userSource != null && userSource.Dictionary != null)
                    userSource.Dictionary.Dispose();

                if (userTarget != null && userTarget.Dictionary != null)
                    userTarget.Dictionary.Dispose();

                Trace.WriteLine(exp.ToString());

                throw exp;
            }
        }
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     WordsHelper.CopyWords(this, target as IWords);
 }
示例#42
0
文件: Dictionary.cs 项目: hmehr/OSS
        /// <summary>
        /// Begins the copy to.
        /// </summary>
        /// <param name="dictionary">The dictionary.</param>
        /// <param name="progressDelegate">The progress delegate.</param>
        /// <param name="sourceUser">The source user.</param>
        /// <param name="targetUser">The target user.</param>
        /// <param name="resetAfterCopy">if set to <c>true</c> to reset after copy.</param>
        /// <remarks>Documented by Dev08, 2008-09-26</remarks>
        public void BeginCopyTo(Dictionary dictionary, CopyToProgress progressDelegate, User sourceUser, User targetUser, bool resetAfterCopy)
        {
            Thread copyToThread = new Thread(delegate()
            {
                bool success = false;
                Exception exp = null;
                try
                {
                    CopyTo(dictionary, progressDelegate);

                    if (resetAfterCopy)
                        dictionary.DictionaryDAL.ResetLearningProgress();

                    success = true;
                }
                catch (Exception e)
                {
                    exp = e;
                    Trace.WriteLine("CopyTo(dictionary) failed: " + e.Message);
                }
                finally
                {
                    OnCopyToFinished(new CopyToEventArgs(this, dictionary, sourceUser, targetUser, success, exp));
                }
            });
            copyToThread.Name = "Dictionary CopyTo Thread";
            copyToThread.IsBackground = true;
            copyToThread.CurrentCulture = Thread.CurrentThread.CurrentCulture;
            copyToThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
            copyToThread.Start();
        }
示例#43
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)
 {
     IChapters targetChapters = target as IChapters;
     if (targetChapters != null)
         ChaptersHelper.Copy(this, targetChapters, progressDelegate);
 }
示例#44
0
文件: Dictionary.cs 项目: hmehr/OSS
 /// <summary>
 /// Copies the contents of a dictionary to another one.
 /// </summary>
 /// <param name="dictionary">The dictionary.</param>
 /// <remarks>Documented by Dev02, 2008-09-24</remarks>
 public void CopyTo(Dictionary dictionary, CopyToProgress progressDelegate)
 {
     this.DictionaryDAL.CopyTo(dictionary.DictionaryDAL, progressDelegate);
 }
示例#45
0
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this, target, typeof(IQueryDirections), progressDelegate);
 }
示例#46
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);
 }
 /// <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);
 }
示例#48
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];
            }
        }
示例#49
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)
 {
     throw new Exception("The method or operation is not implemented.");
 }
示例#50
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)
 {
     throw new Exception("The method or operation is not implemented.");
 }
 public void CopyTo(MLifter.DAL.Tools.ICopy target, CopyToProgress progressDelegate)
 {
     CopyBase.Copy(this, target, typeof(IGradeSynonyms), progressDelegate);
 }
示例#52
0
文件: XmlCardStyle.cs 项目: hmehr/OSS
 /// <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(ICardStyle), progressDelegate);
     if (target is MLifter.DAL.DB.DbCardStyle)
     {
         string basePath = Path.GetDirectoryName(this.Parent.GetParentDictionary().Connection);
         ITextStyle[] styles = { (target as MLifter.DAL.DB.DbCardStyle).Question, (target as MLifter.DAL.DB.DbCardStyle).QuestionExample, (target as MLifter.DAL.DB.DbCardStyle).Answer, (target as MLifter.DAL.DB.DbCardStyle).AnswerExample, (target as MLifter.DAL.DB.DbCardStyle).AnswerCorrect, (target as MLifter.DAL.DB.DbCardStyle).AnswerWrong };
         foreach (ITextStyle style in styles)
         {
             string[] keys = new String[style.OtherElements.Keys.Count];
             style.OtherElements.Keys.CopyTo(keys, 0);
             foreach (string key in keys)
             {
                 String value = style.OtherElements[key];
                 Match urlValue = m_ResourceFinder.Match(value);
                 Match m = m_ResourceFinder.Match(value);
                 if (m.Success)
                 {
                     string url = m.Groups["url"].Value.Trim(new char[] { '"', '\'' });
                     Uri uri;
                     Match extractId = m_extractSingleMediaId.Match(url);
                     if (!extractId.Success)
                     {
                         if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
                         {
                             uri = new Uri(url);
                         }
                         else
                         {
                             uri = new Uri(new Uri(basePath + "/"), url);
                         }
                         style.OtherElements[key] = style.OtherElements[key].Replace(url, uri.AbsoluteUri);
                     }
                 }
             }
         }
         (target as MLifter.DAL.DB.DbCardStyle).FlushToDB();
     }
 }
示例#53
0
 public void CopyTo(ICopy target, CopyToProgress progressDelegate)
 {
     WordsHelper.CopyWords(this, target as IWords);
 }
示例#54
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 { }
        }