Exemple #1
0
        public void Run(Logger logger)
        {
            var folders = GlobalConstants.ReportFolders;

            for (int i = 0; i < folders.Length; i++)
            {
                bool isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);

                string linuxFolderToWatch = isLinux ?
                                            GlobalConstants.LinuxFolderToWatch :
                                            GlobalConstants.WindowsFolderToWatch;

                string fullPath = string.Format(linuxFolderToWatch, folders[i]);
                logger.Info(string.Format(InfoMessages.LineHeader, folders[i]));
                int empty = Directory.GetFiles(fullPath).Length;

                if (empty == 0)
                {
                    logger.Info(string.Format(InfoMessages.CheckedFolder, folders[i]));
                    continue;
                }

                FolderHandler.ProcessFolder(folders[i], fullPath, logger, isLinux);

                logger.Info(string.Format(InfoMessages.CheckedFolder, folders[i]));
            }
        }
 public UploadPictureController(IUserService userService, IRemitRecordService remitRecordService, ILogger <UploadPictureController> logger, FolderHandler folderHandler, IUploadPic uploadPic
                                )
 {
     this.logger             = logger;
     this.folderHandler      = folderHandler;
     this.userService        = userService;
     this.remitRecordService = remitRecordService;
     this.uploadPic          = uploadPic;
 }
Exemple #3
0
 // creates a new handler for each folder
 public void BuildHandlers()
 {
     foreach (string s in pathsToListen)
     {
         if (Directory.Exists(s))
         {
             IHandler h = new FolderHandler(s, ref m_controller, ref m_logger);
             h.HandlerClosing += HandlerClosed;
             handlers.Add(h);
             h.Begin();
         }
     }
 }
Exemple #4
0
        public Form1()
        {
            SplashScreen ss = new SplashScreen();

            ss.Show();
            ss.MaxValue = 5;
            ss.SetText("Making components...");
            InitializeComponent();
            ss.IncrementValue(1);
            Thread.Sleep(1000);
            ss.SetText("Initializing UI works...");
            InitializeUIHandler();
            ss.IncrementValue(1);
            Thread.Sleep(1000);

            ss.SetText("Looking for needed directories...");
            // Checking if all the needed folders does exist.
            FolderHandler.InitializeNeededDirectories();
            ss.IncrementValue(1);
            Thread.Sleep(1000);

            ss.SetText("Looking for session story...");
            if (SessionHandler.CheckSessionsStoryExistance())
            {
                ss.MaxValue = 6;
                ss.SetText("Loading session story...");
                SessionHandler.TryReadSessionData();
                SessionHandler.LoadSessionDataListToDataOnDataGridView(ref dataGridView1);
                ss.IncrementValue(1);
                Thread.Sleep(1000);
            }
            ss.IncrementValue(1);
            Thread.Sleep(1000);

            ss.SetText("Changing styles...");
            dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(45, 45, 48);
            dataGridView1.EnableHeadersVisualStyles = false;
            ss.IncrementValue(1);
            Thread.Sleep(1000);

            // Initialization of the TCPSetting being used for work.
            // "//" used for skipping through the validation that were throwing out exceptions of out of index.
            //currentTcpSettings = new TCPSettings("//", "", 0, true, true, false, false, (int)timeOutNumericUpDown.Value);

            ss.SetText("Done!");
            Thread.Sleep(1000);
            ss.Close();
        }
        public Form1()
        {
            InitializeComponent();
            InitializeUIHandler();

            // Checking if all the needed folders does exist.
            FolderHandler.InitializeNeededDirectories();

            if (SessionHandler.CheckSessionsStoryExistance())
            {
                SessionHandler.TryReadSessionData();
                SessionHandler.LoadSessionDataListToDataOnDataGridView(ref dataGridView1);
            }

            // Initialization of the TCPSetting being used for work.
            // "//" used for skipping through the validation that were throwing out exceptions of out of index.
            //currentTcpSettings = new TCPSettings("//", "", 0, true, true, false, false, (int)timeOutNumericUpDown.Value);
        }
Exemple #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        leftEventLabel.Visible = false;

        //Kollar om Username finns i den aktiva sessionen
        if (String.IsNullOrEmpty((string)Session["Username"]))
        {
            string test = (string)Session["Username"];

            Response.Redirect("Default.aspx?SessionActive=false", false);
        }
        else
        {
            if (Session["userFolders"] == null)
            {
                getUserFiles(Session["Username"].ToString());
            }
            else
            {
                _userFolders = (FolderHandler)Session["userFolders"];
                populateFolders();
            }
        }

        if (IsPostBack)
        {
            string eArg = Request["__EVENTARGUMENT"];
            if (!string.IsNullOrEmpty(eArg))
            {
                RaisePostBackEvent(eArg);
            }
        }
        if (!string.IsNullOrEmpty((string)Session["message"]))
        {
            leftEventLabel.CssClass = (string)Session["color"];
            leftEventLabel.Text     = (string)Session["message"];
            leftEventLabel.Visible  = true;
        }
    }
        protected override void BuildXml()
        {
            if (Request.Form["CKFinderCommand"] != "true")
            {
                ConnectorException.Throw(Errors.InvalidRequest);
            }

            if (!this.CurrentFolder.CheckAcl(AccessControlRules.FileRename | AccessControlRules.FileUpload | AccessControlRules.FileDelete))
            {
                ConnectorException.Throw(Errors.Unauthorized);
            }

            if (Request.Form["files[0][type]"] == null)
            {
                ConnectorException.Throw(Errors.InvalidRequest);
            }

            int moved    = 0;
            int movedAll = 0;

            if (Request.Form["moved"] != null)
            {
                movedAll = Int32.Parse(Request.Form["moved"]);
            }
            Settings.ResourceType resourceType;
            Hashtable             resourceTypeConfig = new Hashtable();
            Hashtable             checkedPaths       = new Hashtable();

            int iFileNum = 0;

            while (Request.Form["files[" + iFileNum.ToString() + "][type]"] != null && Request.Form["files[" + iFileNum.ToString() + "][type]"].Length > 0)
            {
                string name    = Request.Form["files[" + iFileNum.ToString() + "][name]"];
                string type    = Request.Form["files[" + iFileNum.ToString() + "][type]"];
                string path    = Request.Form["files[" + iFileNum.ToString() + "][folder]"];
                string options = "";

                if (name == null || name.Length < 1 || type == null || type.Length < 1 || path == null || path.Length < 1)
                {
                    ConnectorException.Throw(Errors.InvalidRequest);
                    return;
                }

                if (Request.Form["files[" + iFileNum.ToString() + "][options]"] != null)
                {
                    options = Request.Form["files[" + iFileNum.ToString() + "][options]"];
                }
                iFileNum++;

                // check #1 (path)
                if (!Connector.CheckFileName(name) || Regex.IsMatch(path, @"(/\.)|(\.\.)|(//)|([\\:\*\?""\<\>\|])"))
                {
                    ConnectorException.Throw(Errors.InvalidRequest);
                    return;
                }

                // get resource type config for current file
                if (!resourceTypeConfig.ContainsKey(type))
                {
                    resourceTypeConfig[type] = Config.Current.GetResourceTypeConfig(type);
                }

                // check #2 (resource type)
                if (resourceTypeConfig[type] == null)
                {
                    ConnectorException.Throw(Errors.InvalidRequest);
                    return;
                }

                resourceType = (Settings.ResourceType)resourceTypeConfig[type];
                FolderHandler folder         = new FolderHandler(type, path);
                string        sourceFilePath = System.IO.Path.Combine(folder.ServerPath, name);

                // check #3 (extension)
                if (!resourceType.CheckExtension(System.IO.Path.GetExtension(name)))
                {
                    this.appendErrorNode(Errors.InvalidExtension, name, type, path);
                    continue;
                }

                // check #4 (extension) - when moving to another resource type, double check extension
                if (this.CurrentFolder.ResourceTypeName != type)
                {
                    if (!this.CurrentFolder.ResourceTypeInfo.CheckExtension(System.IO.Path.GetExtension(name)))
                    {
                        this.appendErrorNode(Errors.InvalidExtension, name, type, path);
                        continue;
                    }
                }

                // check #5 (hidden folders)
                if (!checkedPaths.ContainsKey(path))
                {
                    checkedPaths[path] = true;
                    if (Config.Current.CheckIsHidenPath(path))
                    {
                        ConnectorException.Throw(Errors.InvalidRequest);
                        return;
                    }
                }

                // check #6 (hidden file name)
                if (Config.Current.CheckIsHiddenFile(name))
                {
                    ConnectorException.Throw(Errors.InvalidRequest);
                    return;
                }

                // check #7 (Access Control, need file view permission to source files)
                if (!folder.CheckAcl(AccessControlRules.FileView))
                {
                    ConnectorException.Throw(Errors.Unauthorized);
                    return;
                }

                // check #8 (invalid file name)
                if (!System.IO.File.Exists(sourceFilePath) || System.IO.Directory.Exists(sourceFilePath))
                {
                    this.appendErrorNode(Errors.FileNotFound, name, type, path);
                    continue;
                }

                // check #9 (max size)
                if (this.CurrentFolder.ResourceTypeName != type)
                {
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(sourceFilePath);
                    if (this.CurrentFolder.ResourceTypeInfo.MaxSize > 0 && fileInfo.Length > this.CurrentFolder.ResourceTypeInfo.MaxSize)
                    {
                        this.appendErrorNode(Errors.UploadedTooBig, name, type, path);
                        continue;
                    }
                }

                string destinationFilePath = System.IO.Path.Combine(this.CurrentFolder.ServerPath, name);
                string thumbPath           = System.IO.Path.Combine(folder.ThumbsServerPath, name);

                // finally, no errors so far, we may attempt to copy a file
                // protection against copying files to itself
                if (sourceFilePath == destinationFilePath)
                {
                    this.appendErrorNode(Errors.SourceAndTargetPathEqual, name, type, path);
                    continue;
                }
                // check if file exists if we don't force overwriting
                else if (System.IO.File.Exists(destinationFilePath))
                {
                    if (options.Contains("overwrite"))
                    {
                        try
                        {
                            System.IO.File.Delete(destinationFilePath);
                        }
                        catch (Exception)
                        {
                            this.appendErrorNode(Errors.AccessDenied, name, type, path);
                            continue;
                        }
                        try
                        {
                            System.IO.File.Move(sourceFilePath, destinationFilePath);
                            moved++;

                            try
                            {
                                System.IO.File.Delete(thumbPath);
                            }
                            catch { /* No errors if we are not able to delete the thumb. */ }
                        }
                        catch (Exception)
                        {
                            this.appendErrorNode(Errors.AccessDenied, name, type, path);
                            continue;
                        }
                    }
                    else if (options.Contains("autorename"))
                    {
                        int    iCounter = 1;
                        string fileName;
                        string sFileNameNoExt = CKFinder.Connector.Util.GetFileNameWithoutExtension(name);
                        string sFullExtension = CKFinder.Connector.Util.GetExtension(name);
                        while (true)
                        {
                            fileName            = sFileNameNoExt + "(" + iCounter.ToString() + ")" + sFullExtension;
                            destinationFilePath = System.IO.Path.Combine(this.CurrentFolder.ServerPath, fileName);
                            if (!System.IO.File.Exists(destinationFilePath))
                            {
                                break;
                            }
                            else
                            {
                                iCounter++;
                            }
                        }
                        try
                        {
                            System.IO.File.Move(sourceFilePath, destinationFilePath);
                            moved++;

                            try
                            {
                                System.IO.File.Delete(thumbPath);
                            }
                            catch { /* No errors if we are not able to delete the thumb. */ }
                        }
                        catch (ArgumentException)
                        {
                            this.appendErrorNode(Errors.InvalidName, name, type, path);
                            continue;
                        }
                        catch (System.IO.PathTooLongException)
                        {
                            this.appendErrorNode(Errors.InvalidName, name, type, path);
                            continue;
                        }
                        catch (Exception)
                        {
#if DEBUG
                            throw;
#else
                            this.appendErrorNode(Errors.AccessDenied, name, type, path);
                            continue;
#endif
                        }
                    }
                    else
                    {
                        this.appendErrorNode(Errors.AlreadyExist, name, type, path);
                        continue;
                    }
                }
                else
                {
                    try
                    {
                        System.IO.File.Move(sourceFilePath, destinationFilePath);
                        moved++;

                        try
                        {
                            System.IO.File.Delete(thumbPath);
                        }
                        catch { /* No errors if we are not able to delete the thumb. */ }
                    }
                    catch (ArgumentException)
                    {
                        this.appendErrorNode(Errors.InvalidName, name, type, path);
                        continue;
                    }
                    catch (System.IO.PathTooLongException)
                    {
                        this.appendErrorNode(Errors.InvalidName, name, type, path);
                        continue;
                    }
                    catch (Exception)
                    {
#if DEBUG
                        throw;
#else
                        this.appendErrorNode(Errors.AccessDenied, name, type, path);
                        continue;
#endif
                    }
                }
            }

            XmlNode moveFilesNode = XmlUtil.AppendElement(this.ConnectorNode, "MoveFiles");
            XmlUtil.SetAttribute(moveFilesNode, "moved", moved.ToString());
            XmlUtil.SetAttribute(moveFilesNode, "movedTotal", (movedAll + moved).ToString());

            if (this.ErrorsNode != null)
            {
                ConnectorException.Throw(Errors.MoveFailed);
                return;
            }
        }
Exemple #8
0
 public CommandHandlerBase()
 {
     _CurrentFolder = FolderHandler.GetCurrent();
     _Request = HttpContext.Current.Request;
 }
 public FoldersController()
 {
     this.handler = new FolderHandler();
 }
		protected override void BuildXml()
		{
			if ( Request.Form["CKFinderCommand"] != "true" )
			{
				ConnectorException.Throw( Errors.InvalidRequest );
			}

			if ( !this.CurrentFolder.CheckAcl( AccessControlRules.FileDelete ) )
			{
				ConnectorException.Throw( Errors.Unauthorized );
			}

			Settings.ResourceType resourceType;
			Hashtable resourceTypeConfig = new Hashtable();
			Hashtable checkedPaths = new Hashtable();
			XmlNode oDeletedFileNode = null;
			int iFileNum = 0;
			int deletedNum = 0;

			while ( Request.Form["files[" + iFileNum.ToString() + "][type]"] != null && Request.Form["files[" + iFileNum.ToString() + "][type]"].Length > 0 )
			{
				string name = Request.Form["files[" + iFileNum.ToString() + "][name]"];
				string type = Request.Form["files[" + iFileNum.ToString() + "][type]"];
				string path = Request.Form["files[" + iFileNum.ToString() + "][folder]"];

				if ( name == null || name.Length < 1 || type == null || type.Length < 1 || path == null || path.Length < 1 )
				{
					ConnectorException.Throw( Errors.InvalidRequest );
					return;
				}
				iFileNum++;

				// check #1 (path)
				if ( !Connector.CheckFileName( name ) || Regex.IsMatch( path, @"(/\.)|(\.\.)|(//)|([\\:\*\?""\<\>\|])" ) )
				{
					ConnectorException.Throw( Errors.InvalidRequest );
					return;
				}

				// get resource type config for current file
				if ( !resourceTypeConfig.ContainsKey( type ) )
				{
					resourceTypeConfig[type] = Config.Current.GetResourceTypeConfig( type );
				}

				// check #2 (resource type)
				if ( resourceTypeConfig[type] == null )
				{
					ConnectorException.Throw( Errors.InvalidRequest );
					return;
				}

				resourceType = (Settings.ResourceType)resourceTypeConfig[type];
				FolderHandler folder = new FolderHandler( type, path );
				string filePath = System.IO.Path.Combine( folder.ServerPath, name );

				// check #3 (extension)
				if ( !resourceType.CheckExtension( System.IO.Path.GetExtension( name ) ) )
				{
					ConnectorException.Throw( Errors.InvalidRequest );
					return;
				}

				// check #5 (hidden folders)
				if ( !checkedPaths.ContainsKey( path ) )
				{
					checkedPaths[path] = true;
					if ( Config.Current.CheckIsHidenPath( path ) )
					{
						ConnectorException.Throw( Errors.InvalidRequest );
						return;
					}
				}

				// check #6 (hidden file name)
				if ( Config.Current.CheckIsHiddenFile( name ) )
				{
					ConnectorException.Throw( Errors.InvalidRequest );
					return;
				}

				// check #7 (Access Control, need file view permission to source files)
				if ( !folder.CheckAcl( AccessControlRules.FileDelete ) )
				{
					ConnectorException.Throw( Errors.Unauthorized );
					return;
				}

				// check #8 (invalid file name)
				if ( !System.IO.File.Exists( filePath ) || System.IO.Directory.Exists( filePath ) )
				{
					this.appendErrorNode( Errors.FileNotFound, name, type, path );
					continue;
				}

				bool bDeleted = false;

				try
				{
					System.IO.File.Delete( filePath );
					bDeleted = true;
					deletedNum++;
				}
				catch ( System.UnauthorizedAccessException )
				{
					this.appendErrorNode( Errors.AccessDenied, name, type, path );
				}
				catch ( System.Security.SecurityException )
				{
					this.appendErrorNode( Errors.AccessDenied, name, type, path );
				}
				catch ( System.ArgumentException )
				{
					this.appendErrorNode( Errors.FileNotFound, name, type, path );
				}
				catch ( System.IO.PathTooLongException )
				{
					this.appendErrorNode( Errors.FileNotFound, name, type, path );
				}
				catch
				{
#if DEBUG
				throw;
#else
					this.appendErrorNode( Errors.Unknown, name, type, path );
#endif
				}

				if ( bDeleted )
				{
					try
					{
						string thumbPath = System.IO.Path.Combine( folder.ThumbsServerPath, name );
						System.IO.File.Delete( thumbPath );
					}
					catch { /* No errors if we are not able to delete the thumb. */ }
				}
			}
			oDeletedFileNode = XmlUtil.AppendElement( this.ConnectorNode, "DeleteFiles" );
			XmlUtil.SetAttribute( oDeletedFileNode, "deleted", deletedNum.ToString() );
			if ( this.ErrorsNode != null )
			{
				ConnectorException.Throw( Errors.DeleteFailed );
				return;
			}
		}
        protected override void BuildXml()
        {
            if (Request.Form["CKFinderCommand"] != "true")
            {
                ConnectorException.Throw(Errors.InvalidRequest);
            }

            if (!this.CurrentFolder.CheckAcl(AccessControlRules.FileDelete))
            {
                ConnectorException.Throw(Errors.Unauthorized);
            }

            Settings.ResourceType resourceType;
            Hashtable             resourceTypeConfig = new Hashtable();
            Hashtable             checkedPaths       = new Hashtable();
            XmlNode oDeletedFileNode = null;
            int     iFileNum         = 0;
            int     deletedNum       = 0;

            while (Request.Form["files[" + iFileNum.ToString() + "][type]"] != null && Request.Form["files[" + iFileNum.ToString() + "][type]"].Length > 0)
            {
                string name = Request.Form["files[" + iFileNum.ToString() + "][name]"];
                string type = Request.Form["files[" + iFileNum.ToString() + "][type]"];
                string path = Request.Form["files[" + iFileNum.ToString() + "][folder]"];

                if (name == null || name.Length < 1 || type == null || type.Length < 1 || path == null || path.Length < 1)
                {
                    ConnectorException.Throw(Errors.InvalidRequest);
                    return;
                }
                iFileNum++;

                // check #1 (path)
                if (!Connector.CheckFileName(name) || Regex.IsMatch(path, @"(/\.)|(\.\.)|(//)|([\\:\*\?""\<\>\|])"))
                {
                    ConnectorException.Throw(Errors.InvalidRequest);
                    return;
                }

                // get resource type config for current file
                if (!resourceTypeConfig.ContainsKey(type))
                {
                    resourceTypeConfig[type] = Config.Current.GetResourceTypeConfig(type);
                }

                // check #2 (resource type)
                if (resourceTypeConfig[type] == null)
                {
                    ConnectorException.Throw(Errors.InvalidRequest);
                    return;
                }

                resourceType = (Settings.ResourceType)resourceTypeConfig[type];
                FolderHandler folder   = new FolderHandler(type, path);
                string        filePath = System.IO.Path.Combine(folder.ServerPath, name);

                // check #3 (extension)
                if (!resourceType.CheckExtension(System.IO.Path.GetExtension(name)))
                {
                    ConnectorException.Throw(Errors.InvalidRequest);
                    return;
                }

                // check #5 (hidden folders)
                if (!checkedPaths.ContainsKey(path))
                {
                    checkedPaths[path] = true;
                    if (Config.Current.CheckIsHidenPath(path))
                    {
                        ConnectorException.Throw(Errors.InvalidRequest);
                        return;
                    }
                }

                // check #6 (hidden file name)
                if (Config.Current.CheckIsHiddenFile(name))
                {
                    ConnectorException.Throw(Errors.InvalidRequest);
                    return;
                }

                // check #7 (Access Control, need file view permission to source files)
                if (!folder.CheckAcl(AccessControlRules.FileDelete))
                {
                    ConnectorException.Throw(Errors.Unauthorized);
                    return;
                }

                // check #8 (invalid file name)
                if (!System.IO.File.Exists(filePath) || System.IO.Directory.Exists(filePath))
                {
                    this.appendErrorNode(Errors.FileNotFound, name, type, path);
                    continue;
                }

                bool bDeleted = false;

                try
                {
                    System.IO.File.Delete(filePath);
                    bDeleted = true;
                    deletedNum++;
                }
                catch (System.UnauthorizedAccessException)
                {
                    this.appendErrorNode(Errors.AccessDenied, name, type, path);
                }
                catch (System.Security.SecurityException)
                {
                    this.appendErrorNode(Errors.AccessDenied, name, type, path);
                }
                catch (System.ArgumentException)
                {
                    this.appendErrorNode(Errors.FileNotFound, name, type, path);
                }
                catch (System.IO.PathTooLongException)
                {
                    this.appendErrorNode(Errors.FileNotFound, name, type, path);
                }
                catch
                {
#if DEBUG
                    throw;
#else
                    this.appendErrorNode(Errors.Unknown, name, type, path);
#endif
                }

                if (bDeleted)
                {
                    try
                    {
                        string thumbPath = System.IO.Path.Combine(folder.ThumbsServerPath, name);
                        System.IO.File.Delete(thumbPath);
                    }
                    catch { /* No errors if we are not able to delete the thumb. */ }
                }
            }
            oDeletedFileNode = XmlUtil.AppendElement(this.ConnectorNode, "DeleteFiles");
            XmlUtil.SetAttribute(oDeletedFileNode, "deleted", deletedNum.ToString());
            if (this.ErrorsNode != null)
            {
                ConnectorException.Throw(Errors.DeleteFailed);
                return;
            }
        }
        protected override void BuildXml()
        {
            if ( Request.Form["CKFinderCommand"] != "true" )
            {
                ConnectorException.Throw( Errors.InvalidRequest );
            }

            if ( !this.CurrentFolder.CheckAcl( AccessControlRules.FileRename | AccessControlRules.FileUpload | AccessControlRules.FileDelete ) )
            {
                ConnectorException.Throw( Errors.Unauthorized );
            }

            if ( Request.Form["files[0][type]"] == null )
            {
                ConnectorException.Throw( Errors.InvalidRequest );
            }

            int copied = 0;
            int copiedAll = 0;
            if ( Request.Form["copied"] != null )
            {
                copiedAll = Int32.Parse(Request.Form["copied"]);
            }
            Settings.ResourceType resourceType;
            Hashtable resourceTypeConfig = new Hashtable();
            Hashtable checkedPaths = new Hashtable();

            int iFileNum = 0;
            while ( Request.Form["files[" + iFileNum.ToString() + "][type]"] != null && Request.Form["files[" + iFileNum.ToString() + "][type]"].Length > 0 )
            {
                string name = Request.Form["files[" + iFileNum.ToString() + "][name]"];
                string type = Request.Form["files[" + iFileNum.ToString() + "][type]"];
                string path = Request.Form["files[" + iFileNum.ToString() + "][folder]"];
                string options = "";

                if ( name == null || name.Length < 1 || type == null || type.Length < 1 || path == null || path.Length < 1 )
                {
                    ConnectorException.Throw( Errors.InvalidRequest );
                    return;
                }

                if ( Request.Form["files[" + iFileNum.ToString() + "][options]"] != null )
                {
                    options = Request.Form["files[" + iFileNum.ToString() + "][options]"];
                }
                iFileNum++;

                // check #1 (path)
                if ( !Connector.CheckFileName( name ) || Regex.IsMatch( path, @"(/\.)|(\.\.)|(//)|([\\:\*\?""\<\>\|])" ) )
                {
                    ConnectorException.Throw( Errors.InvalidRequest );
                    return;
                }

                // get resource type config for current file
                if ( !resourceTypeConfig.ContainsKey( type ) )
                {
                    resourceTypeConfig[type] = Config.Current.GetResourceTypeConfig( type );
                }

                // check #2 (resource type)
                if ( resourceTypeConfig[type] == null )
                {
                    ConnectorException.Throw( Errors.InvalidRequest );
                    return;
                }

                resourceType = (Settings.ResourceType)resourceTypeConfig[type];
                FolderHandler folder = new FolderHandler( type, path );
                string sourceFilePath = System.IO.Path.Combine( folder.ServerPath, name );

                // check #3 (extension)
                if ( !resourceType.CheckExtension( System.IO.Path.GetExtension( name ) ) )
                {
                    this.appendErrorNode( Errors.InvalidExtension, name, type, path );
                    continue;
                }

                // check #4 (extension) - when moving to another resource type, double check extension
                if ( this.CurrentFolder.ResourceTypeName != type )
                {
                    if ( !this.CurrentFolder.ResourceTypeInfo.CheckExtension( System.IO.Path.GetExtension( name ) ) )
                    {
                        this.appendErrorNode( Errors.InvalidExtension, name, type, path );
                        continue;
                    }
                }

                // check #5 (hidden folders)
                if ( !checkedPaths.ContainsKey( path ) )
                {
                    checkedPaths[path] = true;
                    if ( Config.Current.CheckIsHidenPath( path ) )
                    {
                        ConnectorException.Throw( Errors.InvalidRequest );
                        return;
                    }
                }

                // check #6 (hidden file name)
                if ( Config.Current.CheckIsHiddenFile( name ) )
                {
                    ConnectorException.Throw( Errors.InvalidRequest );
                    return;
                }

                // check #7 (Access Control, need file view permission to source files)
                if ( !folder.CheckAcl( AccessControlRules.FileView ) )
                {
                    ConnectorException.Throw( Errors.Unauthorized );
                    return;
                }

                // check #8 (invalid file name)
                if ( !System.IO.File.Exists( sourceFilePath ) || System.IO.Directory.Exists( sourceFilePath ) )
                {
                    this.appendErrorNode( Errors.FileNotFound, name, type, path );
                    continue;
                }

                // check #9 (max size)
                if ( this.CurrentFolder.ResourceTypeName != type )
                {
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo( sourceFilePath );
                    if ( this.CurrentFolder.ResourceTypeInfo.MaxSize > 0 && fileInfo.Length > this.CurrentFolder.ResourceTypeInfo.MaxSize )
                    {
                        this.appendErrorNode( Errors.UploadedTooBig, name, type, path );
                        continue;
                    }
                }

                string destinationFilePath = System.IO.Path.Combine( this.CurrentFolder.ServerPath, name );

                // finally, no errors so far, we may attempt to copy a file
                // protection against copying files to itself
                if ( sourceFilePath == destinationFilePath )
                {
                    this.appendErrorNode( Errors.SourceAndTargetPathEqual, name, type, path );
                    continue;
                }
                // check if file exists if we don't force overwriting
                else if ( System.IO.File.Exists( destinationFilePath ) && !options.Contains( "overwrite" ) )
                {
                    if ( options.Contains( "autorename" ) )
                    {
                        int iCounter = 1;
                        string fileName;
                        string sFileNameNoExt = System.IO.Path.GetFileNameWithoutExtension( name );
                        while ( true )
                        {
                            fileName = sFileNameNoExt + "(" + iCounter.ToString() + ")" + System.IO.Path.GetExtension( name );
                            destinationFilePath = System.IO.Path.Combine( this.CurrentFolder.ServerPath, fileName );
                            if ( !System.IO.File.Exists( destinationFilePath ) )
                                break;
                            else
                                iCounter++;
                        }
                        try
                        {
                            System.IO.File.Copy( sourceFilePath, destinationFilePath );
                            copied++;
                        }
                        catch ( ArgumentException )
                        {
                            this.appendErrorNode( Errors.InvalidName, name, type, path );
                            continue;
                        }
                        catch ( System.IO.PathTooLongException )
                        {
                            this.appendErrorNode( Errors.InvalidName, name, type, path );
                            continue;
                        }
                        catch ( Exception )
                        {
            #if DEBUG
                            throw;
            #else
                            this.appendErrorNode( Errors.AccessDenied, name, type, path );
                            continue;
            #endif
                        }
                    }
                    else
                    {
                        this.appendErrorNode( Errors.AlreadyExist, name, type, path );
                        continue;
                    }
                }
                else {
                    try
                    {
                        // overwrite without warning
                        System.IO.File.Copy( sourceFilePath, destinationFilePath, true );
                        copied++;
                    }
                    catch ( ArgumentException )
                    {
                        this.appendErrorNode( Errors.InvalidName, name, type, path );
                        continue;
                    }
                    catch ( System.IO.PathTooLongException )
                    {
                        this.appendErrorNode( Errors.InvalidName, name, type, path );
                        continue;
                    }
                    catch ( Exception )
                    {
            #if DEBUG
                            throw;
            #else
                        this.appendErrorNode( Errors.AccessDenied, name, type, path );
                        continue;
            #endif
                    }
                }
            }

            XmlNode copyFilesNode = XmlUtil.AppendElement( this.ConnectorNode, "CopyFiles" );
            XmlUtil.SetAttribute( copyFilesNode, "copied", copied.ToString() );
            XmlUtil.SetAttribute( copyFilesNode, "copiedTotal", (copiedAll + copied).ToString() );

            if ( this.ErrorsNode != null )
            {
                ConnectorException.Throw( Errors.CopyFailed );
                return;
            }
        }
Exemple #13
0
 public CommandHandlerBase()
 {
     _CurrentFolder = FolderHandler.GetCurrent();
     _Request       = HttpContext.Current.Request;
 }
        public FileManager()
        {
            FolderHandler fileHandler = new FolderHandler();

            fileHandler.SearchDrive();
        }
Exemple #15
0
 public Service()
 {
     _webCrawler    = new Crawler();
     _folderHandler = new FolderHandler();
 }
Exemple #16
0
 public UploadPicToLocalService(FolderHandler folderHandler, IWebHostEnvironment webHostEnvironment)
 {
     this.folderHandler      = folderHandler;
     this.webHostEnvironment = webHostEnvironment;
     this.workingRootPath    = webHostEnvironment.ContentRootPath;
 }
 public ArcValidationTask(ILogger <ArcValidationTask> logger, FolderHandler folderHandler, IConfiguration configuration)
 {
     this.logger         = logger;
     this.folderHandler  = folderHandler;
     this._configuration = configuration;
 }
Exemple #18
0
 /// <summary>
 /// Skapar en ny instans av _userFolders, används när filträdet behöver förnyas
 /// </summary>
 /// <param name="user">Den aktiva användaren</param>
 private void getUserFiles(string user)
 {
     _userFolders = new FolderHandler(user);
     populateFolders();
     Session["userFolders"] = _userFolders;
 }