/// <inheritdoc /> public override Task WriteResponseBodyAsync([NotNull] OutputFormatterContext context) { var tempWriterSettings = WriterSettings.Clone(); tempWriterSettings.Encoding = context.SelectedEncoding; using (var xmlWriter = CreateXmlWriter(context.HttpContext.Response.Body, tempWriterSettings)) { var obj = context.Object; var runtimeType = obj?.GetType(); var resolvedType = ResolveType(context.DeclaredType, runtimeType); var wrappingType = GetSerializableType(resolvedType); // Wrap the object only if there is a wrapping type. if (wrappingType != null && wrappingType != resolvedType) { var wrapperProvider = WrapperProviderFactories.GetWrapperProvider( new WrapperProviderContext( declaredType: resolvedType, isSerialization: true)); obj = wrapperProvider.Wrap(obj); } var dataContractSerializer = GetCachedSerializer(wrappingType); dataContractSerializer.WriteObject(xmlWriter, obj); } return(Task.FromResult(true)); }
/// <summary> /// Calls FitDimensionsToFileSize method and writes result info to console /// </summary> private static void CallFitDimensionsToFileSize(string srcPath, WriterSettings settings, long maxAllowedSize, string dstPath) { Console.WriteLine("Fit image dimensions to {0}", FormatFileSize(maxAllowedSize)); using (var reader = ImageReader.Create(srcPath)) { Console.WriteLine("Source: \n - Dimensions: {0} x {1}\n - Format: {2}", reader.Width, reader.Height, reader.FileFormat); } FitDimensionsToFileSize(srcPath, settings, maxAllowedSize, dstPath); Console.WriteLine("Destination:\n - Format: {0}\n - File size: {1}", settings.Format, FormatFileSize(new FileInfo(dstPath).Length)); var unsupportedFormats = new List <FileFormat> { FileFormat.Eps, FileFormat.Pdf }; if (!unsupportedFormats.Contains(settings.Format)) { using (var reader = ImageReader.Create(dstPath)) Console.WriteLine(" - Dimensions: {0} x {1}", reader.Width, reader.Height); } Console.WriteLine(); }
private static AttributeWriter GetAttributeWriter(IMemberDefinition member, SupportedLanguage language, StringWriter stringWriter) { ILanguage decompilerLangauge = GetLanguage(language); IFormatter formatter = new PlainTextFormatter(stringWriter); IWriterSettings settings = new WriterSettings(writeExceptionsAsComments: true); switch (language) { case SupportedLanguage.CSharp: { JustAssemblyCSharpWriter cSharpWriter = new JustAssemblyCSharpWriter(member, new SimpleWriterContextService(new EmptyDecompilationCacheService(), true), decompilerLangauge, formatter, SimpleExceptionFormatter.Instance, settings); return(new CSharpAttributeWriter(cSharpWriter)); } case SupportedLanguage.VB: { JustAssemblyVisualBasicWriter visualBasicWriter = new JustAssemblyVisualBasicWriter(member, new SimpleWriterContextService(new EmptyDecompilationCacheService(), true), decompilerLangauge, formatter, SimpleExceptionFormatter.Instance, settings); return(new VisualBasicAttributeWriter(visualBasicWriter)); } default: throw new NotSupportedException("Not supported AttributeWriter language."); } }
/// <summary> /// Called to do initial creation of a fragment. /// </summary> /// <param name="savedInstanceState">If the fragment is being re-created from a previous saved state, /// this is the state.</param> protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Utils.SetLocaleFromPrefereces(this); SetContentView(Resource.Layout.main); SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetTitle(Resource.String.title_barcode_viewer); string xmlSerialization = Intent.GetStringExtra("barcode"); WriterSettings barcodeWriterSettings = Utils.DeserializeBarcodeWriterSettings(xmlSerialization); string barcodeDescription = Intent.GetStringExtra("barcodeDescription"); string barcodeSubset = Intent.GetStringExtra("barcodeSubset"); string barcodeValue = Intent.GetStringExtra("barcodeValue"); _barcode = new Utils.BarcodeInformation(barcodeWriterSettings, barcodeValue, barcodeDescription, barcodeSubset); _barcodeViewerFragment = new BarcodeViewerFragment(this); // create a new transaction Android.Support.V4.App.FragmentTransaction transaction = SupportFragmentManager.BeginTransaction(); // add fragment to the container transaction.Replace(Resource.Id.mainContentFrame, _barcodeViewerFragment); // commit the transaction transaction.Commit(); }
/// <summary> /// This is called for activities that set launchMode to "singleTop" in their package, /// or if a client used the <see cref="Android.Content.ActivityFlags.SingleTop"/> flag when calling /// <see cref="Android.Content.ContextWrapper.StartActivity(Android.Content.Intent)"/>. /// </summary> /// <param name="intent">The new intent that was started for the activity.</param> protected override void OnNewIntent(Intent intent) { bool isBarcodeShouldBeDeleted = intent.GetBooleanExtra("delete", false); // if barcode should be deleted if (isBarcodeShouldBeDeleted) { // if clicked item index is correct if (_barcodeGeneratorFragment.ClickedItemIndex != -1) { // get adapter ArrayAdapter <Utils.BarcodeInformation> adapter = _barcodeGeneratorFragment.ListAdapter as ArrayAdapter <Utils.BarcodeInformation>; // remove barcode adapter.Remove(adapter.GetItem(_barcodeGeneratorFragment.ClickedItemIndex)); adapter.NotifyDataSetChanged(); } } else { // get barcode writer settings string xmlSerialization = intent.GetStringExtra("barcode"); if (xmlSerialization != null) { WriterSettings barcodeWriterSettings = Utils.DeserializeBarcodeWriterSettings(xmlSerialization); // get barcode description string barcodeDescription = intent.GetStringExtra("barcodeDescription"); // get barcode subset string barcodeSubset = intent.GetStringExtra("barcodeSubset"); string barcodeValue = intent.GetStringExtra("barcodeValue"); ArrayAdapter <Utils.BarcodeInformation> adapter = _barcodeGeneratorFragment.ListAdapter as ArrayAdapter <Utils.BarcodeInformation>; // if barcode writer settings is not empty if (barcodeWriterSettings != null) { // if clicked item index is correct if (_barcodeGeneratorFragment.ClickedItemIndex != -1) { // update list item Utils.BarcodeInformation item = adapter.GetItem(_barcodeGeneratorFragment.ClickedItemIndex); item.BarcodeWriterSetting = barcodeWriterSettings; item.BarcodeValue = barcodeValue; item.BarcodeDescription = barcodeDescription; item.BarcodeSubsetName = barcodeSubset; } else { // add value to the list adapter.Add(new Utils.BarcodeInformation(barcodeWriterSettings, barcodeValue, barcodeDescription, barcodeSubset)); } adapter.NotifyDataSetChanged(); } } } SaveHistory(); base.OnNewIntent(intent); }
Task <bool> IWriterEnvironment.ShowSettingsAsync(WriterSettings settings) { var dialog = new SettingsDialog(settings); dialog.ShowDialog(); return(Task.FromResult(true)); }
/// <summary> /// A wrapper for FitDimensionsToFileSize method with path arguments /// </summary> public static void FitDimensionsToFileSize(string srcPath, WriterSettings settings, long maxAllowedSize, string dstPath) { using (var srcStream = new FileStream(srcPath, FileMode.Open, FileAccess.Read)) using (var dstStream = new FileStream(dstPath, FileMode.Create, FileAccess.Write)) { FitDimensionsToFileSize(srcStream, settings, maxAllowedSize, dstStream); } }
/// <summary> /// Called during serialization to get the XML writer to use for writing objects to the stream. /// </summary> /// <param name="writeStream">The <see cref="Stream"/> to write to.</param> /// <param name="content">The <see cref="HttpContent"/> for the content being written.</param> /// <returns>The <see cref="XmlWriter"/> to use for writing objects.</returns> protected internal virtual XmlWriter CreateXmlWriter(Stream writeStream, HttpContent content) { Encoding effectiveEncoding = SelectCharacterEncoding(content != null ? content.Headers : null); XmlWriterSettings writerSettings = WriterSettings.Clone(); writerSettings.Encoding = effectiveEncoding; return(XmlWriter.Create(writeStream, writerSettings)); }
private string WriteAssemblyInfo(AssemblyDefinition assembly, out bool createdNewFile) { string fileContent; IAssemblyAttributeWriter writer = null; using (StringWriter stringWriter = new StringWriter()) { IWriterSettings settings = new WriterSettings(writeExceptionsAsComments: true); writer = language.GetAssemblyAttributeWriter(new PlainTextFormatter(stringWriter), this.exceptionFormater, settings); IWriterContextService writerContextService = this.GetWriterContextService(); writer.ExceptionThrown += OnExceptionThrown; writerContextService.ExceptionThrown += OnExceptionThrown; // "Duplicate 'TargetFramework' attribute" when having it written in AssemblyInfo writer.WriteAssemblyInfo(assembly, writerContextService, true, new string[1] { "System.Runtime.Versioning.TargetFrameworkAttribute" }, new string[1] { "System.Security.UnverifiableCodeAttribute" }); fileContent = stringWriter.ToString(); writer.ExceptionThrown -= OnExceptionThrown; writerContextService.ExceptionThrown -= OnExceptionThrown; } string parentDirectory = Path.GetDirectoryName(this.TargetPath); string relativePath = filePathsService.GetAssemblyInfoRelativePath(); string fullPath = Path.Combine(parentDirectory, relativePath); string dirPath = Path.GetDirectoryName(fullPath); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } if (File.Exists(fullPath) && assembly.MainModule.Types.FirstOrDefault(x => x.FullName == "Properties.AssemblyInfo") != null) { createdNewFile = false; PushAssemblyAttributes(fullPath, fileContent, writer); } else { createdNewFile = true; using (StreamWriter fileWriter = new StreamWriter(fullPath, false, Encoding.UTF8)) { fileWriter.Write(fileContent); } } return(relativePath); }
private string GetNamespacePerLanguage(ILanguage language, string @namespace) { var formatter = new PlainTextFormatter(new StringWriter()); IWriterSettings settings = new WriterSettings(writeExceptionsAsComments: true, renameInvalidMembers: true); ILanguageWriter writer = language.GetWriter(formatter, SimpleExceptionFormatter.Instance, settings); writer.ExceptionThrown += OnExceptionThrown; writer.WriteNamespaceNavigationName(@namespace); writer.ExceptionThrown -= OnExceptionThrown; return(formatter.ToString()); }
public WebImageLoader(BitmapViewer bitmapViewer) { _tiles = new List <RectangleF>(); _bitmapViewer = bitmapViewer; _filePrefix = Guid.NewGuid(); _encoderOptions = bitmapViewer.GetBrowserImageFormatEncoderOptions(); _fileExtension = bitmapViewer.GetCacheFileExtension(); // Zoom _zoom100Threshold = Math.Max(1 / BitmapViewer.ActualSizeHorizontalScale, 1 / BitmapViewer.ActualSizeVerticalScale); _useZoom100Threshold = ((BitmapViewer.ZoomQuality == ZoomQuality.Low) || (BitmapViewer.ZoomQuality == ZoomQuality.ShrinkHighStretchLow)) && (BitmapViewer.Zoom - _zoom100Threshold > s_eps); }
/// <inheritdoc /> public override Task WriteResponseBodyAsync([NotNull] OutputFormatterContext context) { var tempWriterSettings = WriterSettings.Clone(); tempWriterSettings.Encoding = context.SelectedEncoding; var innerStream = context.ActionContext.HttpContext.Response.Body; using (var outputStream = new DelegatingStream(innerStream)) using (var xmlWriter = CreateXmlWriter(outputStream, tempWriterSettings)) { var dataContractSerializer = (DataContractSerializer)CreateSerializer(GetObjectType(context)); dataContractSerializer.WriteObject(xmlWriter, context.Object); } return(Task.FromResult(true)); }
private IDecompilationResults GetAssemblyAttributesDecompilationResults(string assemblyAttributesFilePath) { AvalonEditCodeFormatter formatter = new AvalonEditCodeFormatter(new StringWriter()); IWriterSettings settings = new WriterSettings(writeExceptionsAsComments: true); IAssemblyAttributeWriter writer = language.GetAssemblyAttributeWriter(formatter, this.exceptionFormater, settings); IWriterContextService writerContextService = new TypeCollisionWriterContextService(new ProjectGenerationDecompilationCacheService(), decompilationPreferences.RenameInvalidMembers); string fileContent; try { writer.WriteAssemblyInfo(assembly, writerContextService, true, new string[1] { "System.Runtime.Versioning.TargetFrameworkAttribute" }, new string[1] { "System.Security.UnverifiableCodeAttribute" }); fileContent = formatter.GetSourceCode().GetSourceCode(); } catch (Exception e) { string[] exceptionMessageLines = exceptionFormater.Format(e, null, assemblyAttributesFilePath); fileContent = string.Join(Environment.NewLine, exceptionMessageLines); } using (StreamWriter outfile = new StreamWriter(assemblyAttributesFilePath)) { outfile.Write(fileContent); } JustDecompile.EngineInfrastructure.ICodeViewerResults originalcodeViewerResults = formatter.GetSourceCode(); if (!(originalcodeViewerResults is JustDecompile.EngineInfrastructure.DecompiledSourceCode)) { throw new Exception("Unexpected code viewer results type."); } JustDecompile.EngineInfrastructure.DecompiledSourceCode decompiledSourceCode = originalcodeViewerResults as JustDecompile.EngineInfrastructure.DecompiledSourceCode; ICodeViewerResults codeViewerResults = new CodeViewerResults(decompiledSourceCode); return(new DecompilationResults(assemblyAttributesFilePath, codeViewerResults, new Dictionary <uint, IOffsetSpan>(), new Dictionary <uint, IOffsetSpan>(), new Dictionary <uint, IOffsetSpan>(), new Dictionary <uint, IOffsetSpan>(), new HashSet <uint>())); }
/// <inheritdoc /> public void SerializeToStream(Stream stream, object item, Type type) { Guard.Guard.Against.Null(stream, nameof(stream)); Guard.Guard.Against.Null(item, nameof(item)); Guard.Guard.Against.Null(type, nameof(type)); type = CheckType(type, item); if (WriterSettings.IsNull()) { new XmlSerializer(type).Serialize(stream, item, Namespaces); } else { using (var xmlWriter = XmlWriter.Create(stream, WriterSettings)) new XmlSerializer(type).Serialize(xmlWriter, item, Namespaces); } }
/// <inheritdoc /> public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (selectedEncoding == null) { throw new ArgumentNullException(nameof(selectedEncoding)); } var writerSettings = WriterSettings.Clone(); writerSettings.Encoding = selectedEncoding; // Wrap the object only if there is a wrapping type. var value = context.Object; var wrappingType = GetSerializableType(context.ObjectType); if (wrappingType != null && wrappingType != context.ObjectType) { var wrapperProvider = WrapperProviderFactories.GetWrapperProvider(new WrapperProviderContext( declaredType: context.ObjectType, isSerialization: true)); value = wrapperProvider.Wrap(value); } var dataContractSerializer = GetCachedSerializer(wrappingType); using (var textWriter = context.WriterFactory(context.HttpContext.Response.Body, writerSettings.Encoding)) { using (var xmlWriter = CreateXmlWriter(textWriter, writerSettings)) { dataContractSerializer.WriteObject(xmlWriter, value); } // Perf: call FlushAsync to call WriteAsync on the stream with any content left in the TextWriter's // buffers. This is better than just letting dispose handle it (which would result in a synchronous // write). await textWriter.FlushAsync(); } }
/// <inheritdoc /> public override Task WriteResponseBodyAsync([NotNull] OutputFormatterContext context) { var response = context.ActionContext.HttpContext.Response; var tempWriterSettings = WriterSettings.Clone(); tempWriterSettings.Encoding = context.SelectedEncoding; var innerStream = context.ActionContext.HttpContext.Response.Body; using (var outputStream = new DelegatingStream(innerStream)) using (var xmlWriter = CreateXmlWriter(outputStream, tempWriterSettings)) { var runtimeType = context.Object == null ? null : context.Object.GetType(); var type = GetSerializableType(context.DeclaredType, runtimeType); var xmlSerializer = CreateSerializer(type); xmlSerializer.Serialize(xmlWriter, context.Object); } return(Task.FromResult(true)); }
/// <inheritdoc /> public string SerializeToString(object item, Type type) { Guard.Guard.Against.Null(item, nameof(item)); Guard.Guard.Against.Null(type, nameof(type)); type = CheckType(type, item); var builder = new StringBuilder(); if (WriterSettings.IsNull()) { using (var writer = new EncodedStringWriter(builder)) new XmlSerializer(type).Serialize(writer, item, Namespaces); } else { using (var stringWriter = new EncodedStringWriter(builder, WriterSettings.Encoding)) using (var writer = XmlWriter.Create(stringWriter, WriterSettings)) new XmlSerializer(type).Serialize(writer, item, Namespaces); } return(builder.ToString()); }
public void GetSetTest() { var settings = new WriterSettings(); foreach (var trueName in Names) { foreach (var name in Names) { settings.Set(name, name == trueName); } foreach (var name in Names) { var expected = name == trueName; var actual = settings.Get(name); if (IsButton(trueName) == IsButton(name) || !IsButton(name)) { Assert.AreEqual(expected, actual); } else { Assert.IsTrue(IsButton(name)); var count = (settings.Get(WriterSettingName.SmallButtons) ? 1 : 0) + (settings.Get(WriterSettingName.MediumButtons) ? 1 : 0) + (settings.Get(WriterSettingName.LargeButtons) ? 1 : 0); Assert.AreEqual(1, count); } } } bool IsButton(WriterSettingName name) => name == WriterSettingName.SmallButtons || name == WriterSettingName.MediumButtons || name == WriterSettingName.LargeButtons; }
/// <inheritdoc /> public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var writerSettings = WriterSettings.Clone(); writerSettings.Encoding = context.ContentType?.Encoding ?? Encoding.UTF8; // Wrap the object only if there is a wrapping type. var value = context.Object; var wrappingType = GetSerializableType(context.ObjectType); if (wrappingType != null && wrappingType != context.ObjectType) { var wrapperProvider = WrapperProviderFactories.GetWrapperProvider(new WrapperProviderContext( declaredType: context.ObjectType, isSerialization: true)); value = wrapperProvider.Wrap(value); } var dataContractSerializer = GetCachedSerializer(wrappingType); using (var textWriter = context.WriterFactory(context.HttpContext.Response.Body, writerSettings.Encoding)) { using (var xmlWriter = CreateXmlWriter(textWriter, writerSettings)) { dataContractSerializer.WriteObject(xmlWriter, value); } } return(TaskCache.CompletedTask); }
/// <summary> /// Incrementally applies a resize transform to fit encoded image into maxAllowedSize limit /// </summary> public static void FitDimensionsToFileSize(Stream srcStream, WriterSettings settings, long maxAllowedSize, Stream dstStream) { float scale = 1.0f; const float minScale = 0.98f; var ms = ResizeImageToMemoryStream(srcStream, scale, settings); try { while (ms.Length > maxAllowedSize) { scale *= (float)Math.Min(Math.Sqrt((float)maxAllowedSize / (float)ms.Length), minScale); ms.Dispose(); ms = ResizeImageToMemoryStream(srcStream, scale, settings); } ms.WriteTo(dstStream); } finally { ms.Dispose(); } }
public bool WriteTypeToFile(TypeDefinition type, IProjectItemFileWriter itemWriter, Dictionary <string, ICollection <string> > membersToSkip, bool shouldBePartial, ILanguage language, out List <WritingInfo> writingInfos, out string theCodeString) { theCodeString = string.Empty; writingInfos = null; StringWriter theWriter = new StringWriter(); bool showCompilerGeneratedMembers = Utilities.IsVbInternalTypeWithoutRootNamespace(type) || Utilities.IsVbInternalTypeWithRootNamespace(type); IFormatter formatter = GetFormatter(theWriter); IWriterSettings settings = new WriterSettings(writeExceptionsAsComments: true, writeFullyQualifiedNames: decompilationPreferences.WriteFullNames, writeDocumentation: decompilationPreferences.WriteDocumentation, showCompilerGeneratedMembers: showCompilerGeneratedMembers, writeLargeNumbersInHex: decompilationPreferences.WriteLargeNumbersInHex); ILanguageWriter writer = language.GetWriter(formatter, this.exceptionFormater, settings); IWriterContextService writerContextService = this.GetWriterContextService(); writer.ExceptionThrown += OnExceptionThrown; writerContextService.ExceptionThrown += OnExceptionThrown; bool exceptionOccurred = false; try { if (!(writer is INamespaceLanguageWriter)) { writingInfos = writer.Write(type, writerContextService); } else { if (shouldBePartial) { writingInfos = (writer as INamespaceLanguageWriter).WritePartialTypeAndNamespaces(type, writerContextService, membersToSkip); } else { writingInfos = (writer as INamespaceLanguageWriter).WriteTypeAndNamespaces(type, writerContextService); } } this.RecordGeneratedFileData(type, itemWriter.FullSourceFilePath, theWriter, formatter, writerContextService, writingInfos); MemoryStream sourceFileStream = new MemoryStream(Encoding.UTF8.GetBytes(theWriter.ToString())); itemWriter.CreateProjectSourceFile(sourceFileStream); sourceFileStream.Close(); theWriter.Close(); } catch (Exception e) { exceptionOccurred = true; string[] exceptionMessageLines = exceptionFormater.Format(e, type.FullName, itemWriter.FullSourceFilePath); string exceptionMessage = string.Join(Environment.NewLine, exceptionMessageLines); string commentedExceptionMessage = language.CommentLines(exceptionMessage); itemWriter.CreateProjectSourceFile(new MemoryStream(Encoding.UTF8.GetBytes(commentedExceptionMessage))); OnExceptionThrown(this, e); } theCodeString = theWriter.ToString(); writer.ExceptionThrown -= OnExceptionThrown; writerContextService.ExceptionThrown -= OnExceptionThrown; return(exceptionOccurred || writerContextService.ExceptionsWhileDecompiling.Any()); }
public override Task <DecompileTypeResponse> DecompileType(DecompileTypeRequest request, ServerCallContext context) { if (!this.decompilationContext.DecompilationContext.FilePathToType.ContainsKey(request.FilePath)) { throw new RpcException(new Status(StatusCode.NotFound, "No type to corresponding file path")); } TypeDefinition type = this.decompilationContext.DecompilationContext.FilePathToType[request.FilePath]; IExceptionFormatter exceptionFormatter = SimpleExceptionFormatter.Instance; ILanguage language = LanguageFactory.GetLanguage(CSharpVersion.V7); StringWriter theWriter = new StringWriter(); CodeFormatter formatter = new CodeFormatter(theWriter); IWriterSettings settings = new WriterSettings(writeExceptionsAsComments: true, writeFullyQualifiedNames: false, writeDocumentation: true, showCompilerGeneratedMembers: false, writeLargeNumbersInHex: false); ILanguageWriter writer = language.GetWriter(formatter, exceptionFormatter, settings); IWriterContextService writerContextService = new TypeCollisionWriterContextService(new ProjectGenerationDecompilationCacheService(), true); try { List <WritingInfo> infos = (writer as INamespaceLanguageWriter).WriteTypeAndNamespaces(type, writerContextService); DecompiledTypeMetadata decompiledTypeMetadata = new DecompiledTypeMetadata(); decompiledTypeMetadata.CodeSpanToMemberReference.AddRange(formatter.CodeSpanToMemberReference); foreach (WritingInfo info in infos) { decompiledTypeMetadata.MemberDeclarationToCodeSpan.AddRange(info.MemberDeclarationToCodeSpan); decompiledTypeMetadata.CodeMappingInfo.NodeToCodeMap.AddRange(info.CodeMappingInfo.NodeToCodeMap); decompiledTypeMetadata.CodeMappingInfo.InstructionToCodeMap.AddRange(info.CodeMappingInfo.InstructionToCodeMap); decompiledTypeMetadata.CodeMappingInfo.FieldConstantValueToCodeMap.AddRange(info.CodeMappingInfo.FieldConstantValueToCodeMap); decompiledTypeMetadata.CodeMappingInfo.VariableToCodeMap.AddRange(info.CodeMappingInfo.VariableToCodeMap); decompiledTypeMetadata.CodeMappingInfo.ParameterToCodeMap.AddRange(info.CodeMappingInfo.ParameterToCodeMap); decompiledTypeMetadata.CodeMappingInfo.MethodDefinitionToMethodReturnTypeCodeMap.AddRange(info.CodeMappingInfo.MethodDefinitionToMethodReturnTypeCodeMap); decompiledTypeMetadata.CodeMappingInfo.FieldDefinitionToFieldTypeCodeMap.AddRange(info.CodeMappingInfo.FieldDefinitionToFieldTypeCodeMap); decompiledTypeMetadata.CodeMappingInfo.PropertyDefinitionToPropertyTypeCodeMap.AddRange(info.CodeMappingInfo.PropertyDefinitionToPropertyTypeCodeMap); decompiledTypeMetadata.CodeMappingInfo.EventDefinitionToEventTypeCodeMap.AddRange(info.CodeMappingInfo.EventDefinitionToEventTypeCodeMap); decompiledTypeMetadata.CodeMappingInfo.ParameterDefinitionToParameterTypeCodeMap.AddRange(info.CodeMappingInfo.ParameterDefinitionToParameterTypeCodeMap); decompiledTypeMetadata.CodeMappingInfo.VariableDefinitionToVariableTypeCodeMap.AddRange(info.CodeMappingInfo.VariableDefinitionToVariableTypeCodeMap); } this.decompilationContext.AddTypeMetadataToCache(type, decompiledTypeMetadata); return(Task.FromResult(new DecompileTypeResponse() { SourceCode = theWriter.ToString() })); } catch (Exception e) { string[] exceptionMessageLines = exceptionFormatter.Format(e, type.FullName, null); string exceptionMessage = string.Join(Environment.NewLine, exceptionMessageLines); string commentedExceptionMessage = language.CommentLines(exceptionMessage); return(Task.FromResult(new DecompileTypeResponse() { SourceCode = commentedExceptionMessage })); } }
/// <summary> /// Sets barcode type by name. /// </summary> /// <param name="settings">The barcode writer settings.</param> /// <param name="name">The name of barcode type.</param> private static void SetBarcodeType(WriterSettings settings, string name) { switch (name) { case "AustralianPost": settings.Barcode = BarcodeType.AustralianPost; break; case "Aztec": settings.Barcode = BarcodeType.Aztec; break; case "Codabar": settings.Barcode = BarcodeType.Codabar; break; case "Code11": settings.Barcode = BarcodeType.Code11; break; case "Code128": settings.Barcode = BarcodeType.Code128; break; case "Code16K": settings.Barcode = BarcodeType.Code16K; break; case "Code39": settings.Barcode = BarcodeType.Code39; break; case "Code93": settings.Barcode = BarcodeType.Code93; break; case "DataMatrix": settings.Barcode = BarcodeType.DataMatrix; break; case "DotCode": settings.Barcode = BarcodeType.DotCode; break; case "DutchKIX": settings.Barcode = BarcodeType.DutchKIX; break; case "EAN13": settings.Barcode = BarcodeType.EAN13; break; case "EAN13Plus2": settings.Barcode = BarcodeType.EAN13Plus2; break; case "EAN13Plus5": settings.Barcode = BarcodeType.EAN13Plus5; break; case "EAN8": settings.Barcode = BarcodeType.EAN8; break; case "EAN8Plus2": settings.Barcode = BarcodeType.EAN8Plus2; break; case "EAN8Plus5": settings.Barcode = BarcodeType.EAN8Plus5; break; case "HanXinCode": settings.Barcode = BarcodeType.HanXinCode; break; case "IATA2of5": settings.Barcode = BarcodeType.IATA2of5; break; case "IntelligentMail": settings.Barcode = BarcodeType.IntelligentMail; break; case "Interleaved2of5": settings.Barcode = BarcodeType.Interleaved2of5; break; case "Mailmark4StateC": settings.Barcode = BarcodeType.Mailmark4StateC; break; case "Mailmark4StateL": settings.Barcode = BarcodeType.Mailmark4StateL; break; case "Matrix2of5": settings.Barcode = BarcodeType.Matrix2of5; break; case "MaxiCode": settings.Barcode = BarcodeType.MaxiCode; break; case "MicroPDF417": settings.Barcode = BarcodeType.MicroPDF417; break; case "MicroQR": settings.Barcode = BarcodeType.MicroQR; break; case "MSI": settings.Barcode = BarcodeType.MSI; break; case "PDF417": settings.Barcode = BarcodeType.PDF417; break; case "PDF417Compact": settings.Barcode = BarcodeType.PDF417Compact; break; case "PatchCode": settings.Barcode = BarcodeType.PatchCode; break; case "Pharmacode": settings.Barcode = BarcodeType.Pharmacode; break; case "Planet": settings.Barcode = BarcodeType.Planet; break; case "Postnet": settings.Barcode = BarcodeType.Postnet; break; case "QR": settings.Barcode = BarcodeType.QR; break; case "RoyalMail": settings.Barcode = BarcodeType.RoyalMail; break; case "RSS14": settings.Barcode = BarcodeType.RSS14; break; case "RSS14Stacked": settings.Barcode = BarcodeType.RSS14Stacked; break; case "RSSExpanded": settings.Barcode = BarcodeType.RSSExpanded; break; case "RSSExpandedStacked": settings.Barcode = BarcodeType.RSSExpandedStacked; break; case "RSSLimited": settings.Barcode = BarcodeType.RSSLimited; break; case "Standard2of5": settings.Barcode = BarcodeType.Standard2of5; break; case "Telepen": settings.Barcode = BarcodeType.Telepen; break; case "UPCA": settings.Barcode = BarcodeType.UPCA; break; case "UPCAPlus2": settings.Barcode = BarcodeType.UPCAPlus2; break; case "UPCAPlus5": settings.Barcode = BarcodeType.UPCAPlus5; break; case "UPCE": settings.Barcode = BarcodeType.UPCE; break; case "UPCEPlus2": settings.Barcode = BarcodeType.UPCEPlus2; break; case "UPCEPlus5": settings.Barcode = BarcodeType.UPCEPlus5; break; default: throw new NotSupportedException(string.Format("Barcode type '{0}' is undefined.", name)); } }
public SettingsDialog(WriterSettings settings) { InitializeComponent(); DataContext = settings; }
public static DialogResult ShowEncoderDialog(Aurigma.GraphicsMill.Bitmap bitmap, System.Windows.Forms.UserControl propertyPage, WriterSettings encoderOptions) { IEncoderPropertyPage tpp = (IEncoderPropertyPage)propertyPage; tpp.Bitmap = bitmap; tpp.EncoderOptions = encoderOptions; EncoderOptionsDialog dialog = new EncoderOptionsDialog(); dialog.SuspendLayout(); dialog.ClientSize = new System.Drawing.Size(propertyPage.Width + 118, Math.Max(propertyPage.Height + 16, dialog.buttonCancel.Location.Y + dialog.buttonCancel.Size.Height + 8)); propertyPage.Location = new System.Drawing.Point(8, 8); dialog.Controls.Add(propertyPage); dialog.buttonOK.Left = propertyPage.Width + 24; dialog.buttonCancel.Left = propertyPage.Width + 24; dialog.ResumeLayout(false); dialog.Text = tpp.Title; return(dialog.ShowDialog()); }
/// <summary> /// Resizes an image and gets a result as a memory stream /// </summary> private static MemoryStream ResizeImageToMemoryStream(Stream stream, float scale, WriterSettings settings) { var ms = new MemoryStream(); using (var reader = ImageReader.Create(stream)) using (var writer = ImageWriter.Create(ms, settings)) using (var resize = new Resize((int)(reader.Width * scale), (int)(reader.Height * scale))) { Pipeline.Run(reader + resize + writer); writer.Close(); } return(ms); }
protected void SendStickyInput(string inputText, WriterSettings writerSettings) { textWriter.SendStickyInput(inputText, writerSettings, SetKeyTitle); }
public BarcodeWriterToolForm(WriterSettings settings) : this() { barcodeWriterSettingsControl1.BarcodeWriterSettings = settings; barcodeWriterSettingsControl1.CanChangeBarcodeSize = false; }
/// <summary> /// Save dialog button is clicked. /// </summary> private void SaveDialogButtonClicked(object sender, DialogClickEventArgs args) { // get colors edit text views EditText foregroundColorEdtiText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.barcode_foreground_edit_text); EditText backgroundColorEdtiText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.barcode_backround_edit_text); backgroundColorEdtiText.TextChanged -= ColorEdtiText_TextChanged; foregroundColorEdtiText.TextChanged -= ColorEdtiText_TextChanged; // if "Save" button clicked if (args.Which == (int)DialogButtonType.Positive) { // get file path EditText filePathEditText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.filepath_edit_text); EditText fileNameEditText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.filename_edit_text); if (string.IsNullOrWhiteSpace(fileNameEditText.Text)) { Toast.MakeText(_barcodeViewerActivity, Resource.String.filename_empty_message, ToastLength.Long).Show(); return; } if (string.IsNullOrWhiteSpace(filePathEditText.Text)) { Toast.MakeText(_barcodeViewerActivity, Resource.String.filepath_empty_message, ToastLength.Long).Show(); return; } // get width and height EditText widthEditText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.barcode_width_edit_text); EditText heightEditText = _saveBarcodeImageDialog.FindViewById <EditText>(Resource.Id.barcode_height_edit_text); // save showing settings WriterSettings previousSettings = _barcodeWriter.Settings.Clone(); // set colors to the writer _barcodeWriter.Settings.ForeColor = ((ColorDrawable)foregroundColorEdtiText.Background).Color; _barcodeWriter.Settings.BackColor = ((ColorDrawable)backgroundColorEdtiText.Background).Color; // get path to the file string fullPathWithExtention = System.IO.Path.Combine(filePathEditText.Text, fileNameEditText.Text) + ".png"; try { int width = Int32.Parse(widthEditText.Text); int height = Int32.Parse(heightEditText.Text); // create a file using (FileStream outStream = new FileStream(fullPathWithExtention, FileMode.Create, FileAccess.Write)) { // if barcode type is EAN or UPCA or UPCE type if (Utils.IsEanOrUpcaOrUpceBarcode(_barcodeWriter.Settings.Barcode)) { _barcodeWriter.Settings.Height = height; _barcodeWriter.Settings.SetWidth(width); _barcodeWriter.Settings.ValuePaint.TextSize = Resources.GetDimensionPixelSize(Resource.Dimension.barcode_value_viewer_text_size); // draw the barcode // create the barcode image using (Bitmap barcodeImage = _barcodeWriter.GetBarcodeAsBitmap()) { // save the barcode image to the file barcodeImage.Compress(Bitmap.CompressFormat.Png, 100, outStream); } } else { // create the barcode image using (Bitmap barcodeImage = _barcodeWriter.GetBarcodeAsBitmap(width, height, UnitOfMeasure.Pixels)) { // save the barcode image to the file barcodeImage.Compress(Bitmap.CompressFormat.Png, 100, outStream); } } } // notify user that the barcode image is successfully saved to the file string message = string.Format(Resources.GetString(Resource.String.barcode_saved_message), fullPathWithExtention); Toast.MakeText(_barcodeViewerActivity, message, ToastLength.Long).Show(); } catch (Exception e) { Toast.MakeText(_barcodeViewerActivity, e.Message, ToastLength.Long).Show(); if (File.Exists(fullPathWithExtention)) { File.Delete(fullPathWithExtention); } } // return showing settings _barcodeWriter.Settings = previousSettings; } }