コード例 #1
0
 public string GetFileImage(CFile file)
 {
     if (file.IsDirectory())
     {
         return("../../" + GetFolderIcon(file));
     }
     else
     {
         ;
         string imgpath;
         try {
             imgpath = FileBrowserImageFactory.GetInstance().GetExtensionImage(
                 Path.GetExtension(file.Name));
         } catch (Exception) {
             imgpath = null;
         }
         if (imgpath == null)
         {
             return("../../attributes/filebrowser/misc.gif");
         }
         else
         {
             return("../../attributes/filebrowser/" + imgpath);
         }
     }
 }
コード例 #2
0
ファイル: content.ascx.cs プロジェクト: lokygb/FrontDesk
        private void BindData()
        {
            FileSystem fs   = new FileSystem(Globals.CurrentIdentity);
            CFile      file = fs.GetFile(GetFileID());

            if (!GetStudentMode())
            {
                divPerms.Visible   = true;
                ucFilePerms.FileID = file.ID;
                ucFilePerms.BindData();
            }
            else
            {
                divPerms.Visible = false;
            }

            cmdUpdate.Visible = iDirections.Visible = divUpload.Visible = !GetStudentMode();
            txtName.Text      = file.Alias;
            if (file.IsDirectory())
            {
                divData.Visible = false;
                txtType.Enabled = false;
                txtType.Text    = "Folder";
            }
            else
            {
                divData.Visible = true;

                txtType.Enabled = true;
                txtType.Text    = Path.GetExtension(file.Name);
                txtDesc.Text    = file.Description;

                if (txtType.Text == ".url")
                {
                    fs.LoadFileData(file);
                    string url = new string(file.Data);
                    txtUrl.Text = url;
                    lnkEdit.Attributes.Add("onClick",
                                           @"window.open('" + url + "', '" + "Mike" + @"', 'width=800, height=600 " +
                                           @", scrollbars=yes, menubar=yes, resizable=yes, status=yes, toolbar=yes')");
                    lnkDownload.Enabled = false;
                    rdbData.Checked     = false; rdbLink.Checked = true;
                }
                else
                {
                    txtUrl.Text     = "";
                    rdbData.Checked = true; rdbLink.Checked = false;
                    lnkEdit.Attributes.Add("onClick",
                                           @"window.open('Controls/Filesys/viewfile.aspx?FileID=" + file.ID +
                                           @"', '" + file.ID + @"', 'width=770, height=580')");
                    lnkDownload.Attributes.Add("onClick",
                                               @"window.open('Controls/Filesys/dlfile.aspx?FileID=" + file.ID +
                                               @"', '" + file.ID + @"', 'width=770, height=580')");
                    lnkDownload.Enabled = true;
                }
            }

            txtType.Enabled = txtDesc.Enabled = txtName.Enabled =
                !GetStudentMode();
        }
コード例 #3
0
        /// <summary>
        /// Copy a file into another file
        /// dest must be a directory
        /// </summary>
        public bool MoveFile(CFile dest, CFile src, bool overwrite)
        {
            //Destination must be a directory
            if (!dest.IsDirectory())
            {
                throw new FileOperationException("Destination of a copy must be a directory");
            }

            //Check to make sure one is copying onto themselves
            if (src.ID == dest.ID)
            {
                throw new FileOperationException("Destination and source cannot be the same file: " +
                                                 src.FullPath);
            }

            //Cannot move a readonly file
            if (src.ReadOnly)
            {
                throw new FileOperationException("Cannot move a readonly file");
            }

            //Check to make sure a file is not there with same name
            CFile.FileList dirlist = m_dp.ListDirectory(dest);
            foreach (CFile dirmem in dirlist)
            {
                if (dirmem.Name == src.Name)
                {
                    if (!overwrite)
                    {
                        throw new FileOperationException("File with same already exists in destination");
                    }
                    else
                    {
                        DeleteFile(dirmem);
                    }
                }
            }

            //Update the times
            PercolateModified(src, DateTime.Now);
            PercolateModified(dest, DateTime.Now);

            //Get the user
            User user = new Users(m_ident).GetInfo(m_ident.Name, null);

            //Do the copy
            m_dp.MoveFile(dest, src, user.PrincipalID);

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Synchronize the file against the system
        /// </summary>
        public bool UpdateFileInfo(CFile file, bool modupdate)
        {
            //Authorize
            if (!Authorize(file, FileAction.WRITE))
            {
                throw new FileOperationException("Permission denied on action: WRITE");
            }

            //Check name
            if (!ValidateFileName(file.Name))
            {
                throw new FileOperationException("Invalid file name: " + file.Name);
            }

            //Rename checks
            CFile ofile = GetFile(file.ID);

            if (file.FullPath != ofile.FullPath)
            {
                //Dup check
                if (GetFile(file.FullPath) != null)
                {
                    throw new FileOperationException("Cannot rename file, one already exists with same name");
                }
            }

            m_dp.SyncFile(file);
            if (modupdate)
            {
                PercolateModified(file, file.FileModified);
            }

            //Rename move
            if (file.FullPath != ofile.FullPath && file.IsDirectory())
            {
                CFile.FileList dirfiles = ListDirectory(ofile);
                try {
                    MoveFiles(file, dirfiles, false);
                } catch (FileOperationException er) {
                    //Undo the rename
                    m_dp.SyncFile(ofile);
                    throw er;
                }
            }

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Load data for a file
        /// </summary>
        public bool LoadFileData(CFile file)
        {
            if (file.IsDirectory())
            {
                return(false);
            }

            //Authorize
            if (!Authorize(file, FileAction.READ))
            {
                throw new FileOperationException("Permission denied for action: READ");
            }

            //Connect to data service
            FileDataWebGateway fds = (FileDataWebGateway)m_fdss[m_ident.Name];

            if (fds != null)
            {
                DataEnvelope data;
                try {
                    data = fds.LoadFileData(file.ID);
                } catch (Exception) {
                    FileServiceInit(m_ident, true);
                    fds = (FileDataWebGateway)m_fdss[m_ident.Name];
                    try {
                        data = fds.LoadFileData(file.ID);
                    } catch (Exception) {
                        throw new FileOperationException("Unable to connect to the file system or file not found");
                    }
                }
                if (data.Size > 0)
                {
                    file.RawData = data.Data;
                }
                else
                {
                    file.RawData = new byte[0];
                }
            }
            else
            {
                m_fs.FetchData(file);
            }

            return(true);
        }
コード例 #6
0
        protected void CopyFileData(string dir, string dbase, string sbase)
        {
            string spath = Path.Combine(sbase, dir);
            CFile  sfile = GetFile(spath);

            if (sfile.IsDirectory())
            {
                foreach (CFile dirmem in ListDirectory(sfile))
                {
                    CopyFileData(Path.Combine(dir, dirmem.Name), dbase, sbase);
                }
            }
            else
            {
                string dpath = Path.Combine(dbase, dir);
                CFile  dfile = GetFile(dpath);

                //Copy file
                FileDataWebGateway fds = (FileDataWebGateway)m_fdss[m_ident.Name];
                if (fds != null)
                {
                    try {
                        fds.CreateFile(sfile.ID);
                        fds.CopyFile(sfile.ID, dfile.ID);
                    } catch (Exception) {
                        FileServiceInit(m_ident, true);
                        fds = (FileDataWebGateway)m_fdss[m_ident.Name];
                        try {
                            fds.CreateFile(sfile.ID);
                            fds.CopyFile(sfile.ID, dfile.ID);
                        } catch (Exception) {
                            throw new FileOperationException("Unable to connect to the file system");
                        }
                    }
                }
                else
                {
                    m_fs.CreateFile(sfile);
                    m_fs.CopyFile(sfile, dfile);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Copy a file into another file
        /// dest must be a directory
        /// </summary>
        public bool CopyFile(CFile dest, CFile src, bool overwrite)
        {
            //Destination must be a directory
            if (!dest.IsDirectory())
            {
                throw new FileOperationException("Destination of a copy must be a directory");
            }
            //Check to make sure one is copying onto themselves
            if (src.ID == dest.ID)
            {
                throw new FileOperationException("Destination and source cannot be the same file: " +
                                                 src.FullPath);
            }

            //Check to make sure a file is not there with same name
            CFile.FileList dirlist = m_dp.ListDirectory(dest);
            foreach (CFile dirmem in dirlist)
            {
                if (dirmem.Name == src.Name)
                {
                    if (!overwrite)
                    {
                        throw new FileOperationException("File with same already exists in destination");
                    }
                    else
                    {
                        DeleteFile(dirmem);
                    }
                }
            }

            //Update the times
            PercolateModified(src, DateTime.Now);
            PercolateModified(dest, DateTime.Now);

            //Do the copy
            m_dp.CopyFile(dest, src, m_user.PrincipalID);
            CopyFileData("", Path.Combine(dest.FullPath, src.Name), src.FullPath);

            return(true);
        }
コード例 #8
0
 private void DeleteDirData(CFile dir)
 {
     if (dir.IsDirectory())
     {
         CFile.FileList dirlist = ListDirectory(dir);
         foreach (CFile file in dirlist)
         {
             if (file.IsDirectory())
             {
                 DeleteDirData(file);
             }
             else
             {
                 DeleteFileData(file);
             }
         }
     }
     else
     {
         DeleteFileData(dir);
     }
 }
コード例 #9
0
        private void dgFiles_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            System.Web.UI.WebControls.Image img;
            ImageButton imgDownload;
            TextBox     txtName;
            LinkButton  lnkName, lnkRename;
            Label       lblSize;
            CheckBox    chkSelect;

            if (null != (lblSize = e.Item.FindControl("lblSize") as Label))
            {
                lnkName     = (LinkButton)e.Item.FindControl("lnkName");
                img         = (System.Web.UI.WebControls.Image)e.Item.FindControl("FileImage");
                imgDownload = (ImageButton)e.Item.FindControl("imgDownload");
                lnkRename   = (LinkButton)e.Item.FindControl("lnkRename");
                chkSelect   = (CheckBox)e.Item.FindControl("chkSelect");

                CFile file = e.Item.DataItem as CFile;
                if (img != null)
                {
                    img.ImageUrl = GetFileImage(file);
                }

                int kb = file.Size / 1000;
                if (kb > 0)
                {
                    lblSize.Text = String.Format("{0} KB", kb);
                }
                else
                {
                    lblSize.Text = String.Format("{0} bytes", file.Size);
                }

                img = (System.Web.UI.WebControls.Image)e.Item.FindControl("imgReadOnly");
                if (!file.ReadOnly)
                {
                    img.Visible = false;
                }
                else
                {
                    img.ImageUrl = "../../attributes/filebrowser/ro.gif";
                }

                img = (System.Web.UI.WebControls.Image)e.Item.FindControl("imgLock");
                if (new FileSystem(Globals.CurrentIdentity).IsLocked(file))
                {
                    img.ImageUrl = "../../attributes/filebrowser/lock.gif";
                }
                else
                {
                    img.Visible = false;
                }

                if (imgDownload != null)
                {
                    imgDownload.Attributes.Add("onClick",
                                               @"window.open('Controls/Filesys/dlfile.aspx?FileID=" + file.ID +
                                               @"', '" + file.ID + @"', 'width=770, height=580')");
                }

                if (lnkName != null)
                {
                    if (m_curdir.ID != file.ID)
                    {
                        lnkName.Text = file.Alias;
                    }
                    else
                    {
                        lnkRename.Enabled = false;
                        chkSelect.Enabled = false;
                        lnkName.Text      = ".";
                    }
                    if (!file.IsDirectory())
                    {
                        int subID;
                        if (0 > (subID = GetSubID(tvFiles.GetNodeFromIndex(tvFiles.SelectedNodeIndex))))
                        {
                            lnkName.Attributes.Add("onClick",
                                                   @"window.open('Controls/Filesys/viewfile.aspx?FileIDs=" + file.ID +
                                                   @"', '" + file.ID + @"', 'width=770, height=580')");
                        }
                        else
                        {
                            lnkName.Attributes.Add("onClick",
                                                   @"window.open('Controls/Filesys/viewfile.aspx?SubID=" + subID +
                                                   "&FileIDs=" + file.ID +
                                                   @"', '" + file.ID + @"', 'width=770, height=580')");
                        }
                        lnkName.CommandName = "PopUp";
                    }
                }
            }
            if (null != (txtName = (TextBox)e.Item.FindControl("txtName")))
            {
                CFile file = (CFile)e.Item.DataItem;
                txtName.Text = file.Name;
            }
        }
コード例 #10
0
        /// <summary>
        /// Export data to the specified external sink
        /// </summary>
        public void ExportData(DataSet expdata, string prefix, CFile dir, IExternalSink extsink,
                               bool exportfp, string relpath)
        {
            if (!dir.IsDirectory())
            {
                throw new FileOperationException("Cannot export a single file");
            }

            //Authorize
            if (!Authorize(dir, FileAction.READ))
            {
                throw new FileOperationException("Permission denied for operation: READ");
            }

            CFile.FileList dirlist = ListDirectory(dir);
            foreach (CFile file in dirlist)
            {
                string epath;

                if (prefix.Length > 0 && prefix[prefix.Length - 1] != '\\')
                {
                    prefix += @"\";
                }
                if (exportfp)
                {
                    epath = prefix + GetExportPath(file);
                }
                else
                {
                    epath = prefix + relpath + file.Name;
                }

                DataRow dirrow = expdata.Tables["File"].NewRow();
                if (!exportfp)
                {
                    dirrow["path"] = relpath + file.Name;
                }
                else
                {
                    dirrow["path"] = epath;
                }

                ExternalFile extfile = new ExternalFile();
                extfile.Path = epath;

                if (file.IsDirectory())
                {
                    dirrow["type"] = "dir";
                    expdata.Tables["File"].Rows.Add(dirrow);

                    //Create the directory
                    extfile.Directory = true;
                    extsink.PutFile(extfile);

                    ExportData(expdata, prefix, file, extsink, exportfp, relpath + file.Name + @"\");
                }
                else
                {
                    new FileSystem(m_ident).LoadFileData(file);
                    extfile.Size       = file.RawData.Length;
                    extfile.DataStream = new MemoryStream(file.RawData, 0, file.RawData.Length);

                    //File row
                    dirrow["type"] = "file";
                    expdata.Tables["File"].Rows.Add(dirrow);

                    extsink.PutFile(extfile);
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Create a new directory
        /// </summary>
        public void ImportData(string fullpath, IExternalSource extsource, bool modupdate, bool over)
        {
            ExternalFile efile;

            CFile idir = GetFile(fullpath);

            if (!idir.IsDirectory())
            {
                throw new FileOperationException("Cannot import data into a non-directory");
            }

            //Authorize
            if (!Authorize(idir, FileAction.WRITE))
            {
                throw new FileOperationException("Permission denied on action: WRITE");
            }

            //Do the import
            try {
                while (null != (efile = extsource.NextFile()))
                {
                    string fpath = Path.Combine(fullpath, efile.Path);
                    CFile  file;
                    if (efile.Directory)
                    {
                        try {
                            file = CreateDirectory(fpath, false, null, false);
                        } catch (FileExistsException) { }
                    }
                    else
                    {
                        if (over)
                        {
                            if (null == (file = GetFile(fpath)))
                            {
                                file = CreateFile(fpath, false, null, false);
                            }
                        }
                        else
                        {
                            file = CreateFile(fpath, false, null, false);
                        }

                        //Read file
                        MemoryStream memstr = new MemoryStream();
                        int          size = 4096; byte[] data = new byte[size];
                        while (true)
                        {
                            size = efile.DataStream.Read(data, 0, data.Length);
                            if (size > 0)
                            {
                                memstr.Write(data, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }
                        //Commit data to database
                        memstr.Seek(0, SeekOrigin.Begin);
                        data         = Globals.ReadStream(memstr, (int)memstr.Length);
                        file.RawData = data; file.Size = data.Length;
                        m_dp.SyncFile(file);
                        CommitData(file);
                    }
                    extsource.CloseFile(efile);
                }
                extsource.CloseSource();
            } catch (Exception er) {
                throw new FileOperationException("Error during the import of the external source. If this source is an archive, please make sure that the format is supported by FrontDesk: MESSAGE: " + er.Message);
            }

            if (modupdate)
            {
                PercolateModified(idir, DateTime.Now);
            }
        }