示例#1
0
 private uint GetIdentifierCRC32(string identifier)
 {
     using (Stream stream = File.OpenRead(BuildFileName(identifier)))
     {
         return(CRC32Utility.GetCRC32(stream));
     }
 }
示例#2
0
 public void AsyncLoad()
 {
     try
     {
         uint cRC32 = 0;
         if (System.IO.File.Exists(_fileName))
         {
             // compute the CRC of the existing file
             using (FileStream stream = new FileStream(_fileName, FileMode.Open, FileAccess.Read))
                 cRC32 = CRC32Utility.GetCRC32(stream);
         }
         using
         (
             DAE.Runtime.Data.Row row = (DAE.Runtime.Data.Row)_process.Evaluate
                                        (
                 String.Format
                 (
                     "LoadIfNecessary('{0}', {1})",
                     _document.Replace("'", "''"),
                     ((int)cRC32).ToString()
                 ),
                 null
                                        )
         )
         {
             if (!(bool)row["CRCMatches"])
             {
                 Directory.CreateDirectory(Path.GetDirectoryName(_fileName));
                 using (Stream sourceStream = row.GetValue("Value").OpenStream())
                     using (FileStream targetStream = new FileStream(_fileName, FileMode.Create, FileAccess.Write))
                         StreamUtility.CopyStream(sourceStream, targetStream);
             }
         }
         Session.SafelyInvoke(new AsyncFinishHandler(AsyncFinish), new object[] { true });
     }
     catch
     {
         Session.SafelyInvoke(new AsyncFinishHandler(AsyncFinish), new object[] { false });
         // Don't allow exceptions to go unhandled... the framework will abort the application
     }
 }
示例#3
0
        public override object InternalExecute(Program program, object[] arguments)
        {
            IDataValue tempValue = arguments[0] as IDataValue;

            if (tempValue == null)
            {
                tempValue = DataValue.FromNative(program.ValueManager, arguments[0]);
            }

            if (tempValue.IsPhysicalStreaming)
            {
                using (Stream stream = tempValue.OpenStream())
                {
                    return((int)CRC32Utility.GetCRC32(stream));
                }
            }
            else
            {
                byte[] physical = new byte[tempValue.GetPhysicalSize(true)];
                tempValue.WriteToPhysical(physical, 0, true);
                return((int)CRC32Utility.GetCRC32(physical));
            }
        }