private void MoveKeyfileToInternalFolder() { Func <Action> copyAndReturnPostExecute = () => { try { CompositeKey masterKey = App.Kp2a.CurrentDb.KpDatabase.MasterKey; var sourceIoc = ((KcpKeyFile)masterKey.GetUserKey(typeof(KcpKeyFile))).Ioc; var newIoc = IoUtil.ImportFileToInternalDirectory(sourceIoc, Activity, App.Kp2a); ((KcpKeyFile)masterKey.GetUserKey(typeof(KcpKeyFile))).ResetIoc(newIoc); var keyfileString = IOConnectionInfo.SerializeToString(newIoc); App.Kp2a.StoreOpenedFileAsRecent(App.Kp2a.CurrentDb.Ioc, keyfileString, false); return(() => { UpdateImportKeyfilePref(); var builder = new AlertDialog.Builder(Activity); builder .SetMessage(Resource.String.KeyfileMoved); builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { }); builder.Show(); }); } catch (Exception e) { return(() => { Toast.MakeText(Activity, App.Kp2a.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, ToastLength.Long).Show(); }); } }; new SimpleLoadingDialog(Activity, GetString(Resource.String.CopyingFile), false, copyAndReturnPostExecute ).Execute(); }
/// <summary> /// Delete the cluster container directory. /// </summary> public void DeleteDirectory() { if (null != clusteredServiceDir) { IoUtil.Delete(clusteredServiceDir, false); } }
public virtual DeploymentBuilder addInputStream(string resourceName, Stream inputStream) { ensureNotNull("inputStream for resource '" + resourceName + "' is null", "inputStream", inputStream); sbyte[] bytes = IoUtil.readInputStream(inputStream, resourceName); return(addBytes(resourceName, bytes)); }
private void ConnectToDriver() { var startMs = _epochClock.Time(); while (!_cncFile.Exists) { if (_epochClock.Time() > startMs + _driverTimeoutMs) { throw new DriverTimeoutException("CnC file is created by not initialised."); } Thread.Yield(); } _cncByteBuffer = IoUtil.MapExistingFile(CncFile().FullName, MapMode.ReadWrite); _cncMetaDataBuffer = CncFileDescriptor.CreateMetaDataBuffer(_cncByteBuffer); int cncVersion; while (0 == (cncVersion = _cncMetaDataBuffer.GetInt(CncFileDescriptor.CncVersionOffset(0)))) { if (_epochClock.Time() > startMs + _driverTimeoutMs) { throw new DriverTimeoutException("CnC file is created by not initialised."); } Thread.Yield(); } if (CncFileDescriptor.CNC_VERSION != cncVersion) { throw new InvalidOperationException( "aeron cnc file version not understood: version=" + cncVersion); } }
public void TestNavyMessagingM3() { string fileName = IoUtil.MonthFileName(DateTime.Now.Year, DateTime.Now.Month, ".xml"); string digraphFileName = IoUtil.DigraphFileName(DateTime.Now.Year, DateTime.Now.Month); string folder = Path.GetTempPath(); string xmlFullPath = Path.Combine(folder, fileName); string digraphFullPath = Path.Combine(folder, digraphFileName); MonthlySettings monSet = MonthlySettings.Random(DateTime.Now.Year, DateTime.Now.Month, MachineType.M3K); monSet.Save(xmlFullPath); IoUtil.SaveDigraphTable(DateTime.Now.Year, DateTime.Now.Month, folder); NavyMessage msg = new NavyMessage(xmlFullPath, digraphFullPath, LONG_TEST_PLAIN_TEXT, DateTime.Now.Day, "XYZ"); string messageText = msg.ToString(); string decrypted = NavyMessage.Decrypt(xmlFullPath, digraphFullPath, messageText); string cleanPlain = Utility.GetPaddedString(Utility.CleanString(LONG_TEST_PLAIN_TEXT), 4); Assert.AreEqual(decrypted, cleanPlain); File.Delete(xmlFullPath); File.Delete(digraphFullPath); }
private void BrowseButton_Click(object sender, EventArgs e) { string inputFilepath = FormUtil.ShowFileBrowserDialog(); if (string.IsNullOrWhiteSpace(inputFilepath)) { return; } FilepathTextBox.Text = inputFilepath; bool isSubFile = Path.GetExtension(inputFilepath) !.Equals(".sub", StringComparison.OrdinalIgnoreCase); XDocument inputDocument = isSubFile ? IoUtil.LoadSub(inputFilepath) : XDocument.Load(inputFilepath); if (isSubFile) { string preview = inputDocument.Root?.Attribute("previewimage")?.Value; if (!string.IsNullOrWhiteSpace(preview)) { pictureBox1.Image = FormUtil.GetImageFromString(inputDocument.Root?.Attribute("previewimage")?.Value); } } else { pictureBox1.Image = null; // Assemblies do not contain preview images } }
private void UpdateImportDbPref() { //Import db/key file preferences: Preference importDb = FindPreference("import_db_prefs"); bool isLocalOrContent = App.Kp2a.CurrentDb.Ioc.IsLocalFile() || App.Kp2a.CurrentDb.Ioc.Path.StartsWith("content://"); if (!isLocalOrContent) { importDb.Summary = GetString(Resource.String.OnlyAvailableForLocalFiles); importDb.Enabled = false; } else { if (IoUtil.IsInInternalDirectory(App.Kp2a.CurrentDb.Ioc.Path, Activity)) { importDb.Summary = GetString(Resource.String.FileIsInInternalDirectory); importDb.Enabled = false; } else { importDb.Enabled = true; importDb.PreferenceClick += delegate { MoveDbToInternalFolder(); }; } } }
protected internal override void starting(Description description) { if (perfTestConfiguration == null) { File file = IoUtil.getFile(PROPERTY_FILE_NAME); if (!file.exists()) { throw new PerfTestException("Cannot load file '" + PROPERTY_FILE_NAME + "': file does not exist."); } FileStream propertyInputStream = null; try { propertyInputStream = new FileStream(file, FileMode.Open, FileAccess.Read); Properties properties = new Properties(); properties.load(propertyInputStream); perfTestConfiguration = new PerfTestConfiguration(properties); } catch (Exception e) { throw new PerfTestException("Cannot load properties from file " + PROPERTY_FILE_NAME + ": " + e); } finally { IoUtil.closeSilently(propertyInputStream); } } }
public virtual void executeSchemaResource(string operation, string component, string resourceName, bool isOptional) { Stream inputStream = null; try { inputStream = ReflectUtil.getResourceAsStream(resourceName); if (inputStream == null) { if (isOptional) { LOG.missingSchemaResource(resourceName, operation); } else { throw LOG.missingSchemaResourceException(resourceName, operation); } } else { executeSchemaResource(operation, component, resourceName, inputStream); } } finally { IoUtil.closeSilently(inputStream); } }
private IOConnectionInfo ImportFileToInternalDirectory(IOConnectionInfo sourceIoc) { Java.IO.File internalDirectory = IoUtil.GetInternalDirectory(Activity); string targetPath = UrlUtil.GetFileName(sourceIoc.Path); targetPath = targetPath.Trim("|\\?*<\":>+[]/'".ToCharArray()); if (targetPath == "") { targetPath = "imported"; } if (new File(internalDirectory, targetPath).Exists()) { int c = 1; var ext = UrlUtil.GetExtension(targetPath); var filenameWithoutExt = UrlUtil.StripExtension(targetPath); do { c++; targetPath = filenameWithoutExt + c; if (!String.IsNullOrEmpty(ext)) { targetPath += "." + ext; } } while (new File(internalDirectory, targetPath).Exists()); } var targetIoc = IOConnectionInfo.FromPath(new File(internalDirectory, targetPath).CanonicalPath); IoUtil.Copy(targetIoc, sourceIoc, App.Kp2a); return(targetIoc); }
private void MoveDbToInternalFolder() { Func <Action> copyAndReturnPostExecute = () => { try { var sourceIoc = App.Kp2a.CurrentDb.Ioc; var newIoc = IoUtil.ImportFileToInternalDirectory(sourceIoc, Activity, App.Kp2a); return(() => { var builder = new AlertDialog.Builder(Activity); builder .SetMessage(Resource.String.DatabaseFileMoved); builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { var key = App.Kp2a.CurrentDb.KpDatabase.MasterKey; App.Kp2a.CloseDatabase(App.Kp2a.CurrentDb); PasswordActivity.Launch(Activity, newIoc, key, new ActivityLaunchModeSimple(), false); }); builder.Show(); }); } catch (Exception e) { return(() => { Toast.MakeText(Activity, App.Kp2a.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, ToastLength.Long).Show(); }); } }; new SimpleLoadingDialog(Activity, GetString(Resource.String.CopyingFile), false, copyAndReturnPostExecute ).Execute(); }
public override void Run() { StatusLogger.UpdateMessage(UiStringKey.exporting_database); try { var fileStorage = _app.GetFileStorage(_targetIoc); if (fileStorage is IOfflineSwitchable) { ((IOfflineSwitchable)fileStorage).IsOffline = false; } CompositeKey masterKey = App.Kp2a.CurrentDb.KpDatabase.MasterKey; var sourceIoc = ((KcpKeyFile)masterKey.GetUserKey(typeof(KcpKeyFile))).Ioc; IoUtil.Copy(_targetIoc, sourceIoc, App.Kp2a); if (fileStorage is IOfflineSwitchable) { ((IOfflineSwitchable)fileStorage).IsOffline = App.Kp2a.OfflineMode; } Finish(true); } catch (Exception ex) { Finish(false, ex.Message); } }
protected internal virtual string DoConvertToString(IDmnModelInstance modelInstance) { // validate DOM document DoValidateModel(modelInstance); // convert to XML string return(IoUtil.ConvertXmlDocumentToString(modelInstance.Document)); }
protected internal virtual void DoWriteModelToOutputStream(System.IO.Stream os, IDmnModelInstance modelInstance) { // validate DOM document DoValidateModel(modelInstance); // write XML IoUtil.WriteDocumentToOutputStream(modelInstance.Document, os); }
public void TestSplitAddress() { IoUtil.SplitAddress(0x12345678, out var bank, out var offset); Assert.AreEqual(0x12, bank); Assert.AreEqual(0x345678, offset); }
public static void writeStringToFile(string value, string filePath, bool deleteFile) { BufferedOutputStream outputStream = null; try { File file = new File(filePath); if (file.exists() && deleteFile) { file.delete(); } outputStream = new BufferedOutputStream(new FileStream(file, true)); outputStream.write(value.GetBytes()); outputStream.flush(); } catch (Exception e) { throw new PerfTestException("Could not write report to file", e); } finally { IoUtil.closeSilently(outputStream); } }
public void Dispose() { foreach (var buffer in _mappedByteBuffers) { IoUtil.Unmap(buffer); } }
public LogBuffers(string logFileName) { var fileInfo = new FileInfo(logFileName); var logLength = fileInfo.Length; var termLength = LogBufferDescriptor.ComputeTermLength(logLength); LogBufferDescriptor.CheckTermLength(termLength); _termLength = termLength; // if log length exceeds MAX_INT we need multiple mapped buffers, (see FileChannel.map doc). if (logLength < int.MaxValue) { var mappedBuffer = IoUtil.MapExistingFile(logFileName); _mappedByteBuffers = new[] { mappedBuffer }; var metaDataSectionOffset = termLength * LogBufferDescriptor.PARTITION_COUNT; for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { var metaDataOffset = metaDataSectionOffset + (i * LogBufferDescriptor.TERM_META_DATA_LENGTH); _atomicBuffers[i] = new UnsafeBuffer(mappedBuffer.Pointer, i * termLength, termLength); _atomicBuffers[i + LogBufferDescriptor.PARTITION_COUNT] = new UnsafeBuffer(mappedBuffer.Pointer, metaDataOffset, LogBufferDescriptor.TERM_META_DATA_LENGTH); } _atomicBuffers[_atomicBuffers.Length - 1] = new UnsafeBuffer(mappedBuffer.Pointer, (int)(logLength - LogBufferDescriptor.LOG_META_DATA_LENGTH), LogBufferDescriptor.LOG_META_DATA_LENGTH); } else { _mappedByteBuffers = new MappedByteBuffer[LogBufferDescriptor.PARTITION_COUNT + 1]; var metaDataSectionOffset = termLength * (long)LogBufferDescriptor.PARTITION_COUNT; var metaDataSectionLength = (int)(logLength - metaDataSectionOffset); var memoryMappedFile = IoUtil.OpenMemoryMappedFile(logFileName); var metaDataMappedBuffer = new MappedByteBuffer(memoryMappedFile, metaDataSectionOffset, metaDataSectionLength); _mappedByteBuffers[_mappedByteBuffers.Length - 1] = metaDataMappedBuffer; for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { _mappedByteBuffers[i] = new MappedByteBuffer(memoryMappedFile, termLength * (long)i, termLength); _atomicBuffers[i] = new UnsafeBuffer(_mappedByteBuffers[i].Pointer, termLength); _atomicBuffers[i + LogBufferDescriptor.PARTITION_COUNT] = new UnsafeBuffer(metaDataMappedBuffer.Pointer, i * LogBufferDescriptor.TERM_META_DATA_LENGTH, LogBufferDescriptor.TERM_META_DATA_LENGTH); } _atomicBuffers[_atomicBuffers.Length - 1] = new UnsafeBuffer(metaDataMappedBuffer.Pointer, metaDataSectionLength - LogBufferDescriptor.LOG_META_DATA_LENGTH, LogBufferDescriptor.LOG_META_DATA_LENGTH); } // TODO try/catch foreach (var buffer in _atomicBuffers) { buffer.VerifyAlignment(); } }
public virtual IDeploymentBuilder AddInputStream(string resourceName, Stream inputStream) { EnsureUtil.EnsureNotNull("inputStream for resource '" + resourceName + "' is null", "inputStream", inputStream); var bytes = IoUtil.ReadInputStream(inputStream, resourceName); return(AddBytes(resourceName, bytes)); }
private bool GetIocFromViewIntent(Intent intent) { IOConnectionInfo ioc = new IOConnectionInfo(); //started from "view" intent (e.g. from file browser) ioc.Path = intent.DataString; if (ioc.Path.StartsWith("file://")) { ioc.Path = URLDecoder.Decode(ioc.Path.Substring(7)); if (ioc.Path.Length == 0) { // No file name Toast.MakeText(this, Resource.String.FileNotFound, ToastLength.Long).Show(); return(false); } File dbFile = new File(ioc.Path); if (!dbFile.Exists()) { // File does not exist Toast.MakeText(this, Resource.String.FileNotFound, ToastLength.Long).Show(); return(false); } } else { if (!ioc.Path.StartsWith("content://")) { Toast.MakeText(this, Resource.String.error_can_not_handle_uri, ToastLength.Long).Show(); return(false); } IoUtil.TryTakePersistablePermissions(this.ContentResolver, intent.Data); } if (App.Kp2a.TrySelectCurrentDb(ioc)) { if (OpenAutoExecEntries(App.Kp2a.CurrentDb)) { return(false); } LaunchingOther = true; AppTask.CanActivateSearchViewOnStart = true; AppTask.LaunchFirstGroupActivity(this); } else { Intent launchIntent = new Intent(this, typeof(PasswordActivity)); Util.PutIoConnectionToIntent(ioc, launchIntent); LaunchingOther = true; StartActivityForResult(launchIntent, ReqCodeOpenNewDb); } return(true); }
public static void CompressDirectory(string inDir, string outDir) { Console.WriteLine($"Compressing {inDir}..."); string outPath = Path.Combine(outDir, $"{Path.GetFileName(inDir)}.save"); IoUtil.CompressDirectory(inDir, outPath); Console.WriteLine($"Compressed to {outPath}..."); Console.WriteLine("...success"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Deployment public void testRenderDateFieldWithPattern() public virtual void testRenderDateFieldWithPattern() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); string renderedForm = (string)formService.getRenderedStartForm(processDefinition.Id); string expectedForm = IoUtil.readClasspathResourceAsString("org/camunda/bpm/engine/test/api/form/HtmlFormEngineTest.testRenderDateFieldWithPattern.html"); assertHtmlEquals(expectedForm, renderedForm); }
public virtual void testRenderDateField() { var processDefinition = repositoryService.CreateProcessDefinitionQuery() .First(); var renderedForm = (string)formService.GetRenderedStartForm(processDefinition.Id); var expectedForm = IoUtil.ReadFileAsString("resources/api/form/HtmlFormEngineTest.TestRenderDateField.html"); AssertHtmlEquals(expectedForm, renderedForm); }
public static void DecompressToDirectory(string inPath, string outDir) { Console.WriteLine($"Decompressing {outDir}..."); string newDir = Path.Combine(outDir, Path.GetFileNameWithoutExtension(inPath)); Directory.CreateDirectory(newDir); IoUtil.DecompressToDirectory(inPath, newDir); Console.WriteLine($"Decompressed to {newDir}..."); Console.WriteLine("...success"); }
// DRD retrieval //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void decisionRequirementsDiagramRetrieval() throws java.io.FileNotFoundException, java.net.URISyntaxException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void decisionRequirementsDiagramRetrieval() { sbyte[] actual = given().pathParam("id", MockProvider.EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID).expect().statusCode(Status.OK.StatusCode).contentType("image/png").header("Content-Disposition", "attachment; filename=" + MockProvider.EXAMPLE_DECISION_DEFINITION_DIAGRAM_RESOURCE_NAME).when().get(DIAGRAM_DEFINITION_URL).Body.asByteArray(); verify(repositoryServiceMock).getDecisionRequirementsDefinition(MockProvider.EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID); verify(repositoryServiceMock).getDecisionRequirementsDiagram(MockProvider.EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID); sbyte[] expected = IoUtil.readInputStream(new FileStream(File, FileMode.Open, FileAccess.Read), "decision requirements diagram"); Assert.assertArrayEquals(expected, actual); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void fileByteArrayIsEqualToFileValueContent() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void fileByteArrayIsEqualToFileValueContent() { Stream file = this.GetType().ClassLoader.getResourceAsStream("org/camunda/bpm/engine/test/variables/simpleFile.txt"); string fileName = "simpleFile.txt"; FileValue fileValue = Variables.fileValue(fileName).file(file).create(); file = this.GetType().ClassLoader.getResourceAsStream("org/camunda/bpm/engine/test/variables/simpleFile.txt"); assertThat(IoUtil.inputStreamAsByteArray(fileValue.Value), equalTo(IoUtil.inputStreamAsByteArray(file))); }
public void Dispose() { var length = _mappedByteBuffers.Length; for (var i = 0; i < length; i++) { var buffer = _mappedByteBuffers[i]; IoUtil.Unmap(buffer); _mappedByteBuffers[i] = null; } }
public void Save(string fileName) { XmlSerializer ser = new XmlSerializer(typeof(MonthlySettings)); using (FileStream stm = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) { ser.Serialize(stm, this); } //this extracts the xsd file into the same directory as the settings file IoUtil.ExtractXsd(fileName); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void fileByteArrayIsEqualToFileValueContentCase2() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void fileByteArrayIsEqualToFileValueContentCase2() { sbyte[] bytes = new sbyte[] { (sbyte)-16, (sbyte)-128, (sbyte)-128, (sbyte)-128 }; Stream byteStream = new MemoryStream(bytes); string fileName = "simpleFile.txt"; FileValue fileValue = Variables.fileValue(fileName).file(byteStream).create(); assertThat(IoUtil.inputStreamAsByteArray(fileValue.Value), equalTo(bytes)); }
public Database GetDatabase(string databaseId) { foreach (Database db in OpenDatabases) { if (IoUtil.IocAsHexString(db.Ioc) == databaseId) { return(db); } } throw new Exception("Database not found for databaseId!"); }