Exemple #1
0
        public bool set_dokanio_flag2(bool flag)
        {
            if (m_state == FILE_STATE.FILE_DELETED)
            {
                return(false);
            }

            if (_mywip != null)
            {
                lock (this)
                {
                    if (_mywip == null)
                    {
                        return(false);                //probably unmounted or deleted.
                    }
                }

                DEFS.ASSERT(_mywip != null, "_mywip cannot be null when setting dokan io flag");
                if (flag)
                {
                    DEFS.ASSERT(m_state == FILE_STATE.FILE_IN_DOKAN_IO || m_state == FILE_STATE.FILE_DEFAULT, "Incorrect mstate = " + m_state);
                    m_state = FILE_STATE.FILE_IN_DOKAN_IO;
                }
                else
                {
                    if (m_state != FILE_STATE.FILE_UNMOUNTED)
                    {
                        m_state = FILE_STATE.FILE_DEFAULT;
                    }
                }
                return(true);
            }
            return(false);
        }
Exemple #2
0
        void CInode.unmount(bool inshutdown)
        {
            long curr    = DateTime.Now.ToUniversalTime().Ticks;
            int  seconds = (int)((curr - creation_time) / 10000000);

            DEFS.DEBUG("UNMOUNT", "CFile (" + m_inode + ") umnount : " + m_name +
                       " inshutdown flag = " + inshutdown + " is _mywip null = " + (_mywip == null) +
                       " secs = " + seconds);

            if (inshutdown == false && timeoutcheck() == false && m_state == FILE_STATE.FILE_IN_DOKAN_IO)
            {
                return;
            }

            /*
             * We cannot unmount a dirty wip directly, it must first be cleaned, so we
             * dont do this here. The next sync iteration will clean the wip, and then
             * we are good to unmount. If we are being shutdown, then we sync() here itself.
             */
            if ((inshutdown == false) && ((_mywip == null)))// || _mywip.is_dirty == false))
            {
                DEFS.ASSERT(m_state != FILE_STATE.FILE_IN_DOKAN_IO, "Cannot be dokan io when _mywip = NULL");
                return;
            }

            /*
             * _mywip is not null and dirty, or we are shutting down.
             */
            lock (this)
            {
                DEFS.ASSERT(m_state != FILE_STATE.FILE_ORPHANED, "We are in sync path can cannot have an orphaned file");
                if (_mywip != null)
                {
                    REDDY.ptrRedFS.sync(_mywip);
                    REDDY.ptrRedFS.flush_cache(_mywip, inshutdown);
                }
                lock (REDDY.FSIDList[m_associated_fsid])
                {
                    if (_mywip != null)
                    {
                        RedFS_Inode inowipX = REDDY.FSIDList[m_associated_fsid].get_inode_file_wip("Umount file iwp:" + m_name);
                        OPS.Checkin_Wip(inowipX, _mywip, m_inode);
                        DEFS.ASSERT(m_state != FILE_STATE.FILE_DELETED, "Wrong state detected222!");
                        REDDY.FSIDList[m_associated_fsid].sync_internal();
                        REDDY.FSIDList[m_associated_fsid].set_dirty(true);
                        _mywip = null;
                    }
                    m_state = FILE_STATE.FILE_UNMOUNTED;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Переводим состояния операций над файлами в строку для отображения
        /// </summary>
        private static string FileStateToString(FILE_STATE state)
        {
            switch (state)
            {
            case FILE_STATE.CHANGED:
                return("Changed");

            case FILE_STATE.CREATED:
                return("Created");

            case FILE_STATE.REMOVED:
                return("Removed");

            case FILE_STATE.RENAMED:
                return("Renamed");

            default:
                return(null);
            }
        }
Exemple #4
0
        public void remove_ondisk_data2()
        {
            open_file(false);
            touch();

            if (m_state == FILE_STATE.FILE_DELETED)
            {
                return;
            }
            m_state = FILE_STATE.FILE_DELETED;

            DEFS.ASSERT(_mywip != null, "Cannot be null in remove() after calling open()");


            lock (this)
            {
                lock (REDDY.FSIDList[m_associated_fsid])
                {
                    DEFS.ASSERT(_mywip != null, "Unmount couldnt have worked on this");
                    RedFS_Inode inowip = REDDY.FSIDList[m_associated_fsid].get_inode_file_wip("DF:" + m_name);

                    //REDDY.ptrRedFS.sync(_mywip);
                    REDDY.ptrRedFS.flush_cache(_mywip, false);
                    REDDY.ptrRedFS.redfs_delete_wip(m_associated_fsid, _mywip, true);

                    DEFS.ASSERT(_mywip.get_filesize() == 0, "After delete, all the wip contents must be cleared off");
                    for (int i = 0; i < 16; i++)
                    {
                        DEFS.ASSERT(_mywip.get_child_dbn(i) == DBN.INVALID, "dbns are not set after delete wip " +
                                    i + "  " + _mywip.get_child_dbn(i));
                    }
                    OPS.CheckinZerodWipData(inowip, m_inode);
                    REDDY.FSIDList[m_associated_fsid].sync_internal();

                    _mywip = null;
                }
            }
            DEFS.DEBUG("IFSD", "<<<< DELETED FILE >>>> " + m_name);
        }
Exemple #5
0
    /// <summary>
    /// 将指定Excel文件的内容读取到DataTable中
    /// </summary>
    public static DataTable ReadXlsxFile(string filePath, out string errorString)
    {
        // 检查文件是否存在且没被打开
        FILE_STATE fileState = Utils.GetFileState(filePath);

        if (fileState == FILE_STATE.INEXIST)
        {
            errorString = string.Format("{0}文件不存在", filePath);
            return(null);
        }
        else if (fileState == FILE_STATE.IS_OPEN)
        {
            errorString = string.Format("{0}文件正在被其他软件打开,请关闭后重新运行本程序", filePath);
            return(null);
        }

        OleDbConnection  conn = null;
        OleDbDataAdapter da   = null;
        DataSet          ds   = null;

        try
        {
            // 初始化连接并打开
            string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=NO;IMEX=1\"";

            conn = new OleDbConnection(connectionString);
            conn.Open();

            // 获取数据源的表定义元数据
            DataTable dtSheet = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });

            // 找到Sheet名为data的数据表
            bool isFound = false;
            for (int i = 0; i < dtSheet.Rows.Count; ++i)
            {
                string sheetName = dtSheet.Rows[i]["TABLE_NAME"].ToString();

                if (sheetName == AppValues.EXCEL_SHEET_NAME)
                {
                    isFound = true;
                    break;
                }
            }
            if (!isFound)
            {
                errorString = string.Format("错误:{0}中不含有Sheet名为{1}的数据表", filePath, AppValues.EXCEL_SHEET_NAME.Replace("$", ""));
                return(null);
            }

            // 初始化适配器
            da = new OleDbDataAdapter();
            da.SelectCommand = new OleDbCommand(String.Format("Select * FROM [{0}]", AppValues.EXCEL_SHEET_NAME), conn);

            ds = new DataSet();
            da.Fill(ds, AppValues.EXCEL_SHEET_NAME);
        }
        catch
        {
            errorString = "错误:连接Excel失败,你可能尚未安装Office数据连接组件: http://www.microsoft.com/en-US/download/details.aspx?id=23734 \n";
            return(null);
        }
        finally
        {
            // 关闭连接
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
                // 由于C#运行机制,即便因为表格中没有Sheet名为data的工作簿而return null,也会继续执行finally,而此时da为空,故需要进行判断处理
                if (da != null)
                {
                    da.Dispose();
                }
                conn.Dispose();
            }
        }

        errorString = null;
        return(ds.Tables[0]);
    }
Exemple #6
0
        /*
         * We dont expect a write to come before opening because, cdirectory would
         * call a open_file() before inserting into the DIR CACHE. We shouldnt call
         * this with cfile-lock held.
         */
        public bool open_file(bool justcreated)
        {
            if (m_state == FILE_STATE.FILE_DELETED)
            {
                return(false);
            }
            else if (m_state == FILE_STATE.FILE_IN_DOKAN_IO)
            {
                DEFS.ASSERT(_mywip != null, "My wip cannot be null when dokan_io flag is set in open_file");
                return(true);
            }

            touch();
            if (_mywip == null)
            {
                lock (this)
                {
                    if (_mywip != null)
                    {
                        /*
                         * It could be the case that someone already opend it, maybe previous call
                         * that was locked in open_file(), just bail out.
                         */
                        DEFS.ASSERT(m_state != FILE_STATE.FILE_IN_DOKAN_IO, "Suddendly cannot be in dokan io when it was just null");
                        return(true);
                    }

                    lock (REDDY.FSIDList[m_associated_fsid])
                    {
                        _mywip = new RedFS_Inode(WIP_TYPE.REGULAR_FILE, m_inode, m_parent_inode);
                        long oldsize = _mywip.get_filesize();

                        RedFS_Inode inowip = REDDY.FSIDList[m_associated_fsid].get_inode_file_wip("OF:" + m_name);
                        DEFS.DEBUG("F(_mywip)", "Loaded ino= " + m_inode + "wip from disk, size = " + _mywip.get_filesize());

                        bool ret = OPS.Checkout_Wip2(inowip, _mywip, m_inode);

                        if (ret)
                        {
                            DEFS.DEBUG("FILE", "Loaded ino= " + m_inode + "wip from disk, size = " + _mywip.get_filesize());
                        }
                        else
                        {
                            DEFS.DEBUG("FILE", "Loaded ino = " + m_inode + " (new) size = " + _mywip.get_filesize());
                            _mywip.set_ino(m_parent_inode, m_inode);
                        }

                        DEFS.ASSERT(m_size == _mywip.get_filesize(), "File size should match, irrespecitive of weather its " +
                                    " from disk, (=0) then, or inserted from an existing dir load, >= 0 in that case, msize:" + m_size +
                                    " _mywip.size:" + _mywip.get_filesize() + " fname =" + m_name + " ino=" + m_inode + " beforeread size = " +
                                    oldsize + " contents : " + _mywip.get_string_rep2() + " ret = " + ret);

                        if (justcreated)
                        {
                            DEFS.ASSERT(ret == false, "This should be a new file " + _mywip.get_filesize() + " fname =" + m_name +
                                        " ino=" + m_inode + " beforeread size = " + oldsize + " contents : " + _mywip.get_string_rep2());
                            _mywip.setfilefsid_on_dirty(m_associated_fsid);
                            _mywip.is_dirty = true; //this must make it to disk.
                        }
                        REDDY.FSIDList[m_associated_fsid].sync_internal();
                        m_state = FILE_STATE.FILE_DEFAULT;
                    }
                }
            }
            return(true);
        }