コード例 #1
0
ファイル: SearchFile.cs プロジェクト: VBarbarych/csharp-tasks
        public List <FileInfo> GetFilesFromDirectory(DirectoryInfo root)
        {
            FileInfo[]      files   = null;
            DirectoryInfo[] subDirs = null;

            try
            {
                files = root.GetFiles("*.*");
                allFilesinDirectories.AddRange(files);
            }
            catch (UnauthorizedAccessException e)
            {
                logger.Log(LogLevel.Error, e.Message);
            }
            catch (DirectoryNotFoundException e)
            {
                logger.Log(LogLevel.Error, e.Message);
            }

            if (allFilesinDirectories != null)
            {
                subDirs = root.GetDirectories();

                foreach (DirectoryInfo dirInfo in subDirs)
                {
                    GetFilesFromDirectory(dirInfo);
                }
            }
            else
            {
                writeReadOfData.Write("Directory is empty");
            }

            return(allFilesinDirectories);
        }
コード例 #2
0
        public void Run()
        {
            writeReadOfData.Write("========Serialization=======\n");
            writeReadOfData.Write("Serialized and Deserialized. Check related files");

            ImplementBinarySerialization();
            ImplementXMLSerialization();
            ImplementJSONSerialization();
        }
コード例 #3
0
        private void ImplementOfTask1()
        {
            writeReadOfData.Write("\n\n==========Struct==========\n");
            writeReadOfData.Write("=====Implement Task1======\n");

            Person person = new Person("Tom", "Carry", 34);

            writeReadOfData.Write(person.PrintString(33));
        }
コード例 #4
0
        private void ImplementOfTask1()
        {
            writeReadOfData.Write("\n==========Enum==========\n");
            writeReadOfData.Write("====Implement Task1=====\n");

            Month month = new Month(writeReadOfData, logger);

            month.InputMonth();
            month.OutputMonth();
        }
コード例 #5
0
        private void ImplementOfTask1()
        {
            writeReadOfData.Write("\n========IO Stream=======\n");
            writeReadOfData.Write("=====Implement Task1====\n");
            writeReadOfData.Write("Show all file from directory: ");

            FileFromDirectories fileFromDirectories = new FileFromDirectories(writeReadOfData, logger);

            fileFromDirectories.OutputFilesFromDirectory();
        }
コード例 #6
0
ファイル: ExcelData.cs プロジェクト: VBarbarych/csharp-tasks
        public void Output(IWriteReadable writeReadOfData, HashSet <string> uniqueElementsSecondFirstColumn, HashSet <string> uniqueElementsFromSecondColumn)
        {
            writeReadOfData.Write($"Unique elements from first column: ");
            foreach (string element in uniqueElementsSecondFirstColumn)
            {
                writeReadOfData.Write(element);
            }

            writeReadOfData.Write($"\nUnique elements from second column: ");
            foreach (string element in uniqueElementsFromSecondColumn)
            {
                writeReadOfData.Write(element);
            }
        }
コード例 #7
0
        public void AsyncSumOfMatrix()
        {
            const int countOfThreads     = 4;
            int       colThread          = col / countOfThreads;
            int       sumElementOfMatrix = 0;
            var       partialSums        = new int[countOfThreads];


            Parallel.For(0, 4, (counter) =>
            {
                int sum = 0;

                for (int i = 0; i < row; i++)
                {
                    for (int j = counter * colThread; j < colThread * (counter + 1); j++)
                    {
                        sum += matrix[i, j];
                    }
                }

                partialSums[counter] = sum;
            });

            foreach (var sum in partialSums)
            {
                sumElementOfMatrix += sum;
            }

            writeReadOfData.Write($"Sum element of Matrix {sumElementOfMatrix}");
        }
コード例 #8
0
 public void OutputColors()
 {
     foreach (int i in colors)
     {
         writeReadOfData.Write($"{Enum.GetName(typeof(Color), i)} = {i}");
     }
 }
コード例 #9
0
        public void Run()
        {
            writeReadOfData.Write("\n=========================================")
            writeReadOfData.Write("\nCreate own Ioc Container\n");

            var services = new IoCServiceCollection();

            services.RegisterSingleton <ICar, BMW>();
            //services.RegisterTransient<ICar, BMW>();
            //services.RegisterSingleton<ICar, Audi>();

            var container = services.GenerateContainer();

            var serviceFirst  = container.GetService <ICar>();
            var serviceSecond = container.GetService <ICar>();

            serviceFirst.Move();
            serviceSecond.Move();
        }
コード例 #10
0
        public void ImplementTaskWithDirectories()
        {
            writeReadOfData.Write("\n\n=============Additional Task with Directories and file==============");

            SearchFile      fileFromDirectories     = new SearchFile(writeReadOfData, logger);
            List <FileInfo> allFiles                = new List <FileInfo>();
            List <string>   allFilesFromDirectories = new List <string>();
            List <string>   identicalFiles          = new List <string>();
            List <string>   distinctFiles           = new List <string>();

            string path;

            DirectoryInfo dirInfo;

            try
            {
                path    = ConfigurationManager.AppSettings.Get("TaskWithDirectories"); // path from App.config
                dirInfo = new DirectoryInfo(path);

                writeReadOfData.Write("All file in your directory and subdirectories: \n");
                allFiles = fileFromDirectories.GetFilesFromDirectory(dirInfo);

                foreach (FileInfo fi in allFiles)
                {
                    allFilesFromDirectories.Add(Path.GetFileName(fi.ToString()));
                }

                fileFromDirectories.OutputFile(allFilesFromDirectories);

                identicalFiles = fileFromDirectories.GetIdenticalFiles(allFilesFromDirectories);
                writeReadOfData.Write("\nIdentical files: ");
                fileFromDirectories.OutputFile(identicalFiles);
                writeReadOfData.Write($"\nCount of Identical files: {identicalFiles.Count}");

                writeReadOfData.Write("\nDistinct files: \n");
                distinctFiles = fileFromDirectories.GetDistinctFiles(allFilesFromDirectories);
                fileFromDirectories.OutputFile(distinctFiles);
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, ex.Message);
            }
        }
コード例 #11
0
        public void GetFilesFromDirectory(DirectoryInfo root)
        {
            FileInfo[]      files   = null;
            DirectoryInfo[] subDirs = null;

            try
            {
                files = root.GetFiles("*.*");
            }
            catch (UnauthorizedAccessException e)
            {
                logger.Log(LogLevel.Error, e.Message);
            }
            catch (DirectoryNotFoundException e)
            {
                logger.Log(LogLevel.Error, e.Message);
            }

            if (files != null)
            {
                foreach (FileInfo fi in files)
                {
                    writeReadOfData.Write(fi.FullName);
                    writeReadOfData.Write(" ");
                }

                subDirs = root.GetDirectories();
                foreach (DirectoryInfo dirInfo in subDirs)
                {
                    GetFilesFromDirectory(dirInfo);
                }
            }
            else
            {
                writeReadOfData.Write("Directory is empty");
            }
        }
コード例 #12
0
        public void ImplementTask1()
        {
            writeReadOfData.Write("\n====TaskOfReflection=====\n");
            Type type = Type.GetType("TaskOfReflection.Car");

            foreach (MemberInfo mi in type.GetMembers())
            {
                writeReadOfData.Write($"{mi.DeclaringType} {mi.MemberType} {mi.Name}");
            }

            Type type1 = Type.GetType("TaskOfReflection.MainClassOfReflection");

            writeReadOfData.Write("===============");
            foreach (MemberInfo mi in type1.GetMembers())
            {
                writeReadOfData.Write($"{mi.DeclaringType} {mi.MemberType} {mi.Name}");
            }
        }
コード例 #13
0
        public void ImplementTaskWithExcel()
        {
            writeReadOfData.Write("\n\n=============Additional Task with Excel File==============");
            try
            {
                ExcelData excelData = new ExcelData();

                string firstColumn  = ConfigurationManager.AppSettings.Get("FirstColumn");
                string secondColumn = ConfigurationManager.AppSettings.Get("SecondColumn");
                path = ConfigurationManager.AppSettings.Get("ExcelFilePath"); // path from App.config

                HashSet <string> uniqueElementsFromFirstColumn  = new HashSet <string>();
                HashSet <string> uniqueElementsFromSecondColumn = new HashSet <string>();

                uniqueElementsFromFirstColumn  = excelData.Read(path, firstColumn);
                uniqueElementsFromSecondColumn = excelData.Read(path, secondColumn);
                excelData.Output(writeReadOfData, uniqueElementsFromFirstColumn, uniqueElementsFromSecondColumn);
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, ex.Message);
            }
        }
コード例 #14
0
ファイル: Circle.cs プロジェクト: VBarbarych/csharp-tasks
 public void OutputCircle(IWriteReadable writeReadOfData)
 {
     writeReadOfData.Write($"Center of the circle ({Center.X}, {Center.Y}), Radius: {Radius}");
 }
コード例 #15
0
 public void OutputMonth()
 {
     writeReadOfData.Write(Enum.GetName(typeof(MonthOfYear), 3));
 }
コード例 #16
0
        public void ImplementTask1()
        {
            Rectangle firstRectangle  = new Rectangle(new Point(1, 6), new Point(4, 2));
            Rectangle secondRectangle = new Rectangle(new Point(3, 5), new Point(7, 1));

            CoordinatePlaneRectangle CPRectangle = new CoordinatePlaneRectangle(firstRectangle, secondRectangle);

            Rectangle constructionRectangleContainingTwoGiven;
            Rectangle constructionRectangleUnionTwoGiven;

            writeReadOfData.Write("\n\n=========Task of StyleCop=======\n");
            writeReadOfData.Write("The starting points of the rectangle: ");
            firstRectangle.OutputPoints(writeReadOfData);
            secondRectangle.OutputPoints(writeReadOfData);

            writeReadOfData.Write("\nRectangle that contain two another rectangles: ");
            constructionRectangleContainingTwoGiven = CPRectangle.ConstructionRectangleContainingTwoGiven();
            constructionRectangleContainingTwoGiven.OutputPoints(writeReadOfData);

            writeReadOfData.Write("\nRectangle that is union of two another rectangles: ");
            constructionRectangleUnionTwoGiven = CPRectangle.ConstructionRectangleUnionTwoGiven();
            constructionRectangleUnionTwoGiven.OutputPoints(writeReadOfData);

            CPRectangle.MoveSelectedFigure(firstRectangle, Direction.Left, 1);
            CPRectangle.MoveSelectedFigure(secondRectangle, Direction.Right, 2);
            writeReadOfData.Write("\nFirst rectangle after move on the left on 1: ");
            firstRectangle.OutputPoints(writeReadOfData);
            writeReadOfData.Write("\nSecond rectangle after move on the right on 2: ");
            secondRectangle.OutputPoints(writeReadOfData);

            writeReadOfData.Write("\nChange size of rectangle: ");
            CPRectangle.ChangeFigureSize(firstRectangle, Size.Enlarge, 2);
            firstRectangle.OutputPoints(writeReadOfData);
        }
コード例 #17
0
 public void Run()
 {
     writeReadOfData.Write("/n =============TaskOfThreading==============/n");
     ImplementTask();
 }