コード例 #1
0
ファイル: Sync.cs プロジェクト: Jeavon/wa-accelerator-umbraco
        private IEnumerable<Tuple<string, FileEntry>> EnumerateLocalEntries()
        {
            foreach (var directory in Directory.EnumerateFileSystemEntries(this._localPath, "*", SearchOption.AllDirectories))
            {
                var relativePath = directory.Substring(this._localPath.Length + 1).Replace('\\', '/');
                var info = new FileInfo(directory);
                var entry = new FileEntry
                {
                    LocalLastModified = info.LastWriteTimeUtc,
                    IsDirectory = info.Attributes.HasFlag(FileAttributes.Directory)
                };

                if (IsExcluded(relativePath))
                    continue;

                if (entry.IsDirectory)
                    continue;

                yield return new Tuple<string, FileEntry>(relativePath, entry);
            }
        }
コード例 #2
0
ファイル: Sync.cs プロジェクト: Jeavon/wa-accelerator-umbraco
        private void SyncBlobToLocal(HashSet<string> seen, HashSet<string> newCerts)
        {
            foreach (var blob in this._container.ListBlobs(new BlobRequestOptions { UseFlatBlobListing = true, BlobListingDetails = BlobListingDetails.Metadata }).OfType<CloudBlob>())
            {
                var path = blob.Uri.ToString().Substring(this._container.Uri.ToString().Length + 1);
                var entry = new FileEntry { IsDirectory = blob.Metadata["IsDirectory"] == "true", CloudLastModified = blob.Properties.LastModifiedUtc };

                seen.Add(path);

                if (!this._entries.ContainsKey(path) || this._entries[path].CloudLastModified < entry.CloudLastModified)
                {
                    if (entry.IsDirectory)
                    {
                        TryFiveTimes(() =>
                            {
                                Directory.CreateDirectory(Path.Combine(this._localPath, path));
                            });
                    }
                    else if (string.IsNullOrEmpty(Path.GetDirectoryName(path)) && Path.GetExtension(path).ToLowerInvariant() == ".pfx")
                    {
                        newCerts.Add(Path.GetFileNameWithoutExtension(path).ToLowerInvariant());

                        // don't actually download this, no need to have the cert sitting around on disk
                        this._entries[path] = entry;
                    }
                    else
                    {
                        if (Path.GetFileName(path).ToLowerInvariant() != "umbraco.config") // ignore umbraco.config
                        {
                            TryFiveTimes(() =>
                                {
                                    Directory.CreateDirectory(Path.Combine(this._localPath, Path.GetDirectoryName(path)));
                                });

                            TryFiveTimes(() =>
                                {
                                    using (var stream = File.Open(Path.Combine(this._localPath, path), FileMode.Create, FileAccess.Write, FileShare.ReadWrite | FileShare.Delete))
                                    {
                                        blob.DownloadToStream(stream);
                                    }
                                });
                        }
                    }

                    TryFiveTimes(() =>
                        {
                            entry.LocalLastModified = new FileInfo(Path.Combine(this._localPath, path)).LastWriteTimeUtc;
                        });
                    this._entries[path] = entry;
                }
            }

            //delete local entries that are not represented in blob storage
            foreach (var path in this._entries.Keys.Where(k => !seen.Contains(k) && Path.GetFileName(k).ToLowerInvariant() != "umbraco.config").ToArray())
            {
                if (this._entries[path].IsDirectory)
                {
                    TryFiveTimes(() =>
                        {
                            Directory.Delete(Path.Combine(this._localPath, path), true);
                        });
                }
                else
                {
                    if (string.IsNullOrEmpty(Path.GetDirectoryName(path)) && Path.GetExtension(path).ToLowerInvariant() == ".pfx")
                    {
                        newCerts.Add(Path.GetFileNameWithoutExtension(path).ToLowerInvariant());
                    }

                    try
                    {
                        TryFiveTimes(() =>
                            {
                                File.Delete(Path.Combine(this._localPath, path));
                            });
                    }
                    catch
                    {
                    }
                }
                this._entries.Remove(path);
            }
        }