/// <summary> /// 报告指定的字节数组在源数组中的第一个匹配项的索引。 /// </summary> /// <param name="data">源数组</param> /// <param name="target">指定的字节数组</param> /// <param name="position">开始匹配的位置</param> /// <returns>索引值。为-1时,指无匹配项。</returns> public static int Find(this byte[] data, byte[] target, int position = 0) { if (UtilCollection.IsNullOrEmpty(target)) { return(-1); } int i; for (i = position; i < data.Length; i++) { if (i + target.Length <= data.Length) { int j; for (j = 0; j < target.Length; j++) { if (data[i + j] != target[j]) { break; } } if (j == target.Length) { return(i); } } else { break; } } return(-1); }
/// <summary> /// 快速创建并追加一个普通的数据节点 /// </summary> /// <param name="element">The element.</param> /// <param name="localName">The localName.</param> /// <param name="value">The value.</param> /// <param name="attributes">属性集合</param> public static XmlElement SetChildElement(this XmlElement element, string localName, object value, params Tuple <string, string>[] attributes) { XmlElement ele = null; if (element != null && element.OwnerDocument != null) { ele = element.OwnerDocument.CreateElement(localName); if (value != null && !string.IsNullOrWhiteSpace(value.ToString())) { ele.InnerText = value.ToString(); } if (!UtilCollection.IsNullOrEmpty(attributes)) { foreach (var attribute in attributes) { if (!ele.HasAttribute(attribute.Item1)) { ele.SetAttribute(attribute.Item1, attribute.Item2); } } } element.AppendChild(ele); } return(ele); }
/// <summary>判断指定的字节数组是否是被GZip压缩过的 /// </summary> /// <param name="bytes">The bytes.</param> /// <returns> /// <c>true</c> if the specified bytes is compressed; otherwise, <c>false</c>. /// </returns> public static bool IsCompressed(this byte[] bytes) { if (UtilCollection.IsNullOrEmpty(bytes)) { return(false); } return((bytes[0] == 31) && (bytes[1] == 139)); }
public void Execute(string taskKey, string[] parameters) { var taskHolderList = _taskLocator.GetTaskHolderList(); var taskHolder = taskHolderList.FirstOrDefault(h => h.Key == taskKey); if (taskHolder == null) { Console.WriteLine(Strings.task_not_found); return; } var dic = UtilCollection.ExtractParams(parameters).ToDictionary(itm => itm.Key, itm => (object)itm.Value); taskHolder.Task.Execute(dic); }
private void ListModified(float[] elements) { product = UtilCollection.Product(elements); OnProductUpdated(product); }