コード例 #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));
        }
コード例 #3
0
        public ActionResult UploadEx()
        {
            string fileNameCopy = "n/a";

            try
            {
                foreach (string fileName in Request.Files)
                {
                    fileNameCopy = fileName;
                    HttpPostedFileBase file = Request.Files[fileName];
                    uint weenieId           = 0;

                    using (MemoryStream memStream = new MemoryStream())
                    {
                        file.InputStream.CopyTo(memStream);
                        byte[] data = memStream.ToArray();

                        string         serialized = Encoding.UTF8.GetString(data);
                        CachePwnWeenie pw         = JsonConvert.DeserializeObject <CachePwnWeenie>(serialized);

                        List <string> messages = new List <string>();
                        Weenie        w        = pw.ConvertToWeenie(out messages);
                        ImportedWeenie = w;
                        weenieId       = w.DataObjectId;
                    }

                    return(Json(new { id = weenieId }));
                }
            }
            catch (Exception ex)
            {
                log.Error($"Error parsing uploaded weenie {fileNameCopy}.", ex);
            }

            return(new EmptyResult());
        }