Example #1
0
        /// <summary>
        /// 封装log对象 并压入队列
        /// </summary>
        /// <param name="file"></param>
        private void InsertLog(monitorServer ms, FileSystemEventArgs item)
        {
            //insert log
            try
            {
                FileInfoStruct fi = FSUtil.FindSpecialFileInfo(item.FullPath);

                log logInfo = new log();
                logInfo.monitorServerID   = ms.id;
                logInfo.monitorFileName   = fi.Name;
                logInfo.monitorFileStatus = "正常完了";

                if (item.Name.Contains('\\'))
                {
                    logInfo.monitorFilePath = ms.monitorDrive + "\\" + item.Name.Substring(0, item.Name.LastIndexOf('\\'));
                }
                else
                {
                    logInfo.monitorFilePath = ms.monitorDrive;
                }
                logInfo.monitorFileType = fi.Extension;
                logInfo.monitorFileSize = fi.Length.ToString();
                logInfo.monitorTime     = DateTime.Now;
                logInfo.transferFlg     = (short)1;
                //根据monitorServer 查询backupServerGroup表monitorServerID 获取其id
                logInfo.backupServerGroupID = ms.backupServerGroupID;

                //根据backupServerGroupID 查询backupServerGroupDetail表 获取backupServerID
                logInfo.backupServerID       = ms.backupServerID;
                logInfo.backupServerFileName = fi.Name;

                logInfo.backupServerFilePath = DefaultValue.DEFAULTCHAR_VALUE;
                logInfo.backupServerFileType = fi.Extension;
                logInfo.backupServerFileSize = fi.Length.ToString();
                logInfo.backupStartTime      = DateTime.Now;
                logInfo.backupEndTime        = DateTime.Now;
                logInfo.backupTime           = (logInfo.backupEndTime - logInfo.backupStartTime).TotalMilliseconds.ToString() + "ms";
                logInfo.backupFlg            = (short)1;
                logInfo.copyStartTime        = logInfo.backupStartTime;
                logInfo.copyEndTime          = logInfo.backupEndTime;
                logInfo.copyTime             = logInfo.backupTime;

                logInfo.copyFlg = 2;

                logInfo.deleteFlg   = DefaultValue.DEFAULTINT_VALUE;
                logInfo.deleter     = DefaultValue.DEFAULTCHAR_VALUE;
                logInfo.deleteDate  = DefaultValue.DEFAULTDATETIME_VALUE;
                logInfo.creater     = "exe";
                logInfo.createDate  = DateTime.Now;
                logInfo.updater     = "exe";
                logInfo.updateDate  = DateTime.Now;
                logInfo.restorer    = DefaultValue.DEFAULTCHAR_VALUE;
                logInfo.restoreDate = DefaultValue.DEFAULTDATETIME_VALUE;
                rqueue.Enqueue(logInfo);
            }
            catch (Exception e)
            {
                logger.Error("LogTableManager" + Environment.NewLine + item.FullPath + Environment.NewLine + MessageUtil.GetExceptionMsg(e, ""));
            }
        }
Example #2
0
        public static FileInfoStruct GetFileInfoBYWin32API(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(path);
            }

            WIN32_FIND_DATA findData;

            if (!path.Substring(0, 2).Equals(@"\\"))
            {
                path = String.Concat(@"\\?\", path);
            }

            var findHandle = FindFirstFile(path, out findData);

            if (findHandle != INVALID_HANDLE_VALUE)
            {
                try
                {
                    FileInfoStruct fis = new FileInfoStruct();
                    fis.Name = findData.cFileName;
                    //extension
                    int eIndex = findData.cFileName.LastIndexOf('.');
                    if (eIndex > 0)
                    {
                        fis.Extension = findData.cFileName.Substring(eIndex);
                    }
                    else
                    {
                        fis.Extension = "";
                    }

                    //length
                    fis.Length = ((((long)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow).ToString();
                    //CreationTime
                    fis.CreationTime = ConvertFromFileTime(findData.ftCreationTime);
                    //LastAccessTime
                    fis.LastAccessTime = ConvertFromFileTime(findData.ftLastAccessTime);
                    //LastWriteTime
                    fis.LastWriteTime = ConvertFromFileTime(findData.ftLastWriteTime);

                    return(fis);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    FindClose(findHandle);
                }
            }

            throw new Exception("Failed to find file",
                                Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()));
        }
Example #3
0
        /// <summary>
        /// 更新事件
        /// </summary>
        /// <param name="ms"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private monitorFileListen GetWhenChangedType(monitorServer ms, FileSystemEventArgs item)
        {
            monitorFileListen mflinfo = new monitorFileListen();
            FileInfoStruct    fi      = FSUtil.FindSpecialFileInfo(item.FullPath);

            mflinfo.monitorServerID             = ms.id;
            mflinfo.monitorType                 = "更新";
            mflinfo.monitorFileRelativeFullPath = "\\" + item.Name;
            mflinfo.monitorFileSize             = fi.Length.ToString();
            mflinfo.updateDate = DateTime.Now;

            return(mflinfo);
        }
Example #4
0
 public static Icon GetSmallIcon(string pFilePath)
 {
     FileInfoStruct _info = new FileInfoStruct();
     GetFileInfo(pFilePath, 0, ref _info, Marshal.SizeOf(_info),
         (int)(FileInfoFlags.SHGFI_ICON | FileInfoFlags.SHGFI_SMALLICON));
     try
     {
         return Icon.FromHandle(_info.hIcon);
     }
     catch
     {
         return null;
     }
 }
Example #5
0
        public ReturnTypes AddFile(FileInfoStruct fileInfo)
        {
            log.Info("Add file called");
            BioFileInfo bioFileInfo = new BioFileInfo()
            {
                Filename   = fileInfo.Filename,
                FileNumber = fileInfo.FileNumber,
                FileSize   = fileInfo.FileSize,
                Timestamp  = fileInfo.ModificationDate,
                PathType   = fileInfo.type == FileEntityTypes.FOLDER ? BioFileInfo.EntityAtPathType.Folder : BioFileInfo.EntityAtPathType.Regular
            };
            CollectorState res = collectorService.AddFile(bioFileInfo);

            return(T(res));
        }
Example #6
0
        private static Icon GetSmallIcon(string 路径)
        {
            FileInfoStruct _info = new FileInfoStruct();

            GetFileInfo(路径, 0, ref _info, Marshal.SizeOf(_info),
                        (int)(FileInfoFlags.SHGFI_ICON | FileInfoFlags.SHGFI_SMALLICON));
            try
            {
                return(Icon.FromHandle(_info.hIcon));
            }
            catch
            {
                return(null);
            }
        }
Example #7
0
        /// <summary>
        /// 创建事件
        /// </summary>
        /// <param name="ms"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private monitorFileListen GetWhenCreatedType(monitorServer ms, FileSystemEventArgs item)
        {
            monitorFileListen mflinfo = new monitorFileListen();
            FileInfoStruct    fi      = FSUtil.FindSpecialFileInfo(item.FullPath);

            mflinfo.monitorServerID  = ms.id;
            mflinfo.monitorFileName  = fi.Name;
            mflinfo.monitorType      = "新規";
            mflinfo.monitorServerIP  = ms.monitorServerIP;
            mflinfo.sharePoint       = ms.startFile;
            mflinfo.monitorLocalPath = ms.monitorLocalPath;
            if (item.Name.Contains('\\'))
            {
                mflinfo.monitorFileRelativeDirectory = "\\" + item.Name.Substring(0, item.Name.LastIndexOf('\\'));
            }
            else
            {
                mflinfo.monitorFileRelativeDirectory = "";
            }

            mflinfo.monitorFileRelativeFullPath = "\\" + item.Name;

            mflinfo.monitorFileLastWriteTime = fi.LastWriteTime;
            mflinfo.monitorFileSize          = fi.Length.ToString();
            mflinfo.monitorFileExtension     = fi.Extension;

            mflinfo.monitorFileCreateTime     = fi.CreationTime;
            mflinfo.monitorFileLastAccessTime = fi.LastAccessTime;
            mflinfo.monitorStatus             = "転送済";
            mflinfo.monitorFileStartTime      = DateTime.Now;
            mflinfo.monitorFileEndTime        = DateTime.Now;
            mflinfo.deleteFlg  = DefaultValue.DEFAULTINT_VALUE;
            mflinfo.deleter    = DefaultValue.DEFAULTCHAR_VALUE;
            mflinfo.deleteDate = DefaultValue.DEFAULTDATETIME_VALUE;
            mflinfo.creater    = "admin";
            mflinfo.createDate = DateTime.Now;
            mflinfo.updater    = "admin";
            mflinfo.updateDate = DateTime.Now;

            return(mflinfo);
        }
Example #8
0
        /// <summary>
        /// Updates the data grid with the found streams.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timerGrid_Tick(object sender, System.EventArgs e)
        {
            this.timerGrid.Enabled = false;
            int cnt = ArrayFileInfo.Count;

            for (int i = lastIndexAdded; i < cnt; i++)
            {
                FileInfoStruct fis = (FileInfoStruct)ArrayFileInfo[i];

                FileInfoData.FileInfoRow r = this.fileInfoDataStreams.FileInfo.NewFileInfoRow();
                r.BeginEdit();
                r.File_Name     = fis.File_Name;
                r.Stream_Name   = fis.Stream_Name;
                r.Stream_Size   = fis.Stream_Size;
                r.Location      = fis.Location;
                r.Creation_Date = fis.Creation_Date;
                r.EndEdit();
                this.fileInfoDataStreams.FileInfo.AddFileInfoRow(r);
            }

            lastIndexAdded         = cnt;
            this.timerGrid.Enabled = true;
        }
Example #9
0
 public static extern int GetFileInfo(string pszPath, int dwFileAttributes,
     ref   FileInfoStruct psfi, int cbFileInfo, int uFlags);
Example #10
0
 private static Icon GetLargeIcon(string 路径)
 {
     FileInfoStruct _info = new FileInfoStruct();
     GetFileInfo(路径, 0, ref  _info, Marshal.SizeOf(_info),
         (int)(FileInfoFlags.SHGFI_ICON | FileInfoFlags.SHGFI_LARGEICON));
     try
     {
         return Icon.FromHandle(_info.hIcon);
     }
     catch
     {
         return null;
     }
 }
Example #11
0
        public static Icon GetSmallIcon(string pFilePath)
        {
            Icon icon = null;

            FileInfoStruct info = new FileInfoStruct();
            GetFileInfo(pFilePath, 0, ref info, Marshal.SizeOf(info), (int)(FileInfoFlags.SHGFI_ICON | FileInfoFlags.SHGFI_SMALLICON));
            try
            {
                icon = Icon.FromHandle(info.hIcon);
            }
            catch
            {
                ;
            }

            return icon;
        }