コード例 #1
0
ファイル: FileCreator.cs プロジェクト: ChrisRisner/Veritas
        public static MediaObjectInfo Create(MediaObject media, string username)
        {
            MediaObjectInfo info = new MediaObjectInfo();

            if (!Directory.Exists(HttpContext.Current.Server.MapPath("..") + "/files/media/image/WindowsLiveWriter"))
            {
                if (!Directory.Exists(HttpContext.Current.Server.MapPath("..") + "/files"))
                {
                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath("..") + "/files");
                }
                if (!Directory.Exists(HttpContext.Current.Server.MapPath("..") + "/files/media"))
                {
                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath("..") + "/files/media");
                }
                if (!Directory.Exists(HttpContext.Current.Server.MapPath("..") + "/files/media/image"))
                {
                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath("..") + "/files/media/image");
                }
                if (!Directory.Exists(HttpContext.Current.Server.MapPath("..") + "/files/media/image/WindowsLiveWriter"))
                {
                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath("..") + "/files/media/image/WindowsLiveWriter");
                }
            }
            string[] pathParts = Regex.Split(media.name, "/");
            if (!Directory.Exists(HttpContext.Current.Server.MapPath("..") + "/files/media/image/WindowsLiveWriter/" + pathParts[1]))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("..") + "/files/media/image/WindowsLiveWriter/" + pathParts[1]);
            }
            FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("..") + "/files/media/image/" + media.name, FileMode.Create, FileAccess.Write);
            fs.Write(media.bits, 0, media.bits.Length);
            fs.Close();

            string host = HttpContext.Current.Request.Url.Host;
            int port = HttpContext.Current.Request.Url.Port;
            if (port != 80)
            {
                host += ":" + port;
            }
            info.url = "http://" + host + "/files/media/image/" + media.name;

            //Save a media record for this file
            BlogMedia bMedia = new BlogMedia();
            bMedia.BlogConfigId = CacheHandler.BlogConfigId;
            VeritasRepository repo = VeritasRepository.GetInstance();
            bMedia.CreatedById = repo.GetBlogUserByUserName(CacheHandler.BlogConfigId, username).BlogUserId;
            bMedia.FileName = media.name;
            bMedia.FilePath = HttpContext.Current.Server.MapPath("..") + "/files/media/image/" + media.name;
            bMedia.ServerPath = info.url;
            repo.Add(bMedia);
            repo.Save();

            return info;
        }
コード例 #2
0
        public void SaveFile(System.Web.HttpPostedFileBase httpPostedFileBase)
        {
            int lastPeriod = httpPostedFileBase.FileName.LastIndexOf(".");
            string fileName = httpPostedFileBase.FileName;
            httpPostedFileBase.SaveAs(HttpContext.Current.Server.MapPath("~/Upload/") + fileName);

            BlogMedia media = new BlogMedia();
            media.BlogConfigId = this.blogConfig.BlogConfigId;
            media.FileName = fileName;
            media.FilePath = HttpContext.Current.Server.MapPath("/Upload/") + fileName;
            //info.url = "http://" + host + "/files/media/image/" + media.name;
            media.ServerPath = "http://" + this.blogConfig.Host + "/upload/" + fileName;
            media.CreateDate = DateTime.Now;
            media.CreatedById = SessionHandler.CurrentUserId;
            repo.Add(media);
            repo.Save();
        }
コード例 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the BlogMedias EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBlogMedias(BlogMedia blogMedia)
 {
     base.AddObject("BlogMedias", blogMedia);
 }
コード例 #4
0
 /// <summary>
 /// Create a new BlogMedia object.
 /// </summary>
 /// <param name="blogMediaId">Initial value of the BlogMediaId property.</param>
 /// <param name="blogConfigId">Initial value of the BlogConfigId property.</param>
 /// <param name="fileName">Initial value of the FileName property.</param>
 /// <param name="filePath">Initial value of the FilePath property.</param>
 /// <param name="serverPath">Initial value of the ServerPath property.</param>
 /// <param name="createDate">Initial value of the CreateDate property.</param>
 public static BlogMedia CreateBlogMedia(global::System.Int32 blogMediaId, global::System.Int32 blogConfigId, global::System.String fileName, global::System.String filePath, global::System.String serverPath, global::System.DateTime createDate)
 {
     BlogMedia blogMedia = new BlogMedia();
     blogMedia.BlogMediaId = blogMediaId;
     blogMedia.BlogConfigId = blogConfigId;
     blogMedia.FileName = fileName;
     blogMedia.FilePath = filePath;
     blogMedia.ServerPath = serverPath;
     blogMedia.CreateDate = createDate;
     return blogMedia;
 }
コード例 #5
0
 public static BlogMedia GetFakeBlogMedia(int blogConfigId, int blogUserId)
 {
     var blogMedia = new BlogMedia()
     {
         BlogConfigId = blogConfigId,
         CreateDate = DateTime.Now,
         CreatedById = blogUserId,
         FileName = "test",
         FilePath = "test",
         ServerPath = "test"
     };
     return blogMedia;
 }
コード例 #6
0
 public void Delete(BlogMedia blogMedia)
 {
     db.BlogMedias.DeleteObject(blogMedia);
 }
コード例 #7
0
 public void Add(BlogMedia blogMedia)
 {
     db.BlogMedias.AddObject(blogMedia);
 }