Пример #1
0
 public override IndexOutput CreateOutput(string name)
 {
     SetDirty();
     CheckDirty();
     LoggingService.Log(new LogEntry(LogLevel.Info, null, $"Opening output for {_oldIndexFolderName}"));
     return(CacheDirectory.CreateOutput(name));
 }
Пример #2
0
        public void WriteCachedFileETag(string name, string eTag)
        {
            var fileName = name + ".etag";

            using (var output = CacheDirectory.CreateOutput(fileName))
            {
                output.WriteString(eTag);
            }
        }
Пример #3
0
        public CompositeIndexOutput(SyncDirectory syncDirectory, string name)
        {
            _name = name;

            _fileMutex = SyncMutexManager.GrabMutex(_name);
            _fileMutex.WaitOne();
            try
            {
                _syncDirectory = syncDirectory;

                // create the local cache one we will operate against...
                _indexOutput = CacheDirectory.CreateOutput(_name, IOContext.DEFAULT);
            }
            finally
            {
                _fileMutex.ReleaseMutex();
            }
        }
Пример #4
0
        public AzureIndexOutput(AzureDirectory azureDirectory, string name, CloudBlockBlob blob)
        {
            this._name = name;
            _fileMutex = BlobMutexManager.GrabMutex(_name);
            _fileMutex.WaitOne();
            try
            {
                _azureDirectory = azureDirectory;
                _blobContainer  = _azureDirectory.BlobContainer;
                _blob           = blob;

                // create the local cache one we will operate against...
                _indexOutput = CacheDirectory.CreateOutput(_name, IOContext.DEFAULT);
            }
            finally
            {
                _fileMutex.ReleaseMutex();
            }
        }
Пример #5
0
        public SyncIndexOutput(SyncDirectory syncDirectory, string name)
        {
            if (syncDirectory == null)
            {
                throw new ArgumentNullException(nameof(syncDirectory));
            }

            //TODO: _name was null here, is this intended? https://github.com/azure-contrib/AzureDirectory/issues/19
            // I have changed this to be correct now
            _name          = name;
            _syncDirectory = syncDirectory;
            _fileMutex     = SyncMutexManager.GrabMutex(_syncDirectory, _name);
            _fileMutex.WaitOne();
            try
            {
                // create the local cache one we will operate against...
                _indexOutput = CacheDirectory.CreateOutput(_name);
            }
            finally
            {
                _fileMutex.ReleaseMutex();
            }
        }
Пример #6
0
        public CompositeIndexInput(SyncDirectory azuredirectory, string name, string resourceDescription) : base(resourceDescription)
        {
            _name = name;

#if FULLDEBUG
            Debug.WriteLine(String.Format("opening {0} ", _name));
#endif
            _fileMutex = SyncMutexManager.GrabMutex(_name);
            _fileMutex.WaitOne();
            try
            {
                _syncDirectory = azuredirectory;

                var fileName = _name;

                var fFileNeeded = false;
                if (!CacheDirectory.FileExists(fileName))
                {
                    fFileNeeded = true;
                }
                else
                {
                    long cachedLength  = CacheDirectory.FileLength(fileName);
                    long primaryLength = PrimaryDirectory.FileLength(fileName);
                    if (cachedLength != primaryLength)
                    {
                        fFileNeeded = true;
                    }
                    else
                    {
                        // cachedLastModifiedUTC was not ouputting with a date (just time) and the time was always off
                        var cachedFilePath      = Path.Combine(_syncDirectory.CacheDirectoryPath, fileName);
                        var primaryFilePath     = Path.Combine(_syncDirectory.PrimaryDirectoryPath, fileName);
                        var cachedLastModified  = File.GetLastWriteTimeUtc(cachedFilePath);
                        var primaryLastModified = File.GetLastWriteTimeUtc(primaryFilePath);

                        if (cachedLastModified != primaryLastModified)
                        {
                            var timeSpan = primaryLastModified.Subtract(cachedLastModified);
                            if (timeSpan.TotalSeconds > 1)
                            {
                                fFileNeeded = true;
                            }
                            else
                            {
#if FULLDEBUG
                                Debug.WriteLine(timeSpan.TotalSeconds);
#endif
                                // file not needed
                            }
                        }
                    }
                }

                // if the file does not exist
                // or if it exists and it is older then the lastmodified time in the blobproperties (which always comes from the blob storage)
                if (fFileNeeded)
                {
                    var    primaryInput      = PrimaryDirectory.OpenInput(fileName, IOContext.DEFAULT);
                    byte[] primaryInputBytes = new byte[primaryInput.Length];
                    primaryInput.ReadBytes(primaryInputBytes, 0, (int)primaryInputBytes.Length);

                    using (var cachedOutput = CacheDirectory.CreateOutput(fileName, IOContext.DEFAULT))
                    {
                        cachedOutput.WriteBytes(primaryInputBytes, (int)primaryInputBytes.Length);
                        cachedOutput.Flush();
                    }
                    primaryInput.Dispose();

                    var cachedFilePath      = Path.Combine(_syncDirectory.CacheDirectoryPath, fileName);
                    var primaryFilePath     = Path.Combine(_syncDirectory.PrimaryDirectoryPath, fileName);
                    var primaryLastModified = File.GetLastWriteTimeUtc(primaryFilePath);
                    File.SetLastWriteTimeUtc(cachedFilePath, primaryLastModified);

                    //using (var fileStream = _azureDirectory.CreateCachedOutputAsStream(fileName))
                    //{

                    //    // get the blob
                    //    _blob.DownloadToStream(fileStream);

                    //    fileStream.Flush();
                    //    Debug.WriteLine(string.Format("GET {0} RETREIVED {1} bytes", _name, fileStream.Length));
                    //}


                    // and open it as an input
                    _indexInput = CacheDirectory.OpenInput(fileName, IOContext.DEFAULT);
                }
                else
                {
#if FULLDEBUG
                    Debug.WriteLine(String.Format("Using cached file for {0}", _name));
#endif

                    // open the file in read only mode
                    _indexInput = CacheDirectory.OpenInput(fileName, IOContext.DEFAULT);
                }
            }
            finally
            {
                _fileMutex.ReleaseMutex();
            }
        }
Пример #7
0
 internal StreamOutput CreateCachedOutputAsStream(string name)
 {
     return(new StreamOutput(CacheDirectory.CreateOutput(name)));
 }