示例#1
0
        public ActionResult DownloadOriginalToPhatJson(uint id)
        {
            try
            {
                Weenie                 model = SandboxContentProviderHost.CurrentProvider.GetWeenie(GetUserToken(), id);
                CachePwnWeenie         pwn   = CachePwnWeenie.ConvertFromWeenie(model);
                JsonSerializerSettings s     = new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                };
                string content  = JsonConvert.SerializeObject(pwn, Formatting.None, s);
                string filename = model.StringProperties.First(p => p.StringPropertyId == (int)StringPropertyId.Name).Value + " (" + id.ToString() + ").json";
                return(File(Encoding.UTF8.GetBytes(content), "application/json", filename));
            }
            catch (Exception ex)
            {
                log.Error($"Error exporting weenie {id}", ex);

                IndexModel model = new IndexModel();
                model.ErrorMessages.Add($"Error exporting weenie {id}");
                model.Exception   = ex;
                CurrentIndexModel = model;

                return(RedirectToAction("Index"));
            }
        }
示例#2
0
        public ActionResult DownloadSandboxToPhatJson(uint id, string userGuid)
        {
            WeenieChange wc = null;

            if (string.IsNullOrWhiteSpace(userGuid))
            {
                // no userGuid specified, assume your own sandbox
                wc = SandboxContentProviderHost.CurrentProvider.GetMySandboxedChange(GetUserToken(), id);
            }
            else
            {
                // validate dev/admin or matches your id
                if (User.IsInRole("Developer") || GetUserGuid() == userGuid)
                {
                    wc = SandboxContentProviderHost.CurrentProvider.GetSandboxedChange(Guid.Parse(userGuid), id);
                }
                else
                {
                    return(new HttpNotFoundResult());
                }
            }

            if (wc == null)
            {
                return(new HttpNotFoundResult());
            }

            CachePwnWeenie         pwn = CachePwnWeenie.ConvertFromWeenie(wc.Weenie);
            JsonSerializerSettings s   = new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            };
            string content  = JsonConvert.SerializeObject(pwn, Formatting.None, s);
            string filename = wc.Weenie.StringProperties.First(p => p.StringPropertyId == (int)StringPropertyId.Name).Value + $" ({id}).json";

            return(File(Encoding.UTF8.GetBytes(content), "application/json", filename));
        }