public virtual IEnumerable <IDirectory> GetDirectories()
 {
     foreach (var directory in PhysicalDirectory.GetDirectories())
     {
         yield return(new SubtextDirectory(directory));
     }
 }
 public virtual IEnumerable <IFile> GetFiles()
 {
     foreach (var file in PhysicalDirectory.GetFiles())
     {
         yield return(new SubtextFile(file));
     }
 }
 public void Delete(bool recursive)
 {
     if (PhysicalDirectory.Exists)
     {
         PhysicalDirectory.Delete(recursive);
     }
 }
Esempio n. 4
0
        public void DeleteImage(int imageId, string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException();
            }

            Image imageToDelete = Database.ImageRepository.Find(imageId);

            if (imageToDelete == null)
            {
                throw new ArgumentNullException("Invalid image id");
            }

            if (imageToDelete.UserId != userId)
            {
                throw new ArgumentNullException("UserId of image does not coincide with userId in parameters");
            }

            var fullImagePath = Path.Combine(PhysicalDirectory.CurrentServerLocation,
                                             imageToDelete.LocalPath);

            try
            {
                Database.ImageRepository.Delete(imageToDelete);
                Database.Commit();
                PhysicalDirectory.DeleleImageFromServerPhysically(fullImagePath);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 5
0
 public override void Stop()
 {
     _server.Stop();
     if (RemoveSiteWhenStop)
     {
         PhysicalDirectory.Delete(true);
     }
 }
Esempio n. 6
0
        public void DeleteRepository()
        {
            PhysicalDirectory.Empty();
            Mountpoint.Empty();

            Directory.Delete(PhysicalDirectory.FullName);
            Directory.Delete(Mountpoint.FullName);
        }
Esempio n. 7
0
 public PhysicalDirectoryTreeNode(IServiceProvider serviceProvider, PhysicalDirectory physicalDirectory)
     : base(physicalDirectory.Name, serviceProvider)
 {
     ImageIndex         = 6;
     SelectedImageIndex = 6;
     PhysicalDirectory  = physicalDirectory;
     Nodes.Add("temp");
     ServerManager = physicalDirectory.Application.Server;
 }
Esempio n. 8
0
        public PhysicalDirectoryPage(PhysicalDirectory physicalDirectory, MainForm main)
        {
            InitializeComponent();
            btnView.Image    = DefaultTaskList.ViewImage;
            btnGo.Image      = DefaultTaskList.GoImage;
            btnShowAll.Image = DefaultTaskList.ShowAllImage;

            _physicalDirectory = physicalDirectory;
            _main = main;
        }
Esempio n. 9
0
 public ConfigurationService(Form form, Configuration config, ManagementScope scope, ServerManager server, Site site, Microsoft.Web.Administration.Application application, VirtualDirectory virtualDirectory, PhysicalDirectory physicalDirectory, string location)
 {
     Scope             = scope;
     Server            = server;
     Application       = application;
     Site              = site;
     Form              = form;
     VirtualDirectory  = virtualDirectory;
     PhysicalDirectory = physicalDirectory;
     _config           = config;
     _location         = location;
 }
Esempio n. 10
0
 public void DeleteRepository()
 {
     if (Directory.Exists(PhysicalDirectory.FullName))
     {
         PhysicalDirectory.Empty();
         Directory.Delete(PhysicalDirectory.FullName);
     }
     if (Directory.Exists(Mountpoint.FullName))
     {
         Mountpoint.Empty();
         Directory.Delete(Mountpoint.FullName);
     }
 }
Esempio n. 11
0
        public override void Stop()
        {
            using (var server = new WebServerIIS(_settings))
            {
                var app = server.DefaultWebSite.Applications.FirstOrDefault(a => a.Path == "/" + VirtualPath);
                if (app != null)
                {
                    server.DefaultWebSite.Applications.Remove(app);
                    server.ServerManager.CommitChanges();
                }
                server.Stop();
            }

            if (RemoveSiteWhenStop)
            {
                PhysicalDirectory.Delete(true);
            }
        }
Esempio n. 12
0
        public void UpdateUserAvatar(byte[] buffer, string fileName, string userId)
        {
            string fileExtension = Path.GetExtension(fileName);

            fileName = Guid.NewGuid() + fileExtension;


            //should be information of registered user
            UserProfile user = Database.UserRepository.Find(userId);

            if (user == null)
            {
                throw new NullReferenceException("Invalid User id");
            }

            var localpath = Path.Combine(PhysicalDirectory.ImagesStoreFolder, user.Id, fileName);

            //path to image location on server
            var path = Path.Combine(PhysicalDirectory.CurrentServerLocation, localpath);


            try
            {
                PhysicalDirectory.WriteImageOnServerPhysically(buffer, path);

                //deletes old image if exists
                if (!string.IsNullOrEmpty(user.AvatarUrl))
                {
                    var oldpath = Path.Combine(PhysicalDirectory.CurrentServerLocation, user.Id, user.AvatarUrl);
                    PhysicalDirectory.DeleleImageFromServerPhysically(oldpath);
                }

                user.AvatarUrl = localpath;
                Database.UserRepository.Update(user);
                Database.Commit();
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 13
0
        public void AddImage(UploadedImage image)
        {
            string fileExtension = Path.GetExtension(image.FileName);
            string fileName      = Guid.NewGuid() + fileExtension;

            UserProfile user = Database.UserRepository.Find(image.UserId);

            if (user == null)
            {
                throw new NullReferenceException("Invalid User id");
            }

            //will be written into photo data
            var localpath     = Path.Combine(PhysicalDirectory.ImagesStoreFolder, user.Id, fileName);
            var fullImagePath = Path.Combine(PhysicalDirectory.CurrentServerLocation, localpath);

            PhysicalDirectory.WriteImageOnServerPhysically(image.Buffer, fullImagePath);

            Image newImage = new Image
            {
                User        = user,
                LocalPath   = localpath,
                ImageName   = fileName,
                Description = image.Description,
            };

            newImage.Tags = AddTags(image.Tags, newImage);

            try
            {
                Database.ImageRepository.Add(newImage);
                Database.Commit();
            }
            catch (Exception)
            {
                //Rolling Back happend an error
                PhysicalDirectory.DeleleImageFromServerPhysically(fullImagePath);
                throw;
            }
        }
Esempio n. 14
0
        public override string Start()
        {
            PhysicalDirectory.Refresh();
            if (!PhysicalDirectory.Exists)
            {
                throw new DirectoryNotFoundException(PhysicalDirectory.FullName);
            }

            SetUserPermission(Users, PhysicalDirectory);

            var settings = new WebServerSettings();

            settings.RootPhysicalPath = PhysicalDirectory.FullName;

            _server = new WebServerIISExpress(settings);
            var application = _server.DefaultWebSite.Applications.Add("/" + VirtualPath, PhysicalDirectory.FullName);

            _server.ServerManager.CommitChanges();

            Thread.Sleep(IISDelay);

            return(_server.DefaultWebSite.GetHttpVirtualPath() + application.Path);
        }
 public IDirectory Create()
 {
     PhysicalDirectory.Create();
     return(this);
 }
Esempio n. 16
0
 public static void Register()
 {
     PhysicalDirectory.CurrentServerLocation = HttpContext.Current.Server.MapPath("~/");
     PhysicalDirectory.ImagesStoreFolder     = "photos";
     PhysicalDirectory.EnsureFolderExists();
 }
Esempio n. 17
0
        /// <summary>
        ///     Creates a new repository folder from scratch
        /// </summary>
        /// <returns></returns>
        public void CreateDirectories(bool performFullCheckout)
        {
            if (!Directory.Exists(PhysicalDirectory.FullName))
            {
                Directory.CreateDirectory(PhysicalDirectory.FullName);
            }
            if (!Directory.Exists(Mountpoint.FullName))
            {
                Directory.CreateDirectory(Mountpoint.FullName);
            }

            if (CreateNew)
            {
                var result = GetCommandLineOutput("cmd.exe", "/C gin.exe create " + Name,
                                                  PhysicalDirectory.Parent.FullName, out var error);

                if (!string.IsNullOrEmpty(error))
                {
                    OnFileOperationError(error);
                }
            }
            else
            {
                if (PhysicalDirectory.IsEmpty())
                {
                    OnFileOperationStarted(new FileOperationEventArgs {
                        File = Address
                    });

                    GetCommandLineOutputEvent("cmd.exe", "/C gin.exe get --json " + Address,
                                              PhysicalDirectory.Parent.FullName, out var error);

                    var result = string.IsNullOrEmpty(error);

                    if (result)
                    {
                        OnFileOperationCompleted(new FileOperationEventArgs {
                            File = Address, Success = true
                        });
                    }
                    else
                    {
                        OnFileOperationError(error);
                    }
                }

                if (performFullCheckout)
                {
                    OnFileOperationStarted(new FileOperationEventArgs {
                        File = Address
                    });

                    GetCommandLineOutputEvent("cmd.exe", "/C gin.exe download --json --content",
                                              PhysicalDirectory.Parent.FullName, out var error);

                    var result = string.IsNullOrEmpty(error);

                    if (result)
                    {
                        OnFileOperationCompleted(new FileOperationEventArgs {
                            File = Address, Success = true
                        });
                    }
                    else
                    {
                        OnFileOperationError(error);
                    }
                }
            }
        }
 public PhysicalFileSystem(IHostingEnvironment hostingEnvironment)
 {
     CurrentDirectory = new PhysicalDirectory(hostingEnvironment.WorkingDirectory);
 }
Esempio n. 19
0
        /// <summary>
        ///     Creates a new repository folder from scratch
        /// </summary>
        /// <returns></returns>
        public bool CreateDirectories(bool performFullCheckout)
        {
            try
            {
                if (!Directory.Exists(PhysicalDirectory.FullName))
                {
                    Directory.CreateDirectory(PhysicalDirectory.FullName);
                }
            }
            catch (Exception e)
            {
                OnFileOperationError("Could not create checkout directory. Exception: " + e.Message + "\n InnerException: " + e.InnerException);
                return(false);
            }

            try
            {
                if (!Directory.Exists(Mountpoint.FullName))
                {
                    Directory.CreateDirectory(Mountpoint.FullName);
                }
            }
            catch (Exception e)
            {
                OnFileOperationError("Could not create mountpoint directory. Exception: " + e.Message + "\n InnerException: " + e.InnerException);
                return(false);
            }

            if (PhysicalDirectory.IsEmpty())
            {
                OnFileOperationStarted(new FileOperationEventArgs {
                    File = Address
                });
                GetCommandLineOutputEvent(GinCliExe, " get --json " + Address,
                                          PhysicalDirectory.Parent.FullName, out var error);
                var result = string.IsNullOrEmpty(error);
                if (result)
                {
                    OnFileOperationCompleted(new FileOperationEventArgs {
                        File = Address, Success = true
                    });
                }
                else
                {
                    OnFileOperationError(error);
                    return(false);
                }
            }

            if (performFullCheckout)
            {
                OnFileOperationStarted(new FileOperationEventArgs {
                    File = Address
                });
                GetCommandLineOutputEvent(GinCliExe, " download --json --content",
                                          PhysicalDirectory.FullName, out var error);
                var result = string.IsNullOrEmpty(error);
                if (result)
                {
                    OnFileOperationCompleted(new FileOperationEventArgs {
                        File = Address, Success = true
                    });
                }
                else
                {
                    OnFileOperationError(error);
                    return(false);
                }
            }
            return(true);
        }