public CedLibContentheader(long _ContentLength, CedLibContenttype _ContentType, CedLibProtocolVersion _CedLibProtocolVersion, string _FileSum, string _FileName) { ContentLength = _ContentLength; ContentType = _ContentType; CedLibProtocolVersion = _CedLibProtocolVersion; FileSum = _FileSum; FileName = _FileName; }
/// <summary> /// Parses the CedLib Content header.. /// </summary> /// <param name="header">The header string as given by the remote endpoint.</param> /// <returns>An instant of the CedLibContentheader class.</returns> public static CedLibContentheader ParseContentHeader(string header) { CedLibContentheader returnheader = new CedLibContentheader(); if (header.StartsWith("Contentheader")) { foreach (string line in header.Split('\n')) { if (line.StartsWith("Contentheader")) if (!Enum.TryParse<CedLibContenttype>(line.Split(':')[1], out returnheader.ContentType)) throw new Exception(string.Format("Failed to parse Contentheader type.\nAnyone heard what {0} is? Cause i haven't o3o", line.Split(':'))); if (line.StartsWith("CedLibProtVersion|:")) { CedLibProtocolVersion protver = new CedLibProtocolVersion(); if (Enum.TryParse<CedLibProtocolVersion>(line.Split(':')[1], out protver)) returnheader.CedLibProtocolVersion = protver; else returnheader.CedLibProtocolVersion = CedLibProtocolVersion.UNKNOWN; } if (line.StartsWith("Contentlength|:")) { long contlength = 0; if (!long.TryParse(line.Split(':')[1], out contlength)) throw new Exception(string.Format("Failed to parse Contentlength!\nCouldn't parse {0} to integer", line.Split(':')[1])); returnheader.ContentLength = contlength; } if (line.StartsWith("FileSum|:")) { returnheader.FileSum = line.Split(':')[1]; } if (line.StartsWith("FileName|:")) { returnheader.FileName = line.Split(':')[1]; } } } else throw new Exception("Content header provided is not a valid CedLib content header."); return returnheader; }
public CedLibContentheader(long _ContentLength, CedLibContenttype _ContentType, CedLibProtocolVersion _CedLibProtocolVersion) { ContentLength = _ContentLength; ContentType = _ContentType; CedLibProtocolVersion = _CedLibProtocolVersion; }