/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { MemoryStream msInput = new MemoryStream(data); MemoryStream msOutput = new MemoryStream(); InflaterInputStream iis = new InflaterInputStream(msInput, new Inflater(false)); int cbRead; byte[] abResult = new byte[32768]; do { cbRead = iis.Read(abResult, 0, abResult.Length); if (cbRead > 0) { msOutput.Write(abResult, 0, cbRead); } }while (cbRead > 0); iis.Close(); msOutput.Flush(); if (msOutput.Length >= 0) { msOutput.Capacity = (int)msOutput.Length; return(msOutput.GetBuffer()); } return(null); }
/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { if (data == null) { throw new ArgumentNullException("data"); } data = RemoveWhiteSpace(data); int count = data.Length; if (count % 2 == 1) { count++; byte[] temp = data; data = new byte[count]; temp.CopyTo(data, 0); } count <<= 2; byte[] bytes = new byte[count]; for (int i = 0, j = 0; i < count; i++) { byte hi = data[j++]; byte lo = data[j++]; bytes[i] = (byte)((hi > '9' ? hi - 'A' : hi - '0') * 16 + (lo > '9' ? lo - 'A' : lo - '0')); } return(bytes); }
/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { if (data[0] == 0x00 && data[1] == 0x01) throw new Exception("LZW flavour not supported."); MemoryStream outputStream = new MemoryStream(); InitializeDictionary(); _data = data; _bytePointer = 0; _nextData = 0; _nextBits = 0; int code, oldCode = 0; byte[] str; while ((code = NextCode) != 257) { if (code == 256) { InitializeDictionary(); code = NextCode; if (code == 257) { break; } outputStream.Write(_stringTable[code], 0, _stringTable[code].Length); oldCode = code; } else { if (code < _tableIndex) { str = _stringTable[code]; outputStream.Write(str, 0, str.Length); AddEntry(_stringTable[oldCode], str[0]); oldCode = code; } else { str = _stringTable[oldCode]; outputStream.Write(str, 0, str.Length); AddEntry(str, str[0]); oldCode = code; } } } if (outputStream.Length >= 0) { #if !NETFX_CORE && !UWP outputStream.Capacity = (int)outputStream.Length; return outputStream.GetBuffer(); #else return outputStream.ToArray(); #endif } return null; }
/// <summary> /// Decodes to a raw string. /// </summary> public virtual string DecodeToString(byte[] data, FilterParms parms) { byte[] bytes = Decode(data, parms); string text = PdfEncoders.RawEncoding.GetString(bytes, 0, bytes.Length); return(text); }
/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { if (data == null) throw new ArgumentNullException("data"); data = RemoveWhiteSpace(data); int count = data.Length; // Ignore EOD (end of data) character. // EOD can be anywhere in the stream, but makes sense only at the end of the stream. if (count > 0 && data[count - 1] == '>') --count; if (count % 2 == 1) { count++; byte[] temp = data; data = new byte[count]; temp.CopyTo(data, 0); } count >>= 1; byte[] bytes = new byte[count]; for (int i = 0, j = 0; i < count; i++) { // Must support 0-9, A-F, a-f - "Any other characters cause an error." byte hi = data[j++]; byte lo = data[j++]; if (hi >= 'a' && hi <= 'f') hi -= 32; if (lo >= 'a' && lo <= 'f') lo -= 32; // TODO Throw on invalid characters. Stop when encountering EOD. Add one more byte if EOD is the lo byte. bytes[i] = (byte)((hi > '9' ? hi - '7'/*'A' + 10*/: hi - '0') * 16 + (lo > '9' ? lo - '7'/*'A' + 10*/: lo - '0')); } return bytes; }
/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { if (data[0] == 0x00 && data[1] == 0x01) { throw new Exception("LZW flavour not supported."); } MemoryStream outputStream = new MemoryStream(); InitializeDictionary(); this.data = data; bytePointer = 0; nextData = 0; nextBits = 0; int code, oldCode = 0; byte[] str; while ((code = NextCode) != 257) { if (code == 256) { InitializeDictionary(); code = NextCode; if (code == 257) { break; } outputStream.Write(stringTable[code], 0, stringTable[code].Length); oldCode = code; } else { if (code < tableIndex) { str = stringTable[code]; outputStream.Write(str, 0, str.Length); AddEntry(stringTable[oldCode], str[0]); oldCode = code; } else { str = stringTable[oldCode]; outputStream.Write(str, 0, str.Length); AddEntry(str, str[0]); oldCode = code; } } } if (outputStream.Length >= 0) { outputStream.Capacity = (int)outputStream.Length; return(outputStream.GetBuffer()); } return(null); }
/// <summary> /// Decodes to a raw string with the specified filter. /// </summary> public static string DecodeToString(byte[] data, string filterName, FilterParms parms) { Filter filter = GetFilter(filterName); if (filter != null) { return(filter.DecodeToString(data, parms)); } return(null); }
/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { MemoryStream msInput = new MemoryStream(data); MemoryStream msOutput = new MemoryStream(); #if NET_ZIP // See http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=97064 // It seems to work when skipping the first two bytes. byte header; // 0x30 0x59 header = (byte)msInput.ReadByte(); //Debug.Assert(header == 48); header = (byte)msInput.ReadByte(); //Debug.Assert(header == 89); DeflateStream zip = new DeflateStream(msInput, CompressionMode.Decompress, true); int cbRead; byte[] abResult = new byte[1024]; do { cbRead = zip.Read(abResult, 0, abResult.Length); if (cbRead > 0) { msOutput.Write(abResult, 0, cbRead); } }while (cbRead > 0); zip.Close(); msOutput.Flush(); if (msOutput.Length >= 0) { msOutput.Capacity = (int)msOutput.Length; return(msOutput.GetBuffer()); } return(null); #else InflaterInputStream iis = new InflaterInputStream(msInput, new Inflater(false)); int cbRead; byte[] abResult = new byte[32768]; do { cbRead = iis.Read(abResult, 0, abResult.Length); if (cbRead > 0) { msOutput.Write(abResult, 0, cbRead); } }while (cbRead > 0); iis.Close(); msOutput.Flush(); if (msOutput.Length >= 0) { msOutput.Capacity = (int)msOutput.Length; return(msOutput.GetBuffer()); } return(null); #endif }
public static dynamic ApplyFilter <T>(this T value , FilterParms parms) { //IDomainActionFilter filter = parms.Factory.GetFilter(parms) as IDomainActionFilter; dynamic filter = parms.Factory.GetFilter(parms); parms.FilterSource = value; filter.ApplyFilter(parms); return(filter.ReturnValue()); }
public void ApplyFilter(FilterParms parms) { var key = parms.ParmInputs.Keys.First(); dynamic retValue = parms.ParmInputs[key]; var Filter = new List <string>(); Filter.Add("SomeValue1"); Filter.Add("SomeValue2"); Filter.Add("SomeValue3"); Filter.Add("SomeValue4"); ((IDictionary <String, Object>)retValue.Attributes)[key] = Filter; }
public IFilter GetFilter(FilterParms AvailableFilters) { var filter = default(IDomainActionFilter); switch (AvailableFilters.FilterEnum.ToString()) { case "TestFilter": filter = new TestFilterAction(); break; case "TestSubCategoryFilter": filter = new TestSubCategoryFilter(); break; } return(filter); }
public void Test_Apply_Filter_V1() { FilterParms filterParms = default(FilterParms); filterParms = default(FilterParms); filterParms.Factory = new TestFilterFactory(); filterParms.FilterEnum = EnumTest.TestFilter; var expectedResult = 3; filterParms.ParmInputs = new Dictionary <string, object> { { "Arg", expectedResult } }; var result = expectedResult.ApplyFilter(filterParms); Assert.AreEqual(expectedResult, result, string.Format("Filter, Expected{0} Got {1}", expectedResult, result)); }
/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { if (data == null) { throw new ArgumentNullException("data"); } data = RemoveWhiteSpace(data); int count = data.Length; // Ignore EOD (end of data) character. // EOD can be anywhere in the stream, but makes sense only at the end of the stream. if (count > 0 && data[count - 1] == '>') { --count; } if (count % 2 == 1) { count++; byte[] temp = data; data = new byte[count]; temp.CopyTo(data, 0); } count >>= 1; byte[] bytes = new byte[count]; for (int i = 0, j = 0; i < count; i++) { // Must support 0-9, A-F, a-f - "Any other characters cause an error." byte hi = data[j++]; byte lo = data[j++]; if (hi >= 'a' && hi <= 'f') { hi -= 32; } if (lo >= 'a' && lo <= 'f') { lo -= 32; } // TODO Throw on invalid characters. Stop when encountering EOD. Add one more byte if EOD is the lo byte. bytes[i] = (byte)((hi > '9' ? hi - '7' /*'A' + 10*/: hi - '0') * 16 + (lo > '9' ? lo - '7' /*'A' + 10*/: lo - '0')); } return(bytes); }
//[Test] public void Test_Apply_Attribute_Filter_IsValid() { Assert.False(1 == 1, "Test is Broken"); var sc = new TestSubCategory(); FilterParms filterParms = default(FilterParms); filterParms.Factory = new TestFilterFactory(); filterParms.FilterEnum = EnumTest.TestSubCategoryFilter; // var dynfilter = 3; filterParms.ParmInputs = new Dictionary <string, object> { { "Filter", sc.CategoryTypeId } }; sc.ApplyFilter(filterParms); var bres = sc.CategoryTypeId.HasAttributes(EnumAttributes.filter); Assert.IsTrue(bres, "Cannot Find Attributes Filter"); }
/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { if (data == null) throw new ArgumentNullException("data"); data = RemoveWhiteSpace(data); int count = data.Length; if (count % 2 == 1) { count++; byte[] temp = data; data = new byte[count]; temp.CopyTo(data, 0); } count <<= 2; byte[] bytes = new byte[count]; for (int i = 0, j = 0; i < count; i++) { byte hi = data[j++]; byte lo = data[j++]; bytes[i] = (byte)((hi > '9' ? hi - 'A' : hi - '0') * 16 + (lo > '9' ? lo - 'A' : lo - '0')); } return bytes; }
/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { MemoryStream msInput = new MemoryStream(data); MemoryStream msOutput = new MemoryStream(); #if NET_ZIP // See http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=97064 // It seems to work when skipping the first two bytes. byte header; // 0x30 0x59 header = (byte)msInput.ReadByte(); //Debug.Assert(header == 48); header = (byte)msInput.ReadByte(); //Debug.Assert(header == 89); DeflateStream zip = new DeflateStream(msInput, CompressionMode.Decompress, true); int cbRead; byte[] abResult = new byte[1024]; do { cbRead = zip.Read(abResult, 0, abResult.Length); if (cbRead > 0) msOutput.Write(abResult, 0, cbRead); } while (cbRead > 0); zip.Close(); msOutput.Flush(); if (msOutput.Length >= 0) { msOutput.Capacity = (int)msOutput.Length; return msOutput.GetBuffer(); } return null; #else InflaterInputStream iis = new InflaterInputStream(msInput, new Inflater(false)); int cbRead; byte[] abResult = new byte[32768]; do { cbRead = iis.Read(abResult, 0, abResult.Length); if (cbRead > 0) msOutput.Write(abResult, 0, cbRead); } while (cbRead > 0); iis.Close(); msOutput.Flush(); if (msOutput.Length >= 0) { msOutput.Capacity = (int)msOutput.Length; return msOutput.GetBuffer(); } return null; #endif }
/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { if (data == null) { throw new ArgumentNullException("data"); } int idx; int length = data.Length; int zCount = 0; int idxOut = 0; for (idx = 0; idx < length; idx++) { char ch = (char)data[idx]; if (ch >= '!' && ch <= 'u') { data[idxOut++] = (byte)ch; } else if (ch == 'z') { data[idxOut++] = (byte)ch; zCount++; } else if (ch == '~') { if ((char)data[idx + 1] != '>') { throw new ArgumentException("Illegal character.", "data"); } break; } // ingnore unknown character } // Loop not ended with break? if (idx == length) { throw new ArgumentException("Illegal character.", "data"); } length = idxOut; int nonZero = length - zCount; int byteCount = 4 * (zCount + (nonZero / 5)); // full 4 byte blocks int remainder = nonZero % 5; if (remainder == 1) { throw new InvalidOperationException("Illegal character."); } if (remainder != 0) { byteCount += remainder - 1; } byte[] output = new byte[byteCount]; idxOut = 0; idx = 0; while (idx + 4 < length) { char ch = (char)data[idx]; if (ch == 'z') { idx++; idxOut += 4; } else { uint val = (uint)(data[idx++] - '!') * (85 * 85 * 85 * 85) + (uint)(data[idx++] - '!') * (85 * 85 * 85) + (uint)(data[idx++] - '!') * (85 * 85) + (uint)(data[idx++] - '!') * 85 + (uint)(data[idx++] - '!'); output[idxOut++] = (byte)(val >> 24); output[idxOut++] = (byte)(val >> 16); output[idxOut++] = (byte)(val >> 8); output[idxOut++] = (byte)val; } } // I've found no appropriate algorithm, so I write my own. In some rare cases the value must not // increased by one, but I cannot found a general formula or a proof. // All possible cases are tested programmatically. if (remainder == 2) // one byte { uint value = (uint)(data[idx++] - '!') * (85 * 85 * 85 * 85) + (uint)(data[idx] - '!') * (85 * 85 * 85); // Always increase if not zero (tried out) if (value != 0) { value += 0x01000000; } output[idxOut] = (byte)(value >> 24); } else if (remainder == 3) // two bytes { int idxIn = idx; uint value = (uint)(data[idx++] - '!') * (85 * 85 * 85 * 85) + (uint)(data[idx++] - '!') * (85 * 85 * 85) + (uint)(data[idx] - '!') * (85 * 85); if (value != 0) { value &= 0xFFFF0000; uint val = value / (85 * 85); byte c3 = (byte)(val % 85 + '!'); val /= 85; byte c2 = (byte)(val % 85 + '!'); val /= 85; byte c1 = (byte)(val + '!'); if (c1 != data[idxIn] || c2 != data[idxIn + 1] || c3 != data[idxIn + 2]) { value += 0x00010000; //Count2++; } } output[idxOut++] = (byte)(value >> 24); output[idxOut] = (byte)(value >> 16); } else if (remainder == 4) // three bytes { int idxIn = idx; uint value = (uint)(data[idx++] - '!') * (85 * 85 * 85 * 85) + (uint)(data[idx++] - '!') * (85 * 85 * 85) + (uint)(data[idx++] - '!') * (85 * 85) + (uint)(data[idx] - '!') * 85; if (value != 0) { value &= 0xFFFFFF00; uint val = value / 85; byte c4 = (byte)(val % 85 + '!'); val /= 85; byte c3 = (byte)(val % 85 + '!'); val /= 85; byte c2 = (byte)(val % 85 + '!'); val /= 85; byte c1 = (byte)(val + '!'); if (c1 != data[idxIn] || c2 != data[idxIn + 1] || c3 != data[idxIn + 2] || c4 != data[idxIn + 3]) { value += 0x00000100; //Count3++; } } output[idxOut++] = (byte)(value >> 24); output[idxOut++] = (byte)(value >> 16); output[idxOut] = (byte)(value >> 8); } return(output); }
/// <summary> /// Decodes the specified data. /// </summary> public override byte[] Decode(byte[] data, FilterParms parms) { if (data == null) throw new ArgumentNullException("data"); int idx; int length = data.Length; int zCount = 0; int idxOut = 0; for (idx = 0; idx < length; idx++) { char ch = (char)data[idx]; if (ch >= '!' && ch <= 'u') data[idxOut++] = (byte)ch; else if (ch == 'z') { data[idxOut++] = (byte)ch; zCount++; } else if (ch == '~') { if ((char)data[idx + 1] != '>') throw new ArgumentException("Illegal character.", "data"); break; } // ingnore unknown character } // Loop not ended with break? if (idx == length) throw new ArgumentException("Illegal character.", "data"); length = idxOut; int nonZero = length - zCount; int byteCount = 4 * (zCount + (nonZero / 5)); // full 4 byte blocks int remainder = nonZero % 5; if (remainder == 1) throw new InvalidOperationException("Illegal character."); if (remainder != 0) byteCount += remainder - 1; byte[] output = new byte[byteCount]; idxOut = 0; idx = 0; while (idx + 4 < length) { char ch = (char)data[idx]; if (ch == 'z') { idx++; idxOut += 4; } else { uint val = (uint)(data[idx++] - '!') * (85 * 85 * 85 * 85) + (uint)(data[idx++] - '!') * (85 * 85 * 85) + (uint)(data[idx++] - '!') * (85 * 85) + (uint)(data[idx++] - '!') * 85 + (uint)(data[idx++] - '!'); output[idxOut++] = (byte)(val >> 24); output[idxOut++] = (byte)(val >> 16); output[idxOut++] = (byte)(val >> 8); output[idxOut++] = (byte)val; } } // I've found no appropriate algorithm, so I write my own. In some rare cases the value must not // increased by one, but I cannot found a general formula or a proof. // All possible cases are tested programmatically. if (remainder == 2) // one byte { uint value = (uint)(data[idx++] - '!') * (85 * 85 * 85 * 85) + (uint)(data[idx] - '!') * (85 * 85 * 85); // Always increase if not zero (tried out) if (value != 0) value += 0x01000000; output[idxOut] = (byte)(value >> 24); } else if (remainder == 3) // two bytes { int idxIn = idx; uint value = (uint)(data[idx++] - '!') * (85 * 85 * 85 * 85) + (uint)(data[idx++] - '!') * (85 * 85 * 85) + (uint)(data[idx] - '!') * (85 * 85); if (value != 0) { value &= 0xFFFF0000; uint val = value / (85 * 85); byte c3 = (byte)(val % 85 + '!'); val /= 85; byte c2 = (byte)(val % 85 + '!'); val /= 85; byte c1 = (byte)(val + '!'); if (c1 != data[idxIn] || c2 != data[idxIn + 1] || c3 != data[idxIn + 2]) { value += 0x00010000; //Count2++; } } output[idxOut++] = (byte)(value >> 24); output[idxOut] = (byte)(value >> 16); } else if (remainder == 4) // three bytes { int idxIn = idx; uint value = (uint)(data[idx++] - '!') * (85 * 85 * 85 * 85) + (uint)(data[idx++] - '!') * (85 * 85 * 85) + (uint)(data[idx++] - '!') * (85 * 85) + (uint)(data[idx] - '!') * 85; if (value != 0) { value &= 0xFFFFFF00; uint val = value / 85; byte c4 = (byte)(val % 85 + '!'); val /= 85; byte c3 = (byte)(val % 85 + '!'); val /= 85; byte c2 = (byte)(val % 85 + '!'); val /= 85; byte c1 = (byte)(val + '!'); if (c1 != data[idxIn] || c2 != data[idxIn + 1] || c3 != data[idxIn + 2] || c4 != data[idxIn + 3]) { value += 0x00000100; //Count3++; } } output[idxOut++] = (byte)(value >> 24); output[idxOut++] = (byte)(value >> 16); output[idxOut] = (byte)(value >> 8); } return output; }
/// <summary> /// When implemented in a derived class decodes the specified data. /// </summary> public abstract byte[] Decode(byte[] data, FilterParms parms);
public void ApplyFilter(FilterParms parms) { retValue = parms.FilterSource; }
/// <summary> /// Decodes to a raw string. /// </summary> public virtual string DecodeToString(byte[] data, FilterParms parms) { byte[] bytes = Decode(data, parms); string text = PdfEncoders.RawEncoding.GetString(bytes, 0, bytes.Length); return text; }
/// <summary> /// Decodes to a raw string with the specified filter. /// </summary> public static string DecodeToString(byte[] data, string filterName, FilterParms parms) { Filter filter = GetFilter(filterName); return(filter?.DecodeToString(data, parms)); }
/// <summary> /// Decodes to a raw string with the specified filter. /// </summary> public static string DecodeToString(byte[] data, string filterName, FilterParms parms) { Filter filter = GetFilter(filterName); if (filter != null) return filter.DecodeToString(data, parms); return null; }