Esempio n. 1
0
        /// <summary>
        /// Encodes specified data with IMAP modified UTF7 encoding. Defined in RFC 3501 5.1.3.  Mailbox International Naming Convention.
        /// Example: �� is encoded to &amp;APYA9g-.
        /// </summary>
        /// <param name="text">Text to encode.</param>
        /// <returns></returns>
        public static string Encode_IMAP_UTF7_String(string text)
        {
            /* RFC 3501 5.1.3.  Mailbox International Naming Convention
				In modified UTF-7, printable US-ASCII characters, except for "&",
				represent themselves; that is, characters with octet values 0x20-0x25
				and 0x27-0x7e.  The character "&" (0x26) is represented by the
				two-octet sequence "&-".

				All other characters (octet values 0x00-0x1f and 0x7f-0xff) are
				represented in modified BASE64, with a further modification from
				[UTF-7] that "," is used instead of "/".  Modified BASE64 MUST NOT be
				used to represent any printing US-ASCII character which can represent
				itself.
				
				"&" is used to shift to modified BASE64 and "-" to shift back to
				US-ASCII.  There is no implicit shift from BASE64 to US-ASCII, and
				null shifts ("-&" while in BASE64; note that "&-" while in US-ASCII
				means "&") are not permitted.  However, all names start in US-ASCII,
				and MUST end in US-ASCII; that is, a name that ends with a non-ASCII
				ISO-10646 character MUST end with a "-").
			*/

            // Base64 chars, except '/' is replaced with ','
            char[] base64Chars = new[]
                                     {
                                         'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
                                         'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
                                         'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
                                         'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
                                         '4', '5', '6', '7', '8', '9', '+', ','
                                     };

            MemoryStream retVal = new MemoryStream();
            for (int i = 0; i < text.Length; i++)
            {
                char c = text[i];

                // The character "&" (0x26) is represented by the two-octet sequence "&-".
                if (c == '&')
                {
                    retVal.Write(new[] {(byte) '&', (byte) '-'}, 0, 2);
                }
                    // It is allowed char, don't need to encode
                else if (c >= 0x20 && c <= 0x25 || c >= 0x27 && c <= 0x7E)
                {
                    retVal.WriteByte((byte) c);
                }
                    // Not allowed char, encode it
                else
                {
                    // Superfluous shifts are not allowed. 
                    // For example: �� may not encoded as &APY-&APY-, but must be &APYA9g-.

                    // Get all continuous chars that need encoding and encode them as one block
                    MemoryStream encodeBlock = new MemoryStream();
                    for (int ic = i; ic < text.Length; ic++)
                    {
                        char cC = text[ic];

                        // Allowed char
                        if (cC >= 0x20 && cC <= 0x25 || cC >= 0x27 && cC <= 0x7E)
                        {
                            break;
                        }
                        else
                        {
                            encodeBlock.WriteByte((byte) ((cC & 0xFF00) >> 8));
                            encodeBlock.WriteByte((byte) (cC & 0xFF));
                            i = ic;
                        }
                    }

                    // Ecode block
                    byte[] encodedData = Base64EncodeEx(encodeBlock.ToArray(), base64Chars, false);
                    retVal.WriteByte((byte) '&');
                    retVal.Write(encodedData, 0, encodedData.Length);
                    retVal.WriteByte((byte) '-');
                }
            }

            return Encoding.Default.GetString(retVal.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        /// Decodes IMAP modified UTF7 encoded data. Defined in RFC 3501 5.1.3.  Mailbox International Naming Convention.
        /// Example: &amp;APYA9g- is decoded to ��.
        /// </summary>
        /// <param name="text">Text to encode.</param>
        /// <returns></returns>
        public static string Decode_IMAP_UTF7_String(string text)
        {
            /* RFC 3501 5.1.3.  Mailbox International Naming Convention
				In modified UTF-7, printable US-ASCII characters, except for "&",
				represent themselves; that is, characters with octet values 0x20-0x25
				and 0x27-0x7e.  The character "&" (0x26) is represented by the
				two-octet sequence "&-".

				All other characters (octet values 0x00-0x1f and 0x7f-0xff) are
				represented in modified BASE64, with a further modification from
				[UTF-7] that "," is used instead of "/".  Modified BASE64 MUST NOT be
				used to represent any printing US-ASCII character which can represent
				itself.
				
				"&" is used to shift to modified BASE64 and "-" to shift back to
				US-ASCII.  There is no implicit shift from BASE64 to US-ASCII, and
				null shifts ("-&" while in BASE64; note that "&-" while in US-ASCII
				means "&") are not permitted.  However, all names start in US-ASCII,
				and MUST end in US-ASCII; that is, a name that ends with a non-ASCII
				ISO-10646 character MUST end with a "-").
			*/

            // Base64 chars, except '/' is replaced with ','
            char[] base64Chars = new[]
                                     {
                                         'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
                                         'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
                                         'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
                                         'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
                                         '4', '5', '6', '7', '8', '9', '+', ','
                                     };

            StringBuilder retVal = new StringBuilder();
            for (int i = 0; i < text.Length; i++)
            {
                char c = text[i];

                // Encoded block or escaped &
                if (c == '&')
                {
                    int endingPos = -1;
                    // Read encoded block
                    for (int b = i + 1; b < text.Length; b++)
                    {
                        // - marks block end
                        if (text[b] == '-')
                        {
                            endingPos = b;
                            break;
                        }
                            // Invalid & sequence, just treat it as '&' char and not like shift.
                            // &....&, but must be &....-
                        else if (text[b] == '&')
                        {
                            break;
                        }
                    }

                    // If no ending -, invalid encoded block. Treat it like it is
                    if (endingPos == -1)
                    {
                        // Just let main for to handle other chars after &
                        retVal.Append(c);
                    }
                        // If empty block, then escaped &
                    else if (endingPos - i == 1)
                    {
                        retVal.Append(c);
                        // Move i over '-'
                        i++;
                    }
                        // Decode block
                    else
                    {
                        // Get encoded block
                        byte[] encodedBlock =
                            Encoding.Default.GetBytes(text.Substring(i + 1, endingPos - i - 1));

                        // Convert to UTF-16 char						
                        byte[] decodedData = Base64DecodeEx(encodedBlock, base64Chars);
                        char[] decodedChars = new char[decodedData.Length/2];
                        for (int iC = 0; iC < decodedChars.Length; iC++)
                        {
                            decodedChars[iC] = (char) (decodedData[iC*2] << 8 | decodedData[(iC*2) + 1]);
                        }

                        // Decode data
                        retVal.Append(decodedChars);

                        // Move i over '-'
                        i += encodedBlock.Length + 1;
                    }
                }
                    // Normal byte
                else
                {
                    retVal.Append(c);
                }
            }

            return retVal.ToString();
        }
Esempio n. 3
0
        /// <summary>
        /// Converts data to hex data.
        /// </summary>
        /// <param name="data">Data to convert.</param>
        /// <returns></returns>
        public static byte[] ToHex(byte[] data)
        {
            char[] hexChars = new[]
                                  {
                                      '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
                                      'F'
                                  };

            MemoryStream retVal = new MemoryStream(data.Length*2);
            foreach (byte b in data)
            {
                byte[] hexByte = new byte[2];

                // left 4 bit of byte
                hexByte[0] = (byte) hexChars[(b & 0xF0) >> 4];

                // right 4 bit of byte
                hexByte[1] = (byte) hexChars[b & 0x0F];

                retVal.Write(hexByte, 0, 2);
            }

            return retVal.ToArray();
        }
        /// <summary>
        /// Gets the input argument.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="isoMount">The iso mount.</param>
        /// <returns>System.String.</returns>
        protected string GetInputArgument(BaseItem item, IIsoMount isoMount)
        {
            var type = InputType.AudioFile;

            var inputPath = new[] { item.Path };

            var video = item as Video;

            if (video != null)
            {
                if (!(video.VideoType == VideoType.Iso && isoMount == null))
                {
                    inputPath = MediaEncoderHelpers.GetInputArgument(video, isoMount, out type);
                }
            }

            return MediaEncoder.GetInputArgument(inputPath, type);
        }
Esempio n. 5
0
		public void TestGuidConversion()
		{
            var uidPairs = new[]
		    {
                // This is the reference sample for 2.25 style UIDs given on 
                // David Clunie's website (http://www.dclunie.com/medical-image-faq/html/part2.html)
		        new[] {"f81d4fae-7dec-11d0-a765-00a0c91e6bf6", "329800735698586629295641978511506172918"},

                //These were generated by http://www.itu.int/en/ITU-T/asn1/Pages/UUID/generate_uuid.aspx
		        new[] {"caee1380-7593-11e4-a963-0002a5d5c51b", "269740217344259109252606731820088018203"},
		        new[] {"f5a37f60-7594-11e4-9390-0002a5d5c51b", "326509786863557582563524645431476077851"},
		        new[] {"ff12f6c0-7594-11e4-8f6b-0002a5d5c51b", "339051604989565627204284007819374871835"},
		        new[] {"12180b20-7595-11e4-aece-0002a5d5c51b", "24050944726930122795090541006869087515"},
		        new[] {"212f91a0-7595-11e4-9147-0002a5d5c51b", "44111515475541853071648199882988438811"},
		        new[] {"2b3f40a0-7595-11e4-b63b-0002a5d5c51b", "57485229307949673260101171979388044571"},
		        new[] {"3d31ac80-7595-11e4-b088-0002a5d5c51b", "81340829040994665309106583434536797467"},
		        new[] {"45bc4220-7595-11e4-85ea-0002a5d5c51b", "92694224729288744883190539521772340507"},
		        new[] {"4e8e8f20-7595-11e4-95e8-0002a5d5c51b", "104419992781399866848187402726153766171"},
		        new[] {"74063be0-7595-11e4-aa2b-0002a5d5c51b", "154222815737866429460949140611561538843"},
		        
                //Special cases.
                new[] {Guid.Empty.ToString(), "0"},

                //I used this generator to get the expected value for these. It uses functionality
                //built into Python to convert a GUID to a decimal value.
                //http://guid-convert.appspot.com/
                //Basically, in Python, the UUID class has a .int property that returns the 128-bit
                //integer representation of the UUID, which is what we want.
                new []{"00000000-0000-0000-0000-000000000001", "1"},
                new []{"00000000-0000-0000-0001-000000000000", "281474976710656"},
                new []{"00000000-0000-0001-0000-000000000000", "18446744073709551616"},
                new []{"00000000-0001-0000-0000-000000000000", "1208925819614629174706176"},
                new []{"00000001-0000-0000-0000-000000000000", "79228162514264337593543950336"},

                new []{"00000000-0000-0000-0000-F00000000000", "263882790666240"},
                new []{"00000000-0000-0000-F000-000000000000", "17293822569102704640"},
                new []{"00000000-0000-F000-0000-000000000000", "1133367955888714851287040"},
                new []{"00000000-F000-0000-0000-000000000000", "74276402357122816493947453440"},
                new []{"F0000000-0000-0000-0000-000000000000", "319014718988379809496913694467282698240"},
                new []{"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF", "340282366920938463463374607431768211455"},

                //These UIDs were generated by Visual Studio, and converted to decimal with the Python
                //converter mentioned above.
                new []{"33A4D06F-5B4A-420C-8778-12764A03B4E2", "68646392033606928191667069969500452066"},
                new []{"534918E5-534E-4918-8DB1-5C3E698C141C", "110705466267682660489308928177165046812"},
                new []{"DFDC8525-1F47-4E32-91A1-CAD58D3224F5", "297562848870513438750843654525464749301"},
                new []{"B71DDAB0-8242-4E0C-9DAB-88574866AF42", "243403735387300522275477254959389912898"},
                new []{"CBFD1BFE-28DE-44DC-BE4A-7F4757DE23B0", "271147502011207917925458937881779119024"},
                new []{"5633F579-429C-42DA-BBCD-789CC81C0CBA", "114583393574863518951200517614724713658"},
                new []{"19A8A9E3-3DA2-47E9-B877-B75F4883641D", "34106451497947426915778147192985052189"},
                new []{"DAF7AD50-F7ED-48DA-889A-A8E78EAEF297", "291057715677013852484148561513041293975"},
                new []{"C8CBF162-D1F5-4716-8238-E3208CF77F7B", "266904531309319040621529214696040136571"}
		    };

            foreach (var uidPair in uidPairs)
            {
                Console.WriteLine("Test value: {0}", uidPair[0]);
                Console.WriteLine(" Expected: {0}", uidPair[1]);

                var guidString = uidPair[0];
                var decimalString = uidPair[1];

                var guid = new Guid(guidString);
                var guidDecimalString = DicomUid.ConvertGuid(guid);
                Assert.AreEqual(decimalString, guidDecimalString);
                Console.WriteLine(" ConvertGuid: {0}", guidDecimalString);
#if !__MonoCS__
                var bigIntString = FromBigInt(guid);
                Console.WriteLine(" BigInteger:  {0}", bigIntString);
                Assert.AreEqual(decimalString, bigIntString);
#endif
                Console.WriteLine();
            }
		}
		public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)
		{
		    try
		    {
                // TODO: Create entries in .resx for these messages
			    Uri uri;
			    if (!Uri.TryCreate(name, UriKind.Relative, out uri))
			    {                    
                    ShowMessage(string.Format("The file {0} cannot be uploaded because it would create an invalid URL. Please, rename the file before upload.", name));
			        return "";
			    }

                var invalidChars = new[] {'<', '>', '*', '%', '&', ':', '\\', '?', '+'};
			    if (invalidChars.Any(uri.ToString().Contains))
			    {
                    ShowMessage(string.Format("The file {0} contains some invalid characters. The file name cannot contain any of the following characters: {1}", name, new String(invalidChars)));
                    return "";
                }

			    string virtualPath = FileSystemValidation.ToVirtualPath(path);

				string returnValue = DNNValidator.OnCreateFile(FileSystemValidation.CombineVirtualPath(virtualPath, name), file.ContentLength);
				if (!string.IsNullOrEmpty(returnValue))
				{
					return returnValue;
				}

                var folder = DNNValidator.GetUserFolder(virtualPath);

			    var fileInfo = new Services.FileSystem.FileInfo();
                FillFileInfo(file, ref fileInfo);

				//Add or update file
				FileManager.Instance.AddFile(folder, name, file.InputStream);

				return returnValue;
			}
			catch (Exception ex)
			{
				return DNNValidator.LogUnknownError(ex, path, name);
			}
		}
Esempio n. 7
0
        public static Claim UnlockClaim(Claim claim)
        {
            var sw = Stopwatch.StartNew();
            try
            {
                var parameters = new[]
                                     {
                                         claim.GeniusXHeaderId.ToString(CultureInfo.InvariantCulture), true.ToString(),
                                         String.Empty, false.ToString()
                                     };
                var transaction =
                    (AmendClaimWithoutValidationTransaction)
                    BusinessTransactionFactory.GetBusinessTransactionByName("Claims.AmendClaimWithoutValidation", parameters);
                var claimHeaderId = transaction.ClaimHeader.ClaimHeaderID;
                var policyHeaderID = transaction.ClaimHeader.PolicyHeaderID;
                transaction.Cancel();
                var claimHeaderLocks = LockManager.CheckLock(claimHeaderId.ToString(CultureInfo.InvariantCulture),
                                                             LockLevel.ClaimHeader,
                                                             LockDurationType.Persistent, LockType.Update,
                                                             LockOrigin.Underwriting);
                if (claimHeaderLocks.Any())
                {
                    foreach (var @lock in claimHeaderLocks)
                    {
                        LockManager.RemoveLock(@lock.LockLevel, @lock.LockData, @lock.TransactionID);
                        Logger.InfoFormat("Clearing Claim Header lock\r\n{0}",
                                          JObject.FromObject(new {claim.ClaimReference, Lock = @lock}));
                    }
                }

                var claimReferenceLocks = LockManager.CheckLock(claim.ClaimReference, LockLevel.ClaimReference,
                                                                LockDurationType.Transaction, LockType.Update,
                                                                LockOrigin.ClaimInput);

                if (claimReferenceLocks.Any())
                {
                    foreach (var @lock in claimReferenceLocks)
                    {
                        LockManager.RemoveLock(@lock.LockLevel, @lock.LockData, @lock.TransactionID);
                        Logger.InfoFormat("Clearing Claim Reference lock\r\n{0}",
                                          JObject.FromObject(new {claim.ClaimReference, Lock = @lock}));
                    }
                }

                var policyReferenceLocks = LockManager.CheckLock(policyHeaderID.ToString(), LockLevel.HeaderReference,
                                                                 LockDurationType.Transaction, LockType.Update,
                                                                 LockOrigin.Underwriting);
                if (policyReferenceLocks.Any())
                {
                    foreach (var @lock in policyReferenceLocks)
                    {
                        LockManager.RemoveLock(@lock.LockLevel, @lock.LockData, @lock.TransactionID);
                        Logger.InfoFormat("Clearing Policy locks\r\n{0}",
                                          JObject.FromObject(new {claim.PolicyNumber, Lock = @lock}));
                    }
                }
                claim.ClaimProcessingCompleted = true;

                return claim;
            }
            finally
            {
                sw.Stop();
                var workDone = GlobalClaimWakeUp.Statistics.GetOrAdd(typeof (ClearLocksBlock).Name,
                                                          TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds));
                GlobalClaimWakeUp.Statistics[typeof (ClearLocksBlock).Name] = (workDone + TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds));
            }
        }