Esempio n. 1
0
        public async Task <string> DownloadFileAsync(GridFSFileInfo file)
        {
            var    gridFsBucket = new GridFSBucket(GetDatabase());
            string filename     = file.Metadata["fileName"].AsString;
            string targetDir    = Path.Combine(ProgramUI.GetWorkspaceDirectory(), MongoConfig.MongoConfigName);

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

            string extension = ".bin";

            if (file.ContentType.Equals("plain/text", StringComparison.CurrentCultureIgnoreCase))
            {
                extension = ".txt";
            }
            string targetFilename = Path.Combine(targetDir, filename + "_" + file.Id.ToString() + extension);

            Logger.Log($"Saving file to {targetFilename}");
            // using (GridFSDownloadStream<ObjectId> sourceStream = await gridFsBucket.OpenDownloadStreamByNameAsync(filename))
            using (GridFSDownloadStream sourceStream = await gridFsBucket.OpenDownloadStreamAsync(file.Id))
            {
                using (FileStream destinationStream = File.Open(targetFilename, FileMode.Create))
                {
                    await sourceStream.CopyToAsync(destinationStream);
                }
            }
            return(targetFilename);
        }
Esempio n. 2
0
        public override void SaveWorkspace()
        {
            var    config      = GetConfigFromUI();
            string wsDirectory = ProgramUI.GetWorkspaceDirectory();

            if (!Directory.Exists(wsDirectory))
            {
                Directory.CreateDirectory(wsDirectory);
            }
            if (string.IsNullOrEmpty(this.filename))
            {
                this.filename = RESTConfig.GetWorkspaceFilename();
            }
            string json = JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings
            {
                Converters = new List <JsonConverter> {
                    new StringEnumConverter()
                },
                NullValueHandling          = NullValueHandling.Ignore,
                Formatting                 = Formatting.Indented,
                DefaultValueHandling       = DefaultValueHandling.Ignore,
                ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
                PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                ContractResolver           = new CamelCasePropertyNamesContractResolver()
            });

            File.WriteAllText(this.filename, json, Encoding.UTF8);
        }
Esempio n. 3
0
        internal void SaveResults(Rules rules, FileInfo file)
        {
            string wsDirectory = ProgramUI.GetWorkspaceDirectory();

            if (!Directory.Exists(wsDirectory))
            {
                Directory.CreateDirectory(wsDirectory);
            }
            string filename = GetResultRulesFilename(file);

            rules.File = file.FullName;

            string json = JsonConvert.SerializeObject(rules, Formatting.Indented, this.JsonSerializerSettings);

            int    nbResults    = 0;
            string resultsTitle = "";

            foreach (var rule in rules?.RulesList)
            {
                if (rule.Results?.Count > 0)
                {
                    resultsTitle += $"{rule.GetName()}: {rule.Results?.Count} results  ";
                    nbResults    += rule.Results == null ? 0 : rule.Results.Count;
                }
            }
            this.logger.Log($"Save result in {filename}. {resultsTitle} Total results: {nbResults}", nbResults > 0);
            File.WriteAllText(filename, json, Encoding.UTF8);
        }
Esempio n. 4
0
 internal static string GetResultDirTarget()
 {
     if (string.IsNullOrEmpty(resultDirectoryTarget))
     {
         resultDirectoryTarget = Path.Combine(ProgramUI.GetWorkspaceDirectory(), DateTime.Now.ToString("yyyyMMddHHmm"));
     }
     return(resultDirectoryTarget);
 }
Esempio n. 5
0
        private static FileInfo[] ConfigurationFileList()
        {
            FileInfo[] files = new FileInfo[0];
            var        dir   = new DirectoryInfo(ProgramUI.GetWorkspaceDirectory());

            if (dir.Exists)
            {
                files = dir.GetFiles();
                foreach (var item in files)
                {
                    PromptHelper.ShowPromptInfo($"{item.Name}");
                }
                PromptHelper.ShowPromptInfo($" ");
            }
            return(files);
        }
Esempio n. 6
0
        private void CreateDefaultConfigFile()
        {
            string fileName = GetConfigFilename();

            this.logger.Log($"Create ConfigFile: {fileName}");
            this.rules = CreateDefaultConfig();

            string wsDirectory = ProgramUI.GetWorkspaceDirectory();

            if (!Directory.Exists(wsDirectory))
            {
                Directory.CreateDirectory(wsDirectory);
            }
            string json = JsonConvert.SerializeObject(rules, Formatting.Indented, this.JsonSerializerSettings);

            File.WriteAllText(fileName, json, Encoding.UTF8);
        }
Esempio n. 7
0
        public void BuildTreeView()
        {
            tvFileSystem.TopNode.Nodes.Clear();

            var dir = new DirectoryInfo(ProgramUI.GetWorkspaceDirectory());

            if (!dir.Exists)
            {
                return;
            }
            var files = dir.GetFiles();

            foreach (var item in files)
            {
                AddNode(item);
            }

            tvFileSystem.TopNode.Expand();
        }
Esempio n. 8
0
        public static void SaveWorkspace(string filename, IConfigService data)
        {
            string wsDirectory = ProgramUI.GetWorkspaceDirectory();

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

            string json = JsonConvert.SerializeObject(data, Formatting.Indented, new JsonSerializerSettings
            {
                Converters = new List <JsonConverter> {
                    new StringEnumConverter()
                },
                NullValueHandling          = NullValueHandling.Ignore,
                Formatting                 = Formatting.Indented,
                DefaultValueHandling       = DefaultValueHandling.Ignore,
                ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
                PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                ContractResolver           = new CamelCasePropertyNamesContractResolver()
            });

            if (File.Exists(filename))
            {
                string oldJson = File.ReadAllText(filename);
                if (!oldJson.Equals(json))
                {
                    DialogResult r = MessageBox.Show($"Data have changed. Do you want to save it to {Path.GetFileName(filename)} ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
                    if (r == DialogResult.Yes)
                    {
                        File.WriteAllText(filename, json, Encoding.UTF8);
                    }
                }
            }
            else
            {
                File.WriteAllText(filename, json, Encoding.UTF8);
            }
        }
Esempio n. 9
0
 internal static string GetWorkspaceFilename()
 {
     return(System.IO.Path.Combine(ProgramUI.GetWorkspaceDirectory(), GetWorkspaceShortFilename()));
 }
Esempio n. 10
0
 internal static string GetConfigFilename()
 {
     return(Path.Combine(ProgramUI.GetWorkspaceDirectory(), GetConfigShortFilename()));
 }
Esempio n. 11
0
 private void llOpenFolder_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     Process.Start("explorer.exe", ProgramUI.GetWorkspaceDirectory());
 }
Esempio n. 12
0
        private void btBrowseFile_Click(object sender, EventArgs e)
        {
            var folderDialog = new FolderBrowserDialog();

            folderDialog.ShowNewFolderButton = true;
            folderDialog.RootFolder          = Environment.SpecialFolder.UserProfile;
            folderDialog.SelectedPath        = !string.IsNullOrEmpty(tbFolder.Text) ? tbFolder.Text : ProgramUI.GetWorkspaceDirectory();
            var result = folderDialog.ShowDialog();

            if (result == DialogResult.OK || result == DialogResult.Yes)
            {
                tbFolder.Text = folderDialog.SelectedPath;
            }
        }