Inheritance: CancelEventArgs
Ejemplo n.º 1
0
        public void SyncAll()
        {
            bool started    = false;
            var  cloudBlobs = container.ListBlobs(new BlobRequestOptions()
            {
                UseFlatBlobListing = true, BlobListingDetails = BlobListingDetails.Metadata
            }).OfType <CloudBlob>();
            var cloudBlobNames = new HashSet <string>(cloudBlobs.Select(b => b.Uri.ToString()));
            var localBlobNames = new HashSet <string>(localBlobs.Keys);

            localBlobNames.ExceptWith(cloudBlobNames);
            foreach (var name in localBlobNames)
            {
                started = true;
                if (!started && SyncStarted != null)
                {
                    SyncStarted(this);
                }
                File.Delete(GetLocalPath(name));
                localBlobs.Remove(name);
            }
            foreach (var blob in cloudBlobs)
            {
                if (!localBlobs.ContainsKey(blob.Uri.ToString()) ||
                    blob.Attributes.Properties.ETag != localBlobs[blob.Uri.ToString()])
                {
                    if (!started)
                    {
                        started = true;
                        if (SyncStarted != null)
                        {
                            SyncStarted(this);
                        }
                    }
                    var path = GetLocalPath(blob.Uri.ToString());
                    var args = new UpdatingFileEventArgs(blob, path);
                    if (UpdatingFile != null)
                    {
                        UpdatingFile(this, args);
                    }
                    if (!args.Cancel)
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(path));
                        using (var stream = File.Create(GetLocalPath(blob.Uri.ToString())))
                        {
                            blob.DownloadToStream(stream);
                        }
                    }
                    localBlobs[blob.Uri.ToString()] = blob.Properties.ETag;
                }
            }
            if (started && SyncCompleted != null)
            {
                SyncCompleted(this);
            }
        }
Ejemplo n.º 2
0
 public void SyncAll()
 {
     bool started = false;
     var cloudBlobs = container.ListBlobs(new BlobRequestOptions() { UseFlatBlobListing = true, BlobListingDetails = BlobListingDetails.Metadata }).OfType<CloudBlob>();
     var cloudBlobNames = new HashSet<string>(cloudBlobs.Select(b => b.Uri.ToString()));
     var localBlobNames = new HashSet<string>(localBlobs.Keys);
     localBlobNames.ExceptWith(cloudBlobNames);
     foreach (var name in localBlobNames)
     {
         started = true;
         if (!started && SyncStarted != null)
         {
             SyncStarted(this);
         }
         File.Delete(GetLocalPath(name));
         localBlobs.Remove(name);
     }
     foreach (var blob in cloudBlobs)
     {
         if (!localBlobs.ContainsKey(blob.Uri.ToString()) ||
             blob.Attributes.Properties.ETag != localBlobs[blob.Uri.ToString()])
         {
             if (!started)
             {
                 started = true;
                 if (SyncStarted != null)
                 {
                     SyncStarted(this);
                 }
             }
             var path = GetLocalPath(blob.Uri.ToString());
             var args = new UpdatingFileEventArgs(blob, path);
             if (UpdatingFile != null)
             {
                 UpdatingFile(this, args);
             }
             if (!args.Cancel)
             {
                 Directory.CreateDirectory(Path.GetDirectoryName(path));
                 using (var stream = File.Create(GetLocalPath(blob.Uri.ToString())))
                 {
                     blob.DownloadToStream(stream);
                 }
             }
             localBlobs[blob.Uri.ToString()] = blob.Properties.ETag;
         }
     }
     if (started && SyncCompleted != null)
     {
         SyncCompleted(this);
     }
 }