public FastAzureIndexInput(AzureDirectory azuredirectory, BlobMeta blobMeta)
 {
     this._name      = blobMeta.Name;
     this._fileMutex = BlobMutexManager.GrabMutex(this._name);
     this._fileMutex.WaitOne();
     try
     {
         this._azureDirectory = azuredirectory;
         this._blobContainer  = azuredirectory.BlobContainer;
         this._blob           = blobMeta.Blob;
         string name = this._name;
         bool   flag = false;
         if (!this.CacheDirectory.FileExists(name))
         {
             flag = true;
         }
         else
         {
             long     num      = this.CacheDirectory.FileLength(name);
             long     result1  = blobMeta.Length;
             DateTime dateTime = blobMeta.LastModified;
             if (num != result1)
             {
                 flag = true;
             }
             else
             {
                 long ticks = this.CacheDirectory.FileModified(name);
                 if (ticks > FastAzureIndexInput.ticks1970)
                 {
                     ticks -= FastAzureIndexInput.ticks1970;
                 }
                 DateTime universalTime = new DateTime(ticks, DateTimeKind.Local).ToUniversalTime();
                 if (universalTime != dateTime && dateTime.Subtract(universalTime).TotalSeconds > 1.0)
                 {
                     flag = true;
                 }
             }
         }
         if (flag)
         {
             StreamOutput cachedOutputAsStream = this._azureDirectory.CreateCachedOutputAsStream(name);
             this._blob.ParallelDownloadBlob((Stream)cachedOutputAsStream);
             cachedOutputAsStream.Flush();
             cachedOutputAsStream.Close();
             this._indexInput = this.CacheDirectory.OpenInput(name);
         }
         else
         {
             this._indexInput = this.CacheDirectory.OpenInput(name);
         }
     }
     finally
     {
         this._fileMutex.ReleaseMutex();
     }
 }
Пример #2
0
        public override string[] ListAll()
        {
            if (_blobMetaLookup == null)
            {
                ReloadMetadata();
            }
            var blobList  = BlobContainer.ListBlobs(_rootFolder, true, BlobListingDetails.All);
            var blobMetas = _blobMetaLookup;

            foreach (var meta in blobList)
            {
                if (meta is CloudBlockBlob)
                {
                    var fullBlob = (CloudBlockBlob)meta;
                    var newMeta  = new BlobMeta(fullBlob);
                    if (newMeta.Name == null)
                    {
                        continue;
                    }
                    BlobMeta oldMeta;
                    if (blobMetas.TryGetValue(newMeta.Name, out oldMeta))
                    {
                        if (newMeta.Length != oldMeta.Length || newMeta.LastModified != oldMeta.LastModified)
                        {
                            BlobMeta tmp;
                            if (blobMetas.TryRemove(newMeta.Name, out tmp))
                            {
                                blobMetas.TryAdd(newMeta.Name, newMeta);
                            }
                        }
                    }
                    else
                    {
                        blobMetas.TryAdd(newMeta.Name, newMeta);
                    }
                }
            }
            return(blobList.Select(blob => blob.Uri.AbsolutePath.Substring(blob.Uri.AbsolutePath.LastIndexOf('/') + 1)).ToArray());
        }
 public FastAzureIndexInput(AzureDirectory azuredirectory, ICloudBlob blob, out BlobMeta meta)
 {
     meta            = new BlobMeta();
     this._name      = blob.Uri.Segments[blob.Uri.Segments.Length - 1];
     this._fileMutex = BlobMutexManager.GrabMutex(this._name);
     this._fileMutex.WaitOne();
     try
     {
         this._azureDirectory = azuredirectory;
         this._blobContainer  = azuredirectory.BlobContainer;
         this._blob           = blob;
         string name = this._name;
         bool   flag = false;
         if (!this.CacheDirectory.FileExists(name))
         {
             flag = true;
         }
         else
         {
             long num     = this.CacheDirectory.FileLength(name);
             long result1 = blob.Properties.Length;
             long.TryParse(blob.Metadata["CachedLength"], out result1);
             long     result2  = 0;
             DateTime dateTime = blob.Properties.LastModified.Value.UtcDateTime;
             if (long.TryParse(blob.Metadata["CachedLastModified"], out result2))
             {
                 if (result2 > FastAzureIndexInput.ticks1970)
                 {
                     result2 -= FastAzureIndexInput.ticks1970;
                 }
                 dateTime = new DateTime(result2).ToUniversalTime();
             }
             if (num != result1)
             {
                 flag = true;
             }
             else
             {
                 long ticks = this.CacheDirectory.FileModified(name);
                 if (ticks > FastAzureIndexInput.ticks1970)
                 {
                     ticks -= FastAzureIndexInput.ticks1970;
                 }
                 DateTime universalTime = new DateTime(ticks, DateTimeKind.Local).ToUniversalTime();
                 if (universalTime != dateTime && dateTime.Subtract(universalTime).TotalSeconds > 1.0)
                 {
                     flag = true;
                 }
             }
             meta.Name         = this._name;
             meta.LastModified = dateTime;
             meta.Length       = result1;
             meta.Blob         = blob;
         }
         if (flag)
         {
             StreamOutput cachedOutputAsStream = this._azureDirectory.CreateCachedOutputAsStream(name);
             this._blob.ParallelDownloadBlob((Stream)cachedOutputAsStream);
             cachedOutputAsStream.Flush();
             cachedOutputAsStream.Close();
             this._indexInput = this.CacheDirectory.OpenInput(name);
         }
         else
         {
             this._indexInput = this.CacheDirectory.OpenInput(name);
         }
         meta.HasData = true;
     }
     finally
     {
         this._fileMutex.ReleaseMutex();
     }
 }