/// <summary> /// Returns the specified byte. /// </summary> /// <param name="value">Reference value.</param> /// <param name="onebyte">Byte to retrieve.</param> /// <returns></returns> public static byte GetByte(this int value, Bytes onebyte) { SentinelHelper.IsEnumValid(onebyte); SentinelHelper.IsTrue((byte)onebyte > (byte)Bytes.Byte03); return(value.GetByte((byte)onebyte)); }
/// <summary> /// Returns the current state of the specified bit. /// </summary> /// <param name="value">Reference value.</param> /// <param name="bit">Bit to check.</param> /// <returns> /// Returns <b>1</b> if specified bit is active; otherwise <b>0</b>. /// </returns> public static uint GetBit(this uint value, Bits bit) { SentinelHelper.IsEnumValid(bit); SentinelHelper.IsTrue((byte)bit > 31); return(value.GetBit((byte)bit)); }
/// <summary> /// Create or return an element with the specified Prefix, LocalName and NamespaceUri, and adds it to the document in the specified node. /// </summary> /// <param name="root">The root node of new element.</param> /// <param name="prefix">The prefix of the new element.</param> /// <param name="localName">The local name of the new element.</param> /// <param name="namespaceUri">The namespace URI of the new element.</param> /// <returns> /// The new <see cref="System.Xml.XmlNode" />. /// </returns> /// <exception cref="T:System.ArgumentNullException">If <paramref name="root" /> is <c>null</c>.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="prefix" /> is empty.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="prefix" /> length is less than 1.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="localName" /> is empty.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="localName" /> length is less than 1.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="namespaceUri" /> is empty.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="namespaceUri" /> length is less than 1.</exception> public static XmlNode CreateOrDefaultAndAppendElementToNode(XmlNode root, string prefix, string localName, string namespaceUri) { SentinelHelper.ArgumentNull(root); SentinelHelper.IsTrue(string.IsNullOrEmpty(prefix), "No puede estar vacio"); SentinelHelper.IsTrue(prefix.Length < 1, "La longitud minima ha de ser 1"); SentinelHelper.IsTrue(string.IsNullOrEmpty(localName), "No puede estar vacio"); SentinelHelper.IsTrue(localName.Length < 1, "La longitud minima ha de ser 1"); SentinelHelper.IsTrue(string.IsNullOrEmpty(namespaceUri), "No puede estar vacio"); SentinelHelper.IsTrue(namespaceUri.Length < 1, "La longitud minima ha de ser 1"); var element = new StringBuilder(); element.Append(prefix); element.Append(":"); element.Append(localName); var exist = HasElement(root, element.ToString()); var tempNode = exist ? GetXmlNode(root, element.ToString()) : CreateElement(prefix, localName, namespaceUri); if (root == null) { ChartXml.AppendChild(tempNode); } else { root.AppendChild(tempNode); } return(tempNode); }
/// <summary> /// Try to get the item in the specified node if exist is returned in the parameter <paramref name="node"/>, otherwise will contain <c>null</c>, if the operation is performed returns <c>true</c>. /// </summary> /// <param name="root">The root node of new element.</param> /// <param name="name">The element name.</param> /// <param name="node">The output node.</param> /// <returns> /// <c>true</c> if exist; otherwise, <c>false</c>. /// </returns> /// <exception cref="T:System.ArgumentNullException">If <paramref name="root" /> is <c>null</c>.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> is empty.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> length is less than 3.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> contains white spaces.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> has not correct format.</exception> public static bool TryGetElementFrom(XmlNode root, string name, out XmlNode node) { SentinelHelper.ArgumentNull(root); SentinelHelper.IsTrue(name.Length <= 3, "El parametro element debe contener al menos tres caracteres"); SentinelHelper.IsTrue(string.IsNullOrEmpty(name), "El parametro element no puede estar en blanco"); SentinelHelper.IsFalse(name.Contains(":"), "El formato no es correcto. Se esperaba prefijo:localname"); SentinelHelper.IsTrue(name.Contains(" "), "El formato no es correcto. No se permiten espacios en el elemento"); var exist = HasElement(root, name); if (exist) { node = GetXmlNode(root, name); } else { var piece = name.Split(':'); var prefix = piece[0]; var localName = piece[1]; node = CreateElement(prefix, localName); } return(exist); }
/// <summary> /// Returns a value indicating whether the specified bit is enabled. /// </summary> /// <param name="value">Reference value.</param> /// <param name="bit">Bit to check.</param> /// <returns> /// <b>true</b> if specified <paramref name="bit" /> is enabled; otherwise, <b>false</b>. /// </returns> public static bool CheckBit(this long value, Bits bit) { SentinelHelper.IsEnumValid(bit); SentinelHelper.IsTrue((byte)bit > 63); return(value.CheckBit((byte)bit)); }
/// <summary> /// Returns a <b>Quadriple Word</b> from this array of bytes starting in <paramref name="start"/>. /// </summary> /// <param name="data">Target data.</param> /// <param name="start">Start byte.</param> /// <returns> /// A <see cref="T:System.Int64" /> containing the value. /// </returns> public static long GetQuadrupleWord(this byte[] data, byte start) { SentinelHelper.ArgumentNull(data); SentinelHelper.IsTrue(start + 7 > data.Length); return(data.GetDoubleWord(start) | data.GetDoubleWord((byte)(start + 4)) << 32); }
/// <summary> /// Gets a <b>Word</b> from this array of bytes. ( { a, b, n, n + 1, ...}, n ) => (n + 1, n) /// </summary> /// <param name="data">Target data.</param> /// <param name="start">Start byte.</param> /// <returns> /// A <see cref="T:System.Int32" /> containing the value. /// </returns> public static int GetWord(this byte[] data, byte start) { SentinelHelper.ArgumentNull(data); SentinelHelper.IsTrue(start + 1 > data.Length); return(data[start] | data[start + 1] << 8); }
/// <summary> /// Gets a <b>Double Word</b> from this array of bytes. /// </summary> /// <param name="data">Target data.</param> /// <param name="start">Start byte.</param> /// <returns> /// A <see cref="T:System.Int32" /> containing the value. /// </returns> public static int GetDoubleWord(this byte[] data, byte start) { SentinelHelper.ArgumentNull(data); SentinelHelper.IsTrue(start + 3 > data.Length); return(data[start] | data[start + 1] << 8 | data[start + 2] << 16 | data[start + 3] << 24); }
/// <summary> /// Returns the current state of the specified bit. /// </summary> /// <param name="value">Reference value.</param> /// <param name="bit">Bit to retrieve.</param> /// <returns> /// Returns <c>1</c> if specified bit is active; otherwise <c>0</c>. /// </returns> public static byte GetBit(this ulong value, Bits bit) { SentinelHelper.IsEnumValid(bit); SentinelHelper.IsTrue((byte)bit > 63); return(value.GetBit((byte)bit)); }
/// <summary> /// Returns the specified byte. /// </summary> /// <param name="value">Reference value.</param> /// <param name="onebyte">Byte to retrieve.</param> /// <returns> /// A <see cref="T:System.Byte"/> that contains the result. /// </returns> public static byte GetByte(this ulong value, Bytes onebyte) { SentinelHelper.IsEnumValid(onebyte); SentinelHelper.IsTrue((byte)onebyte > 7); return(value.GetByte((byte)onebyte)); }
/// <summary> /// Retrieves <c>Xml</c> content of specified <paramref name="table" /> in a file. /// </summary> /// <param name="fileName">Target filename</param> /// <param name="table">Table to retrieve</param> /// <returns> /// A collection of <see cref="T:System.Xml.Linq.XElement"/> that contains the table content as <strong>XML</strong>. /// </returns> protected static IEnumerable <XElement> LoadXmlFromFile(string fileName, string table) { SentinelHelper.IsTrue(string.IsNullOrEmpty(table)); SentinelHelper.IsTrue(string.IsNullOrEmpty(fileName)); IEnumerable <XElement> nodes = null; using (var stream = new FileStream(iTin.Core.IO.Path.PathResolver(fileName), FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)) { var reader = new XmlTextReader(stream); var document = XDocument.Load(reader); var root = document.Root; if (root != null) { nodes = table == "*" ? root.Elements() : root.Elements(table); } ////var query = from element in root.Elements() //// group element.Attributes().FirstOrDefault() by element.Name; ////var qq = from e in query let c = e.Count() where c > 1 select e.GetEnumerator(); ////var vvvv = qq.Cast<XAttribute>().ToList(); } return(nodes); }
/// <summary> /// Copies the files. /// </summary> /// <param name="sourceDirectory">Source directory.</param> /// <param name="targetDirectory">Target directory.</param> /// <param name="criterial">File criteria.</param> /// <param name="overrides">if is <strong>true</strong> overrides destination file.</param> public static void CopyFiles(string sourceDirectory, string targetDirectory, string criterial, bool overrides) { Logger.Instance.Debug(""); Logger.Instance.Debug(" Assembly: iTin.Core.IO, Namespace: iTin.Core.IO, Class: File"); Logger.Instance.Debug(" Copies specified files from source to target directory"); Logger.Instance.Debug($" > Signature: (void) CopyFiles({typeof(string)}, {typeof(string)}, {typeof(string)}, {typeof(bool)})"); SentinelHelper.IsTrue(string.IsNullOrEmpty(sourceDirectory)); Logger.Instance.Debug($" > sourceDirectory: {sourceDirectory}"); SentinelHelper.IsTrue(string.IsNullOrEmpty(targetDirectory)); Logger.Instance.Debug($" > targetDirectory: {targetDirectory}"); Logger.Instance.Debug($" > criterial: {criterial}"); Logger.Instance.Debug($" > overrides: {overrides}"); string[] items = NativeDirectory.GetFiles(sourceDirectory, criterial, NativeIO.SearchOption.TopDirectoryOnly); foreach (var item in items) { string filename = NativePath.GetFileName(item); string target = NativePath.Combine(targetDirectory, filename); NativeFile.Copy(item, target, overrides); } Logger.Instance.Debug($" > Output: Has been copied correctly from {sourceDirectory} to {targetDirectory}"); }
public static void WriteXsltStartVariable(this XmlWriter writer, string name) { SentinelHelper.ArgumentNull(writer); SentinelHelper.IsTrue(string.IsNullOrEmpty(name)); writer.WriteStartElement("xsl:variable"); writer.WriteAttributeString("name", name); }
public static void WriteXsltStartIf(this XmlWriter writer, string condition) { SentinelHelper.ArgumentNull(writer); SentinelHelper.IsTrue(string.IsNullOrEmpty(condition)); writer.WriteStartElement("xsl:if"); writer.WriteAttributeString("test", condition); }
/// <summary> /// Saves this memory stream into file /// </summary> /// <param name="stream">Stream to save.</param> /// <param name="fileName">Destination file.</param> public static void SaveToFile(this Stream stream, string fileName) { SentinelHelper.ArgumentNull(stream); SentinelHelper.IsTrue(string.IsNullOrEmpty(fileName)); var memoryStream = stream as MemoryStream ?? stream.ToMemoryStream(); memoryStream.SaveToFile(fileName); }
public static void WriteXsltStartWhen <T>(this XmlWriter writer, string test, T testok) { SentinelHelper.ArgumentNull(writer); SentinelHelper.IsTrue(testok.Equals(null)); SentinelHelper.IsTrue(string.IsNullOrEmpty(test)); writer.WriteStartElement("xsl:when"); writer.WriteAttributeString("test", test); writer.WriteValue(testok); }
/// <summary> /// Saves this byte array into file. /// </summary> /// <param name="data">Data to save.</param> /// <param name="filename">Destination file.</param> public static void SaveToFile(this byte[] data, string filename) { SentinelHelper.ArgumentNull(data); SentinelHelper.IsTrue(string.IsNullOrEmpty(filename)); using (var ms = new MemoryStream(data)) { ms.SaveToFile(filename); } }
/// <summary> /// Creates an element with the specified Prefix, LocalName, and NamespaceURI. /// </summary> /// <param name="prefix">The prefix of the new element.</param> /// <param name="localName">The local name of the new element.</param> /// <param name="namespaceUri">The namespace URI of the new element.</param> /// <returns> /// The new <see cref="System.Xml.XmlElement" />. /// </returns> /// <exception cref="T:System.InvalidOperationException">If <paramref name="prefix" /> is empty.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="prefix" /> length is less than 1.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="localName" /> is empty.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="localName" /> length is less than 1.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="namespaceUri" /> is empty.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="namespaceUri" /> length is less than 1.</exception> public static XmlElement CreateElement(string prefix, string localName, string namespaceUri) { SentinelHelper.IsTrue(string.IsNullOrEmpty(prefix), "No puede estar vacio"); SentinelHelper.IsTrue(prefix.Length < 1, "La longitud minima ha de ser 1"); SentinelHelper.IsTrue(string.IsNullOrEmpty(localName), "No puede estar vacio"); SentinelHelper.IsTrue(localName.Length < 1, "La longitud minima ha de ser 1"); SentinelHelper.IsTrue(string.IsNullOrEmpty(namespaceUri), "No puede estar vacio"); SentinelHelper.IsTrue(namespaceUri.Length < 1, "La longitud minima ha de ser 1"); return(ChartXml.CreateElement(prefix, localName, namespaceUri)); }
/// <summary> /// Create or return an element with the specified name, and adds it to the document in the specified node. /// </summary> /// <param name="root">The root node of new element.</param> /// <param name="name">The name of the new element.</param> /// <returns> /// Return if it already exists, else it is created and added to the specified node. /// </returns> /// <exception cref="T:System.ArgumentNullException">If <paramref name="root" /> is <c>null</c>.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> is empty.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> length is less than 3.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> contains white spaces.</exception> /// <exception cref="T:System.InvalidOperationException">If <paramref name="name" /> has not correct format.</exception> public static XmlNode CreateOrDefaultAndAppendElementToNode(XmlNode root, string name) { SentinelHelper.ArgumentNull(root); SentinelHelper.IsTrue(name.Length <= 3, "El parametro element debe contener al menos tres caracteres"); SentinelHelper.IsTrue(string.IsNullOrEmpty(name), "El parametro element no puede estar en blanco"); SentinelHelper.IsFalse(name.Contains(":"), "El formato no es correcto. Se esperaba prefijo:localname"); SentinelHelper.IsTrue(name.Contains(" "), "El formato no es correcto. No se permiten espacios en el elemento"); var piece = name.Split(':'); var prefix = piece[0]; var localName = piece[1]; return(CreateOrDefaultAndAppendElementToNode(root, prefix, localName, NamespaceManager.LookupNamespace(prefix))); }
/// <summary> /// Saves this byte array into file. /// </summary> /// <param name="data">Data to save.</param> /// <param name="filename">Destination file.</param> /// <returns> /// A <see cref="IResult"/> object that contains the operation result /// </returns> public static IResult SaveToFile(this byte[] data, string filename) { Logger.Instance.Debug(""); Logger.Instance.Debug(" Assembly: iTin.Core.IO, Namespace: iTin.Core.IO, Class: ByteArrayExtensions"); Logger.Instance.Debug(" Saves this byte array into file"); Logger.Instance.Debug($" > Signature: ({typeof(IResult)}) SaveToFile(this {typeof(byte[])}, {typeof(string)})"); SentinelHelper.ArgumentNull(data, nameof(data)); Logger.Instance.Debug($" > data: {data.Length} byte(s) [{data[0]} {data[1]} {data[2]} ...]"); SentinelHelper.IsTrue(string.IsNullOrEmpty(filename)); Logger.Instance.Debug($" > filename: {filename}"); return(data.ToMemoryStream().SaveToFile(filename)); }
/// <summary> /// Returns a value indicating whether the specified bit is enabled. /// </summary> /// <param name="value">Reference value.</param> /// <param name="bit">Bit to check.</param> /// <returns> /// <b>true</b> if bit specified in <paramref name="bit" /> parameter is enabled; otherwise, <b>false</b>. /// </returns> public static bool CheckBit(this ushort value, byte bit) { Logger.Instance.Debug(""); Logger.Instance.Debug(" Assembly: iTin.Core, Namespace: iTin.Core, Class: ByteArrayExtensions"); Logger.Instance.Debug(" Returns a value indicating whether the specified bit is enabled"); Logger.Instance.Debug($" > Signature: ({typeof(bool)}) CheckBit(this {typeof(ushort)}, {typeof(byte)})"); Logger.Instance.Debug($" > value: {value}"); SentinelHelper.IsTrue(bit > 15); Logger.Instance.Debug($" > bit: {bit}"); bool result = (value & (1 << bit)) == 1 << bit; Logger.Instance.Info($" > Output: {result}"); return(result); }
/// <summary> /// Returns the current state of the specified bit. /// </summary> /// <param name="value">Reference value.</param> /// <param name="bit">Bit to check.</param> /// <returns> /// Returns <b>1</b> if specified bit is active; otherwise <b>0</b>. /// </returns> public static byte GetBit(this ushort value, byte bit) { Logger.Instance.Debug(""); Logger.Instance.Debug(" Assembly: iTin.Core, Namespace: iTin.Core, Class: ByteArrayExtensions"); Logger.Instance.Debug(" Returns the current state of the specified bit"); Logger.Instance.Debug($" > Signature: ({typeof(byte)}) GetBit(this {typeof(ushort)}, {typeof(byte)})"); Logger.Instance.Debug($" > value: {value}"); SentinelHelper.IsTrue(bit > 15); Logger.Instance.Debug($" > bit: {bit}"); byte result = (byte)(value & bit) == bit ? (byte)1 : (byte)0; Logger.Instance.Info($" > Output: {result}"); return(result); }
/// <summary> /// Returns a value indicating whether the specified bit is enabled. /// </summary> /// <param name="value">Reference value.</param> /// <param name="bit">Bit to check.</param> /// <returns> /// <b>true</b> if specified <paramref name="bit" /> is enabled; otherwise, <b>false</b>. /// </returns> public static bool CheckBit(this byte value, Bits bit) { Logger.Instance.Debug(""); Logger.Instance.Debug(" Assembly: iTin.Core, Namespace: iTin.Core, Class: ByteArrayExtensions"); Logger.Instance.Debug(" Returns a value indicating whether the specified bit is enabled"); Logger.Instance.Debug($" > Signature: ({typeof(bool)}) CheckBit(this {typeof(byte)}, {typeof(Bits)})"); Logger.Instance.Debug($" > value: {value}"); SentinelHelper.IsEnumValid(bit); SentinelHelper.IsTrue((byte)bit > 7); Logger.Instance.Debug($" > bit: {bit}"); bool result = value.CheckBit((byte)bit); Logger.Instance.Info($" > Output: {result}"); return(result); }
/// <summary> /// Returns the current state of the specified bit. /// </summary> /// <param name="value">Reference value.</param> /// <param name="bit">Bit to check.</param> /// <returns> /// Returns <b>1</b> if specified bit is active; otherwise <b>0</b>. /// </returns> public static byte GetBit(this byte value, Bits bit) { Logger.Instance.Debug(""); Logger.Instance.Debug(" Assembly: iTin.Core, Namespace: iTin.Core, Class: ByteArrayExtensions"); Logger.Instance.Debug(" Returns the current state of the specified bit"); Logger.Instance.Debug($" > Signature: ({typeof(byte)}) GetBit(this {typeof(byte)}, {typeof(Bits)})"); Logger.Instance.Debug($" > value: {value}"); SentinelHelper.IsEnumValid(bit); SentinelHelper.IsTrue((byte)bit > 7); Logger.Instance.Debug($" > bit: {bit}"); byte result = value.GetBit((byte)bit); Logger.Instance.Info($" > Output: {result}"); return(result); }
/// <summary> /// Returns a <b>Double Word</b> from this array of bytes starting in <paramref name="start"/>. /// </summary> /// <param name="data">Target data.</param> /// <param name="start">Start byte.</param> /// <returns> /// A <see cref="T:System.Int32" /> containing the value. /// </returns> public static int GetDoubleWord(this byte[] data, byte start) { Logger.Instance.Debug(""); Logger.Instance.Debug(" Assembly: iTin.Core, Namespace: iTin.Core, Class: ByteArrayExtensions"); Logger.Instance.Debug(" Returns a Double Word from this array of bytes starting in start"); Logger.Instance.Debug($" > Signature: ({typeof(int)}) GetDoubleWord(this {typeof(byte[])}, {typeof(byte)})"); SentinelHelper.ArgumentNull(data, nameof(data)); Logger.Instance.Debug($" > data: {data.Length} byte(s) [{data[0]} {data[1]} {data[2]} ...]"); SentinelHelper.IsTrue(start + 3 > data.Length); Logger.Instance.Debug($" > start: {start}"); int result = data[start] | data[start + 1] << 8 | data[start + 2] << 16 | data[start + 3] << 24; Logger.Instance.Debug($" > Output: {result}"); return(result); }
/// <summary> /// Returns a <b>Quadriple Word</b> from this array of bytes starting in <paramref name="start"/>. /// </summary> /// <param name="data">Target data.</param> /// <param name="start">Start byte.</param> /// <returns> /// A <see cref="T:System.Int64" /> containing the value. /// </returns> public static long GetQuadrupleWord(this byte[] data, byte start) { Logger.Instance.Debug(""); Logger.Instance.Debug(" Assembly: iTin.Core, Namespace: iTin.Core, Class: ByteArrayExtensions"); Logger.Instance.Debug(" Returns a Quadriple Word from this array of bytes starting in start"); Logger.Instance.Debug($" > Signature: ({typeof(long)}) GetQuadrupleWord(this {typeof(byte[])}, {typeof(byte)})"); SentinelHelper.ArgumentNull(data, nameof(data)); Logger.Instance.Debug($" > data: {data.Length} byte(s) [{data[0]} {data[1]} {data[2]} ...]"); SentinelHelper.IsTrue(start + 7 > data.Length); Logger.Instance.Debug($" > start: {start}"); long result = data.GetDoubleWord(start) | data.GetDoubleWord((byte)(start + 4)) << 32; Logger.Instance.Debug($" > Output: {result}"); return(result); }
/// <summary> /// Returns a <see cref="T:System.IO.Stream"/> which contains specified streams list compressed. The <paramref name="itemNames"/> contains the names for every stream entry in streams list. /// </summary> /// <param name="items">Elements to compress.</param> /// <param name="itemNames">The names for every stream entry in streams list.</param> /// <returns> /// A <see cref="T:System.String" /> than contains the path to created file. /// </returns> public static Stream AsZipStream(this IEnumerable <Stream> items, IEnumerable <string> itemNames) { IList <Stream> elementList = items as IList <Stream> ?? items.Clone().ToList(); SentinelHelper.ArgumentNull(elementList, nameof(elementList)); IList <string> elementNamesList = itemNames as IList <string> ?? itemNames.ToList(); SentinelHelper.ArgumentNull(elementNamesList, nameof(elementNamesList)); SentinelHelper.IsTrue(elementList.Count != elementNamesList.Count, "The parameter 'itemsNames' must have the same number of elements as the 'items' list"); try { Stream zippedStream = new MemoryStream(); string tempDirectory = iTinIO.File.TempDirectoryFullName; Uri tempFilenameUri = iTinIO.File.GetUniqueTempRandomFile(); string tempFilename = Path.GetFileName(tempFilenameUri.AbsolutePath); string fullTempPath = Path.Combine(tempDirectory, tempFilename); using (ZipFile zip = new ZipFile(fullTempPath)) { int currentFile = 0; foreach (Stream element in elementList) { element.Position = 0; zip.AddEntry(elementNamesList[currentFile], element); currentFile++; } zip.Save(zippedStream); } return(zippedStream); } catch { return(Stream.Null); } }
/// <summary> /// Returns a value than represents a known node. /// </summary> /// <param name="element">A <see cref="KnownChartElement"/> value.</param> /// <returns> /// <see cref="XmlNode"/> reference that contains <c>Xml</c> node. /// </returns> /// <exception cref="InvalidEnumArgumentException">The value specified is outside the range of valid values.</exception> public XmlNode FromKnownChartElement(KnownChartElement element) { SentinelHelper.IsEnumValid(element); XmlNode knownRootNode = null; switch (element) { case KnownChartElement.Self: knownRootNode = GetXmlNode(ChartSpaceRootNode); break; case KnownChartElement.Legend: knownRootNode = GetXmlNode(ChartLegendRootNode); break; case KnownChartElement.PlotArea: knownRootNode = GetXmlNode(ChartPlotAreaRootNode); break; case KnownChartElement.ChartTitle: knownRootNode = GetXmlNode(ChartTitleRootNode); break; case KnownChartElement.PrimaryCategoryAxis: knownRootNode = GetElementsByTagName("c:catAx").ToList()[0]; break; case KnownChartElement.PrimaryValueAxis: knownRootNode = GetElementsByTagName("c:valAx").ToList()[0]; break; case KnownChartElement.SecondaryCategoryAxis: var catAxisXmlList = GetElementsByTagName("c:catAx").ToList(); SentinelHelper.IsTrue(catAxisXmlList.Count <= 1, "Error the secondary axis does not exist"); knownRootNode = catAxisXmlList[1]; break; case KnownChartElement.SecondaryValueAxis: var valAxisXmlList = GetElementsByTagName("c:valAx").ToList(); SentinelHelper.IsTrue(valAxisXmlList.Count <= 1, "Error the secondary axis does not exist"); knownRootNode = valAxisXmlList[1]; break; case KnownChartElement.PrimaryCategoryAxisTitle: knownRootNode = GetXmlNode(GetElementsByTagName("c:catAx").ToList()[0], "c:title"); break; case KnownChartElement.PrimaryValueAxisTitle: knownRootNode = GetXmlNode(GetElementsByTagName("c:valAx").ToList()[0], "c:title"); break; case KnownChartElement.SecondaryCategoryAxisTitle: var catAxisXmlList1 = GetElementsByTagName("c:catAx").ToList(); SentinelHelper.IsTrue(catAxisXmlList1.Count <= 1, "Error the secondary axis does not exist"); knownRootNode = GetXmlNode(catAxisXmlList1[1], "c:title"); break; case KnownChartElement.SecondaryValueAxisTitle: var valAxisXmlList2 = GetElementsByTagName("c:valAx").ToList(); SentinelHelper.IsTrue(valAxisXmlList2.Count <= 1, "Error the secondary axis does not exist"); knownRootNode = GetXmlNode(valAxisXmlList2[1], "c:title"); break; } return(knownRootNode); }
/// <summary> /// Returns the current state of the specified bit. /// </summary> /// <param name="value">Reference value.</param> /// <param name="bit">Bit to check.</param> /// <returns> /// Returns <c>1</c> if specified bit is active; otherwise <c>0</c>. /// </returns> public static byte GetBit(this ulong value, byte bit) { SentinelHelper.IsTrue(bit > 63); return((value & bit) == bit ? (byte)1 : (byte)0); }
/// <summary> /// Returns a value indicating whether the specified bit is enabled. /// </summary> /// <param name="value">Reference value.</param> /// <param name="bit">Bit to check.</param> /// <returns> /// <b>true</b> if bit specified in <paramref name="bit" /> parameter is enabled; otherwise, <b>false</b>. /// </returns> public static bool CheckBit(this ulong value, byte bit) { SentinelHelper.IsTrue(bit > 63); return((value & ((ulong)1 << bit)) == (ulong)1 << bit); }