// ------------------------------------------------------------------------------------ // Name: DoLike // Goal: Perform the "Like" function using the pattern (or patterns) stored in [strPattern] // There can be more than 1 pattern in [strPattern], which must be separated // by a vertical bar: | // History: // 17-06-2010 ERK Created // ------------------------------------------------------------------------------------ public static bool DoLike(string strText, string strPattern) { string[] arPattern = null; // Array of patterns int intI = 0; // Counter try { // Validate if ((strText == null)) { return(true); } // If the text to compare is empty, then we return false if ((string.IsNullOrEmpty(strText))) { return(false); } // Reduce the [strPattern] strPattern = strPattern.Trim().ToLower(); // Take lower case of the text strText = strText.ToLower(); // SPlit the [strPattern] into different ones arPattern = strPattern.Split(new string[] { "|" }, StringSplitOptions.None); // Perform the "Like" operation for all needed patterns for (intI = 0; intI < arPattern.Length; intI++) { // See if something positive comes out of this comparison if (strText.IsLike(arPattern[intI])) { return(true); } } // No match has happened, so return false return(false); } catch (Exception ex) { // Show error ErrHandle.HandleErr("General/DoLike", ex); // Return failure return(false); } }
/// <summary> /// File-to-file buffered decompression /// </summary> /// <param name="sFileIn"></param> /// <param name="sFileOut"></param> /// <returns></returns> public static bool DecompressFile(String sFileIn, String sFileOut) { const int size = 8192; byte[] buffer = new byte[size]; try { using (FileStream fCompr = new FileStream(sFileIn, FileMode.Open, FileAccess.Read)) using (FileStream fDecom = new FileStream(sFileOut, FileMode.Create, FileAccess.Write)) using (GZipStream alg = new GZipStream(fCompr, CompressionMode.Decompress)) { int bytesRead = 0; do { // Read buffer bytesRead = alg.Read(buffer, 0, buffer.Length); // Write buffer away if (bytesRead > 0) { fDecom.Write(buffer, 0, bytesRead); } } while (bytesRead > 0); // finish writing fDecom.Flush(); fDecom.Close(); fDecom.Dispose(); // Finish reading alg.Close(); fCompr.Close(); fCompr.Dispose(); } // Return success return(true); } catch (Exception ex) { ErrHandle.HandleErr("DecompressFile", ex); // Return failure return(false); } }
/// <summary> /// Convert a string consisting of base64 encoded characters to a number /// </summary> /// <param name="sEncoded"></param> /// <returns></returns> public static int base64ToInt(String sEncoded) { int iBack = 0; try { // COnvert string into byte array char[] arEncoded = sEncoded.ToCharArray(); // Treat the characters one-by-one from right-to-left for (int i = 0; i < arEncoded.Length; i++) { // Conversion depends on the character values char chThis = arEncoded[i]; int iThis = 0; switch (chThis) { case 'A': iThis = 0; break; case 'B': iThis = 1; break; case 'C': iThis = 2; break; case 'D': iThis = 3; break; case 'E': iThis = 4; break; case 'F': iThis = 5; break; case 'G': iThis = 6; break; case 'H': iThis = 7; break; case 'I': iThis = 8; break; case 'J': iThis = 9; break; case 'K': iThis = 10; break; case 'L': iThis = 11; break; case 'M': iThis = 12; break; case 'N': iThis = 13; break; case 'O': iThis = 14; break; case 'P': iThis = 15; break; case 'Q': iThis = 16; break; case 'R': iThis = 17; break; case 'S': iThis = 18; break; case 'T': iThis = 19; break; case 'U': iThis = 20; break; case 'V': iThis = 21; break; case 'W': iThis = 22; break; case 'X': iThis = 23; break; case 'Y': iThis = 24; break; case 'Z': iThis = 25; break; case 'a': iThis = 26; break; case 'b': iThis = 27; break; case 'c': iThis = 28; break; case 'd': iThis = 29; break; case 'e': iThis = 30; break; case 'f': iThis = 31; break; case 'g': iThis = 32; break; case 'h': iThis = 33; break; case 'i': iThis = 34; break; case 'j': iThis = 35; break; case 'k': iThis = 36; break; case 'l': iThis = 37; break; case 'm': iThis = 38; break; case 'n': iThis = 39; break; case 'o': iThis = 40; break; case 'p': iThis = 41; break; case 'q': iThis = 42; break; case 'r': iThis = 43; break; case 's': iThis = 44; break; case 't': iThis = 45; break; case 'u': iThis = 46; break; case 'v': iThis = 47; break; case 'w': iThis = 48; break; case 'x': iThis = 49; break; case 'y': iThis = 50; break; case 'z': iThis = 51; break; case '0': iThis = 52; break; case '1': iThis = 53; break; case '2': iThis = 54; break; case '3': iThis = 55; break; case '4': iThis = 56; break; case '5': iThis = 57; break; case '6': iThis = 58; break; case '7': iThis = 59; break; case '8': iThis = 60; break; case '9': iThis = 61; break; case '+': iThis = 62; break; case '/': iThis = 63; break; } // Add the new value to the existing ones iBack = iBack * 64 + iThis; } return(iBack); } catch (Exception ex) { ErrHandle.HandleErr("base64ToInt", ex); // Return failure return(-1); } }