public bool ApplyUpdate(FileAsset item)
        {
            var fullPath = this.GetFullPath(item.Id);

            var directoryPath = Path.GetDirectoryName(fullPath);
            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            // check if file exists and if it's date is higher than the one on the server, dont update
            if (File.Exists(fullPath))
            {
                var lastUpdated = File.GetLastWriteTimeUtc(fullPath);
                if (lastUpdated >= item.Updated) return false;
            }

            using (var fs = new FileStream(fullPath, FileMode.Create))
            {
                var byteContent = item.ByteContent;

                if (byteContent == null && !String.IsNullOrEmpty(item.Content))
                    byteContent = Encoding.UTF8.GetBytes(item.Content);

                if(byteContent != null)
                    fs.Write(byteContent, 0, byteContent.Length);

                fs.Close();
            }

            // preserve the date
            File.SetLastWriteTimeUtc(fullPath, item.Updated);

            return true;
        }
        public bool ApplyUpdates(FileAsset[] items)
        {
            var reloadCache = false;

            foreach (var themeAsset in items)
            {
                if (this.ApplyUpdate(themeAsset)) reloadCache = true;
            }

            return reloadCache;
        }
Ejemplo n.º 3
0
 public static FileAsset AsFileModel(this Data2.SyncAsset asset)
 {
     var ret = new FileAsset();
     ret.InjectFrom(asset);
     return ret;
 }