Esempio n. 1
0
        public override void UploadPackage(string filename, Utility.StreamCopyProgressDelegate callback)
        {
            System.IO.FileInfo fi = new System.IO.FileInfo(filename);

            if (callback != null)
                callback(0, fi.Length, fi.Length);

            var res = GetResourceService();
            MgByteSource pkgSource = new MgByteSource(filename);
            MgByteReader rd = pkgSource.GetReader();
            res.ApplyResourcePackage(rd);
            rd.Dispose();
            LogMethodCall("MgResourceService::ApplyResourcePackage", true, "MgByteReader");
            if (callback != null)
                callback(fi.Length, 0, fi.Length);
        }
Esempio n. 2
0
 public override void SetResourceData(string resourceid, string dataname, ResourceDataType datatype, System.IO.Stream stream, Utility.StreamCopyProgressDelegate callback)
 {
     var res = GetResourceService();
     MgByteReader reader = null;
     string tmpPath = null;
     //If stream is under our hard-coded limit (and it's seekable, which is how we're able to get that number), use the
     //overload of MgByteSource that accepts a byte[]. Otherwise dump the stream to a temp file and use the
     //file name overload (otherwise if our input stream happens to be several GBs, we run risk of
     //System.OutOfMemoryExceptions being thrown back at us)
     if (stream.CanSeek && stream.Length < (MAX_INPUT_STREAM_SIZE_MB * 1024 * 1024))
     {
         byte[] data = Utility.StreamAsArray(stream);
         MgByteSource source = new MgByteSource(data, data.Length);
         reader = source.GetReader();
     }
     else
     {
         tmpPath = Path.GetTempFileName();
         using (FileStream fs = File.OpenWrite(tmpPath))
         {
             stream.CopyTo(fs);
         }
         MgByteSource source = new MgByteSource(tmpPath);
         reader = source.GetReader();
     }
     try
     {
         res.SetResourceData(new MgResourceIdentifier(resourceid), dataname, datatype.ToString(), reader);
         LogMethodCall("MgResourceService::SetResourceData", true, resourceid, dataname, datatype.ToString(), "MgByteReader");
     }
     finally
     {
         if (!string.IsNullOrEmpty(tmpPath) && File.Exists(tmpPath))
         {
             //Be a responsible citizen and clean up our temp files when done
             try
             {
                 File.Delete(tmpPath);
             }
             catch { }
         }
     }
 }