当前位置: 首页>>代码示例>>C#>>正文


C# Cache.ListRecursive方法代码示例

本文整理汇总了C#中Cache.ListRecursive方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.ListRecursive方法的具体用法?C# Cache.ListRecursive怎么用?C# Cache.ListRecursive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cache的用法示例。


在下文中一共展示了Cache.ListRecursive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Handle

 public void Handle(string appname, string[] components, HttpRequestHead head, IDataProducer body, IHttpResponseDelegate response)
 {
     // Look inside the cache for a list of files.
     Cache c = new Cache(false);
     string s = "";
     foreach (string key in c.ListRecursive("server/" + appname + "/hashes"))
         s += c.Get<Hash>("server/" + appname + "/hashes/" + key) + " " + key + "\r\n";
     response.OnResponse(new HttpResponseHead()
     {
         Status = "200 OK",
         Headers = new Dictionary<string, string>
             {
                 { "Content-Type", "text/plain" },
                 { "Content-Length", s.Length.ToString() },
                 { "Connection", "close" }
             }
     }, new BufferedProducer(s));
 }
开发者ID:hach-que,项目名称:Pivot.Update,代码行数:18,代码来源:InitialOperation.cs

示例2: Main


//.........这里部分代码省略.........
                            Console.WriteLine("no .pvdeploy file found; please create one.");
                            return;
                        }

                        // Find all files in the current working directory.
                        diff_match_patch dmf = new diff_match_patch();
                        FileFilter filter = FileFilterParser.Parse(".pvdeploy", GetRecursiveFilesInCwd());
                        foreach (KeyValuePair<string, string> kv in filter)
                        {
                            if (c.Exists("server/" + appname + "/store/" + kv.Value))
                            {
                                // File is being updated, get a hash for the current version
                                // and for the stored version.
                                Hash oldHash = Hash.FromFile(c.GetFilePath("server/" + appname + "/store/" + kv.Value));
                                Hash newHash = Hash.FromFile(Path.Combine(Environment.CurrentDirectory, kv.Key));
                                if (oldHash != newHash)
                                {
                                    // Files are different, produce a diff.
                                    byte[] oldData = FileUtils.GetAllBytes(c.GetFilePath("server/" + appname + "/store/" + kv.Value));
                                    byte[] newData = FileUtils.GetAllBytes(Path.Combine(Environment.CurrentDirectory, kv.Key));
                                    List<Patch> patches = dmf.patch_make(Encoding.ASCII.GetString(oldData), Encoding.ASCII.GetString(newData));
                                    string result = dmf.patch_toText(patches);
                                    c.Set<string>("server/" + appname + "/patches/" + kv.Value + "/" + oldHash + "-" + newHash, result);
                                    c.Set<Hash>("server/" + appname + "/hashes/" + kv.Value, newHash);
                                    if (c.Exists("server/" + appname + "/store/" + kv.Value))
                                        c.Delete("server/" + appname + "/store/" + kv.Value);
                                    File.Copy(Path.Combine(Environment.CurrentDirectory, kv.Key), c.GetFilePath("server/" + appname + "/store/" + kv.Value));
                                    if (!c.Exists("server/" + appname + "/store/" + kv.Value))
                                        throw new InvalidOperationException("Unable to copy file to server store.");
                                    Console.WriteLine(oldHash + " => " + newHash + " " + kv.Value);
                                }
                            }
                            else
                            {
                                // A new file is being stored.
                                Hash newHash = Hash.FromFile(Path.Combine(Environment.CurrentDirectory, kv.Key));
                                byte[] newData = FileUtils.GetAllBytes(Path.Combine(Environment.CurrentDirectory, kv.Key));
                                List<Patch> patches = dmf.patch_make("", Encoding.ASCII.GetString(newData));
                                string result = dmf.patch_toText(patches);
                                c.Set<string>("server/" + appname + "/patches/" + kv.Value + "/" + Hash.Empty + "-" + newHash, result);
                                c.Set<Hash>("server/" + appname + "/hashes/" + kv.Value, newHash);
                                if (c.Exists("server/" + appname + "/store/" + kv.Value))
                                    c.Delete("server/" + appname + "/store/" + kv.Value);
                                File.Copy(Path.Combine(Environment.CurrentDirectory, kv.Key), c.GetFilePath("server/" + appname + "/store/" + kv.Value));
                                if (!c.Exists("server/" + appname + "/store/" + kv.Value))
                                    throw new InvalidOperationException("Unable to copy file to server store.");
                                Console.WriteLine(Hash.Empty + " => " + newHash + " " + kv.Value);
                            }
                        }
                        foreach (string s in c.ListRecursive("server/" + appname + "/store"))
                        {
                            if (filter.Count(v => v.Value == s) == 0)
                            {
                                // A file is being deleted.
                                Hash oldHash = Hash.FromFile(c.GetFilePath("server/" + appname + "/store/" + s));
                                byte[] oldData = FileUtils.GetAllBytes(c.GetFilePath("server/" + appname + "/store/" + s));
                                List<Patch> patches = dmf.patch_make(Encoding.ASCII.GetString(oldData), "");
                                string result = dmf.patch_toText(patches);
                                c.Set<string>("server/" + appname + "/patches/" + s + "/" + oldHash.ToString() + "-" + Hash.Empty.ToString(), result);
                                c.Set<Hash>("server/" + appname + "/hashes/" + s, Hash.Empty);
                                if (c.Exists("server/" + appname + "/store/" + s))
                                    c.Delete("server/" + appname + "/store/" + s);
                                if (c.Exists("server/" + appname + "/store/" + s))
                                    throw new InvalidOperationException("Unable to delete file from server store.");
                                Console.WriteLine(oldHash + " => " + Hash.Empty + " " + s);
                            }
                        }

                        Console.WriteLine("flash complete.");
                        return;
                    }
                case "state":
                    {
                        if (args.Length < 2)
                        {
                            Console.WriteLine("must have at least 2 arguments (state <appname>).");
                            return;
                        }

                        string appname = args[1];
                        Cache c = new Cache(false);

                        if (!c.Exists("server/" + appname))
                        {
                            Console.WriteLine("this app does not exist.");
                            return;
                        }

                        foreach (string s in c.ListRecursive("server/" + appname + "/hashes"))
                        {
                            Console.WriteLine(c.Get<Hash>("server/" + appname + "/hashes/" + s) + " " + s);
                        }

                        return;
                    }
                default:
                    Console.WriteLine("invalid command (must be 'flash', 'create', 'state' or 'test-pvdeploy').");
                    return;
            }
        }
开发者ID:hach-que,项目名称:Pivot.Update,代码行数:101,代码来源:Program.cs


注:本文中的Cache.ListRecursive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。