/// <summary>
 /// Prepares the question and enqueues.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="cardId">The card id.</param>
 /// <param name="content">The content.</param>
 /// <returns></returns>
 /// <remarks>Documented by Dev03, 2009-04-27</remarks>
 public static Uri PrepareQuestion(ParentClass parent, int cardId, string content)
 {
     EnqueueQuestion(cardId, content);
     return(DbMediaServer.Instance(parent).GetQuestionUri(cardId));
 }
Exemple #2
0
        /// <summary>
        /// Creates a new media object.
        /// </summary>
        /// <param name="caller">The calling object.</param>
        /// <param name="rpu">A delegate of the type StatusMessageReportProgress.</param>
        /// <param name="type">The type.</param>
        /// <param name="path">The path.</param>
        /// <param name="isActive">if set to <c>true</c> [is active].</param>
        /// <param name="isDefault">if set to <c>true</c> [is default].</param>
        /// <param name="isExample">if set to <c>true</c> [is example].</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev02, 2008-08-11</remarks>
        internal IMedia CreateNewMediaObject(object caller, StatusMessageReportProgress rpu, EMedia type, string path, bool isActive, bool isDefault, bool isExample)
        {
            IMedia media = null;
            Uri    uri;

            if (!this.HasPermission(PermissionTypes.CanModifyMedia))
            {
                throw new PermissionException();
            }

            if (path == null)
            {
                throw new ArgumentNullException("Null value not allowed for media file path!");
            }

            try
            {
                if (File.Exists(Path.Combine(Environment.CurrentDirectory, path)))                 //to allow relative paths
                {
                    path = Path.Combine(Environment.CurrentDirectory, path);
                }

                uri = new Uri(path);
            }
            catch (UriFormatException exception)
            {
                throw new FileNotFoundException("Uri format is invalid.", exception);
            }

            if (uri.Scheme == Uri.UriSchemeFile && uri.IsFile)             //we got a new file
            {
                if (File.Exists(path))
                {
                    int newid;
                    using (FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                        newid = mediaconnector.CreateMedia(stream, type, rpu, caller);

                    media = DbMedia.CreateDisconnectedCardMedia(newid, type, isDefault, isExample, parent);

                    Helper.UpdateMediaProperties(path, newid, mediaconnector);
                }
                else
                {
                    throw new FileNotFoundException("Media file could not be found.", path);
                }
            }
            else if (uri.Scheme == "http" && uri.IsLoopback)             //we got a http reference => file is already in db
            {
                if (DbMediaServer.DbMediaServer.Instance(parent).IsYours(uri))
                {
                    int mediaId = DbMediaServer.DbMediaServer.GetMediaID(uri.AbsolutePath);
                    media = DbMedia.CreateDisconnectedCardMedia(mediaId, type, isDefault, isExample, parent);
                    rpu(new StatusMessageEventArgs(StatusMessageType.CreateMediaProgress, 100, 100), caller);
                }
                else
                {
                    DbMediaServer.DbMediaServer server = DbMediaServer.DbMediaServer.Instance(uri);

                    int newid = mediaconnector.CreateMedia(GetMediaConnector(server.Parent).GetMediaStream(DbMediaServer.DbMediaServer.GetMediaID(uri.AbsolutePath)), type, rpu, caller);

                    media = DbMedia.CreateDisconnectedCardMedia(newid, type, isDefault, isExample, parent);

                    Helper.UpdateMediaProperties(path, newid, mediaconnector);
                }
            }

            return(media);
        }
 /// <summary>
 /// Prepares the answer and enqueues it.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="cardId">The card id.</param>
 /// <param name="content">The content.</param>
 /// <returns></returns>
 /// <remarks>Documented by Dev03, 2009-04-27</remarks>
 public static Uri PrepareAnswer(ParentClass parent, int cardId, string content)
 {
     EnqueueAnswer(cardId, content);
     return(DbMediaServer.Instance(parent).GetAnswerUri(cardId));
 }