private static void Main( string[] args ) { // default CachedDirectory stores cache in local temp folder CloudStorageAccount cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount; CloudStorageAccount.TryParse( CloudConfigurationManager.GetSetting( "blobStorage" ), out cloudStorageAccount ); AzureCloudProvider provider = new AzureCloudProvider( cloudStorageAccount ); Program p = new Program(); p.RunIndexOperations( provider ); }
public bool ObtainLock(string _lockFile) { string _leaseid = null; if (this.leases.ContainsKey(_lockFile)) { _leaseid = this.leases[_lockFile]; } CloudBlockBlob blob = this.blobContainer.GetBlockBlobReference(_lockFile); try { Debug.Print("AzureLock:Obtain({0}) : {1}", _lockFile, _leaseid); if (string.IsNullOrEmpty(_leaseid)) { _leaseid = blob.AcquireLease(TimeSpan.FromSeconds(60), _leaseid); Debug.Print("AzureLock:Obtain({0}): AcquireLease : {1}", _lockFile, _leaseid); // keep the lease alive by renewing every 30 seconds long interval = (long)TimeSpan.FromSeconds(30).TotalMilliseconds; Timer _renewTimer = new Timer(obj => { try { AzureCloudProvider al = (AzureCloudProvider)obj; al.Renew(_lockFile, _leaseid); } catch (Exception err) { Debug.Print(err.ToString()); } }, this, interval, interval); this.timers.Add(_lockFile, _renewTimer); } return(!string.IsNullOrEmpty(_leaseid)); } catch (StorageException webErr) { if (this._handleWebException(blob, webErr, _lockFile)) { return(this.ObtainLock(_lockFile)); } } /*catch (StorageClientException err) { * if (_handleStorageClientException(blob, err)) { * return ObtainLock(_lockFile); * } * }*/ return(false); }