/// <summary> /// Copies the media to. /// </summary> /// <param name="target">The target.</param> /// <remarks>Documented by Dev02, 2009-06-25</remarks> private void CopyMediaTo(DbCardStyle target) { //mapping dictionary current id, new id Dictionary <int, int> mediaMapping = new Dictionary <int, int>(); //copy media objects foreach (int mediaId in connector.GetMediaForCardStyle(Id)) { int newMediaId; //fetch current media data using (Stream mediaStream = mediaConnector.GetMediaStream(mediaId)) { EMedia mediaType = mediaConnector.GetMediaType(mediaId); Dictionary <MediaProperty, string> mediaProperties = mediaConnector.GetProperties(mediaId); //copy to new newMediaId = target.mediaConnector.CreateMedia(mediaStream, mediaType, delegate { return(false); }, null); target.mediaConnector.SetProperties(newMediaId, mediaProperties); } //add target.connector.AddMediaForCardStyle(target.Id, newMediaId); mediaMapping[mediaId] = newMediaId; } //translate ids ITextStyle[] styles = { target.xmlStyle.Question, target.xmlStyle.QuestionExample, target.xmlStyle.Answer, target.xmlStyle.AnswerExample, target.xmlStyle.AnswerCorrect, target.xmlStyle.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) { style.OtherElements[key] = cssUrlEntry.Replace(style.OtherElements[key], delegate(Match urlMatch) { return(replaceMediaIds.Replace(urlMatch.Groups[1].Value, delegate(Match mediaIdMatch) { int id = Convert.ToInt32(mediaIdMatch.Groups[1].Value); if (mediaMapping.ContainsKey(id)) { return string.Format(mediaPlaceHolder, mediaMapping[id]); } return urlMatch.Groups[0].Value; })); }); } } }
/// <summary> /// Copies the media to. /// </summary> /// <param name="target">The target.</param> /// <remarks>Documented by Dev02, 2009-06-25</remarks> private void CopyMediaTo(DbCardStyle target) { //mapping dictionary current id, new id Dictionary<int, int> mediaMapping = new Dictionary<int, int>(); //copy media objects foreach (int mediaId in connector.GetMediaForCardStyle(Id)) { int newMediaId; //fetch current media data using (Stream mediaStream = mediaConnector.GetMediaStream(mediaId)) { EMedia mediaType = mediaConnector.GetMediaType(mediaId); Dictionary<MediaProperty, string> mediaProperties = mediaConnector.GetProperties(mediaId); //copy to new newMediaId = target.mediaConnector.CreateMedia(mediaStream, mediaType, delegate { return false; }, null); target.mediaConnector.SetProperties(newMediaId, mediaProperties); } //add target.connector.AddMediaForCardStyle(target.Id, newMediaId); mediaMapping[mediaId] = newMediaId; } //translate ids ITextStyle[] styles = { target.xmlStyle.Question, target.xmlStyle.QuestionExample, target.xmlStyle.Answer, target.xmlStyle.AnswerExample, target.xmlStyle.AnswerCorrect, target.xmlStyle.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) { style.OtherElements[key] = cssUrlEntry.Replace(style.OtherElements[key], delegate(Match urlMatch) { return replaceMediaIds.Replace(urlMatch.Groups[1].Value, delegate(Match mediaIdMatch) { int id = Convert.ToInt32(mediaIdMatch.Groups[1].Value); if (mediaMapping.ContainsKey(id)) return string.Format(mediaPlaceHolder, mediaMapping[id]); return urlMatch.Groups[0].Value; }); }); } } }