public void JsonFileValidator_Validate_returns_Invalid() { var jfv = new JsonFileHandler(); var bytes = Encoding.UTF8.GetBytes("bad json"); jfv.Validate(bytes, "json", null).ShouldBe(FileStatusCode.Invalid); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (this.DesignMode) return; this.listView1.SelectedIndexChanged += new EventHandler(listView1_SelectedIndexChanged); this.listView1.ItemChecked += new ItemCheckedEventHandler(listView1_ItemChecked); JsonFileHandler<ScriptRepository> h = new JsonFileHandler<ScriptRepository>(); this.installedScripts = h.Read(installedScriptsFile); if (installedScripts == null) { MessageBox.Show("Error loading installed scripts xml:\n" + installedScriptsFile, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } /* foreach (ScriptManifestReference r in this.installedScripts.Scripts) { this.LoadManifest(r.URI); } */ }
public PlayBotSettingsManager(MainWindow main) { this.main = main; this.jsonFileHandler = new JsonFileHandler(); this.playBotActions = jsonFileHandler.loadPlayBotActions(); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (this.DesignMode) return; this.repositoryTree.BeginUpdate(); listView1.SelectedIndexChanged += new EventHandler(listView1_SelectedIndexChanged); listView1.ItemChecked += new ItemCheckedEventHandler(listView1_ItemChecked); this.repositories = new List<ScriptRepository>(); JsonFileHandler<ScriptRepositoryList> h = new JsonFileHandler<ScriptRepositoryList>(); this.repositoryList = h.Read(repositoryListFile); if (this.repositoryList != null) { foreach (ScriptRepositoryReference r in this.repositoryList.Repositories) { this.repositoryTree.Nodes.Add(String.Format("{0} - {1}", r.Name, r.URI)); } } this.repositoryTree.EndUpdate(); }
public void JsonFileValidator_ReturnExtensions() { var jfv = new JsonFileHandler(); jfv.SupportedExtensions.Count().ShouldBe(1); jfv.SupportedExtensions.ShouldContain("json"); }
public void WhenTheTechnicalOfficerImportsAListOfPersons() { _scenarioContext.Set(_dataService.GetAllPersons().Count(), "initialPersonsCount"); _personManager.Import(FILE_TO_IMPORT); var personsToImport = JsonFileHandler.ReadPersons(FILE_TO_IMPORT); Assert.IsTrue(personsToImport.Count() > 0); }
public BotChatActivitySettingsManager(MainWindow main) { this.main = main; this.jsonFileHandler = new JsonFileHandler(); this.bot = main.bot; this.moderators = jsonFileHandler.loadModerators(); this.commands = jsonFileHandler.loadCommands(); }
/// <summary> /// Adds the InstallerConfiguration to the zip package. /// </summary> /// <param name="config">The InstallerConfiguration instance to add.</param> public virtual void AddInstallerConfiguration(InstallerConfiguration config) { using (StringWriter stringWriter = new StringWriter()) { JsonFileHandler<InstallerConfiguration> handler = new JsonFileHandler<InstallerConfiguration>(); handler.Write(stringWriter, config); _currentZipFile.AddEntry(PackageBuilder.InstallerArchivePath + "script" + InstallerConfiguration.DefaultExtension, stringWriter.ToString()); } }
public Installer(IPath installerDirectory, IPath manifestFile, IPath configFile) { this.InstallerDirectory = installerDirectory.AbsolutePath; this.ResourcesDirectory = this.InstallerDirectory + "\\" + PackageBuilder.ResourcesArchivePath; JsonFileHandler<ScriptManifest> manifestHandler = new JsonFileHandler<ScriptManifest>(); this.Manifest = manifestHandler.Read(manifestFile); JsonFileHandler<InstallerConfiguration> configHandler = new JsonFileHandler<InstallerConfiguration>(); this.Configuration = configHandler.Read(configFile); }
public CatalogAdaptor(string path) : base() { BaseConstants.SetExportPath(path); FilmFileHandler = new JsonListFileHandler <Film>(BaseConstants.FilmPath); DistributorCatFileHandler = new JsonListFileHandler <DistributorCat>(BaseConstants.DistributorCatPath); EmptyDirFileHandler = new JsonListFileHandler <string>(BaseConstants.EmptyDirPath); ExtensionFileHandler = new JsonFileHandler <Extension>(BaseConstants.ExtensionPath); ClassificationDefineFileHandler = new JsonFileHandler <ClassificationDefine>(BaseConstants.ClassificationDefinePath); }
public void JsonFileValidator_Validate_returns_Valid(int i) { var arrayJson = "[{\"key1\":\"value1\"},{\"key2\":\"value2\"},{\"key3\":\"value3\"},{\"key4\":\"value4\"}]"; var simpleJson = "{\"data\":{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\"}}"; var jsonArr = new[] { arrayJson, simpleJson }; var bytes = Encoding.UTF8.GetBytes(jsonArr[i]); var jfv = new JsonFileHandler(); jfv.Validate(bytes, "json", null).ShouldBe(FileStatusCode.Valid); }
public void WriteRepositoryListTest() { JsonFileHandler<ScriptRepositoryList> handler = new JsonFileHandler<ScriptRepositoryList>(); IPath path = new BasePath(this.getOutputDirectory() + "repositoryList.json"); try { handler.Write(path, this.repoList); } catch (Exception e) { Assert.Fail(e.Message); } }
public void ReadRepositoryListTest() { this.WriteRepositoryListTest(); JsonFileHandler<ScriptRepositoryList> handler = new JsonFileHandler<ScriptRepositoryList>(); IPath path = new BasePath(TestHelperMethods.GetOutputDirectory() + "repositoryList.json"); ScriptRepositoryList readList = handler.Read(path); Assert.IsNotNull(readList); Assert.IsNotNull(readList.Repositories); Assert.AreEqual(this.repoList.Repositories.Count, readList.Repositories.Count); Assert.AreEqual(this.repoList.Repositories[0].Name, readList.Repositories[0].Name); Assert.AreEqual(this.repoList.Repositories[0].URI, readList.Repositories[0].URI); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // read credentials var jsonFileHandler = new JsonFileHandler(); Globals.Credentials = jsonFileHandler.ReadJson <Credentials>(_credentialFile); }
private void button1_Click(object sender, EventArgs e) { JsonFileHandler<ScriptManifest> handler = new JsonFileHandler<ScriptManifest>(); ScriptManifest manifest = handler.Read(new BasePath("C:/temp/scriptcenter/unpacked_installer/outliner.manifest.xml")); JsonFileHandler<InstallerConfiguration> configHandler = new JsonFileHandler<InstallerConfiguration>(); InstallerConfiguration config = configHandler.Read(new BasePath("C:/temp/scriptcenter/unpacked_installer/config.installer.xml")); Package.Installer installer = new Package.Installer("C:/temp/scriptcenter/unpacked_installer", manifest, config); InstallerUIConfiguration uiConfig = new InstallerUIConfiguration(); ScriptCenter.Package.InstallerUI.InstallerDialog d = new ScriptCenter.Package.InstallerUI.InstallerDialog(installer, uiConfig); d.Show(); }
static void Main(string[] args) { JsonFileHandler jsonFileHandler = new JsonFileHandler(); BookRepository bookRepository = new BookRepository(jsonFileHandler); //bookRepository.Add(new Book { Id = 4, Title = "New book" }); bookRepository.SaveChanges(); WriteBook(bookRepository.Get(1)); WriteBook(bookRepository.Get(3)); WriteBook(bookRepository.Get(2)); WriteBook(bookRepository.Get(4)); }
private void LoadManifest(IPath path) { JsonFileHandler<ScriptManifest> h = new JsonFileHandler<ScriptManifest>(); ScriptManifest m = h.Read(path); ListViewItem i = new ListViewItem(); if (m == null) i.Text = "Error loading manifest " + path.AbsolutePath; else { i.Text = m.Name; //i.SubItems.Add(m.Version.ToString()); } this.listView1.Items.Add(i); }
public IFileHandler CreateFileHandler(FileTypeEnum fileType) { IFileHandler fileHandler = null; if (fileType == FileTypeEnum.JSON) { fileHandler = new JsonFileHandler(); } if (fileType == FileTypeEnum.CSV || fileType == FileTypeEnum.TXT) { fileHandler = new CsvFileHandler(); } return(fileHandler); }
public void ReadTest() { IPath inputFile = new BasePath(TestHelperMethods.GetOutputDirectory() + "repo" + ScriptRepository.DefaultExtension); if (!File.Exists(inputFile.AbsolutePath)) this.WriteTest(); Assert.IsTrue(File.Exists(inputFile.AbsolutePath), "File to read does not exist"); JsonFileHandler<ScriptRepository> handler = new JsonFileHandler<ScriptRepository>(); ScriptRepository readRepo = handler.Read(inputFile); Assert.IsNotNull(readRepo, "Repository should not be null"); Assert.AreEqual(repo.Scripts.Count, readRepo.Scripts.Count, "Number of scripts in default category incorrect"); Assert.AreEqual(repo.Name, readRepo.Name, "Repository name incorrect"); Assert.AreEqual(repo.Categories.Count, readRepo.Categories.Count, "Category count incorrect"); Assert.AreEqual(repo.Categories[0].Scripts.Count, readRepo.Categories[0].Scripts.Count, "Category.Scripts count incorrect"); }
public PlaceAutocompleteSearchProcessTest(ITestOutputHelper output) { _output = output; _logger = new NullLogger(); _testOutputClass = new OutputClass { Message = new List <string> { "test output" } }; var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(_testOutputClass)) }; var httpMessageHanderStub = new HttpMessageHandlerStub((request, cancellationToken) => Task.FromResult(httpResponseMessage)); _httpClient = new HttpClient(httpMessageHanderStub); _restService = new RESTRequest <PlacesResponse, Dictionary <string, string> >(_httpClient); var jsonFileHandler = new JsonFileHandler(); Globals.Credentials = jsonFileHandler.ReadJson <Credentials>(_credentialFile); }
private void readPackage(String file) { JsonFileHandler<ScriptPackage> handler = new JsonFileHandler<ScriptPackage>(); try { ScriptPackage pack = handler.Read(new BasePath(file)); TreeNode tn = this.addPackageToTree(pack, file); filesTree.SelectedNode = tn; } catch (Exception exc) { MessageBox.Show(exc.Message); } }
private void LoadRepository(IPath address) { if (address.AbsolutePath.EndsWith(".manifest")) { LoadManifest(address); return; } if (!address.AbsolutePath.EndsWith(".repository")) address = address.Combine("/" + Defaults.Repository); JsonFileHandler<ScriptRepository> repository_handler = new JsonFileHandler<ScriptRepository>(); repository_handler.ReadComplete += repository_handler_LoadComplete; repository_handler.ReadError += repository_handler_LoadError; repository_handler.ReadAsync(address); }
private void LoadManifest(IPath address) { JsonFileHandler<ScriptManifest> manifest_handler = new JsonFileHandler<ScriptManifest>(); manifest_handler.ReadComplete += manifest_handler_LoadComplete; manifest_handler.ReadError += manifest_handler_LoadError; manifest_handler.ReadAsync(address); }
void comboBox1_KeyUp(object sender, KeyEventArgs e) { if ((e.KeyData & Keys.Enter) == Keys.Enter) { ScriptRepositoryReference rep = new ScriptRepositoryReference(); //rep.URI = this.comboBox1.Text; this.repositoryList.Repositories.Add(rep); JsonFileHandler<ScriptRepositoryList> h = new JsonFileHandler<ScriptRepositoryList>(); h.Write(this.repositoryListFile, this.repositoryList); this.LoadRepository(new BasePath(rep.URI)); } }
private void writePackage(IPath path, ScriptPackage package) { JsonFileHandler<ScriptPackage> handler = new JsonFileHandler<ScriptPackage>(); try { handler.Write(path, package); } catch (Exception exc) { MessageBox.Show(exc.Message); } }
public void ReadTest() { // Write installer config. this.WriteTest(); // Read and compare manifest JsonFileHandler<InstallerConfiguration> handler = new JsonFileHandler<InstallerConfiguration>(); IPath path = new BasePath(TestHelperMethods.GetOutputDirectory() + "/myscript" + InstallerConfiguration.DefaultExtension); InstallerConfiguration readConfig = handler.Read(path); Assert.IsNotNull(readConfig); Assert.AreEqual(config.Actions.Count, readConfig.Actions.Count); Assert.AreEqual(config, config.Actions[0].Configuration); Assert.AreEqual(((CopyFileAction)config.Actions[0]).Source, ((CopyFileAction)readConfig.Actions[0]).Source); Assert.AreEqual(((CopyFileAction)config.Actions[0]).Target, ((CopyFileAction)readConfig.Actions[0]).Target); Assert.AreEqual(((CopyFileAction)config.Actions[0]).UseScriptId, ((CopyFileAction)readConfig.Actions[0]).UseScriptId); Assert.AreEqual(((CopyDirAction)config.Actions[1]).Source, ((CopyDirAction)readConfig.Actions[1]).Source); Assert.AreEqual(((CopyDirAction)config.Actions[1]).Target, ((CopyDirAction)readConfig.Actions[1]).Target); Assert.AreEqual(((CopyDirAction)config.Actions[1]).UseScriptId, ((CopyDirAction)readConfig.Actions[1]).UseScriptId); Assert.AreEqual(((AssignHotkeyAction)config.Actions[2]).Keys, ((AssignHotkeyAction)readConfig.Actions[2]).Keys); Assert.AreEqual(((RunMaxscriptAction)config.Actions[3]).Source, ((RunMaxscriptAction)readConfig.Actions[3]).Source); }
public void WriteTest() { JsonFileHandler<ScriptManifest> handler = new JsonFileHandler<ScriptManifest>(); //Remove the file if it already exists, so we test that it actually writes a file. if (System.IO.File.Exists(outputFile.AbsolutePath)) System.IO.File.Delete(outputFile.AbsolutePath); handler.Write(new BasePath(outputFile.AbsolutePath), this.manifest); Assert.IsTrue(System.IO.File.Exists(outputFile.AbsolutePath)); }
public void Cleanup() { handler = null; }
public void WriteTest() { IPath outputFile = new BasePath(TestHelperMethods.GetOutputDirectory() + "repo" + ScriptRepository.DefaultExtension); if (File.Exists(outputFile.AbsolutePath)) File.Delete(outputFile.AbsolutePath); JsonFileHandler<ScriptRepository> handler = new JsonFileHandler<ScriptRepository>(); handler.Write(outputFile, repo); Assert.IsTrue(File.Exists(outputFile.AbsolutePath)); }
private void button3_Click(object sender, EventArgs e) { InstallerConfiguration config = new InstallerConfiguration(); config.AddAction(new CopyDirAction("scripts", AppPaths.Directory.Scripts)); config.AddAction(new CopyDirAction("startupscripts", AppPaths.Directory.StartupScripts)); config.AddAction(new AssignHotkeyAction(Keys.H | Keys.Alt, "", "")); JsonFileHandler<InstallerConfiguration> handler = new JsonFileHandler<InstallerConfiguration>(); handler.Write(new BasePath("C:/temp/scriptcenter/config.installer"), config); }
public void WriteTest() { JsonFileHandler<InstallerConfiguration> handler = new JsonFileHandler<InstallerConfiguration>(); IPath path = new BasePath(TestHelperMethods.GetOutputDirectory() + "/myscript" + InstallerConfiguration.DefaultExtension); try { handler.Write(path, this.config); } catch (Exception e) { Assert.Fail(e.Message); } }
public void ReadTest() { // Write manifest. this.WriteTest(); // Read and compare manifest JsonFileHandler<ScriptManifest> handler = new JsonFileHandler<ScriptManifest>(); ScriptManifest readManifest = handler.Read(outputFile); Assert.IsNotNull(readManifest); Assert.AreEqual(this.manifest.Id, readManifest.Id); Assert.AreEqual(this.manifest.Name, readManifest.Name); Assert.AreEqual(this.manifest.Author, readManifest.Author); Assert.AreEqual(this.manifest.Versions.Count, readManifest.Versions.Count); Assert.AreEqual(this.manifest.Versions[0].VersionNumber.Major, readManifest.Versions[0].VersionNumber.Major); Assert.AreEqual(this.manifest.Versions[0].VersionNumber.Minor, readManifest.Versions[0].VersionNumber.Minor); Assert.AreEqual(this.manifest.Versions[0].VersionNumber.Revision, readManifest.Versions[0].VersionNumber.Revision); Assert.AreEqual(this.manifest.Metadata["description"], readManifest.Metadata["description"]); }
private void readRepository(String file) { JsonFileHandler<ScriptRepository> handler = new JsonFileHandler<ScriptRepository>(); try { ScriptRepository repo = handler.Read(new BasePath(file)); TreeNode tn = this.addRepositoryToTree(repo, file); filesTree.SelectedNode = tn; } catch (Exception exc) { MessageBox.Show(exc.Message); } }
private void readManifest(String file) { JsonFileHandler<ScriptManifest> handler = new JsonFileHandler<ScriptManifest>(); try { ScriptManifest manif = handler.Read(new BasePath(file)); TreeNode tn = this.addManifestToTree(manif, file); filesTree.SelectedNode = tn; } catch (Exception exc) { MessageBox.Show(exc.Message); } }
public ActionResult Show() { JsonFileHandler ShowLibrary = new JsonFileHandler(); return(View(ShowLibrary.Load())); }
/// <summary> /// Writes a ScriptManifest to a file. /// </summary> /// <param name="manifest">The ScriptManifest to write.</param> /// <param name="filePath">The IPath instance of the file to write to.</param> /// <returns>True upon success.</returns> /// <remarks>Consider removing from this class.</remarks> public Boolean WriteManifest(ScriptManifest manifest, IPath filePath) { //Copy manifest and replace manifest tokens before writing. ScriptManifest manifestCopy = manifest.Copy(); foreach (ScriptVersion v in manifestCopy.Versions) { v.ScriptPath = ScriptManifestTokens.Replace(v.ScriptPath, manifestCopy, v); } //Write manifest. filePath.AbsolutePath = ScriptManifestTokens.Replace(filePath.AbsolutePath, manifest, manifest.LatestVersion); try { JsonFileHandler<ScriptManifest> handler = new JsonFileHandler<ScriptManifest>(); handler.Write(filePath, manifestCopy); } catch { return false; } return true; }
private void writeManifest(IPath path, ScriptManifest manifest) { JsonFileHandler<ScriptManifest> handler = new JsonFileHandler<ScriptManifest>(); try { handler.Write(path, manifest); } catch (Exception exc) { MessageBox.Show(exc.Message); } }
/// <summary> /// Adds the ScriptManifest to the zip package. /// Only includes the supplied ScriptVersion in the package manifest versions list. /// </summary> /// <param name="manifest">The ScriptManifest instance to add.</param> /// <param name="version">The ScriptVersion to filter out from the manifest. All other versions will not be included.</param> public virtual void AddManifest(ScriptManifest manifest, ScriptVersion version) { ScriptManifest manifestCopy = manifest.Copy(); ScriptVersion versionCopy = version.Copy(); versionCopy.ScriptPath = ScriptManifestTokens.Replace(versionCopy.ScriptPath, manifest, version); manifestCopy.Versions = new List<ScriptVersion>() { versionCopy }; using (StringWriter stringWriter = new StringWriter()) { JsonFileHandler<ScriptManifest> handler = new JsonFileHandler<ScriptManifest>(); handler.Write(stringWriter, manifestCopy); //TODO: change this to work with multiple manifests? _currentZipFile.AddEntry(PackageBuilder.InstallerArchivePath + "script" + ScriptManifest.DefaultExtension, stringWriter.ToString()); } }
private void writeRepository(IPath path, ScriptRepository repository) { JsonFileHandler<ScriptRepository> handler = new JsonFileHandler<ScriptRepository>(); try { handler.Write(path, repository); } catch (Exception exc) { MessageBox.Show(exc.Message); } }
public void Init() { handler = new JsonFileHandler<SimpleTestObject>(); }
public void JsonFileValidator_Validate_returns_UnSupported() { var jfv = new JsonFileHandler(); jfv.Validate(null, "fff", null).ShouldBe(FileStatusCode.Unsupported); }