public void FilesDataTestAdd()
        {
            FilesData data = new FilesData();

            data.Dir = new DirectoryInfo(@"c:\Users\Adam\source\repos\FileManager\NUnitTestFM\FolderTestowy");
            data.Start();
            FilesData data2 = new FilesData();

            data2.Dir = new DirectoryInfo(@"c:\Users\Adam\source\repos\FileManager\NUnitTestFM\FolderTestowy");
            data2.Start();
            FilesData data3 = data + data2;

            Assert.AreEqual(data.Files + data2.Files, data3.Files);
            Assert.AreEqual(data.AudioFiles + data2.AudioFiles, data3.AudioFiles);
            Assert.AreEqual(data.ImageFiles + data2.ImageFiles, data3.ImageFiles);
            Assert.AreEqual(data.DocumentFiles + data2.DocumentFiles, data3.DocumentFiles);
            Assert.AreEqual(data.ArchFiles + data2.ArchFiles, data3.ArchFiles);
            Assert.AreEqual(data.FilmFiles + data2.FilmFiles, data3.FilmFiles);
            Assert.AreEqual(data.Bytes + data2.Bytes, data3.Bytes);
            Assert.AreEqual(data.AudioBytes + data2.AudioBytes, data3.AudioBytes);
            Assert.AreEqual(data.ImageBytes + data2.ImageBytes, data3.ImageBytes);
            Assert.AreEqual(data.DocumentBytes + data2.DocumentBytes, data3.DocumentBytes);
            Assert.AreEqual(data.ArchBytes + data2.ArchBytes, data3.ArchBytes);
            Assert.AreEqual(data.FilmBytes + data2.FilmBytes, data3.FilmBytes);
        }
Beispiel #2
0
        /// <summary>
        /// finds total number of records of a file type(xml,dll,nf,config)
        /// </summary>
        /// <param name="fileType"></param>
        /// <returns> int count of records</returns>
        public int GetCount(FilesData filesData, string fileType = null)
        {
            int index = 0;

            if (string.IsNullOrEmpty(fileType))
            {
                return(filesData.Count);
            }
            else
            {
                try
                {
                    Parallel.For(0, filesData.Count, x =>
                    {
                        if (filesData[x].FileType == fileType)
                        {
                            Interlocked.Increment(ref index);
                        }
                    });
                }
                catch (AggregateException ae)
                {
                    // Utility.HandleAggregateExceptions(ae);
                }
            }

            return(index);
        }
        public async Task GetAllDataTestAsync()
        {
            FileManager man  = new FileManager();
            FilesData   data = await Task.Run(() => man.GetAllData());

            Console.WriteLine(data.Files);
        }
Beispiel #4
0
        public static IHtmlString GetPreviewColumn(this HtmlHelper helper, FileDataViewModel viewModel)
        {
            var html     = "";
            var outerDiv = new TagBuilder("img");

            if (Constants.imageString.Contains(viewModel.Extension))
            {
                outerDiv.AddCssClass("img-responsive img-gridCss");
                outerDiv.MergeAttribute("src", viewModel.AbsoluteUri);
                outerDiv.MergeAttribute("width", Constants.ImageWidth);
                outerDiv.MergeAttribute("height", Constants.ImageHeight);
            }
            else if (Constants.TextString.Contains(viewModel.Extension))
            {
                outerDiv = new TagBuilder("p");
                outerDiv.AddCssClass("CssFileTableTd");
                var text       = FilesData.GetTextFromUrl(viewModel.AbsoluteUri);
                var textToShow = text.Substring(0, Math.Min(text.Length, 15)) + "...";
                outerDiv.SetInnerText(text);
            }
            else
            {
                outerDiv.SetInnerText("Invalid format to preview");
            }
            html = outerDiv.ToString(TagRenderMode.Normal);
            return(MvcHtmlString.Create(html));
        }
Beispiel #5
0
        public async Task <ActionResult> DownloadFiles(string downloadData, int degreeOfParallelism)
        {
            ResponseMessage response = new ResponseMessage
            {
                Success = true,
                Message = "Download Cancelled!"
            };

            if (!string.IsNullOrEmpty(downloadData))
            {
                var fileData = new DownloadModel
                {
                    DataUrl             = JsonConvert.DeserializeObject <List <DataUrl> >(downloadData),
                    PathToDownload      = FilesData.MapPathFolder(FilesData.DownloadFiles),
                    degreeOfParallelism = degreeOfParallelism,
                };
                FilesData.CreateDirectoryIfNotExists(FilesData.DownloadFiles);
                if (fileData.DataUrl.Any())
                {
                    response = (ResponseMessage)await _fileServices.DownloadFiles(fileData);
                }
            }

            return(Json(new { data = JsonConvertExtensions.GetJsonConvert(response) }, JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
        public void SaveTest()
        {
            FilesData data = new FilesData();

            data.Dir = new DirectoryInfo(@"c:\Users\Adam\source\repos\FileManager\NUnitTestFM\FolderTestowy");
            data.Start();
            DataContext.SaveDataAll(data);
        }
Beispiel #7
0
        private FilesData GetDatas(Element element)
        {
            FilesData filesData = null;

            if (File.Exists(Path.Combine(Application.StartupPath, element.FileName)))
            {
                filesData = new FilesData()
                {
                    DataName = element.BtnName
                };

                using (StreamReader sr = new StreamReader(Path.Combine(Application.StartupPath, element.FileName)))
                {
                    string firstRow = sr.ReadLine();

                    if (!string.IsNullOrEmpty(firstRow))
                    {
                        var datas = firstRow.Split('_');

                        this._lastDrawCurrent = Convert.ToInt32(datas[0].Trim());

                        filesData.LastDrawCurrent = this._lastDrawCurrent;
                    }
                    else
                    {
                        this._lastDrawCurrent = 0;
                    }
                }
            }

            if (!string.IsNullOrEmpty(element.FileAllName) && File.Exists(Path.Combine(Application.StartupPath, element.FileAllName)))
            {
                if (filesData == null)
                {
                    filesData = new FilesData()
                    {
                        DataName = element.BtnName
                    }
                }
                ;

                using (StreamReader sr = new StreamReader(Path.Combine(Application.StartupPath, element.FileAllName)))
                {
                    string firstRow = sr.ReadLine();

                    if (!string.IsNullOrEmpty(firstRow))
                    {
                        var datas = firstRow.Split('_');

                        this._lastDrawAll = Convert.ToInt32(datas[0].Trim());

                        filesData.LastDrawFull = this._lastDrawAll;
                    }
                }
            }

            return(filesData);
        }
        public void FilesDataTest()
        {
            FilesData     data = new FilesData();
            DirectoryInfo dir  = new DirectoryInfo(@"c:\Users\Adam\source\repos\FileManager\NUnitTestFM\FolderTestowy");//C:\Users\Adam\source\repos\FileManager\NUnitTestFM\FolderTestowy\

            Assert.IsTrue(dir.Exists);
            data.Dir = dir;//C:\Users\Adam\source\repos\FileManager\NUnitTestFM\FolderTestowy\
            Assert.IsNotNull(data.Dir);
        }
 public DiseasesViewDetail(Disease disease)
 {
     InitializeComponent();
     this.disease = disease;
     this.BackgroundImageSource = App.bgImage;
     LabelDiseaseName.Text      = disease.Name;
     Title = disease.Name;
     LabelDiseaseDetail.Text = FilesData.ReaderFiletoText(string.Concat("MedicalHerbs.DiseasesFiles.", disease.Name, ".txt"));
     StatusFavorite(disease);
 }
        public void GetFilesDataTest()
        {
            FilesData data = FileManager.GetFilesData(@"c:\Users\Adam\source\repos\FileManager\NUnitTestFM\FolderTestowy");

            Assert.AreEqual(data.Files, 11);
            Assert.AreEqual(data.AudioFiles, 1);
            Assert.AreEqual(data.ImageFiles, 4);
            Assert.AreEqual(data.DocumentFiles, 3);
            Assert.AreEqual(data.ArchFiles, 1);
            Assert.AreEqual(data.FilmFiles, 1);
        }
Beispiel #11
0
        public static void SaveDataAll(FilesData data)
        {
            DataContext db  = new DataContext();
            DataSet     set = new DataSet();

            set.Data = data;
            set.Date = DateTime.Now;
            set.Name = "All";
            db.SavedDataFiles.Add(set);
            db.SaveChanges();
        }
        public async Task FileManagerTestAsync()
        {
            FileManager man = new FileManager();

            man.Path = @"c:\Users\Adam\source\repos\FileManager\NUnitTestFM\FolderTestowy";
            FilesData data = await Task.Run(() => man.GetAllData());

            Assert.AreEqual(18, data.Files);
            Assert.AreEqual(6, data.ImageFiles);
            Assert.AreEqual(2, data.AudioFiles);
            Assert.AreEqual(17633248 * 2, data.ArchBytes);
        }
Beispiel #13
0
        public void FilesDataTestBytes()
        {
            FilesData data = new FilesData();

            data.Dir = new DirectoryInfo(@"c:\Users\Adam\source\repos\FileManager\NUnitTestFM\FolderTestowy");
            data.Start();
            Assert.AreEqual(data.Bytes, 60506485);
            Assert.AreEqual(data.AudioBytes, 6278839);
            Assert.AreEqual(data.ImageBytes, 409175);
            Assert.AreEqual(data.DocumentBytes, 2796882);
            Assert.AreEqual(data.ArchBytes, 17633248);
            Assert.AreEqual(data.FilmBytes, 33386334);
        }
Beispiel #14
0
        public void FilesDataTestFiles()
        {
            FilesData data = new FilesData();

            data.Dir = new DirectoryInfo(@"c:\Users\Adam\source\repos\FileManager\NUnitTestFM\FolderTestowy");
            data.Start();
            Assert.AreEqual(data.Files, 11);
            Assert.AreEqual(data.AudioFiles, 1);
            Assert.AreEqual(data.ImageFiles, 4);
            Assert.AreEqual(data.DocumentFiles, 3);
            Assert.AreEqual(data.ArchFiles, 1);
            Assert.AreEqual(data.FilmFiles, 1);
        }
        public JsonResult Get()
        {
            this.log.Information("Listing files:");
            var files   = new FilesData();
            var dbfiles = from file in this.Db.Files where file.Uploader == User.GetUserName() select file;

            foreach (var file in dbfiles)
            {
                files.files.Add(file.ToSerializeable());
                this.log.Verbose("Found {FileName} {Size}", file.Name, Format.Bytes(file.Size));
            }
            this.log.Information("Found {FileCount} file(s)", files.files.Count);
            return(this.Json(files));
        }
Beispiel #16
0
 private void FillDate(FileInfo file)
 {
     FilesData.Invoke(new Action(() =>
     {
         FilesData.Rows.Add(
             DateTime.Now.ToString("dd.MM.yyyy"),
             " ",
             file.LastWriteTime.ToString("dd.MM.yyyy"),
             " ", " ", " ",
             file.Name,
             file.LastAccessTime.ToString("HH-mm"),
             GetFileSize(file.FullName));
     }));
 }
Beispiel #17
0
 private bool RefreshLastActivityList(List <Uri> urls)
 {
     try
     {
         FilesData.CreateDirectoryIfNotExists(FilesData.LastFilesUrls);
         var path = FilesData.GetDirectoryPath(FilesData.LastFilesUrls, FilesData.TextFile);
         FilesData.SetFileTextWithData(path, urls);
         return(true);
     }
     catch (Exception ex)  {
         //Log Exception
         return(false);
     }
 }
Beispiel #18
0
        static bool CheckInstalled(FilesData fd)
        {
            var file = BuildPath(fd);

            if (File.Exists(file))
            {
                if (MD5.Match(file, fd.fHash))
                {
                    return(true);
                }
                File.Delete(file);
            }
            return(false);
        }
Beispiel #19
0
        private FileViewModel GetFileViewModel(bool isRefresh)
        {
            var model     = new FileViewModel();
            var dataFiles = _fileServices.GetListOfFiles().ToList();

            if (!isRefresh)
            {
                var path         = FilesData.MapPathFolder(FilesData.LastFiles);
                var lastActivity = _memoryCache.Get(string.Format(Constants.GetLastActivityListOfFilesCacheKey), () => _fileServices.GetLastActivityListOfFiles(path).ToList());
                _fileModelFactory.PrepareLastFileViewModel(lastActivity, model);
            }
            _fileModelFactory.PrepareFileViewModel(dataFiles, model);
            RefreshLastActivityList(dataFiles);
            return(model);
        }
Beispiel #20
0
        public void SaveTest2()
        {
            FilesData data = new FilesData();

            data.Dir = new DirectoryInfo(@"c:\Users\Adam\source\repos\FileManager\NUnitTestFM\FolderTestowy");
            data.Start();
            var            db     = new SaveData.DataContext();
            List <DataSet> drives = new List <DataSet>();
            DataSet        set1   = new DataSet();

            set1.Data = data;
            set1.Name = @"C:\";
            set1.Date = DateTime.Now;
            drives.Add(set1);
            DataContext.SaveDataDrives(drives);
        }
Beispiel #21
0
        /// <inheritdoc />
        public IResponseMessage CleanCurrentDirecoryData()
        {
            ResponseMessage response = new ResponseMessage {
                Success = true,
                Message = "Direcory deleted sucessfully"
            };

            try    {
                FilesData.DeleteDirectoryOrContent(FilesData.MapPathFolder(FilesData.DownloadFiles), true);
                FilesData.DeleteDirectoryOrContent(FilesData.MapPathFolder(FilesData.LastFiles), true);
                return(response);
            }catch (Exception ex) {
                response.Success = false;
                response.Message = ex.GetFullMessage();
                return(response);
            }
        }
Beispiel #22
0
        /// <summary>
        /// Register Configuration for AutoMapper and mapping properties
        /// </summary>
        public static void RegisterConfiguration()
        {
            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Uri, FileDataViewModel>()
                .ForMember(m => m.FileName, d => d.MapFrom(src => FilesData.GetFileName(src.LocalPath)))
                .ForMember(m => m.Extension, d => d.MapFrom(src => FilesData.GetFileExtension(src.LocalPath)));


                cfg.CreateMap <FilesModel, FileDataViewModel>()
                .ForMember(m => m.AbsoluteUri, d => d.Ignore())
                .ForMember(m => m.Authority, d => d.Ignore())
                .ForMember(m => m.LocalPath, d => d.Ignore());
            });

            Mapper.Configuration.AssertConfigurationIsValid();
        }
Beispiel #23
0
    //------------------------------

    public static void Decode(FilesData config)
    {
        //-y -i video.mp4 -r 30 .../image%1d.jpg .../track.mp3
        string[] command =
        {
            REWRITE_INSTRUCTION,
            INPUT_INSTRUCTION,
            config.inputPath,
            RESIZE_INSTRUCTION,
            config.fps.ToString(),
            config.outputPath,
            config.soundPath
        };

        DebugCommand(command);

        Wrapper.Execute(command);
    }
Beispiel #24
0
        public void UpdateDatas(FilesData filesData)
        {
            this.InvoceAction(() =>
            {
                if (filesData != null)
                {
                    if (filesData.LastDrawCurrent != 0)
                    {
                        this.fileDataCurrrent.Text = Convert.ToString(filesData.LastDrawCurrent);
                    }

                    if (filesData.LastDrawFull != 0)
                    {
                        this.fileDataAll.Text = Convert.ToString(filesData.LastDrawFull);
                    }
                }
            });
        }
Beispiel #25
0
        /// <summary>
        /// This method finds average of size number of records of a file type(xml,dll,nf,config)
        /// </summary>
        /// <param name="fileType"></param>
        /// <returns>double average of record's size property</returns>
        public double GetAverageSize(FilesData filesData, string fileType)
        {
            double average = 0;

            try
            {
                int totalSize  = GetSize(fileType);
                int totalFiles = GetCount(fileType);
                if (totalFiles != 0)
                {
                    average = (double)totalSize / totalFiles;
                }

                return(Math.Floor(average * 100) / 100);
            }
            catch (AggregateException ae)
            {
                //Utility.HandleAggregateExceptions(ae);
            }
            return(Math.Floor(average * 100) / 100);
        }
Beispiel #26
0
        protected async System.Threading.Tasks.Task CreateDataAsync()
        {
            FileManager.FileManager manager = new FileManager.FileManager();
            manager.GetDiskData();
            DriveInfo[]      drives       = manager.Drives;
            List <FilesData> listFileData = new List <FilesData>(drives.Length);

            for (int i = 0; i < drives.Length; i++)
            {
                listFileData[i] = await manager.GetAllData(drives[i].Name);
            }
            Serialize(listFileData);
            FilesData Alldata = new FilesData();

            Alldata.Zero();
            foreach (FilesData data in listFileData)
            {
                Alldata += data;
            }
            Serialize(Alldata);
        }
Beispiel #27
0
        void Serialize(FilesData data)
        {
            FileStream      fs        = new FileStream(@"Solution Item/AllDataFile.dat", FileMode.Create);
            BinaryFormatter formatter = new BinaryFormatter();

            try
            {
                formatter.Serialize(fs, data);
            }
            catch (SerializationException e)
            {
                Console.WriteLine("Failed to serialize. Reason: " + e.Message);
                throw;
            }
            finally
            {
                Console.WriteLine("check ");

                fs.Close();
            }
        }
Beispiel #28
0
        static void Main(string[] args)
        {
            string inputFilePath = FilePath();

            try
            {
                FileInfo inputFileInfo = new FileInfo(inputFilePath);
                if (inputFileInfo.Exists)
                {
                    FilesData filesData = new FilesData(FilePath());
                }
                else
                {
                    Console.WriteLine("File does not exist.");
                    Console.ReadLine();
                    return;
                }
            }

            catch (FileNotFoundException fe)
            {
                Logger.Logger.LogError("File not found exception: ", fe);
                Console.WriteLine($"Cannot file find at given file filePath:" + inputFilePath);
                Debug.WriteLine(fe.FileName + " " + fe.InnerException);
                Console.ReadLine();
            }
            catch (PathTooLongException pe)
            {
                Logger.Logger.LogError("Path is too long. ", pe);
                Console.WriteLine("Path is too long.");
                Debug.WriteLine(pe.Message);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Logger.Logger.LogError("File not found exception: ", ex);
                Console.WriteLine("An exception occured while reading file. ");
                Console.ReadLine();
            }
        }
Beispiel #29
0
        /// <summary>
        /// This method finds total sum of size for records of a passed file type(xml,dll,nf,config)
        /// </summary>
        /// <param name="fileType"></param>
        /// <returns>int sum of all record's size property</returns>
        public int GetSize(FilesData filesData, string fileType)
        {
            int    totalSize = 0;
            object locker    = new object();

            try
            {
                Parallel.For(0, filesData.Count, x =>
                {
                    if (filesData[x].FileType == fileType)
                    {
                        Interlocked.Add(ref totalSize, filesData[x].Size);
                    }
                });
            }
            catch (AggregateException ae)
            {
                // Utility.HandleAggregateExceptions(ae);
            }

            return(totalSize);
        }
        /// <summary>
        /// Load Last Activity
        /// </summary>
        public async Task GetLatesActivity()
        {
            try
            {
                var fileServices = DependencyResolver.Current.GetService <IFileServices>();
                var memoryCache  = DependencyResolver.Current.GetService <IMemoryCache>();
                var textFilePath = FilesData.MapPathFolder(FilesData.LastFilesUrls) + FilesData.TextFile;
                FilesData.CreateDirectoryIfNotExists(FilesData.LastFiles);
                var pathLastFiles = FilesData.MapPathFolder(FilesData.LastFiles);
                var downloadModel = new DownloadModel {
                    PathToDownload = pathLastFiles,
                };
                FilesData.GetFileTextWithData(textFilePath).ForEach(x => downloadModel.DataUrl.Add(new DataUrl {
                    AbsoluteUri = x
                }));
                await fileServices.DownloadFiles(downloadModel);

                memoryCache.Set(string.Format(Constants.GetLastActivityListOfFilesCacheKey), fileServices.GetLastActivityListOfFiles(pathLastFiles));
            }
            catch (Exception ex)  {
                //Log Exception
            }
        }