@ -22,306 +22,309 @@ namespace Teknik.Migrations
@@ -22,306 +22,309 @@ namespace Teknik.Migrations
protected override void Seed ( Models . TeknikEntities context )
{
// Pre-populate with the default stuff
/ *
Config config = Config . Load ( ) ;
// Create system blog
Areas . Profile . Models . User systemUser = new Areas . Profile . Models . User ( ) ;
systemUser . Username = Constants . SERVERUSER ;
systemUser . JoinDate = DateTime . Now ;
systemUser . LastSeen = DateTime . Now ;
systemUser . UserSettings = new Areas . Profile . Models . UserSettings ( ) ;
systemUser . BlogSettings = new Areas . Profile . Models . BlogSettings ( ) ;
systemUser . UploadSettings = new Areas . Profile . Models . UploadSettings ( ) ;
context . Users . AddOrUpdate ( systemUser ) ;
context . SaveChanges ( ) ;
Areas . Blog . Models . Blog systemBlog = new Areas . Blog . Models . Blog ( ) ;
systemBlog . UserId = systemUser . UserId ;
systemBlog . BlogId = config . BlogConfig . ServerBlogId ;
context . Blogs . AddOrUpdate ( systemBlog ) ;
context . SaveChanges ( ) ;
// Create roles and groups
Areas . Profile . Models . Role adminRole = new Areas . Profile . Models . Role ( ) ;
adminRole . Name = "Admin" ;
adminRole . Description = "Allows complete access to user specific actions" ;
context . Roles . AddOrUpdate ( adminRole ) ;
if ( config . Migrate )
{
// Pre-populate with the default stuff
// Create system blog
Areas . Profile . Models . User systemUser = new Areas . Profile . Models . User ( ) ;
systemUser . Username = Constants . SERVERUSER ;
systemUser . JoinDate = DateTime . Now ;
systemUser . LastSeen = DateTime . Now ;
systemUser . UserSettings = new Areas . Profile . Models . UserSettings ( ) ;
systemUser . BlogSettings = new Areas . Profile . Models . BlogSettings ( ) ;
systemUser . UploadSettings = new Areas . Profile . Models . UploadSettings ( ) ;
context . Users . AddOrUpdate ( systemUser ) ;
context . SaveChanges ( ) ;
Areas . Profile . Models . Role podcastRole = new Areas . Profile . Models . Role ( ) ;
podcastRole . Name = "Podcast" ;
podcastRole . Description = "Allows create/edit/delete access to podcasts" ;
context . Roles . AddOrUpdate ( podcastRole ) ;
Areas . Blog . Models . Blog systemBlog = new Areas . Blog . Models . Blog ( ) ;
systemBlog . UserId = systemUser . UserId ;
systemBlog . BlogId = config . BlogConfig . ServerBlogId ;
context . Blogs . AddOrUpdate ( systemBlog ) ;
context . SaveChanges ( ) ;
Areas . Profile . Models . Group adminGroup = new Areas . Profile . Models . Group ( ) ;
adminGroup . Name = "Administrators" ;
adminGroup . Description = "System Administrators with full access" ;
adminGroup . Roles = new List < Areas . Profile . Models . Role > ( ) ;
adminGroup . Roles . Add ( adminRole ) ;
adminGroup . Roles . Add ( podcastRole ) ;
context . Groups . AddOrUpdate ( adminGroup ) ;
// Create roles and groups
Areas . Profile . Models . Role adminRole = new Areas . Profile . Models . Role ( ) ;
adminRole . Name = "Admin" ;
adminRole . Description = "Allows complete access to user specific actions" ;
context . Roles . AddOrUpdate ( adminRole ) ;
Areas . Profile . Models . Group podcastGroup = new Areas . Profile . Models . Group ( ) ;
podcastGroup . Name = "Podcast" ;
podcastGroup . Description = "Podcast team members" ;
podcastGroup . Roles = new List < Areas . Profile . Models . Role > ( ) ;
podcastGroup . Roles . Add ( podcastRole ) ;
context . Groups . AddOrUpdate ( podcastGroup ) ;
Areas . Profile . Models . Role podcastRole = new Areas . Profile . Models . Role ( ) ;
podcastRole . Name = "Podcast" ;
podcastRole . Description = "Allows create/edit/delete access to podcasts" ;
context . Roles . AddOrUpdate ( podcastRole ) ;
Areas . Profile . Models . Group memberGroup = new Areas . Profile . Models . Group ( ) ;
memberGroup . Name = "Member" ;
memberGroup . Description = "The default member group with basic permissions" ;
context . Groups . AddOrUpdate ( memberGroup ) ;
Areas . Profile . Models . Group adminGroup = new Areas . Profile . Models . Group ( ) ;
adminGroup . Name = "Administrators" ;
adminGroup . Description = "System Administrators with full access" ;
adminGroup . Roles = new List < Areas . Profile . Models . Role > ( ) ;
adminGroup . Roles . Add ( adminRole ) ;
adminGroup . Roles . Add ( podcastRole ) ;
context . Groups . AddOrUpdate ( adminGroup ) ;
context . SaveChanges ( ) ;
if ( config . DatabaseConfig . Migrate & & ! config . DevEnvironment )
{
Areas . Profile . Models . Group podcastGroup = new Areas . Profile . Models . Group ( ) ;
podcastGroup . Name = "Podcast" ;
podcastGroup . Description = "Podcast team members" ;
podcastGroup . Roles = new List < Areas . Profile . Models . Role > ( ) ;
podcastGroup . Roles . Add ( podcastRole ) ;
context . Groups . AddOrUpdate ( podcastGroup ) ;
// Convert legacy MySQL DB to new MS SQL DB
MysqlDatabase db = new MysqlDatabase ( config . DatabaseConfig ) ;
db . MysqlErrorEvent + = Db_MysqlErrorEvent ;
config . DatabaseConfig . Migrate = false ;
Config . Save ( config ) ;
Areas . Profile . Models . Group memberGroup = new Areas . Profile . Models . Group ( ) ;
memberGroup . Name = "Member" ;
memberGroup . Description = "The default member group with basic permissions" ;
context . Groups . AddOrUpdate ( memberGroup ) ;
// Transfer transactions
var transRet = db . Query ( "SELECT * FROM `transactions`" ) ;
foreach ( var tran in transRet )
{
switch ( tran [ "trans_type" ] . ToString ( ) )
{
case "One-Time" :
Areas . Transparency . Models . OneTime tr = new Areas . Transparency . Models . OneTime ( ) ;
tr . DateSent = DateTime . Parse ( tran [ "date_posted" ] . ToString ( ) ) ;
tr . Amount = Double . Parse ( tran [ "amount" ] . ToString ( ) ) ;
tr . Currency = tran [ "currency" ] . ToString ( ) ;
tr . Recipient = tran [ "recipient" ] . ToString ( ) ;
tr . Reason = tran [ "reason" ] . ToString ( ) ;
context . Transactions . AddOrUpdate ( tr ) ;
break ;
case "Bill" :
Areas . Transparency . Models . Bill bill = new Areas . Transparency . Models . Bill ( ) ;
bill . DateSent = DateTime . Parse ( tran [ "date_posted" ] . ToString ( ) ) ;
bill . Amount = Double . Parse ( tran [ "amount" ] . ToString ( ) ) ;
bill . Currency = tran [ "currency" ] . ToString ( ) ;
bill . Recipient = tran [ "recipient" ] . ToString ( ) ;
bill . Reason = tran [ "reason" ] . ToString ( ) ;
context . Transactions . AddOrUpdate ( bill ) ;
break ;
case "Donation" :
Areas . Transparency . Models . Donation don = new Areas . Transparency . Models . Donation ( ) ;
don . DateSent = DateTime . Parse ( tran [ "date_posted" ] . ToString ( ) ) ;
don . Amount = Double . Parse ( tran [ "amount" ] . ToString ( ) ) ;
don . Currency = tran [ "currency" ] . ToString ( ) ;
don . Sender = tran [ "sender" ] . ToString ( ) ;
don . Reason = tran [ "reason" ] . ToString ( ) ;
context . Transactions . AddOrUpdate ( don ) ;
break ;
}
}
context . SaveChanges ( ) ;
// Transfer Users and Blogs/Posts
Dictionary < int , int > userMapping = new Dictionary < int , int > ( ) ;
Dictionary < int , int > postMapping = new Dictionary < int , int > ( ) ;
var userRet = db . Query ( "SELECT * FROM `users`" ) ;
foreach ( var user in userRet )
/ *
if ( config . DatabaseConfig . Migrate )
{
// Create User
Areas . Profile . Models . User newUser = new Areas . Profile . Models . User ( ) ;
newUser . UserSettings = new Areas . Profile . Models . UserSettings ( ) ;
newUser . BlogSettings = new Areas . Profile . Models . BlogSettings ( ) ;
newUser . UploadSettings = new Areas . Profile . Models . UploadSettings ( ) ;
newUser . TransferAccount = true ;
newUser . Username = user [ "username" ] . ToString ( ) ;
newUser . HashedPassword = user [ "password" ] . ToString ( ) ;
newUser . JoinDate = DateTime . Parse ( user [ "join_date" ] . ToString ( ) ) ;
newUser . LastSeen = DateTime . Parse ( user [ "join_date" ] . ToString ( ) ) ;
newUser . UserSettings . About = user [ "about" ] . ToString ( ) ;
newUser . UserSettings . Website = user [ "website" ] . ToString ( ) ;
newUser . UserSettings . Quote = user [ "quote" ] . ToString ( ) ;
newUser . BlogSettings . Title = user [ "blog_title" ] . ToString ( ) ;
newUser . BlogSettings . Description = user [ "blog_desc" ] . ToString ( ) ;
if ( user [ "site_admin" ] . ToString ( ) = = "1" )
// Convert legacy MySQL DB to new MS SQL DB
MysqlDatabase db = new MysqlDatabase ( config . DatabaseConfig ) ;
db . MysqlErrorEvent + = Db_MysqlErrorEvent ;
config . DatabaseConfig . Migrate = false ;
Config . Save ( config ) ;
// Transfer transactions
var transRet = db . Query ( "SELECT * FROM `transactions`" ) ;
foreach ( var tran in transRet )
{
newUser . Groups . Add ( adminGroup ) ;
switch ( tran [ "trans_type" ] . ToString ( ) )
{
case "One-Time" :
Areas . Transparency . Models . OneTime tr = new Areas . Transparency . Models . OneTime ( ) ;
tr . DateSent = DateTime . Parse ( tran [ "date_posted" ] . ToString ( ) ) ;
tr . Amount = Double . Parse ( tran [ "amount" ] . ToString ( ) ) ;
tr . Currency = tran [ "currency" ] . ToString ( ) ;
tr . Recipient = tran [ "recipient" ] . ToString ( ) ;
tr . Reason = tran [ "reason" ] . ToString ( ) ;
context . Transactions . AddOrUpdate ( tr ) ;
break ;
case "Bill" :
Areas . Transparency . Models . Bill bill = new Areas . Transparency . Models . Bill ( ) ;
bill . DateSent = DateTime . Parse ( tran [ "date_posted" ] . ToString ( ) ) ;
bill . Amount = Double . Parse ( tran [ "amount" ] . ToString ( ) ) ;
bill . Currency = tran [ "currency" ] . ToString ( ) ;
bill . Recipient = tran [ "recipient" ] . ToString ( ) ;
bill . Reason = tran [ "reason" ] . ToString ( ) ;
context . Transactions . AddOrUpdate ( bill ) ;
break ;
case "Donation" :
Areas . Transparency . Models . Donation don = new Areas . Transparency . Models . Donation ( ) ;
don . DateSent = DateTime . Parse ( tran [ "date_posted" ] . ToString ( ) ) ;
don . Amount = Double . Parse ( tran [ "amount" ] . ToString ( ) ) ;
don . Currency = tran [ "currency" ] . ToString ( ) ;
don . Sender = tran [ "sender" ] . ToString ( ) ;
don . Reason = tran [ "reason" ] . ToString ( ) ;
context . Transactions . AddOrUpdate ( don ) ;
break ;
}
}
context . Users . AddOrUpdate ( newUser ) ;
context . SaveChanges ( ) ;
string oldUsername = user [ "username" ] . ToString ( ) ;
Areas . Profile . Models . User newUser = context . Users . Where ( u = > u . Username = = oldUsername ) . FirstOrDefault ( ) ;
if ( newUser ! = null )
// Transfer Users and Blogs/Posts
Dictionary < int , int > userMapping = new Dictionary < int , int > ( ) ;
Dictionary < int , int > postMapping = new Dictionary < int , int > ( ) ;
var userRet = db . Query ( "SELECT * FROM `users`" ) ;
foreach ( var user in userRet )
{
int oldUserId = Int32 . Parse ( user [ "id" ] . ToString ( ) ) ;
int userId = newUser . UserId ;
// Create User
Areas . Profile . Models . User newUser = new Areas . Profile . Models . User ( ) ;
newUser . UserSettings = new Areas . Profile . Models . UserSettings ( ) ;
newUser . BlogSettings = new Areas . Profile . Models . BlogSettings ( ) ;
newUser . UploadSettings = new Areas . Profile . Models . UploadSettings ( ) ;
newUser . TransferAccount = true ;
newUser . Username = user [ "username" ] . ToString ( ) ;
newUser . HashedPassword = user [ "password" ] . ToString ( ) ;
newUser . JoinDate = DateTime . Parse ( user [ "join_date" ] . ToString ( ) ) ;
newUser . LastSeen = DateTime . Parse ( user [ "join_date" ] . ToString ( ) ) ;
newUser . UserSettings . About = user [ "about" ] . ToString ( ) ;
newUser . UserSettings . Website = user [ "website" ] . ToString ( ) ;
newUser . UserSettings . Quote = user [ "quote" ] . ToString ( ) ;
newUser . BlogSettings . Title = user [ "blog_title" ] . ToString ( ) ;
newUser . BlogSettings . Description = user [ "blog_desc" ] . ToString ( ) ;
if ( user [ "site_admin" ] . ToString ( ) = = "1" )
{
newUser . Groups . Add ( adminGroup ) ;
}
userMapping . Add ( oldUserId , userId ) ;
}
// Create Blog for user
Areas . Blog . Models . Blog newBlog = new Areas . Blog . Models . Blog ( ) ;
newBlog . UserId = userId ;
context . Blogs . AddOrUpdate ( newBlog ) ;
context . SaveChanges ( ) ;
int blogId = newBlog . BlogId ;
context . Users . AddOrUpdate ( newUser ) ;
context . SaveChanges ( ) ;
string oldUsername = user [ "username" ] . ToString ( ) ;
Areas . Profile . Models . User newUser = context . Users . Where ( u = > u . Username = = oldUsername ) . FirstOrDefault ( ) ;
if ( newUser ! = null )
{
int oldUserId = Int32 . Parse ( user [ "id" ] . ToString ( ) ) ;
int userId = newUser . User Id ;
// Transfer Blog Posts
var postRet = db . Query ( "SELECT * FROM `blog` WHERE `author_id` = {0}" , new object [ ] { oldUserId } ) ;
if ( postRet ! = null )
{
foreach ( var post in postRet )
userMapping . Add ( oldUserId , userId ) ;
}
// Create Blog for user
Areas . Blog . Models . Blog newBlog = new Areas . Blog . Models . Blog ( ) ;
newBlog . UserId = userId ;
context . Blogs . AddOrUpdate ( newBlog ) ;
context . SaveChanges ( ) ;
int blogId = newBlog . BlogId ;
// Transfer Blog Posts
var postRet = db . Query ( "SELECT * FROM `blog` WHERE `author_id` = {0}" , new object [ ] { oldUserId } ) ;
if ( postRet ! = null )
{
// Create new Blog Post
Areas . Blog . Models . BlogPost newPost = new Areas . Blog . Models . BlogPost ( ) ;
if ( post [ "user_id" ] . ToString ( ) = = "0" )
{
newPost . BlogId = config . BlogConfig . ServerBlogId ;
newPost . System = true ;
}
else
foreach ( var post in postRet )
{
newPost . BlogId = blogId ;
// Create new Blog Post
Areas . Blog . Models . BlogPost newPost = new Areas . Blog . Models . BlogPost ( ) ;
if ( post [ "user_id" ] . ToString ( ) = = "0" )
{
newPost . BlogId = config . BlogConfig . ServerBlogId ;
newPost . System = true ;
}
else
{
newPost . BlogId = blogId ;
}
newPost . DatePosted = DateTime . Parse ( post [ "date_posted" ] . ToString ( ) ) ;
DateTime publishDate = DateTime . Now ;
DateTime . TryParse ( post [ "date_published" ] . ToString ( ) , out publishDate ) ;
if ( publishDate < newPost . DatePosted )
{
publishDate = newPost . DatePosted ;
}
newPost . DatePublished = publishDate ;
newPost . DateEdited = publishDate ;
newPost . Published = ( post [ "published" ] . ToString ( ) = = "True" ) ;
newPost . Title = post [ "title" ] . ToString ( ) ;
newPost . Article = post [ "post" ] . ToString ( ) ;
context . BlogPosts . AddOrUpdate ( newPost ) ;
context . SaveChanges ( ) ;
postMapping . Add ( Int32 . Parse ( post [ "id" ] . ToString ( ) ) , newPost . BlogPostId ) ;
}
newPost . DatePosted = DateTime . Parse ( post [ "date_posted" ] . ToString ( ) ) ;
DateTime publishDate = DateTime . Now ;
DateTime . TryParse ( post [ "date_published" ] . ToString ( ) , out publishDate ) ;
if ( publishDate < newPost . DatePosted )
{
publishDate = newPost . DatePosted ;
}
newPost . DatePublished = publishDate ;
newPost . DateEdited = publishDate ;
newPost . Published = ( post [ "published" ] . ToString ( ) = = "True" ) ;
newPost . Title = post [ "title" ] . ToString ( ) ;
newPost . Article = post [ "post" ] . ToString ( ) ;
context . BlogPosts . AddOrUpdate ( newPost ) ;
context . SaveChanges ( ) ;
postMapping . Add ( Int32 . Parse ( post [ "id" ] . ToString ( ) ) , newPost . BlogPostId ) ;
}
}
}
// Transfer Blog Comments
var commentRet = db . Query ( "SELECT * FROM `comments` WHERE `service` = {0}" , new object [ ] { "blog" } ) ;
foreach ( var comment in commentRet )
{
int postId = Int32 . Parse ( comment [ "reply_id" ] . ToString ( ) ) ;
int userId = Int32 . Parse ( comment [ "user_id" ] . ToString ( ) ) ;
if ( postMapping . ContainsKey ( postId ) & & userMapping . ContainsKey ( userId ) )
{
Areas . Blog . Models . BlogPostComment newComment = new Areas . Blog . Models . BlogPostComment ( ) ;
newComment . BlogPostId = postMapping [ postId ] ;
newComment . UserId = userMapping [ userId ] ;
newComment . Article = comment [ "post" ] . ToString ( ) ;
newComment . DatePosted = DateTime . Parse ( comment [ "date_posted" ] . ToString ( ) ) ;
newComment . DateEdited = DateTime . Parse ( comment [ "date_posted" ] . ToString ( ) ) ;
context . BlogComments . AddOrUpdate ( newComment ) ;
context . SaveChanges ( ) ;
}
}
// Transfer Pastes
var pasteRet = db . Query ( "SELECT * FROM `paste`" ) ;
foreach ( var paste in pasteRet )
{
string pass = paste [ "password" ] . ToString ( ) ;
// If it's a password protected paste, we just skip it
if ( string . IsNullOrEmpty ( pass ) | | pass = = "EMPTY" )
// Transfer Blog Comments
var commentRet = db . Query ( "SELECT * FROM `comments` WHERE `service` = {0}" , new object [ ] { "blog" } ) ;
foreach ( var comment in commentRet )
{
string content = paste [ "code" ] . ToString ( ) ;
string title = paste [ "title" ] . ToString ( ) ;
DateTime posted = DateTime . Parse ( paste [ "posted" ] . ToString ( ) ) ;
int userId = Int32 . Parse ( paste [ "user_id" ] . ToString ( ) ) ;
Areas . Paste . Models . Paste newPaste = PasteHelper . CreatePaste ( content , title ) ;
newPaste . DatePosted = posted ;
newPaste . Url = paste [ "pid" ] . ToString ( ) ;
if ( userMapping . ContainsKey ( userId ) & & userId ! = 0 )
int postId = Int32 . Parse ( comment [ "reply_id" ] . ToString ( ) ) ;
int userId = Int32 . Parse ( comment [ "user_id" ] . ToString ( ) ) ;
if ( postMapping . ContainsKey ( postId ) & & userMapping . ContainsKey ( userId ) )
{
newPaste . UserId = userMapping [ userId ] ;
Areas . Blog . Models . BlogPostComment newComment = new Areas . Blog . Models . BlogPostComment ( ) ;
newComment . BlogPostId = postMapping [ postId ] ;
newComment . UserId = userMapping [ userId ] ;
newComment . Article = comment [ "post" ] . ToString ( ) ;
newComment . DatePosted = DateTime . Parse ( comment [ "date_posted" ] . ToString ( ) ) ;
newComment . DateEdited = DateTime . Parse ( comment [ "date_posted" ] . ToString ( ) ) ;
context . BlogComments . AddOrUpdate ( newComment ) ;
context . SaveChanges ( ) ;
}
context . Pastes . AddOrUpdate ( newPaste ) ;
context . SaveChanges ( ) ;
}
}
// Transfer Uploads
var uploadRet = db . Query ( "SELECT * FROM `uploads`" ) ;
var curUploads = context . Uploads . ToList ( ) ;
if ( curUploads = = null )
curUploads = new List < Areas . Upload . Models . Upload > ( ) ;
int curUpload = 0 ;
int curFinished = 0 ;
//int curDeleted = 0;
foreach ( var upload in uploadRet )
{
curUpload + + ;
try {
string url = upload [ "url" ] . ToString ( ) ;
//Areas.Upload.Models.Upload upFound = curUploads.Find(u => u.Url == url);
//if (upFound != null)
//{
// string subDir = upFound.FileName[0].ToString();
// string filePath = Path.Combine(config.UploadConfig.UploadDirectory, subDir, upFound.FileName);
// if (File.Exists(filePath))
// {
// continue;
// }
// else
// {
// curDeleted++;
// context.Uploads.Remove(upFound);
// context.SaveChanges();
// }
//}
string fileType = upload [ "type" ] . ToString ( ) ;
int contentLength = Int32 . Parse ( upload [ "filesize" ] . ToString ( ) ) ;
string deleteKey = upload [ "delete_key" ] . ToString ( ) ;
int userId = Int32 . Parse ( upload [ "user_id" ] . ToString ( ) ) ;
DateTime uploadDate = DateTime . Parse ( upload [ "upload_date" ] . ToString ( ) ) ;
string fullUrl = string . Format ( "https://u.teknik.io/{0}" , url ) ;
string fileExt = Path . GetExtension ( fullUrl ) ;
if ( ! File . Exists ( Path . Combine ( "Z:\\Uploads_Old" , upload [ "filename" ] . ToString ( ) ) ) )
{
continue ;
}
// Download the old file and re-upload it
using ( WebDownload client = new WebDownload ( 1 0 0 0 0 ) )
// Transfer Pastes
var pasteRet = db . Query ( "SELECT * FROM `paste`" ) ;
foreach ( var paste in pasteRet )
{
byte [ ] fileData ;
try
string pass = paste [ "password" ] . ToString ( ) ;
// If it's a password protected paste, we just skip it
if ( string . IsNullOrEmpty ( pass ) | | pass = = "EMPTY" )
{
fileData = client . DownloadData ( fullUrl ) ;
string content = paste [ "code" ] . ToString ( ) ;
string title = paste [ "title" ] . ToString ( ) ;
DateTime posted = DateTime . Parse ( paste [ "posted" ] . ToString ( ) ) ;
int userId = Int32 . Parse ( paste [ "user_id" ] . ToString ( ) ) ;
Areas . Paste . Models . Paste newPaste = PasteHelper . CreatePaste ( content , title ) ;
newPaste . DatePosted = posted ;
newPaste . Url = paste [ "pid" ] . ToString ( ) ;
if ( userMapping . ContainsKey ( userId ) & & userId ! = 0 )
{
newPaste . UserId = userMapping [ userId ] ;
}
context . Pastes . AddOrUpdate ( newPaste ) ;
context . SaveChanges ( ) ;
}
catch ( Exception ex ) {
}
// Transfer Uploads
var uploadRet = db . Query ( "SELECT * FROM `uploads`" ) ;
var curUploads = context . Uploads . ToList ( ) ;
if ( curUploads = = null )
curUploads = new List < Areas . Upload . Models . Upload > ( ) ;
int curUpload = 0 ;
int curFinished = 0 ;
//int curDeleted = 0;
foreach ( var upload in uploadRet )
{
curUpload + + ;
try {
string url = upload [ "url" ] . ToString ( ) ;
//Areas.Upload.Models.Upload upFound = curUploads.Find(u => u.Url == url);
//if (upFound != null)
//{
// string subDir = upFound.FileName[0].ToString();
// string filePath = Path.Combine(config.UploadConfig.UploadDirectory, subDir, upFound.FileName);
// if (File.Exists(filePath))
// {
// continue;
// }
// else
// {
// curDeleted++;
// context.Uploads.Remove(upFound);
// context.SaveChanges();
// }
//}
string fileType = upload [ "type" ] . ToString ( ) ;
int contentLength = Int32 . Parse ( upload [ "filesize" ] . ToString ( ) ) ;
string deleteKey = upload [ "delete_key" ] . ToString ( ) ;
int userId = Int32 . Parse ( upload [ "user_id" ] . ToString ( ) ) ;
DateTime uploadDate = DateTime . Parse ( upload [ "upload_date" ] . ToString ( ) ) ;
string fullUrl = string . Format ( "https://u.teknik.io/{0}" , url ) ;
string fileExt = Path . GetExtension ( fullUrl ) ;
if ( ! File . Exists ( Path . Combine ( "Z:\\Uploads_Old" , upload [ "filename" ] . ToString ( ) ) ) )
{
continue ;
}
try
// Download the old file and re-upload it
using ( WebDownload client = new WebDownload ( 1 0 0 0 0 ) )
{
// Generate key and iv if empty
string key = Utility . RandomString ( config . UploadConfig . KeySize / 8 ) ;
string iv = Utility . RandomString ( config . UploadConfig . BlockSize / 8 ) ;
fileData = AES . Encrypt ( fileData , key , iv ) ;
if ( fileData = = null | | fileData . Length < = 0 )
byte [ ] fileData ;
try
{
fileData = client . DownloadData ( fullUrl ) ;
}
catch ( Exception ex ) {
continue ;
}
Areas . Upload . Models . Upload up = Uploader . SaveFile ( fileData , fileType , contentLength , fileExt , iv , key , config . UploadConfig . KeySize , config . UploadConfig . BlockSize ) ;
if ( userMapping . ContainsKey ( userId ) )
up . UserId = userMapping [ userId ] ;
if ( ! string . IsNullOrEmpty ( deleteKey ) )
up . DeleteKey = deleteKey ;
up . Url = url ;
context . Entry ( up ) . State = EntityState . Modified ;
context . SaveChanges ( ) ;
curFinished + + ;
}
catch ( Exception ex ) {
try
{
// Generate key and iv if empty
string key = Utility . RandomString ( config . UploadConfig . KeySize / 8 ) ;
string iv = Utility . RandomString ( config . UploadConfig . BlockSize / 8 ) ;
fileData = AES . Encrypt ( fileData , key , iv ) ;
if ( fileData = = null | | fileData . Length < = 0 )
{
continue ;
}
Areas . Upload . Models . Upload up = Uploader . SaveFile ( fileData , fileType , contentLength , fileExt , iv , key , config . UploadConfig . KeySize , config . UploadConfig . BlockSize ) ;
if ( userMapping . ContainsKey ( userId ) )
up . UserId = userMapping [ userId ] ;
if ( ! string . IsNullOrEmpty ( deleteKey ) )
up . DeleteKey = deleteKey ;
up . Url = url ;
context . Entry ( up ) . State = EntityState . Modified ;
context . SaveChanges ( ) ;
curFinished + + ;
}
catch ( Exception ex ) {
}
}
}
catch ( Exception ex ) {
}
}
catch ( Exception ex ) {
}
//}
* /
}
//}
* /
}
//private void Db_MysqlErrorEvent(object sender, string e)