コード例 #1
0
        private void captureByCanvasRect()
        {
            canvas.Children.Remove(rect);

            var dpi = ScreenUtil.GetDPI();
            var res = ScreenUtil.GetScreenResolution();

            // Capture
            Hide();
            var cap = ImageUtil.CaptureScreenshot(
                (int)(Canvas.GetLeft(rect) * dpi.X + Left),
                (int)(Canvas.GetTop(rect) * dpi.Y + Top),
                (int)(rect.Width * dpi.X + Left / dpi.X),
                (int)(rect.Height * dpi.Y + Top / dpi.Y)
                );

            Show();
            playShutterSound();

            switch (this.saveType)
            {
            case SaveType.DISK:
                cap.Save(DiskUtil.GenerateDiskFilePath(), ImageFormat.Png);
                break;

            case SaveType.CLIPBOARD:
                Clipboard.SetImage(ImageUtil.ConvertBitmapToBitmapSource(cap));
                break;
            }

            rect = null;
            Close();
        }
コード例 #2
0
ファイル: Bootstrap.cs プロジェクト: mrdavidlaing/bosh-dotnet
        private void SetupDiskData()
        {
            int dataDiskId = int.Parse(this.platform.GetDataDiskDeviceName, CultureInfo.InvariantCulture);

            string dataDir = Path.Combine(BaseDir, "data");

            if (!Directory.Exists(dataDir))
            {
                Directory.CreateDirectory(dataDir);
            }

            if (!DiskUtil.DiskHasPartition(dataDiskId))
            {
                Logger.Info("Creating partition on drive " + dataDiskId);
                if (DiskUtil.CreatePrimaryPartition(dataDiskId, "data") != 0)
                {
                    Logger.Error("Could not create partition on drive " + dataDiskId);
                }
            }

            if (!DiskUtil.IsMountPoint(dataDir))
            {
                if (DiskUtil.MountPartition(dataDiskId, dataDir) != 0)
                {
                    Logger.Error("Could not mount disk " + dataDiskId + " to " + dataDir);
                }
            }
            SetupDataSys();
        }
コード例 #3
0
        public void TC005_DiskHasPartitionTest()
        {
            // Arrange
            // Try getting info for disk 0 or 1, one of them should exist on a normal Windows installation
            int diskId0 = 0;
            int diskId1 = 1;

            // Act
            bool hasPartition = false;

            try
            {
                hasPartition = DiskUtil.DiskHasPartition(diskId0);
            }
            catch { }

            if (!hasPartition)
            {
                try
                {
                    hasPartition = DiskUtil.DiskHasPartition(diskId1);
                }
                catch { }
            }

            // Assert
            Assert.IsTrue(hasPartition);
        }
コード例 #4
0
        public RecordDisk(string driverName)
        {
            disk = new DiskUtil(driverName);

            recordControl = new RecordControl(disk);

            if (recordControl.IsValid == false)
            {
                return;
            }

            long offset = 512;
            int  index  = 0;

            while (true)
            {
                RecordFile file = new RecordFile(disk, offset, index++);
                if (file.Length == 0)
                {
                    break;
                }


                listFile.Add(file);
                offset += file.Length;
            }
        }
コード例 #5
0
        /// <summary>
        /// 检查target目录所在盘区空间是否充足
        /// </summary>
        /// <returns></returns>
        public static bool CheckDisk(Config config)
        {
            double baseline = Convert.ToDouble(config.Baseline);

            //是否大于设置线
            return(DiskUtil.GetFreeSpace(config.Volume) > baseline);
        }
コード例 #6
0
        public DiskUsage()
        {
            DiskUtil d = new DiskUtil();

            InitializeIcon();

            d.PerformanceCounterEventHandler += DrawDiskUsage;
        }
コード例 #7
0
        public void TC004_GetVolumeDeviceIdTest()
        {
            // Arrange
            string mountPoint = @"c:\";

            // Act
            string volumeDeviceId = DiskUtil.GetVolumeDeviceId(mountPoint);

            // Assert
            Assert.IsNotNull(volumeDeviceId);
        }
コード例 #8
0
        public void TC003_IsMountPointTest()
        {
            // Arrange
            string mountPoint = @"c:\";

            // Act
            bool isMountPoint = DiskUtil.IsMountPoint(mountPoint, false);

            // Assert
            Assert.IsTrue(isMountPoint);
        }
コード例 #9
0
        public void TC015_GetDiskIndexForDiskIdInvalidDiskIdTest()
        {
            // Arrange
            int diskId = int.MinValue;

            // Act
            int index = DiskUtil.GetDiskIndexForDiskId(diskId, false);

            // Assert
            Assert.AreEqual(int.MinValue, index);
        }
コード例 #10
0
        public void TC010_IsMountPointInvalidPathTest()
        {
            // Arrange
            string mountPoint = Path.Combine(@"c:\", Guid.NewGuid().ToString());

            // Act
            bool isMountPoint = DiskUtil.IsMountPoint(mountPoint);

            // Assert
            Assert.IsFalse(isMountPoint);
        }
コード例 #11
0
        public void TC001_GetDiskIndexForMountPointTest()
        {
            // Arrange
            string mountPoint = @"c:\";

            // Act
            int id = DiskUtil.GetDiskIndexForMountPoint(mountPoint);

            // Assert
            Assert.AreNotEqual(int.MinValue, id);
        }
コード例 #12
0
        public void TC011_GetDiskIndexForMountPointInvalidMountPointTest()
        {
            // Arrange
            string mountPoint = Path.Combine(@"c:\", Guid.NewGuid().ToString());
            int    id         = 0;

            // Act
            id = DiskUtil.GetDiskIndexForMountPoint(mountPoint);

            // Assert
            Assert.AreEqual(int.MinValue, id);
        }
コード例 #13
0
        public void TC007_MountEntryInvalidDiskIdTest()
        {
            // Arrange
            int    diskId = int.MinValue;
            string actual = null;

            // Act
            actual = DiskUtil.MountEntry(diskId);

            // Assert
            Assert.IsNull(actual);
        }
コード例 #14
0
        public ActionResult Upload()
        {
            try
            {
                // 个人上传文件夹检查
                var folder     = System.Configuration.ConfigurationManager.AppSettings["UploadPath"];
                var folderPath = folder;
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }

                // 提取上传的文件
                HttpPostedFileBase file = Request.Files[0];

                // 原文件名 Test.txt
                var fileName = Path.GetFileName(file.FileName);
                // 最终文件名 yyyyMMddHHmmss+4random.txt
                var finalFileName = DiskUtil.GetFinalFileName(fileName);
                // 最终存储路径
                var path = Path.Combine(folderPath, finalFileName);

                // 保存文件
                file.SaveAs(path);

                // 判断上传的是反馈文件还是客户签字单
                var att = new YGS_Att();
                att.Name = fileName;
                att.Path = Path.Combine(finalFileName).Replace("\\", "/");

                using (var db = new YGSDbContext())
                {
                    db.Attachment.Add(att);
                    db.SaveChanges();
                }

                return(new JsonNetResult(new
                {
                    status = 200,
                    data = new
                    {
                        id = att.ID,
                        name = att.Name,
                        path = Url.Action("Download", "Common", new { id = att.ID })
                    }
                }));
            }
            catch
            {
                return(ResponseUtil.Error(400, "上传出错"));
            }
        }
コード例 #15
0
        public void TC014_GetVolumeDeviceIdInvalidMountPointTest()
        {
            // Arrange
            string mountPoint     = Path.Combine(@"c:\", Guid.NewGuid().ToString());
            string volumeDeviceId = null;

            // Act
            volumeDeviceId = DiskUtil.GetVolumeDeviceId(mountPoint);

            // Assert
            Assert.IsNotNull(volumeDeviceId);
            Assert.AreEqual(string.Empty, volumeDeviceId);
        }
コード例 #16
0
        public void TC002_GetDiskIndexForDiskIdTest()
        {
            // Arrange
            // Try to get index for disk 0 or 1, should be one of the two on a normal Windows installation
            int diskId0 = 0;
            int diskId1 = 1;

            // Act
            int index0 = DiskUtil.GetDiskIndexForDiskId(diskId0, false);
            int index1 = DiskUtil.GetDiskIndexForDiskId(diskId1, false);

            // Assert
            Assert.AreNotEqual(int.MinValue, Math.Max(index0, index1));
        }
コード例 #17
0
        public void TC016_MountEntryTest()
        {
            // Arrange
            int diskId0 = 0;
            int diskId1 = 1;

            string actual0 = null;
            string actual1 = null;

            // Act
            actual0 = DiskUtil.MountEntry(diskId0);
            actual1 = DiskUtil.MountEntry(diskId1);

            // Assert
            Assert.IsTrue(actual0 != null || actual1 != null);
        }
コード例 #18
0
ファイル: RecordControl.cs プロジェクト: zky001/RecordAnalyse
        public RecordControl(DiskUtil disk)
        {
            this.IsValid = false;

            disk.Read(data, 0, data.Length);

            this.Tag = Encoding.ASCII.GetString(data, 0, 4);

            if (this.Tag != "ctrl")
            {
                return;
            }

            this.IsValid = true;

            this.TotalSector = BitConverter.ToInt32(data, 4);
            this.UsedSector  = BitConverter.ToInt32(data, 8);
        }
コード例 #19
0
        public CaptureWindow(CaptureType captureType, SaveType saveType = SaveType.DISK)
        {
            InitializeComponent();

            this.captureType = captureType;
            this.saveType    = saveType;

            switch (captureType)
            {
            case CaptureType.FULLSCREEN:
                var screenRes = ScreenUtil.GetScreenResolution();

                Hide();
                var cap = ImageUtil.CaptureScreenshot(0, 0, (int)screenRes.Width, (int)screenRes.Height);
                Show();
                playShutterSound();

                switch (saveType)
                {
                case SaveType.DISK:
                    cap.Save(DiskUtil.GenerateDiskFilePath(), ImageFormat.Png);
                    break;

                case SaveType.CLIPBOARD:
                    Clipboard.SetImage(ImageUtil.ConvertBitmapToBitmapSource(cap));
                    break;
                }

                Close();
                break;

            case CaptureType.REGION:
                Cursor = Cursors.Cross;
                break;

            case CaptureType.WINDOW:
                Cursor cameraCursor = new Cursor(
                    Application.GetResourceStream(new Uri("Images/camera.cur", UriKind.Relative)).Stream
                    );
                Cursor = cameraCursor;
                break;
            }
        }
コード例 #20
0
        public static void MountPersistentDisk(int diskId)
        {
            if (!Directory.Exists(StorePath))
            {
                Directory.CreateDirectory(StorePath);
            }
            if (!DiskUtil.DiskHasPartition(diskId))
            {
                if (DiskUtil.CreatePrimaryPartition(diskId, "store") != 0)
                {
                    Logger.Error("Could not create partition on drive " + diskId);
                }
            }

            if (DiskUtil.MountPartition(diskId, StorePath) != 0)
            {
                Logger.Error("Could not mount disk " + diskId + " to " + StorePath);
                throw new Errors.FatalBoshException("Failed to mount: " + diskId + " to " + StorePath);
            }
        }
コード例 #21
0
        public void TC009_IsMountPointNullPathTest()
        {
            // Arrange
            string    mountPoint   = null;
            Exception expected     = null;
            bool      isMountPoint = false;

            // Act
            try
            {
                isMountPoint = DiskUtil.IsMountPoint(mountPoint);
            }
            catch (Exception ex)
            {
                expected = ex;
            }

            // Assert
            Assert.IsFalse(isMountPoint);
            Assert.IsNotNull(expected);
            Assert.IsInstanceOfType(expected, typeof(ArgumentNullException));
        }
コード例 #22
0
        public void TC008_DiskHasPartitionInvalidDiskIdTest()
        {
            // Arrange
            int       diskId       = int.MinValue;
            Exception expected     = null;
            bool      hasPartition = false;

            // Act
            try
            {
                hasPartition = DiskUtil.DiskHasPartition(diskId);
            }
            catch (Exception ex)
            {
                expected = ex;
            }

            // Assert
            Assert.IsFalse(hasPartition);
            Assert.IsNotNull(expected);
            Assert.IsInstanceOfType(expected, typeof(MessageHandlerException));
        }
コード例 #23
0
        public void TC012_GetDiskIndexForMountPointNullMountPointTest()
        {
            // Arrange
            string    mountPoint = null;
            int       id         = int.MinValue;
            Exception expected   = null;

            // Act
            try
            {
                id = DiskUtil.GetDiskIndexForMountPoint(mountPoint);
            }
            catch (Exception ex)
            {
                expected = ex;
            }

            // Assert
            Assert.AreEqual(int.MinValue, id);
            Assert.IsNotNull(expected);
            Assert.IsInstanceOfType(expected, typeof(ArgumentNullException));
        }
コード例 #24
0
        public void TC013_GetVolumeDeviceIdNullMountPointTest()
        {
            // Arrange
            string    mountPoint     = null;
            Exception expected       = null;
            string    volumeDeviceId = null;

            // Act
            try
            {
                volumeDeviceId = DiskUtil.GetVolumeDeviceId(mountPoint);
            }
            catch (Exception ex)
            {
                expected = ex;
            }

            // Assert
            Assert.IsNull(volumeDeviceId);
            Assert.IsNotNull(expected);
            Assert.IsInstanceOfType(expected, typeof(ArgumentNullException));
        }
コード例 #25
0
        public RecordDevice(DiskUtil disk)
        {
            this.IsValid = false;
            disk.Read(sectorData, 0, 512);

            this.Tag = Encoding.ASCII.GetString(sectorData, 0, 4);


            if (this.Tag != " dev")
            {
                return;
            }

            this.IsValid = true;

            this.Time = new DateTime(sectorData[4] + 2000, sectorData[5], sectorData[6], sectorData[7], sectorData[8], sectorData[9]);

            this.devInfo = new DeviceInfo(sectorData, 10);

            this.UsedSector = BitConverter.ToInt32(sectorData, 138);
            this.UsedRate   = BitConverter.ToInt16(sectorData, 142);
            this.Overflow   = BitConverter.ToInt32(sectorData, 144);
        }
コード例 #26
0
ファイル: RecordFile.cs プロジェクト: zky001/RecordAnalyse
        public RecordFile(DiskUtil disk, long offset, int index)
        {
            this.disk     = disk;
            this.Offset   = offset;
            disk.Position = offset;
            device        = new RecordDevice(disk);
            if (device.IsValid == false)
            {
                return;
            }



            disk.Read(dataChannel, 0, 512);

            string tag = ASCIIEncoding.ASCII.GetString(dataChannel, 0, 4);

            if (tag != " chn")
            {
                return;
            }

            int channelNum = dataChannel[4];

            eventWaits = new EventWaitHandle[channelNum];

            for (int i = 0; i < channelNum; i++)
            {
                AutoResetEvent autoEvent = new AutoResetEvent(false);
                SignalChannel  info      = new SignalChannel(this, autoEvent, dataChannel, 5 + 128 * i);
                eventWaits[i] = autoEvent;
                listChannel.Add(info);
            }


            this.FileIndex = index + 1;
        }
コード例 #27
0
        //初始化管理器界面的显示(初始化左窗体的驱动器树形视图和右窗体的文件列表视图)
        private void InitDisplay()
        {
            myComputer.Items.Clear();
            TreeViewItem recentFilesNode = new TreeViewItem()
            {
                Header = "最近访问"
            };

            myComputer.Items.Add(recentFilesNode);
            recentFilesNode.Tag = "最近访问";

            // recentFilesNode.ImageIndex = IconsIndexes.RecentFiles;
            //recentFilesNode.SelectedImageIndex = IconsIndexes.RecentFiles;

            DriveInfo[] driveInfos = DriveInfo.GetDrives();

            foreach (DriveInfo info in driveInfos)
            {
                TreeViewItem driveNode = null;

                switch (info.DriveType)
                {
                //固定磁盘
                case DriveType.Fixed:

                    //显示的名称
                    driveNode = new TreeViewItem()
                    {
                        Header = "本地磁盘(" + info.Name.Split('\\')[0] + ")",
                        Tag    = info.Name
                    };
                    myComputer.Items.Add(driveNode);

                    break;

                //光驱
                case DriveType.CDRom:

                    //显示的名称
                    //driveNode = diskTreeView.Nodes.Add("光驱(" + info.Name.Split('\\')[0] + ")");
                    driveNode = new TreeViewItem()
                    {
                        Header = "光驱(" + info.Name.Split('\\')[0] + ")",
                        Tag    = info.Name
                    };
                    myComputer.Items.Add(driveNode);
                    //真正的路径
                    //driveNode.Tag = info.Name;

                    // driveNode.ImageIndex = IconsIndexes.CDRom;
                    // driveNode.SelectedImageIndex = IconsIndexes.CDRom;

                    break;

                //可移动磁盘
                case DriveType.Removable:

                    //显示的名称
                    // driveNode = diskTreeView.Nodes.Add("可移动磁盘(" + info.Name.Split('\\')[0] + ")");
                    driveNode = new TreeViewItem()
                    {
                        Header = "可移动磁盘(" + info.Name.Split('\\')[0] + ")",
                        Tag    = info.Name
                    };
                    myComputer.Items.Add(driveNode);
                    //真正的路径
                    //driveNode.Tag = info.Name;

                    //driveNode.ImageIndex = IconsIndexes.RemovableDisk;
                    // driveNode.SelectedImageIndex = IconsIndexes.RemovableDisk;

                    break;

                case DriveType.Network:

                    //显示的名称
                    driveNode = new TreeViewItem()
                    {
                        Header = "网络(" + info.Name.Split('\\')[0] + ")",
                        Tag    = info.Name
                    };

                    myComputer.Items.Add(driveNode);

                    break;

                case DriveType.Ram:

                    //显示的名称
                    driveNode = new TreeViewItem()
                    {
                        Header = "Ram(" + info.Name.Split('\\')[0] + ")",
                        Tag    = info.Name
                    };
                    myComputer.Items.Add(driveNode);
                    break;

                case DriveType.Unknown:

                    //显示的名称
                    driveNode = new TreeViewItem()
                    {
                        Header = "Unknown(" + info.Name.Split('\\')[0] + ")",
                        Tag    = info.Name
                    };
                    myComputer.Items.Add(driveNode);
                    break;

                case DriveType.NoRootDirectory:
                    break;

                default:
                    driveNode = new TreeViewItem()
                    {
                        Header = "Unknown(" + info.Name.Split('\\')[0] + ")",
                        Tag    = info.Name
                    };
                    myComputer.Items.Add(driveNode);
                    break;
                }
            }

            //加载每个磁盘下的子目录
            foreach (TreeViewItem node in myComputer.Items)
            {
                if (((string)node.Tag).Equals("最近访问") || DiskUtil.CheckBitLockerIsOn((string)node.Tag))
                {
                    continue;
                }
                LoadChildNodes(node);
            }

            //加载移动设备
            // var devices = MediaDevice.GetDevices();
            // foreach (var item in devices)
            // {
            //
            //     TreeViewItem driveNode = new TreeViewItem()
            //     {
            //         Header = "移动终端(" + item.FriendlyName.Split('\\')[0] + ")",
            //         Tag = item.FriendlyName
            //
            //     };
            //     myComputer.Items.Add(driveNode);
            //
            //
            // }
        }
コード例 #28
0
ファイル: FileListenHelper.cs プロジェクト: hst-bridge/BBS
 /// <summary>
 /// 检查target目录所在盘区空间是否充足
 /// </summary>
 /// <returns></returns>
 public static bool CheckDisk(DirectoryInfo targetDirInfo)
 {
     //是否大于设置线
     return(DiskUtil.GetFreeSpace(targetDirInfo.Root.FullName) > new AppConfig().getSpaceWarnline());
 }