Пример #1
0
        private string LocalRepoMove(MoveCopyImageModel model)
        {
            string localDestinationPath = "";

            try
            {
                string localServerPath = "F:/Danni/";
                string localSourcePath = localServerPath + Helpers.GetLocalParentPath(model.SourceFolderId) + model.SourceFolderName; // + "/" + dbImageFile.FileName;
                //dbSourceFolder.FolderName + "_" + dbImageLink.Id + extension;
                localDestinationPath = localServerPath + Helpers.GetLocalParentPath(model.DestinationFolderId) + model.DestinationFolderName;
                FileInfo      localFile     = new FileInfo(localSourcePath);
                DirectoryInfo directoryInfo = new DirectoryInfo(localDestinationPath);
                if (!directoryInfo.Exists)
                {
                    directoryInfo.Create();
                }
                localFile.MoveTo(localDestinationPath + "/" + "newFileName");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("move file on local drive : " + Helpers.ErrorDetails(ex) + " " + localDestinationPath);
            }
            return("ok");
        }
Пример #2
0
        private string FtpMove(string currentFileName, MoveCopyImageModel model)
        {
            string success;
            string linkId = model.LinkId;

            using (var db = new OggleBoobleMySqlContext())
            {
                ImageFile dbImageFile = db.ImageFiles.Where(i => i.Id == linkId).FirstOrDefault();
                if (dbImageFile == null)
                {
                    return("link [" + linkId + "] not found");
                }
                //imageLinkId = dbImageFile.Id;

                // ? physcially more and rename .jpg
                CategoryFolder dbSourceFolder      = db.CategoryFolders.Where(f => f.Id == model.SourceFolderId).First();
                CategoryFolder dbDestinationFolder = db.CategoryFolders.Where(f => f.Id == model.DestinationFolderId).First();
                //string currentFileName = dbImageFile.FileName;
                string newFileName        = dbSourceFolder.FolderName + "_" + linkId;
                string destinationFtpPath = ftpHost + dbDestinationFolder.RootFolder + ".ogglebooble.com/" + Helpers.GetParentPath(model.DestinationFolderId) + dbDestinationFolder.FolderName;
                string sourceFtpPath      = ftpHost + dbSourceFolder.RootFolder + ".ogglebooble.com/" + Helpers.GetParentPath(model.SourceFolderId) + newFileName;

                if (!FtpUtilies.DirectoryExists(destinationFtpPath))
                {
                    FtpUtilies.CreateDirectory(destinationFtpPath);
                }

                success = FtpUtilies.MoveFile(sourceFtpPath + "/" + dbImageFile.FileName, destinationFtpPath + "/" + newFileName);
                if (success == "ok")
                {
                    #region move file on local drive
                    string localDestinationPath = "";
                    try
                    {
                        string localServerPath = "F:/Danni/";
                        string localSourcePath = localServerPath + Helpers.GetLocalParentPath(model.SourceFolderId) + dbSourceFolder.FolderName + "/" + dbImageFile.FileName;
                        //dbSourceFolder.FolderName + "_" + dbImageLink.Id + extension;
                        localDestinationPath = localServerPath + Helpers.GetLocalParentPath(model.DestinationFolderId) + dbDestinationFolder.FolderName;
                        FileInfo      localFile     = new FileInfo(localSourcePath);
                        DirectoryInfo directoryInfo = new DirectoryInfo(localDestinationPath);
                        if (!directoryInfo.Exists)
                        {
                            directoryInfo.Create();
                        }
                        localFile.MoveTo(localDestinationPath + "/" + newFileName);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine("move file on local drive : " + Helpers.ErrorDetails(ex) + " " + localDestinationPath);
                    }
                    #endregion

                    //2. update ImageFile
                    //string linkPrefix = "http://" + dbDestinationFolder.RootFolder + ".ogglebooble.com/";
                    //newInternalLink = linkPrefix + Helpers.GetParentPath(model.DestinationFolderId) + dbDestinationFolder.FolderName + "/" + newFileName;
                    //var goDaddyrow = db.ImageLinks.Where(g => g.Id == dbImageLink.Id).FirstOrDefault();
                    var oldCatImageLink = db.CategoryImageLinks
                                          .Where(c => c.ImageCategoryId == model.SourceFolderId && c.ImageLinkId == dbImageFile.Id).First();
                    db.CategoryImageLinks.Add(new MySqlDataContext.CategoryImageLink()
                    {
                        ImageCategoryId = model.DestinationFolderId,
                        ImageLinkId     = dbImageFile.Id,
                        SortOrder       = oldCatImageLink.SortOrder
                    });
                    db.SaveChanges();
                    if (model.Mode == "Move")
                    {
                        db.CategoryImageLinks.Remove(oldCatImageLink);
                    }
                    db.SaveChanges();
                }
                return(success);
            }
        }
Пример #3
0
        public SuccessModel MoveCopyArchive(MoveCopyImageModel model)
        {
            SuccessModel successModel = new SuccessModel();

            if (model.SourceFolderId == model.DestinationFolderId)
            {
                successModel.Success = "Source and Destination the same";
                return(successModel);
            }
            try
            {
                string imageLinkId;
                using (var db = new OggleBoobleMySqlContext())
                {
                    ImageFile dbImageFile = db.ImageFiles.Where(i => i.Id == model.LinkId).FirstOrDefault();
                    if (dbImageFile == null)
                    {
                        successModel.Success = "link [" + model.LinkId + "] not found";
                        return(successModel);
                    }
                    imageLinkId = dbImageFile.Id;

                    var categoryImageLinks = db.CategoryImageLinks.Where(l => l.ImageCategoryId == model.DestinationFolderId).ToList();
                    if (model.Mode == "Copy")  // just add a rec to CategoryImageLink (which should be called File_Image)
                    {
                        MySqlDataContext.CategoryImageLink existingLink = categoryImageLinks.Where(l => l.ImageLinkId == imageLinkId).FirstOrDefault();
                        if (existingLink != null)
                        {
                            successModel.Success = "Link already exists";
                        }
                        else
                        {
                            db.CategoryImageLinks.Add(new MySqlDataContext.CategoryImageLink()
                            {
                                ImageCategoryId = model.DestinationFolderId,
                                ImageLinkId     = imageLinkId,
                                SortOrder       = 999
                            });
                            db.SaveChanges();
                            successModel.Success = "ok";
                        }
                    }
                    else  // Archive / Move
                    {
                        var oldCatImageLink = db.CategoryImageLinks
                                              .Where(c => c.ImageCategoryId == model.SourceFolderId && c.ImageLinkId == dbImageFile.Id).First();
                        db.CategoryImageLinks.Add(new MySqlDataContext.CategoryImageLink()
                        {
                            ImageCategoryId = model.DestinationFolderId,
                            ImageLinkId     = dbImageFile.Id,
                            SortOrder       = oldCatImageLink.SortOrder
                        });
                        db.SaveChanges();
                        if (model.Mode == "Move")
                        {
                            db.CategoryImageLinks.Remove(oldCatImageLink);
                        }
                        db.SaveChanges();
                    }
                    // determine if this is the first image added to folder
                    successModel.ReturnValue = db.CategoryImageLinks.Where(c => c.ImageCategoryId == model.DestinationFolderId).Count().ToString();
                }
                successModel.Success = "ok";
            }
            catch (Exception ex)
            {
                successModel.Success = Helpers.ErrorDetails(ex);
            }
            return(successModel);
        }