/// <summary> /// Try to modify the chart plots settings. /// </summary> /// <param name="plots">Reference to chart plots settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetPlotArea(XlsxChartPlotsCollection plots) { if (plots == null) { return BooleanResult.CreateErroResult("legend can not be null"); } try { var chartPlots = Chart.PlotArea; chartPlots.Fill.Color = plots.Parent.GetBackColor(); chartPlots.Border.SetBorder(plots.Border); var series = plots.SelectMany(plot => plot.Series); foreach (var serie in series) { AddColorToSerie(serie); } return BooleanResult.SuccessResult; } catch (Exception e) { return BooleanResult.FromException(e); } }
private static IResult SaveToFile(this NativeIO.MemoryStream stream, string fileName, SaveOptions options = null) { try { var safeOptions = options; if (options == null) { safeOptions = SaveOptions.Default; } string parsedFullFilenamePath = Path.PathResolver(fileName); string directoryName = NativeIO.Path.GetDirectoryName(parsedFullFilenamePath); NativeIO.DirectoryInfo di = new NativeIO.DirectoryInfo(directoryName); bool existDirectory = di.Exists; if (!existDirectory) { if (safeOptions.CreateFolderIfNotExist) { NativeIO.Directory.CreateDirectory(directoryName); } } using (var fs = new NativeIO.FileStream(parsedFullFilenamePath, NativeIO.FileMode.Create, NativeIO.FileAccess.ReadWrite, NativeIO.FileShare.ReadWrite)) { stream.WriteTo(fs); } return(BooleanResult.SuccessResult); } catch (Exception ex) { return(BooleanResult.FromException(ex)); } }
/// <summary> /// Try to modify the chart title settings. /// </summary> /// <param name="title">Reference to title settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetTitle(XlsxChartTitle title) { if (title == null) { return BooleanResult.CreateErroResult("title can not be null"); } if (title.Show == YesNo.No) { return BooleanResult.SuccessResult; } try { var chartTitle = Chart.Title; chartTitle.Text = title.Text; chartTitle.Font.SetFromFont(title.Font.ToFont()); chartTitle.Font.Color = title.Font.GetColor(); chartTitle.Rotation = title.Orientation.ToAngle(); chartTitle.TextVertical = title.Orientation == TextOrientation.Vertical ? eTextVerticalType.WordArtVertical : eTextVerticalType.Horizontal; return BooleanResult.SuccessResult; } catch (Exception e) { return BooleanResult.FromException(e); } }
/// <summary> /// Try to modify the chart legend settings. /// </summary> /// <param name="legend">Reference to legend settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetLegend(XlsxChartLegend legend) { if (legend == null) { return BooleanResult.CreateErroResult("legend can not be null"); } if (legend.Show == YesNo.No) { return BooleanResult.SuccessResult; } try { var chartLegend = Chart.Legend; chartLegend.Font.SetFromFont(legend.Font.ToFont()); chartLegend.Font.Color = legend.Font.GetColor(); chartLegend.Position = legend.Location.AsEnumType<eLegendPosition>(); chartLegend.Border.SetBorder(legend.Border); return BooleanResult.SuccessResult; } catch (Exception e) { return BooleanResult.FromException(e); } }
private IResult SetShadowEffect(XlsxBaseShadow shadow) { if (shadow.Show == YesNo.No) { return BooleanResult.SuccessResult; } var root = XmlWriter.GetXmlNode(XmlChartHelper.ChartSpaceRootNode); if (root == null) { return BooleanResult.SuccessResult; } try { var exist = XmlWriter.TryGetElementFrom(root, "c:spPr", out var shapePropertiesNode); shapePropertiesNode.AddEffectContainerNode(shadow, XmlWriter); if (!exist) { root.AppendChild(shapePropertiesNode); } return BooleanResult.SuccessResult; } catch (Exception e) { return BooleanResult.FromException(e); } }
/// <summary> /// Try to modify the chart border settings. /// </summary> /// <param name="border">Reference to border settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetBorder(XlsxBorder border) { if (border == null) { return BooleanResult.CreateErroResult("border can not be null"); } if (border.Show == YesNo.No) { return BooleanResult.SuccessResult; } try { var chartBorder = Chart.Border; chartBorder.Fill.Style = eFillStyle.SolidFill; chartBorder.Fill.Color = border.GetColor(); chartBorder.Fill.Transparancy = border.Transparency; chartBorder.LineStyle = border.Style.ToEppLineStyle(); chartBorder.Width = border.Width; return BooleanResult.SuccessResult; } catch (Exception e) { return BooleanResult.FromException(e); } }
private IResult SetShadowEffect(XlsxBaseShadow shadow, string pictureName) { if (shadow.Show == YesNo.No) { return(BooleanResult.SuccessResult); } var pictureNode = XmlWriter.GetXmlNode($"xdr:wsDr/xdr:twoCellAnchor/xdr:pic/xdr:nvPicPr/xdr:cNvPr[@name='{pictureName}']"); var root = pictureNode?.ParentNode?.ParentNode; if (root == null) { return(BooleanResult.SuccessResult); } try { var exist = XmlWriter.TryGetElementFrom(root, "xdr:spPr", out var shapePropertiesNode); shapePropertiesNode.AddEffectContainerNode(shadow, XmlWriter); if (!exist) { root.AppendChild(shapePropertiesNode); } return(BooleanResult.SuccessResult); } catch (Exception e) { return(BooleanResult.FromException(e)); } }
/// <summary> /// Saves this stream into a file with name specified by parameter <paramref name="fileName"/>. /// You can indicate whether to automatically create the destination path if it does not exist. By default it will try to create the destination path. /// The use of the <b>~</b> character is allowed to indicate relative paths, and you can also use <b>UNC</b> path. /// </summary> /// <param name="stream">Stream to save</param> /// <param name="fileName">Destination file path. Absolute or relative (~) paths are allowed</param> /// <param name="options">Output save options</param> /// <returns> /// A <see cref="IResult"/> object that contains the operation result /// </returns> public static IResult SaveToFile(this NativeIO.Stream stream, string fileName, SaveOptions options = null) { Logger.Instance.Debug(""); Logger.Instance.Debug(" Assembly: iTin.Core.IO, Namespace: iTin.Core.IO, Class: StreamExtensions"); Logger.Instance.Debug(" Saves this stream into a file with name specified by filename"); Logger.Instance.Debug($" > Signature: ({typeof(IResult)}) SaveToFile(this {typeof(NativeIO.Stream)}, {typeof(string)})"); SentinelHelper.ArgumentNull(stream, nameof(stream)); Logger.Instance.Debug($" > stream: {stream.Length} bytes"); SentinelHelper.ArgumentNull(fileName, nameof(fileName)); Logger.Instance.Debug($" > fileName: {fileName}"); try { IResult saveResult; using (var memoryStream = stream as NativeIO.MemoryStream ?? stream.ToMemoryStream()) { Logger.Instance.Debug(" > Output: Success: True"); saveResult = memoryStream.SaveToFile(fileName, options); } return(saveResult); } catch (Exception ex) { Logger.Instance.Error("Error while save stream to file", ex); Logger.Instance.Info(" > Output: Success: False"); return(BooleanResult.FromException(ex)); } }
/// <summary> /// Try to modify the picture content settings. /// </summary> /// <param name="content">Reference to picture content settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetContent(XlsxPictureContent content) { if (content == null) { return(BooleanResult.CreateErroResult("border can not be null")); } if (content.Show == YesNo.No) { return(BooleanResult.SuccessResult); } try { var element = Picture.Fill; element.Style = eFillStyle.SolidFill; element.Color = content.GetColor(); //element.Transparancy = content.Transparency; return(BooleanResult.SuccessResult); } catch (Exception e) { return(BooleanResult.FromException(e)); } }
private IResult SetReflectionEffect(XlsxReflectionShapeEffect reflection, string shapeName) { if (reflection.Show == YesNo.No) { return(BooleanResult.SuccessResult); } var shapeNode = XmlWriter.GetXmlNode($"xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:nvSpPr/xdr:cNvPr[@name='{shapeName}']"); var root = shapeNode?.ParentNode?.ParentNode; if (root == null) { return(BooleanResult.SuccessResult); } try { var exist = XmlWriter.TryGetElementFrom(root, "xdr:spPr", out var shapePropertiesNode); shapePropertiesNode.AddEffectContainerNode(reflection, XmlWriter); if (!exist) { root.AppendChild(shapePropertiesNode); } return(BooleanResult.SuccessResult); } catch (Exception e) { return(BooleanResult.FromException(e)); } }
/// <summary> /// Try to modify the shape content settings. /// </summary> /// <param name="content">Reference to picture content settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetContent(XlsxShapeContent content) { if (content == null) { return(BooleanResult.CreateErroResult("border can not be null")); } if (content.Show == YesNo.No) { return(BooleanResult.SuccessResult); } try { var element = Shape.Fill; element.Style = eFillStyle.SolidFill; element.Color = content.GetColor(); //element.Transparancy = content.Transparency; Shape.TextAlignment = content.Alignment.Horizontal.ToEppTextHorizontalAlignment(); return(BooleanResult.SuccessResult); } catch (Exception e) { return(BooleanResult.FromException(e)); } }
/// <summary> /// Saves this input into a file. /// </summary> /// <param name="outputPath">The output path. The use of the <b>~</b> character is allowed to indicate relative paths, and you can also use <b>UNC</b> path.</param> /// <param name="options">Save options</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> which implements the <see cref="IResult"/> interface reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Result</b> property will contain the Result; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return Result is <see cref="bool"/>, which contains the operation result /// </para> /// </returns> public IResult SaveToFile(string outputPath, SaveOptions options = null) { try { return(ToStream().SaveToFile(iTinIO.Path.PathResolver(outputPath), options ?? SaveOptions.Default)); } catch (Exception ex) { return(BooleanResult.FromException(ex)); } }
/// <summary> /// Try to modify the chart content settings. /// </summary> /// <param name="content">Reference to chart settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetContent(XlsxChart content) { try { Chart.Fill.Color = content.GetBackColor(); return BooleanResult.SuccessResult; } catch (Exception e) { return BooleanResult.FromException(e); } }
/// <summary> /// Try to modify the shape text. /// </summary> /// <param name="text">Reference to text shape to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetText(string text) { try { Shape.Text = text; return(BooleanResult.SuccessResult); } catch (Exception e) { return(BooleanResult.FromException(e)); } }
/// <summary> /// Try to modify the shape style. /// </summary> /// <param name="style">Reference to shape style to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetShapeStyle(ShapeType style) { try { Shape.Style = style.AsEnumType <eShapeStyle>(); return(BooleanResult.SuccessResult); } catch (Exception e) { return(BooleanResult.FromException(e)); } }
/// <summary> /// Try to Create a zip file with specified elements. /// </summary> /// <param name="items">Element to compress.</param> /// <param name="itemsExtension">File elements extension.</param> /// <param name="outputPath">Zip output path.</param> /// <returns> /// A <see cref="string"/> than contains the path to created file. /// </returns> public static IResult TrySaveAsZip(this IEnumerable <byte[]> items, string itemsExtension, string outputPath) { IList <byte[]> elementList = items as IList <byte[]> ?? items.ToList(); SentinelHelper.ArgumentNull(elementList, nameof(items)); try { string zipFilenameWithoutExtension = Path.GetFileNameWithoutExtension(outputPath); bool existPath = File.Exists(outputPath); if (existPath) { File.Delete(outputPath); } var outputDirectoryName = Path.GetDirectoryName(outputPath); var di = Directory.CreateDirectory(outputDirectoryName); using (var zip = new ZipFile(outputPath)) { int currentFile = 0; bool multipleElements = elementList.Count > 1; var filenameBuilder = new StringBuilder(); foreach (var element in elementList) { filenameBuilder.Clear(); filenameBuilder.Append(zipFilenameWithoutExtension); if (multipleElements) { filenameBuilder.Append(currentFile); } filenameBuilder.Append("."); filenameBuilder.Append(itemsExtension); zip.AddEntry(filenameBuilder.ToString(), element); currentFile++; } zip.Save(); } return(BooleanResult.SuccessResult); } catch (Exception ex) { return(BooleanResult.FromException(ex)); } }
/// <summary> /// Executes the command synchronously. /// </summary> /// <returns> /// Operation result /// </returns> public IResult Execute() { try { OnNotifyFeatureCommandExecuting(new NotifyFeatureCommandExecutingEventArgs(this)); StringBuilder programResult = SystemHelper.RunCommand("dism", Arguments == null ? Command : $"{Command} /{Arguments}"); OnNotifyFeatureCommandExecuted(new NotifyFeatureCommandExecutedEventArgs(this, programResult, BooleanResult.SuccessResult)); return(BooleanResult.SuccessResult); } catch (Exception ex) { return(BooleanResult.FromException(ex)); } }
/// <summary> /// Try to modify the picture size settings. /// </summary> /// <param name="size">Reference to picture size settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetSize(XlsxBaseSize size) { if (size == null) { return(BooleanResult.CreateErroResult("size can not be null")); } try { switch (size.Type) { case KnownSizeType.Percent: Picture.SetSize((int)((XlsxPercentSize)size).Value); break; case KnownSizeType.NullableSize: var nullableSize = (XlsxNullableSize)size; var hasWidth = nullableSize.Width.HasValue; var hasHeight = nullableSize.Height.HasValue; if (!hasWidth && hasHeight) { Picture.SetSize(Picture.Image.Width, nullableSize.Height.Value); } else if (hasWidth && !hasHeight) { Picture.SetSize(nullableSize.Width.Value, Picture.Image.Height); } else if (hasWidth && hasHeight) { Picture.SetSize(nullableSize.Width.Value, nullableSize.Height.Value); } break; default: case KnownSizeType.Size: Picture.SetSize(((XlsxSize)size).Width, ((XlsxSize)size).Height); break; } return(BooleanResult.SuccessResult); } catch (Exception e) { return(BooleanResult.FromException(e)); } }
/// <summary> /// Executes the command asynchronously. /// </summary> /// <returns> /// Operation result /// </returns> public async Task <IResult> ExecuteAsync() { try { OnNotifyFeatureCommandExecuting(new NotifyFeatureCommandExecutingEventArgs(this)); StringBuilder programResult = await SystemHelper.RunCommandAsync("dism", Arguments == null?Command : $"{Command} /{Arguments}"); OnNotifyFeatureCommandExecuted(new NotifyFeatureCommandExecutedEventArgs(this, programResult, BooleanResult.SuccessResult)); return(await Task.FromResult(BooleanResult.SuccessResult)); } catch (Exception ex) { return(await Task.FromResult <IResult>(BooleanResult.FromException(ex))); } }
/// <summary> /// Try to modify the chart size settings. /// </summary> /// <param name="size">Reference to chart size settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetSize(XlsxSize size) { if (size == null) { return BooleanResult.CreateErroResult("size can not be null"); } try { Chart.SetSize(size.Width, size.Height); return BooleanResult.SuccessResult; } catch (Exception e) { return BooleanResult.FromException(e); } }
/// <summary> /// Try to modify the shape font settings. /// </summary> /// <param name="font">Reference to shape font settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetFont(FontModel font) { if (font == null) { return(BooleanResult.CreateErroResult("border can not be null")); } try { Shape.Font.SetFromFont(font.ToFont()); return(BooleanResult.SuccessResult); } catch (Exception e) { return(BooleanResult.FromException(e)); } }
private IResult ExecuteImpl(OutputResultData data) { if (data == null) { return(BooleanResult.NullResult); } var safeOptions = SaveOptions ?? SaveOptions.Default; var outputExtension = data.Zipped ? ZipExtension : PdfExtension; var normalizedPath = iTinIO.Path.PathResolver(OutputPath); var directoryName = NativeIO.Path.GetDirectoryName(normalizedPath); var filename = NativeIO.Path.GetFileName(normalizedPath); var filenameWithoutExtension = NativeIO.Path.GetFileNameWithoutExtension(filename); var filenameWithExtension = $"{filenameWithoutExtension}.{outputExtension}"; var outPath = NativeIO.Path.Combine(directoryName, filenameWithExtension); try { var actionResult = BooleanResult.SuccessResult; bool isMergedFile = data.Configuration is PdfObjectConfig; if (isMergedFile) { var streamIsZipped = ((PdfObjectConfig)data.Configuration).AllowCompression; actionResult.Success = data.Zipped ? streamIsZipped ? data.UncompressOutputStream.Clone().TrySaveAsZip(PdfExtension, outPath).Success : data.UncompressOutputStream.Clone().SaveToFile(outPath, safeOptions).Success : data.OutputStream.Clone().SaveToFile(outPath, safeOptions).Success; } else { actionResult.Success = data.Zipped ? data.UncompressOutputStream.Clone().SaveToFile(outPath, safeOptions).Success : data.OutputStream.Clone().SaveToFile(outPath, safeOptions).Success; } return(actionResult); } catch (Exception ex) { return(BooleanResult.FromException(ex)); } }
/// <summary> /// Try to modify the chart location settings. /// </summary> /// <param name="range">Reference to range location settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetPosition(XlsxBaseRange range) { if (range == null) { return BooleanResult.CreateErroResult("border can not be null"); } try { ExcelAddressBase locationAddress = range.ToEppExcelAddress(); Chart.SetPosition(locationAddress.Start.Row - 1, 0, locationAddress.Start.Column - 1, 0); return BooleanResult.SuccessResult; } catch (Exception e) { return BooleanResult.FromException(e); } }
private static IResult TryRegisterFont(string fontName, string fontFullPath) { try { var isRegistered = FontFactory.IsRegistered(fontName); if (isRegistered) { return(BooleanResult.SuccessResult); } var path = iTinIO.Path.PathResolver(fontFullPath); FontFactory.Register(path, fontName); return(BooleanResult.SuccessResult); } catch (Exception ex) { return(BooleanResult.FromException(ex)); } }
/// <summary> /// Saves this stream into a file with name specified by parameter <paramref name="fileName"/>. /// You can indicate whether to automatically create the destination path if it does not exist. By default it will try to create the destination path. /// The use of the <c>~</c> character is allowed to indicate relative paths, and you can also use <b>UNC</b> path. /// </summary> /// <param name="stream">Stream to save</param> /// <param name="fileName">Destination file path. Absolute or relative (~) paths are allowed</param> /// <param name="options">Output save options</param> /// <returns> /// A <see cref="IResult"/> object that contains the operation result /// </returns> public static IResult SaveToFile(this NativeIO.Stream stream, string fileName, SaveOptions options = null) { SentinelHelper.ArgumentNull(stream, nameof(stream)); SentinelHelper.ArgumentNull(fileName, nameof(fileName)); try { IResult saveResult; using (var memoryStream = stream as NativeIO.MemoryStream ?? stream.ToMemoryStream()) { saveResult = memoryStream.SaveToFile(fileName, options); } return(saveResult); } catch (Exception ex) { return(BooleanResult.FromException(ex)); } }
/// <summary> /// Try to modify the shape effects settings. /// </summary> /// <param name="effects">Reference to chart shape effects settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetShapeEffects(XlsxShapeEffects effects) { if (effects == null) { return BooleanResult.CreateErroResult("size can not be null"); } try { SetIlluminationEffect(effects.Illumination); SetShadowEffect(effects.Shadow); SetReflectionEffect(effects.Reflection); SetSoftEdgeEffect(effects.SoftEdge); return BooleanResult.SuccessResult; } catch (Exception e) { return BooleanResult.FromException(e); } }
/// <summary> /// Try to modify the chart axes settings. /// </summary> /// <param name="axes">Reference to axes settings to apply</param> /// <returns> /// <para> /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b> /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in. /// </para> /// <para> /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result /// </para> /// </returns> public IResult SetAxes(XlsxChartAxes axes) { if (axes == null) { return BooleanResult.CreateErroResult("axes can not be null"); } var chartAxes = Chart.Axis; var axesList = chartAxes.ToList(); var hasAnyAxes = axesList.Any(); if (!hasAnyAxes) { return BooleanResult.SuccessResult; } try { var axesListAsXml = GetXmlAxis().ToList(); // Primary axis axesList[0].SetAxis(axesListAsXml[0], axes.Primary.Category, XmlWriter); axesList[1].SetAxis(axesListAsXml[1], axes.Primary.Values, XmlWriter); // Secondary axis if (axesList.Count <= 2) { return BooleanResult.SuccessResult; } axesList[2].SetAxis(axesListAsXml[2], axes.Secondary.Category, XmlWriter); axesList[3].SetAxis(axesListAsXml[3], axes.Secondary.Values, XmlWriter); return BooleanResult.SuccessResult; } catch (Exception e) { return BooleanResult.FromException(e); } }