コード例 #1
0
        private void SaveCache()
        {
            string dir  = @".\RequestCaches\";
            string file = $@"{dir}\{txController.Text}.{txAction.Text}.json";

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            RequestCache cache = new RequestCache();

            cache.Action     = txAction.Text;
            cache.Controller = txController.Text;
            cache.Parameters = ((IEnumerable)dataGrid.DataSource)
                               .Cast <ServerRequestParameter>()
                               .Where(p => !string.IsNullOrEmpty(p.Key))
                               .ToList();

            string json = JsonConvert.SerializeObject(cache);

            File.WriteAllText(file, json);
        }
コード例 #2
0
        private bool LoadFromCache(string controller, string action)
        {
            string dir  = @".\RequestCaches\";
            string file = $@"{dir}\{controller}.{action}.json";

            if (!File.Exists(file))
            {
                return(false);
            }

            string       json  = File.ReadAllText(file);
            RequestCache cache = JsonConvert.DeserializeObject <RequestCache>(json);

            txAction.Text     = cache.Action;
            txController.Text = cache.Controller;

            if (cache.Parameters.Count > 0)
            {
                dataGrid.DataSource = cache.Parameters;
            }

            return(true);
        }