public static void InstallFont(KwFontFace face) { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { throw new InvalidOperationException("InstallFont is for Win32NT only."); } string name, resourceName; switch (face) { case KwFontFace.NOTOMONO: name = "Noto Mono"; resourceName = "notomono.ttf"; break; default: throw new ArgumentOutOfRangeException($"Font {face} is not supported."); } var ifc = new InstalledFontCollection(); var found = ifc.Families.SingleOrDefault(f => f.Name == name); if (null != found) { return; } using (var tf = new TemporaryFile()) { using (var resourceStream = Qizarate.GetResource("Fonts." + resourceName, Assembly.GetExecutingAssembly())) { using (var outStream = tf.Create()) { resourceStream.CopyTo(outStream); } } // Creates the full path where your font will be installed var destination = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), resourceName); if (!File.Exists(destination)) { // Copies font to destination File.Copy(tf.Path, destination); // Retrieves font name // Makes sure you reference System.Drawing PrivateFontCollection fontCol = new PrivateFontCollection(); fontCol.AddFontFile(destination); var actualFontName = fontCol.Families[0].Name; //Add font AddFontResource(destination); //Add registry entry Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", actualFontName, resourceName, RegistryValueKind.String); } } }
/// <summary> /// Initializes a <see cref="TempFileBuffer"/> object. /// </summary> /// <param name="data">Byte array subject to buffering.</param> public TempFileBuffer(byte[] data) { _file = TemporaryFile.Create(); Size = data.Length; using var stream = _file.OpenWrite(); stream.Write(data, 0, (int)Size); }
public void Create_StoragePathNull_FileAttributesContainTempFlag() { lock (_locker) { TemporaryFile.StoragePath = null; var path = TemporaryFile.Create().Name; Assert.True((File.GetAttributes(path) & FileAttributes.Temporary) == FileAttributes.Temporary); } }
/// <summary> /// Initializes a <see cref="TempFileBuffer"/> object. /// </summary> /// <param name="data">Byte array subject to buffering.</param> public TempFileBuffer(byte[] data) { this.file = TemporaryFile.Create(); this.Size = (uint)data.Length; using (var stream = this.file.OpenWrite()) { stream.Write(data, 0, (int)this.Size); } }
/// <summary> /// The purpose of this method is to return the Stream that a SopInstance received /// via CStoreSCP will be written to. This default implementation creates a temporary /// file and returns a FileStream on top of it. Child classes can override this to write /// to another stream and avoid the I/O associated with the temporary file if so desired. /// Beware that some SopInstances can be very large so using a MemoryStream() could cause /// out of memory situations. /// </summary> /// <param name="file">A DicomFile with FileMetaInfo populated</param> /// <returns>The stream to write the SopInstance to</returns> protected virtual Stream CreateCStoreReceiveStream(DicomFile file) { var fileName = TemporaryFile.Create(); file.Save(fileName); var dimseStream = File.Open(fileName, FileMode.Open, FileAccess.ReadWrite); _isTempFile = true; dimseStream.Seek(0, SeekOrigin.End); return(dimseStream); }
public void Create_StoragePathNonNull_FileAttributesContainTempFlag() { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { lock (_locker) { TemporaryFile.StoragePath = TestData.Resolve("Temporary Path 3"); var path = TemporaryFile.Create().Name; Assert.True((File.GetAttributes(path) & FileAttributes.Temporary) == FileAttributes.Temporary); } } }
public void Create_StoragePathNonNull_LocatedInSpecDirectory() { lock (_locker) { var expected = TestData.Resolve("Temporary Path 2"); TemporaryFile.StoragePath = expected; var temp = TemporaryFile.Create().Name; var actual = Path.GetDirectoryName(temp); Assert.Equal(expected, actual); } }
public void Create_StoragePathNull_LocatedInUserTemp() { lock (_locker) { TemporaryFile.StoragePath = null; var temp = TemporaryFile.Create(); var expected = Path.GetTempPath().TrimEnd('\\').TrimEnd('/'); var actual = Path.GetDirectoryName(temp.Name); Assert.Equal(expected, actual); TemporaryFileRemover.Delete(temp); } }
private void ProcessPDataTF(object state) { var pdu = (PDataTF)state; try { foreach (var pdv in pdu.PDVs) { if (_dimse == null) { // create stream for receiving command if (_dimseStream == null) { _dimseStream = new MemoryStream(); } } else { // create stream for receiving dataset if (_dimseStream == null) { if (_dimse.Type == DicomCommandField.CStoreRequest) { var pc = Association.PresentationContexts.FirstOrDefault(x => x.ID == pdv.PCID); var file = new DicomFile(); file.FileMetaInfo.MediaStorageSOPClassUID = pc.AbstractSyntax; file.FileMetaInfo.MediaStorageSOPInstanceUID = _dimse.Command.Get <DicomUID>(DicomTag.AffectedSOPInstanceUID); file.FileMetaInfo.TransferSyntax = pc.AcceptedTransferSyntax; file.FileMetaInfo.ImplementationClassUID = Association.RemoteImplemetationClassUID; file.FileMetaInfo.ImplementationVersionName = Association.RemoteImplementationVersion; file.FileMetaInfo.SourceApplicationEntityTitle = Association.CallingAE; var fileName = TemporaryFile.Create(); file.Save(fileName); _dimseStream = File.OpenWrite(fileName); _dimseStream.Seek(0, SeekOrigin.End); } else { _dimseStream = new MemoryStream(); } } } _dimseStream.Write(pdv.Value, 0, pdv.Value.Length); if (pdv.IsLastFragment) { if (pdv.IsCommand) { _dimseStream.Seek(0, SeekOrigin.Begin); var command = new DicomDataset(); var reader = new DicomReader(); reader.IsExplicitVR = false; reader.Read(new StreamByteSource(_dimseStream), new DicomDatasetReaderObserver(command)); _dimseStream = null; var type = command.Get <DicomCommandField>(DicomTag.CommandField); switch (type) { case DicomCommandField.CStoreRequest: _dimse = new DicomCStoreRequest(command); break; case DicomCommandField.CStoreResponse: _dimse = new DicomCStoreResponse(command); break; case DicomCommandField.CFindRequest: _dimse = new DicomCFindRequest(command); break; case DicomCommandField.CFindResponse: _dimse = new DicomCFindResponse(command); break; case DicomCommandField.CMoveRequest: _dimse = new DicomCMoveRequest(command); break; case DicomCommandField.CMoveResponse: _dimse = new DicomCMoveResponse(command); break; case DicomCommandField.CEchoRequest: _dimse = new DicomCEchoRequest(command); break; case DicomCommandField.CEchoResponse: _dimse = new DicomCEchoResponse(command); break; case DicomCommandField.NActionRequest: _dimse = new DicomNActionRequest(command); break; case DicomCommandField.NActionResponse: _dimse = new DicomNActionResponse(command); break; case DicomCommandField.NCreateRequest: _dimse = new DicomNCreateRequest(command); break; case DicomCommandField.NCreateResponse: _dimse = new DicomNCreateResponse(command); break; case DicomCommandField.NDeleteRequest: _dimse = new DicomNDeleteRequest(command); break; case DicomCommandField.NDeleteResponse: _dimse = new DicomNDeleteResponse(command); break; case DicomCommandField.NEventReportRequest: _dimse = new DicomNEventReportRequest(command); break; case DicomCommandField.NEventReportResponse: _dimse = new DicomNEventReportResponse(command); break; case DicomCommandField.NGetRequest: _dimse = new DicomNGetRequest(command); break; case DicomCommandField.NGetResponse: _dimse = new DicomNGetResponse(command); break; case DicomCommandField.NSetRequest: _dimse = new DicomNSetRequest(command); break; case DicomCommandField.NSetResponse: _dimse = new DicomNSetResponse(command); break; default: _dimse = new DicomMessage(command); break; } if (!_dimse.HasDataset) { if (DicomMessage.IsRequest(_dimse.Type)) { ThreadPool.QueueUserWorkItem(PerformDimseCallback, _dimse); } else { _processQueue.Queue((_dimse as DicomResponse).RequestMessageID, PerformDimseCallback, _dimse); } _dimse = null; return; } } else { if (_dimse.Type != DicomCommandField.CStoreRequest) { _dimseStream.Seek(0, SeekOrigin.Begin); var pc = Association.PresentationContexts.FirstOrDefault(x => x.ID == pdv.PCID); _dimse.Dataset = new DicomDataset(); _dimse.Dataset.InternalTransferSyntax = pc.AcceptedTransferSyntax; var source = new StreamByteSource(_dimseStream); source.Endian = pc.AcceptedTransferSyntax.Endian; var reader = new DicomReader(); reader.IsExplicitVR = pc.AcceptedTransferSyntax.IsExplicitVR; reader.Read(source, new DicomDatasetReaderObserver(_dimse.Dataset)); _dimseStream = null; } else { var fileName = (_dimseStream as FileStream).Name; _dimseStream.Close(); _dimseStream = null; var request = _dimse as DicomCStoreRequest; try { request.File = DicomFile.Open(fileName); } catch (Exception e) { // failed to parse received DICOM file; send error response instead of aborting connection SendResponse(new DicomCStoreResponse(request, new DicomStatus(DicomStatus.ProcessingFailure, e.Message))); Logger.Error("Error parsing C-Store dataset: " + e.ToString()); (this as IDicomCStoreProvider).OnCStoreRequestException(fileName, e); return; } request.File.File.IsTempFile = true; request.Dataset = request.File.Dataset; } if (DicomMessage.IsRequest(_dimse.Type)) { ThreadPool.QueueUserWorkItem(PerformDimseCallback, _dimse); } else { _processQueue.Queue((_dimse as DicomResponse).RequestMessageID, PerformDimseCallback, _dimse); } _dimse = null; } } } } catch (Exception e) { SendAbort(DicomAbortSource.ServiceUser, DicomAbortReason.NotSpecified); Logger.Error("Exception processing P-Data-TF PDU: " + e.ToString()); } finally { SendNextMessage(); } }
public FileByteBufferTest() { _fileReference = TemporaryFile.Create(); }