Exemplo n.º 1
0
 /// <summary>
 /// 仅仅添加外部b64数据
 /// </summary>
 /// <param name="item"></param>
 /// <param name="b64data"></param>
 public void AddPlain(string item, string b64data)
 {
     if (FileNames.Contains(item) == false)
     {
         Count++;
         FileNames.Add(item);
         FileDatas.Add(item, null);
     }
     if (FileStringDatas.ContainsKey(item) == false)
     {
         FileStringDatas.Add(item, b64data);
     }
     else
     {
         FileStringDatas[item] = (b64data);
     }
 }
        private void UpdateURLs(ref JArray jSource)
        {
            foreach (JObject jObj in jSource)
            {
                try
                {
                    JToken oContentID;

                    //Empty PreRequisites should be handled by the Client; Fix after 1.6.2.14!
                    //try
                    //{
                    //    if (jObj["PreRequisites"] == null)
                    //    {
                    //        string[] oReq = new string[0];
                    //        jObj.Add("PreRequisites", JToken.FromObject(oReq));
                    //    }

                    //    if (!jObj["PreRequisites"].HasValues)
                    //    {
                    //        string[] oReq = new string[0];
                    //        jObj["PreRequisites"] = JToken.FromObject(oReq);
                    //    }
                    //}
                    //catch { }

                    try
                    {
                        jObj["Manufacturer"]   = Base.clean(jObj["Manufacturer"].Value <string>());
                        jObj["ProductName"]    = Base.clean(jObj["ProductName"].Value <string>());
                        jObj["ProductVersion"] = Base.clean(jObj["ProductVersion"].Value <string>());
                    }
                    catch { }

                    if (jObj.TryGetValue("ContentID", out oContentID))
                    {
                        string sContentID = oContentID.Value <string>();

                        List <string> FileNames = new List <string>();
                        if (_cache.TryGetValue("files-" + sContentID, out FileNames))
                        {
                        }
                        else
                        {
                            FileNames = new List <string>();
                            //No need to load blob if local content exists...
                            if (!Directory.Exists(Path.Combine(Settings["content"], sContentID)))
                            {
                                CloudBlobContainer oRepoContainer = new CloudBlobContainer(new Uri(Settings["contURL"] + "?" + Settings["contSAS"]));
                                var oDir = oRepoContainer.GetDirectoryReference(sContentID);

                                foreach (CloudBlockBlob oItem in oDir.ListBlobsSegmentedAsync(new BlobContinuationToken()).Result.Results)
                                {
                                    FileNames.Add(Path.GetFileName(oItem.Name.ToLower()));
                                }

                                var cacheEntryOptions = new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(SlidingExpiration)); //cache hash for x Seconds
                                _cache.Set("files-" + sContentID, FileNames, cacheEntryOptions);
                            }
                        }

                        foreach (JObject oFiles in jObj["Files"])
                        {
                            //Skip blob if local content folder exists
                            string sContentPath = Path.Combine(Settings["content"], sContentID);
                            if (File.Exists(Path.Combine(sContentPath, oFiles["FileName"].Value <string>())))
                            {
                                string sBase = Base.localURL;
                                if (Environment.GetEnvironmentVariable("localURL") != null)
                                {
                                    sBase = Environment.GetEnvironmentVariable("localURL"); //If hosted in a container, the localURL represensts the server URL
                                }
                                oFiles["URL"] = sBase + "/rest/v2/GetFile/" + oContentID + "/" + oFiles["FileName"].ToString().Replace("\\", "/");
                                continue;
                            }

                            if (FileNames.Contains(oFiles["FileName"].Value <string>().ToLower()))
                            {
                                //oFiles["URL"] = Base.localURL + "/rest/v2/GetFile/" + sContentID + "/" + oFiles["FileName"].ToString().Replace("\\", "/");
                                oFiles["URL"] = "https://cdn.ruckzuck.tools/rest/v2/GetFile/" + sContentID + "/" + oFiles["FileName"].ToString().Replace("\\", "/");
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                catch { }
            }
        }
Exemplo n.º 3
0
 public bool Contains(string filePath)
 {
     return(FileNames.Contains(filePath));
 }