Ejemplo n.º 1
0
        public SharedDirectory GetNetworkDisk(string clientUserID, string netDiskID, string dirPath)
        {
            var rootPath = this.networkDiskPathManager.GetNetworkDiskRootPath(clientUserID, netDiskID);

            if (rootPath == null)
            {
                return(null);
            }

            var iniDirName  = this.networkDiskPathManager.GetNetworkDiskIniDirName(clientUserID, netDiskID);
            var diskRpotDir = rootPath + "\\" + iniDirName + "\\";

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

            if (dirPath == null)
            {
                var dir  = new SharedDirectory();
                var disk = new DiskDrive();
                disk.Name               = iniDirName;
                disk.TotalSize          = this.networkDiskPathManager.GetNetworkDiskTotalSize(clientUserID, netDiskID);
                disk.AvailableFreeSpace = disk.TotalSize - this.networkDiskPathManager.GetNetworkDiskSizeUsed(clientUserID, netDiskID);

                dir.DriveList.Add(disk);
                return(dir);
            }

            return(SharedDirectory.GetSharedDirectory(rootPath + dirPath));
        }
Ejemplo n.º 2
0
        public static void ClassInitialize(TestContext context)
        {
            // calculate indices
            var recordingPath = PathHelper.ResolveAsset("Recordings", "OxleyCreek_site_1_1060_244333_20140529T081358+1000_120_0.wav");
            var configPath    = PathHelper.ResolveConfigFile("Towsey.Acoustic.Zooming.yml");
            var arguments     = new AnalyseLongRecording.Arguments
            {
                Source  = recordingPath,
                Config  = configPath.FullName,
                Output  = SharedDirectory,
                TempDir = SharedDirectory.Combine("Temp"),
            };

            context.WriteLine($"{DateTime.Now} generating indices fixture data");
            AnalyseLongRecording.Execute(arguments);
            context.WriteLine($"{DateTime.Now} finished generting fixture");

            ResultsDirectory = SharedDirectory.Combine("Towsey.Acoustic");

            // do some basic checks that the indices were generated
            var listOfFiles = ResultsDirectory.EnumerateFiles().ToArray();

            Assert.AreEqual(20, listOfFiles.Length);
            var csvCount = listOfFiles.Count(f => f.Name.EndsWith(".csv"));

            Assert.AreEqual(16, csvCount);
            var jsonCount = listOfFiles.Count(f => f.Name.EndsWith(".json"));

            Assert.AreEqual(2, jsonCount);
            var pngCount = listOfFiles.Count(f => f.Name.EndsWith(".png"));

            Assert.AreEqual(2, pngCount);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 目标目录下是否存在同名的项目。
        /// </summary>
        private bool ExistSameNameItem(string dirPath, string itemName)
        {
            if (this.currentDirPath == dirPath)
            {
                foreach (ListViewItem item in this.listView_fileDirectory.Items)
                {
                    if (item.Text.ToLower() == itemName.ToLower())
                    {
                        return(true);
                    }
                }
            }
            else
            {
                SharedDirectory containerDirectory = this.fileDirectoryOutter.GetSharedDirectory(this.ownerID, this.netDiskID, dirPath);
                foreach (FileDetail fileDetail in containerDirectory.FileList)
                {
                    if (fileDetail.Name.ToLower() == itemName.ToLower())
                    {
                        return(true);
                    }
                }

                foreach (DirectoryDetail dirDetail in containerDirectory.SubDirectorys)
                {
                    if (dirDetail.Name.ToLower() == itemName.ToLower())
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        public SharedDirectory GetNetworkDisk(string userID, string dirPath)
        {
            string rootPath = this.networkDiskPathManager.GetNetworkDiskRootPath(userID);

            if (rootPath == null)
            {
                return(null);
            }

            if (!Directory.Exists(rootPath + userID))
            {
                Directory.CreateDirectory(rootPath + userID);
            }

            if (dirPath == null)
            {
                SharedDirectory dir  = new SharedDirectory();
                DiskDrive       disk = new DiskDrive();
                disk.Name               = userID;
                disk.TotalSize          = this.networkDiskPathManager.GetNetworkDiskTotalSize(userID);
                disk.AvailableFreeSpace = disk.TotalSize - this.networkDiskPathManager.GetNetworkDiskSizeUsed(userID);

                dir.DriveList.Add(disk);
                return(dir);
            }

            return(SharedDirectory.GetSharedDirectory(rootPath + dirPath));
        }
        public static void MyClassInitialize(TestContext testContext)
        {
            var indonesiaIndices  = PathHelper.ResolveAsset("Concatenation", IndonesiaReduced + ".zip");
            var newZealandIndices = PathHelper.ResolveAsset("Concatenation", NewZealandArk01 + ".zip");

            indonesiaIndicesDirectory       = SharedDirectory.Combine(IndonesiaReduced);
            newZealandArk01IndicesDirectory = SharedDirectory.Combine(NewZealandArk01);

            ZipFile.ExtractToDirectory(indonesiaIndices.FullName, indonesiaIndicesDirectory.FullName);
            ZipFile.ExtractToDirectory(newZealandIndices.FullName, newZealandArk01IndicesDirectory.FullName);
        }
Ejemplo n.º 6
0
        public byte[] HandleQuery(string sourceUserID, int informationType, byte[] info)
        {
            #region ReqDirectory
            if (informationType == this.fileDirectoryInfoTypes.ReqDirectory)
            {
                ReqDirectoryContract contract = CompactPropertySerializer.Default.Deserialize <ReqDirectoryContract>(info, 0);
                SharedDirectory      dir      = this.networkDisk.GetNetworkDisk(sourceUserID, contract.NetDiskID, contract.DirectoryPath);
                return(CompactPropertySerializer.Default.Serialize <ResDirectoryContract>(new ResDirectoryContract(dir)));
            }
            #endregion

            #region ReqNetworkDiskState
            if (informationType == this.fileDirectoryInfoTypes.ReqNetworkDiskState)
            {
                string netDiskID = null;
                if (info != null)
                {
                    netDiskID = System.Text.Encoding.UTF8.GetString(info);
                }
                NetworkDiskState state = this.networkDisk.GetNetworkDiskState(sourceUserID, netDiskID);
                return(CompactPropertySerializer.Default.Serialize <ResNetworkDiskStateContract>(new ResNetworkDiskStateContract(state)));
            }
            #endregion

            if (informationType == this.fileDirectoryInfoTypes.Rename)
            {
                RenameContract contract = CompactPropertySerializer.Default.Deserialize <RenameContract>(info, 0);
                try
                {
                    this.networkDisk.Rename(sourceUserID, contract.NetDiskID, contract.ParentDirectoryPath, contract.IsFile, contract.OldName, contract.NewName);
                    return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract()));
                }
                catch (Exception ee)
                {
                    string error = "";
                    if (ee is IOException)
                    {
                        error = string.Format("{0} 正在被使用!", Path.GetFileName(contract.OldName));
                    }
                    else
                    {
                        error = ee.Message;
                    }
                    return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract(error)));;
                }
            }

            #region DownloadFile
            if (informationType == this.fileDirectoryInfoTypes.Download)
            {
                DownloadContract contract      = CompactPropertySerializer.Default.Deserialize <DownloadContract>(info, 0);
                string           fileOrDirPath = this.networkDisk.GetNetworkDiskRootPath(sourceUserID, contract.NetDiskID) + contract.SourceRemotePath;
                string           error         = "";
                try
                {
                    if (File.Exists(fileOrDirPath))
                    {
                        FileStream stream = File.OpenRead(fileOrDirPath);
                        stream.Close();
                        stream.Dispose();
                    }
                    else
                    {
                        if (!Directory.Exists(fileOrDirPath))
                        {
                            error = string.Format("{0} 不存在或已经被删除!", Path.GetFileName(fileOrDirPath));
                            return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract(error)));
                        }
                    }
                }
                catch (Exception ee)
                {
                    if (ee is FileNotFoundException)
                    {
                        error = string.Format("{0} 不存在或已经被删除!", Path.GetFileName(fileOrDirPath));
                    }
                    else if (ee is IOException)
                    {
                        error = string.Format("{0} 正在被其它进程占用!", Path.GetFileName(fileOrDirPath));
                    }
                    else
                    {
                        error = ee.Message;
                    }

                    return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract(error)));
                }


                string projectID = null;
                this.fileController.BeginSendFile(sourceUserID, fileOrDirPath, Comment4NDisk.BuildComment(contract.SaveLocalPath, contract.NetDiskID), out projectID);

                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract()));
            }
            #endregion

            #region DeleteFileOrDirectory
            if (informationType == this.fileDirectoryInfoTypes.Delete)
            {
                OperationResultConatract resultContract = new OperationResultConatract();
                try
                {
                    DeleteContract contract = CompactPropertySerializer.Default.Deserialize <DeleteContract>(info, 0);
                    this.networkDisk.DeleteFileOrDirectory(sourceUserID, contract.NetDiskID, contract.SourceParentDirectoryPath, contract.FilesBeDeleted, contract.DirectoriesBeDeleted);
                }
                catch (Exception ee)
                {
                    resultContract = new OperationResultConatract(ee.Message);
                }
                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(resultContract));
            }
            #endregion

            #region CopyFileOrDirectory
            if (informationType == this.fileDirectoryInfoTypes.Copy)
            {
                OperationResultConatract resultContract = new OperationResultConatract();
                try
                {
                    CopyContract contract = CompactPropertySerializer.Default.Deserialize <CopyContract>(info, 0);
                    this.networkDisk.Copy(sourceUserID, contract.NetDiskID, contract.SourceParentDirectoryPath, contract.FilesBeCopyed, contract.DirectoriesBeCopyed, contract.DestParentDirectoryPath);
                }
                catch (Exception ee)
                {
                    resultContract = new OperationResultConatract(ee.Message);
                }
                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(resultContract));
            }
            #endregion

            #region MoveFileOrDirectory
            if (informationType == this.fileDirectoryInfoTypes.Move)
            {
                OperationResultConatract resultContract = new OperationResultConatract();
                try
                {
                    MoveContract contract = CompactPropertySerializer.Default.Deserialize <MoveContract>(info, 0);
                    this.networkDisk.Move(sourceUserID, contract.NetDiskID, contract.OldParentDirectoryPath, contract.FilesBeMoved, contract.DirectoriesBeMoved, contract.NewParentDirectoryPath);
                }
                catch (Exception ee)
                {
                    resultContract = new OperationResultConatract(ee.Message);
                }
                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(resultContract));
            }
            #endregion
            return(null);
        }
Ejemplo n.º 7
0
 public void AddSharedDirectory(SharedDirectory dir)
 {
     RemoveSharedDirectory(dir.FullName);
     SharedDirectories.Add(dir);
 }
Ejemplo n.º 8
0
 public ResDirectoryContract(SharedDirectory directory)
 {
     this.sharedDirectory = directory;
 }
Ejemplo n.º 9
0
        private void LoadDirectory(string path, bool tipOnException)
        {
            if (this.ownerID == null)
            {
                return;
            }

            Cursor old = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                SharedDirectory sharedDirectory = this.fileDirectoryOutter.GetSharedDirectory(this.ownerID, this.netDiskID, path);
                if (sharedDirectory == null)
                {
                    MessageBox.Show("网络硬盘未开放!");
                }
                else if (!sharedDirectory.Valid)
                {
                    MessageBox.Show(sharedDirectory.Exception);
                }
                else
                {
                    if (path == null)
                    {
                        this.ownerSharedAllDisk = sharedDirectory.DirectoryPath == null;
                    }

                    #region Action
                    this.listView_fileDirectory.Items.Clear();
                    if (sharedDirectory.DirectoryPath == null)
                    {
                        sharedDirectory.DriveList.Sort();
                        foreach (DiskDrive drive in sharedDirectory.DriveList)
                        {
                            int imageIndex = 2;
                            if (drive.DriveType == DriveType.CDRom)
                            {
                                imageIndex = 3;
                            }
                            if (drive.DriveType == DriveType.Removable)
                            {
                                imageIndex = 4;
                            }
                            ListViewItem item = new ListViewItem(new string[] { drive.Name, "", "" }, imageIndex);
                            item.Tag = new FileOrDirectoryTag(drive.Name, 0, DateTime.Now, false);
                            string name = drive.VolumeLabel;
                            if (name == null || name.Length == 0)
                            {
                                name = drive.Name;
                            }
                            item.ToolTipText = string.Format("{0}\n可用空间:{1}\n总 大 小:{2}", name, PublicHelper.GetSizeString(drive.AvailableFreeSpace), PublicHelper.GetSizeString(drive.TotalSize));
                            this.listView_fileDirectory.Items.Add(item);
                        }
                    }
                    else
                    {
                        foreach (DirectoryDetail dirDetail in sharedDirectory.SubDirectorys)
                        {
                            ListViewItem item = new ListViewItem(new string[] { dirDetail.Name, dirDetail.CreateTime.ToString(), "" }, 0);
                            //ListViewItem item = this.listView_fileDirectory.Items.Add(dirName, 0);
                            item.Tag = new FileOrDirectoryTag(dirDetail.Name, 0, dirDetail.CreateTime, false);
                            this.listView_fileDirectory.Items.Add(item);
                        }

                        foreach (FileDetail file in sharedDirectory.FileList)
                        {
                            ListViewItem item = new ListViewItem(new string[] { file.Name, file.CreateTime.ToString(), PublicHelper.GetSizeString((uint)file.Size) }, this.GetIconIndex(file.Name));
                            //ListViewItem item = this.listView_fileDirectory.Items.Add(file.Name, this.GetIconIndex(file.Name));
                            item.Tag         = new FileOrDirectoryTag(file.Name, file.Size, file.CreateTime, true);
                            item.ToolTipText = string.Format("大    小:{0}\n创建日期:{1}", PublicHelper.GetSizeString((uint)file.Size), file.CreateTime);
                            this.listView_fileDirectory.Items.Add(item);
                        }

                        this.columnIndexToSort = 0;
                        this.asendingOrder     = true;
                        this.listView_fileDirectory.Sort();
                    }

                    this.currentDirPath = path;
                    if (this.currentDirPath != null && !this.currentDirPath.EndsWith("\\"))
                    {
                        this.currentDirPath += "\\";
                    }

                    string displayPath = this.IsNetworkDisk ? "网络硬盘" : "共享磁盘";
                    if (this.currentDirPath != null && this.currentDirPath != sharedDirectory.DirectoryPath)
                    {
                        displayPath += "\\" + this.currentDirPath;
                    }
                    this.toolStripTextBox1.Text = displayPath;

                    this.listView_fileDirectory.LabelEdit = (sharedDirectory.DirectoryPath != null);
                    #endregion
                }
            }
            catch (Exception ee)
            {
                if (tipOnException)
                {
                    MessageBox.Show(ee.Message);
                }
            }
            finally
            {
                Cursor.Current = old;
            }
        }
Ejemplo n.º 10
0
        public byte[] HandleQuery(string sourceUserID, int informationType, byte[] info)
        {
            #region ReqDirectory
            if (informationType == this.fileDirectoryInfoTypes.ReqDirectory)
            {
                ReqDirectoryContract contract = CompactPropertySerializer.Default.Deserialize <ReqDirectoryContract>(info, 0);
                string          fullPath      = this.ConstructFullPath(contract.DirectoryPath);
                SharedDirectory dir           = SharedDirectory.GetSharedDirectory(fullPath);
                return(CompactPropertySerializer.Default.Serialize <ResDirectoryContract>(new ResDirectoryContract(dir)));
            }
            #endregion

            #region Rename
            if (informationType == this.fileDirectoryInfoTypes.Rename)
            {
                RenameContract contract = CompactPropertySerializer.Default.Deserialize <RenameContract>(info, 0);
                string         fullPath = this.ConstructFullPath(contract.ParentDirectoryPath);
                try
                {
                    if (contract.IsFile)
                    {
                        File.Move(fullPath + contract.OldName, fullPath + contract.NewName);
                    }
                    else
                    {
                        Directory.Move(fullPath + contract.OldName, fullPath + contract.NewName);
                    }

                    return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract()));;
                }
                catch (Exception ee)
                {
                    string error = "";
                    if (ee is IOException)
                    {
                        error = string.Format("{0} 正在被使用!", Path.GetFileName(contract.OldName));
                    }
                    else
                    {
                        error = ee.Message;
                    }
                    return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract(error)));;
                }
            }
            #endregion

            #region DownloadFile
            if (informationType == this.fileDirectoryInfoTypes.Download)
            {
                DownloadContract contract = CompactPropertySerializer.Default.Deserialize <DownloadContract>(info, 0);
                string           fullPath = this.ConstructFullPath(contract.SourceRemotePath);
                if (contract.IsFile)
                {
                    try
                    {
                        FileStream stream = File.OpenRead(fullPath);
                        stream.Close();
                        stream.Dispose();
                    }
                    catch (Exception ee)
                    {
                        string error = "";
                        if (ee is FileNotFoundException)
                        {
                            error = string.Format("{0} 不存在或已经被删除!", Path.GetFileName(fullPath));
                        }
                        else if (ee is IOException)
                        {
                            error = string.Format("{0} 正在被其它进程占用!", Path.GetFileName(fullPath));
                        }
                        else
                        {
                            error = ee.Message;
                        }

                        return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract(error)));
                    }
                }
                else
                {
                    if (!Directory.Exists(fullPath))
                    {
                        string error = string.Format("{0} 不存在或已经被删除!", Path.GetFileName(fullPath));
                        return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract(error)));
                    }
                }

                string fileID = null;
                this.fileOutter.BeginSendFile(sourceUserID, fullPath, Comment4NDisk.BuildComment(contract.SaveLocalPath, contract.NetDiskID), out fileID);
                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(new OperationResultConatract()));;
            }
            #endregion

            #region DeleteFileOrDirectory
            if (informationType == this.fileDirectoryInfoTypes.Delete)
            {
                OperationResultConatract resultContract = new OperationResultConatract();
                try
                {
                    DeleteContract contract = CompactPropertySerializer.Default.Deserialize <DeleteContract>(info, 0);
                    string         fullPath = this.ConstructFullPath(contract.SourceParentDirectoryPath);
                    if (contract.FilesBeDeleted != null)
                    {
                        foreach (string fileName in contract.FilesBeDeleted)
                        {
                            string filePath = fullPath + fileName;
                            if (File.Exists(filePath))
                            {
                                File.Delete(filePath);
                            }
                        }
                    }

                    if (contract.DirectoriesBeDeleted != null)
                    {
                        foreach (string dirName in contract.DirectoriesBeDeleted)
                        {
                            string dirPath = fullPath + dirName + "\\";
                            if (Directory.Exists(dirPath))
                            {
                                FileHelper.DeleteDirectory(dirPath);
                            }
                        }
                    }
                }
                catch (Exception ee)
                {
                    resultContract = new OperationResultConatract(ee.Message);
                }
                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(resultContract));
            }
            #endregion

            #region CopyFileOrDirectory
            if (informationType == this.fileDirectoryInfoTypes.Copy)
            {
                OperationResultConatract resultContract = new OperationResultConatract();
                try
                {
                    CopyContract contract = CompactPropertySerializer.Default.Deserialize <CopyContract>(info, 0);
                    FileHelper.Copy(this.ConstructFullPath(contract.SourceParentDirectoryPath), contract.FilesBeCopyed, contract.DirectoriesBeCopyed, this.ConstructFullPath(contract.DestParentDirectoryPath));
                }
                catch (Exception ee)
                {
                    resultContract = new OperationResultConatract(ee.Message);
                }
                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(resultContract));
            }
            #endregion

            #region MoveFileOrDirectory
            if (informationType == this.fileDirectoryInfoTypes.Move)
            {
                OperationResultConatract resultContract = new OperationResultConatract();
                try
                {
                    MoveContract contract = CompactPropertySerializer.Default.Deserialize <MoveContract>(info, 0);
                    FileHelper.Move(this.ConstructFullPath(contract.OldParentDirectoryPath), contract.FilesBeMoved, contract.DirectoriesBeMoved, this.ConstructFullPath(contract.NewParentDirectoryPath));
                }
                catch (Exception ee)
                {
                    resultContract = new OperationResultConatract(ee.Message);
                }
                return(CompactPropertySerializer.Default.Serialize <OperationResultConatract>(resultContract));
            }
            #endregion

            return(null);
        }
Ejemplo n.º 11
0
        public SharedDirectory GetNetworkDisk(string userID, string dirPath)
        {
            string rootPath = this.networkDiskPathManager.GetNetworkDiskRootPath(userID);
            if (rootPath == null)
            {
                return null;
            }

            if (!Directory.Exists(rootPath + userID))
            {
                Directory.CreateDirectory(rootPath + userID);
            }

            if (dirPath == null)
            {
                SharedDirectory dir = new SharedDirectory();
                DiskDrive disk = new DiskDrive();
                disk.Name = userID;
                disk.TotalSize = this.networkDiskPathManager.GetNetworkDiskTotalSize(userID);
                disk.AvailableFreeSpace = disk.TotalSize - this.networkDiskPathManager.GetNetworkDiskSizeUsed(userID);

                dir.DriveList.Add(disk);
                return dir;
            }

            return SharedDirectory.GetSharedDirectory(rootPath + dirPath);
        }