private void WriteToConsole(DirectoryOperation operation)
        {
            Console.WriteLine($"<////////////////{operation.Method.Name}////////////////>");
            Stopwatch myTimer = new Stopwatch();

            myTimer.Start();
            Console.WriteLine($"Count files in ExpectSet {operation().Count}");
            foreach (FileInfo info in operation())
            {
                Console.WriteLine("FullPath ==> {0}, FileName ==> {1}", info.FullName, info.Name);
            }

            Console.WriteLine($"time taken: {+myTimer.Elapsed}");
            Console.WriteLine($"^////////////////{operation.Method.Name}////////////////^");
        }
Esempio n. 2
0
File: Dir.cs Progetto: ltwlf/IronSP
        // TODO: to match the C-Ruby exception
        private static Exception ToRubyException(Exception /*!*/ ex, string path, DirectoryOperation op)
        {
            Assert.NotNull(ex);

            Type exceptionType = ex.GetType();

            switch (op)
            {
            case DirectoryOperation.ChangeDir:
                return(RubyExceptions.CreateEINVAL(path));

            case DirectoryOperation.Open:
                return(RubyExceptions.CreateENOENT("No such file or directory - {0}", path));

            case DirectoryOperation.Delete:
                if (ex is ArgumentException)
                {
                    return(RubyExceptions.CreateEINVAL(path));
                }
                if (ex is IOException)
                {
                    return(Errno.CreateEACCES(path));
                }
                break;

            case DirectoryOperation.Create:
                if (ex is ArgumentException)
                {
                    return(RubyExceptions.CreateEINVAL(path));
                }
                if (ex is IOException)
                {
                    return(RubyExceptions.CreateEEXIST(path));
                }
                break;
            }

            if (ex is UnauthorizedAccessException)
            {
                return(Errno.CreateEACCES(path, ex));
            }

            // throw anyway
            return(RubyExceptions.CreateSystemCallError("unknown scenario - {0}, {1}, {2}", exceptionType, path, op));
        }
Esempio n. 3
0
        // TODO: to match the C-Ruby exception
        private static Exception ToRubyException(Exception /*!*/ ex, string path, DirectoryOperation op)
        {
            Assert.NotNull(ex);

            Type exceptionType = ex.GetType();

            switch (op)
            {
            case DirectoryOperation.ChangeDir:
                return(new Errno.InvalidError(path));

            case DirectoryOperation.Open:
                return(new Errno.NoEntryError(path));

            case DirectoryOperation.Delete:
                if (ex is ArgumentException)
                {
                    return(new Errno.InvalidError(path));
                }
                if (ex is IOException)
                {
                    return(new Errno.AccessError(path));
                }
                break;

            case DirectoryOperation.Create:
                if (ex is ArgumentException)
                {
                    return(new Errno.InvalidError(path));
                }
                if (ex is IOException)
                {
                    return(new Errno.ExistError(path));
                }
                break;
            }

            // throw anyway
            return(RubyExceptions.CreateSystemCallError(String.Format("unknown scenario - {0}, {1}, {2}", exceptionType, path, op)));
        }
Esempio n. 4
0
        // TODO: to match the C-Ruby exception
        private static Exception ToRubyException(Exception/*!*/ ex, string path, DirectoryOperation op) {
            Assert.NotNull(ex);
            
            Type exceptionType = ex.GetType();

            switch (op) {
                case DirectoryOperation.ChangeDir:
                    return RubyExceptions.CreateEINVAL(path);

                case DirectoryOperation.Open:
                    return RubyExceptions.CreateENOENT("No such file or directory - {0}", path);

                case DirectoryOperation.Delete:
                    if (ex is ArgumentException) {
                        return RubyExceptions.CreateEINVAL(path);
                    }
                    if (ex is IOException) {
                        return Errno.CreateEACCES(path);
                    }
                    break;

                case DirectoryOperation.Create:
                    if (ex is ArgumentException) {
                        return RubyExceptions.CreateEINVAL(path);
                    }
                    if (ex is IOException) {
                        return RubyExceptions.CreateEEXIST(path);
                    }
                    break;
            }

            // throw anyway
            return RubyExceptions.CreateSystemCallError("unknown scenario - {0}, {1}, {2}", exceptionType, path, op);
        }
Esempio n. 5
0
        private void WriteToExcel(DirectoryOperation operation)
        {
            try
            {
                string targetToOutput = ConfigurationManager.AppSettings["TargetToOutput"].ToString();
                var    workbook       = new XSSFWorkbook();
                if (File.Exists(targetToOutput))
                {
                    this.fileStream = new FileStream(targetToOutput, FileMode.Open /*, FileAccess.ReadWrite, FileShare.ReadWrite*/);
                    workbook        = new XSSFWorkbook(this.fileStream);
                    this.fileStream.Close();
                }
                else
                {
                    this.fileStream = new FileStream(targetToOutput, FileMode.Create);
                    this.fileStream.Close();
                    workbook = new XSSFWorkbook();
                }

                //this.fileStream = new FileStream("C:\\Users\\GOOD\\Desktop\\test.xls", FileMode.Create, FileAccess.ReadWrite);

                ISheet sheet      = null;
                bool   notContain = true;
                if (workbook.NumberOfSheets != 0)
                {
                    for (int i = 0; i < workbook.NumberOfSheets; i++)
                    {
                        if (workbook.GetSheetName(i).Equals($"{operation.Method.Name}"))
                        {
                            //workbook.RemoveSheetAt(i);
                            notContain = false;
                            sheet      = workbook.GetSheet($"{operation.Method.Name}");
                            break;
                        }
                        else
                        {
                            notContain = true;
                        }
                    }
                }

                if (File.Exists(targetToOutput))
                {
                    this.fileStream = new FileStream(targetToOutput, FileMode.Truncate /*, FileAccess.ReadWrite*/);
                }

                if (notContain)
                {
                    sheet = workbook.CreateSheet($"{operation.Method.Name}");

                    var row             = sheet.CreateRow(0);
                    var row2            = sheet.CreateRow(1);
                    var row3            = sheet.CreateRow(2);
                    var cellStyleBorder = workbook.CreateCellStyle();
                    cellStyleBorder.BorderBottom      = BorderStyle.Thin;
                    cellStyleBorder.BorderLeft        = BorderStyle.Thin;
                    cellStyleBorder.BorderRight       = BorderStyle.Thin;
                    cellStyleBorder.BorderTop         = BorderStyle.Thin;
                    cellStyleBorder.Alignment         = HorizontalAlignment.Center;
                    cellStyleBorder.VerticalAlignment = VerticalAlignment.Center;
                    var cellStyleBorderAndColorGreen = workbook.CreateCellStyle();
                    cellStyleBorderAndColorGreen.CloneStyleFrom(cellStyleBorder);
                    cellStyleBorderAndColorGreen.FillPattern = FillPattern.SolidForeground;
                    ((XSSFCellStyle)cellStyleBorderAndColorGreen).SetFillForegroundColor(new XSSFColor(new byte[] { 198, 239, 206 }));
                    var cellStyleBorderAndColorYellow = workbook.CreateCellStyle();
                    cellStyleBorderAndColorYellow.CloneStyleFrom(cellStyleBorder);
                    cellStyleBorderAndColorYellow.FillPattern = FillPattern.SolidForeground;
                    ((XSSFCellStyle)cellStyleBorderAndColorYellow).SetFillForegroundColor(new XSSFColor(new byte[] { 255, 235, 156 }));
                    row.CreateCell(0);
                    row.CreateCell(1);
                    row2.CreateCell(0);
                    row2.CreateCell(1);
                    row3.CreateCell(0, CellType.String).SetCellValue("FullPath");
                    row3.Cells[0].CellStyle = cellStyleBorderAndColorYellow;
                    row3.CreateCell(1, CellType.String).SetCellValue("FileName");
                    row3.Cells[1].CellStyle = cellStyleBorderAndColorYellow;
                    var cra  = new NPOI.SS.Util.CellRangeAddress(0, 0, 0, 1);
                    var cra2 = new NPOI.SS.Util.CellRangeAddress(1, 1, 0, 1);
                    sheet.AddMergedRegion(cra);
                    sheet.AddMergedRegion(cra2);
                    ICell cell = sheet.GetRow(0).GetCell(0);
                    cell.SetCellType(CellType.String);
                    cell.SetCellValue($"{operation.Method.Name}");
                    cell.CellStyle = cellStyleBorderAndColorGreen;
                    sheet.GetRow(0).GetCell(1).CellStyle = cellStyleBorderAndColorGreen;
                    ICell cell2 = sheet.GetRow(1).GetCell(0);
                    cell2.SetCellType(CellType.String);
                    cell2.SetCellValue($"Count files in ExpectSet {this.ShowerDerectoryInstance.SymmetricalDifference().Count}");
                    cell2.CellStyle = cellStyleBorderAndColorGreen;
                    sheet.GetRow(1).GetCell(1).CellStyle = cellStyleBorderAndColorGreen;

                    int x = 3;

                    foreach (FileInfo info in this.ShowerDerectoryInstance.SymmetricalDifference())
                    {
                        row = sheet.CreateRow(x);
                        row.CreateCell(0).SetCellValue(info.FullName);
                        row.CreateCell(1).SetCellValue(info.Name);
                        x++;
                    }
                }
                else
                {
                    var row = sheet.GetRow(0) == null?sheet.CreateRow(0) : sheet.GetRow(0);

                    var row2 = sheet.GetRow(1) == null?sheet.CreateRow(1) : sheet.GetRow(1);

                    var row3 = sheet.GetRow(2) == null?sheet.CreateRow(2) : sheet.GetRow(2);

                    var row3Cell0 = row3.GetCell(0) == null?row3.CreateCell(0) : row3.GetCell(0);

                    var row3Cell1 = row3.GetCell(1) == null?row3.CreateCell(1) : row3.GetCell(1);

                    row3Cell0.SetCellValue("FilePath");
                    row3Cell1.SetCellValue("FileName");
                    ICell cell      = sheet.GetRow(0).GetCell(0);
                    var   row0Cell0 = row.GetCell(0) == null?row.CreateCell(0) : row.GetCell(0);

                    row0Cell0.SetCellValue($"{operation.Method.Name}");
                    var row2Cell0 = row2.GetCell(0) == null?row2.CreateCell(0) : row2.GetCell(0);

                    row2Cell0.SetCellValue($"Count files in ExpectSet {this.ShowerDerectoryInstance.SymmetricalDifference().Count}");
                    int x = 3;
                    foreach (FileInfo info in this.ShowerDerectoryInstance.SymmetricalDifference())
                    {
                        if (sheet.GetRow(x) == null)
                        {
                            row = sheet.CreateRow(x);
                        }
                        else
                        {
                            row = sheet.GetRow(x);
                        }

                        if (row.GetCell(0) != null)
                        {
                            row.GetCell(0).SetCellValue(info.FullName);
                        }
                        else
                        {
                            row.CreateCell(0).SetCellValue(info.FullName);
                        }

                        if (row.GetCell(1) != null)
                        {
                            row.GetCell(1).SetCellValue(info.Name);
                        }
                        else
                        {
                            row.CreateCell(1).SetCellValue(info.Name);
                        }

                        x++;
                    }
                }

                sheet.AutoSizeColumn(0);
                sheet.AutoSizeColumn(1);
                workbook.Write(this.fileStream);
            }
            catch (ConfigurationErrorsException e)
            {
                throw e;
            }
            catch (NullReferenceException e)
            {
                throw e;
            }
            catch (ArgumentException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (this.fileStream != null)
                {
                    this.fileStream.Close();
                }
            }
        }
Esempio n. 6
0
        // TODO: to match the C-Ruby exception
        private static Exception ToRubyException(Exception/*!*/ ex, string path, DirectoryOperation op) {
            Assert.NotNull(ex);
            
            Type exceptionType = ex.GetType();

            switch (op) {
                case DirectoryOperation.ChangeDir:
                    return new Errno.InvalidError(path);

                case DirectoryOperation.Open:
                    return new Errno.NoEntryError(path);

                case DirectoryOperation.Delete:
                    if (ex is ArgumentException) {
                        return new Errno.InvalidError(path);
                    }
                    if (ex is IOException) {
                        return new Errno.AccessError(path);
                    }
                    break;

                case DirectoryOperation.Create:
                    if (ex is ArgumentException) {
                        return new Errno.InvalidError(path);
                    }
                    if (ex is IOException) {
                        return new Errno.ExistError(path);
                    }
                    break;
            }

            // throw anyway
            return RubyExceptions.CreateSystemCallError(String.Format("unknown scenario - {0}, {1}, {2}", exceptionType, path, op));
        }
Esempio n. 7
0
        public override object Execute(Package package, DtsContainer container)
        {
            object returnValue = null;

            string             argument1 = Properties[PropArgument1].Value;
            string             argument2 = Properties[PropArgument2].Value;
            DirectoryOperation operation = DirectoryOperationFromString(Properties[PropOperation].Value);

            if (operation == DirectoryOperation.Move)
            {
                if (argument2 == string.Empty)
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "argument2 must specify a target path for the {0} operation.", operation));
                }
            }

            CommandParentType commandParentType = GetCommandParentType();

            try
            {
                OnCommandStarted(new CommandStartedEventArgs(DateTime.Now, CommandName, null, null, commandParentType));

                switch (operation)
                {
                case DirectoryOperation.Exists:
                    returnValue = Directory.Exists(argument1);
                    break;

                case DirectoryOperation.Move:
                    Directory.Move(argument1, argument2);
                    returnValue = 0;
                    break;

                case DirectoryOperation.Create:
                    Directory.CreateDirectory(argument1);
                    returnValue = 0;
                    break;

                case DirectoryOperation.Delete:
                    Directory.Delete(argument1);
                    returnValue = 0;
                    break;

                case DirectoryOperation.FileCount:
                    if (argument2 == string.Empty)
                    {
                        argument2 = "*.*";
                    }
                    returnValue = Directory.GetFiles(argument1, argument2).Length;
                    break;
                }

                OnCommandCompleted(new CommandCompletedEventArgs(DateTime.Now, CommandName, null, null, string.Format("The {0} command has completed.", CommandName), commandParentType));
            }
            catch (Exception ex)
            {
                OnCommandFailed(new CommandFailedEventArgs(DateTime.Now, CommandName, null, null, ex.Message, commandParentType));

                throw;
            }

            return(returnValue);
        }
        /// <summary>
        /// 登陆后命令
        /// </summary>
        /// <param name="cmd"></param>
        static void excutecmd(string cmd)
        {
            string[] cmds = cmd.Split(' ');
            cmd = cmds[0];
            switch (cmd)
            {
            //登出
            case "logout":
                CMD.Login.logout(ref user);
                break;

            //清屏
            case "clr":
                Console.Clear();
                break;

            //取消该用户
            case "cancleuser":
                UserOperation.cancle(user);
                Login.logout(ref user);
                break;

            //更改密码
            case "modifypsw":
                PWDChanger.change(user);
                break;

            //输出当前目录下所有文件及子目录
            case "dir":
                Dir.GetDir(user);
                break;

            //显示当前目录名
            case "cd":
                Console.WriteLine(user.GetSinglePath());
                break;

            //进入下一级目录
            case "cdfore":
                PathChanger.fore(user, cmds[1]);
                break;

            //返回上一级目录
            case "cdback":
                PathChanger.back(user);
                break;

            //返回根目录
            case "cdroot":
                PathChanger.root(user);
                break;

            //新建文件夹
            case "mkdir":
                DirectoryOperation.makedir(user, cmds[1]);
                break;

            //删除目录
            case "my_deletedir":
                DirectoryOperation.deletedir(user, cmds[1]);
                break;

            //新建一个文件
            case "my_create":
                FileOperation.create(user, cmds[1]);
                break;

            //删除一个文件
            case "my_deletefile":
                FileOperation.delete(user, cmds[1]);
                break;

            //输入错误
            default:
                if (cmd.Trim() == "\n")
                {
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("没有这样的命令,请检查");
                }
                break;
            }
        }