Esempio n. 1
0
        public ActionResult RecoverApp(HttpPostedFileBase file, bool overideTempApp = false)
        {
            // validate
            if (file == null || file.ContentLength == 0 || (file.ContentType != "text/plain" && file.ContentType != "application/octet-stream" && file.ContentType != "application/json"))
            {
                return(View());
            }

            // get data
            BinaryReader b = new BinaryReader(file.InputStream);

            byte[] binData = b.ReadBytes((int)file.InputStream.Length);
            string result  = Encoding.UTF8.GetString(binData);

            // transfer to object
            var service = new RecoveryService();

            try
            {
                service.RecoverApplication(result, overideTempApp);

                return(RedirectToRoute("Master", new { @controller = "AppAdminManager", @action = "Index" }));
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex, Request);
                ViewData["Message"] = ex.Message;
                return(View());
            }
        }
Esempio n. 2
0
        public ActionResult RecoverApp(HttpPostedFileBase file)
        {
            //if everything is ok
            if (file != null && file.ContentLength > 0 && file.ContentType == "text/plain")
            {
                BinaryReader b       = new BinaryReader(file.InputStream);
                byte[]       binData = b.ReadBytes((int)file.InputStream.Length);

                string result = Encoding.UTF8.GetString(binData);

                //Now we use recover service
                var         service = new RecoveryService();
                Application app     = service.RecoverApplication(result);
                app.IsEnabled   = false;
                app.IsPublished = false;
                app.BuildLocked = false;

                Dictionary <int, MozaicEditorPage> pageMapping = new Dictionary <int, MozaicEditorPage>();
                foreach (var page in app.MozaicEditorPages)
                {
                    pageMapping.Add(page.Id, page);
                }

                try
                {
                    var context = HttpContext.GetCORE().Entitron.GetStaticTables();
                    context.Applications.Add(app);
                    context.SaveChanges();

                    foreach (var meta in app.TapestryDesignerMetablocks)
                    {
                        foreach (var block in meta.Blocks)
                        {
                            foreach (var commit in block.BlockCommits)
                            {
                                List <int> newPageIds = new List <int>();
                                List <int> pageIds    = commit.AssociatedPageIds.Split(',').Select(p => Convert.ToInt32(p)).ToList();
                                foreach (int pageId in pageIds)
                                {
                                    newPageIds.Add(pageMapping[pageId].Id);
                                }

                                commit.AssociatedPageIds = string.Join(",", newPageIds.Select(i => i.ToString()).ToList());
                            }
                        }
                    }
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    Logger.Log.Error(ex, Request);
                    ViewData["Message"] = ex.Message;
                    return(View());
                }
            }
            return(View());
        }