Ejemplo n.º 1
0
 public void update(dirItemsDelta delta) {
   if (delta.empty()) return;
   Parallel.ForEach(delta.delete, it => File.Delete(fileName(it.url)));
   Parallel.ForEach(delta.update.Concat(delta.insert), it => {
     var fn = fileName(it.url); Directory.CreateDirectory(Path.GetDirectoryName(fn));
     File.Copy(Machines.rootDir + it.url.Replace('/', '\\'), fn, true);
   });
   File.WriteAllBytes(fileName("/container.content"), delta.fileMap);
 }
Ejemplo n.º 2
0
 public dirItemsDelta synchronize(dirItems dest, bool isJS, IEnumerable<BuildIds> buildIds, IEnumerable<Langs> langs) {
   //filter
   HashSet<BuildIds> bids = new HashSet<BuildIds>(buildIds); HashSet<Langs> lcs = new HashSet<Langs>(langs);
   var filterDir = dir.Values.Where(v => {
     if (v.url.EndsWith(".js") != isJS) return false;
     return (v.lang == Langs.no || lcs.Contains(v.lang)) && v.buildIdLst.Any(bid => bids.Contains(bid));
   }).ToDictionary(v => v.url);
   //sync
   var res = new dirItemsDelta();
   HashSet<string> srcDone = new HashSet<string>();
   for (int i = dest.items.Count - 1; i >= 0; i--) { //delete, update:
     dirItem destItem = dest.items[i]; buildEnvelope srcItem;
     if (filterDir.TryGetValue(destItem.url, out srcItem)) {
       srcDone.Add(destItem.url);
       if (srcItem.etag == destItem.etag) continue;
       res.update.Add(destItem); destItem.etag = srcItem.etag;
     } else {
       res.delete.Add(destItem);
       dest.items.RemoveAt(i);
     }
   }
   foreach (var srcItem in filterDir.Values) { //insert:
     if (srcDone.Contains(srcItem.url)) continue;
     dirItem destItem = new dirItem { url = srcItem.url, etag = srcItem.etag };
     res.insert.Add(destItem); dest.items.Add(destItem);
   }
   if (res.empty()) return null;
   res.fileMap = XmlUtils.ObjectToBytes(dest);
   return res;
 }
Ejemplo n.º 3
0
    //https://cmatskas.com/working-with-azure-blobs-through-the-net-sdk/
    //https://msdn.microsoft.com/en-us/library/wa_storage_30_reference_home.aspx
    public void update(dirItemsDelta delta) {
      //      var rootContainer = blobClient.GetContainerReference("$root");
      //      if (rootContainer.CreateIfNotExists()) rootContainer.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });

      //      var slAccess = rootContainer.GetBlockBlobReference("clientaccesspolicy.xml");
      //      slAccess.Properties.ContentType = "text/xml; charset=utf-8";
      //      slAccess.UploadText(
      //@"<?xml version=""1.0"" encoding=""utf-8""?>
      //<access-policy>
      //  <cross-domain-access>
      //    <policy>
      //      <allow-from http-methods=""*"" http-request-headers=""*"">
      //        <domain uri=""*"" />
      //        <domain uri=""http://*"" />
      //        <domain uri=""https://*"" />
      //      </allow-from>
      //      <grant-to>
      //        <resource path=""/"" include-subpaths=""true"" />
      //      </grant-to>
      //    </policy>
      //  </cross-domain-access>
      //</access-policy>");

      if (delta == null || delta.empty()) ;
      Parallel.ForEach(delta.delete, new ParallelOptions { MaxDegreeOfParallelism = paralelCount }, it => container.GetBlockBlobReference(it.url.Substring(1)).Delete());
      Parallel.ForEach(delta.update.Concat(delta.insert), new ParallelOptions { MaxDegreeOfParallelism = paralelCount }, it => {
        var blob = container.GetBlockBlobReference(it.url.Substring(1));
        var fn = Machines.rootDir + it.url.Replace('/', '\\');
        blob.Properties.ContentType = Consts.contentTypes[Path.GetExtension(fn)];
        blob.UploadFromFile(fn, FileMode.Open);
      });
      var map = container.GetBlockBlobReference("container.content");
      map.UploadFromByteArray(delta.fileMap, 0, delta.fileMap.Length);
    }