Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void reportProgressOnRecovery() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReportProgressOnRecovery()
        {
            RecoveryService                    recoveryService           = mock(typeof(RecoveryService), Answers.RETURNS_MOCKS);
            CorruptedLogsTruncator             logsTruncator             = mock(typeof(CorruptedLogsTruncator));
            RecoveryMonitor                    recoveryMonitor           = mock(typeof(RecoveryMonitor));
            TransactionCursor                  reverseTransactionCursor  = mock(typeof(TransactionCursor));
            TransactionCursor                  transactionCursor         = mock(typeof(TransactionCursor));
            CommittedTransactionRepresentation transactionRepresentation = mock(typeof(CommittedTransactionRepresentation));

            int         transactionsToRecover         = 5;
            int         expectedMax                   = transactionsToRecover * 2;
            int         lastCommittedTransactionId    = 14;
            LogPosition recoveryStartPosition         = LogPosition.start(0);
            int         firstTxIdAfterLastCheckPoint  = 10;
            RecoveryStartInformation startInformation = new RecoveryStartInformation(recoveryStartPosition, firstTxIdAfterLastCheckPoint);

            when(reverseTransactionCursor.next()).thenAnswer(new NextTransactionAnswer(transactionsToRecover));
            when(transactionCursor.next()).thenAnswer(new NextTransactionAnswer(transactionsToRecover));
            when(reverseTransactionCursor.get()).thenReturn(transactionRepresentation);
            when(transactionCursor.get()).thenReturn(transactionRepresentation);
            when(transactionRepresentation.CommitEntry).thenReturn(new LogEntryCommit(lastCommittedTransactionId, 1L));

            when(recoveryService.RecoveryStartInformation).thenReturn(startInformation);
            when(recoveryService.GetTransactionsInReverseOrder(recoveryStartPosition)).thenReturn(reverseTransactionCursor);
            when(recoveryService.GetTransactions(recoveryStartPosition)).thenReturn(transactionCursor);

            AssertableProgressReporter progressReporter = new AssertableProgressReporter(expectedMax);
            Recovery recovery = new Recovery(recoveryService, logsTruncator, new LifecycleAdapter(), recoveryMonitor, progressReporter, true);

            Recovery.init();

            progressReporter.Verify();
        }
Esempio n. 2
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. 3
0
 public Recovery(RecoveryService recoveryService, CorruptedLogsTruncator logsTruncator, Lifecycle schemaLife, RecoveryMonitor monitor, ProgressReporter progressReporter, bool failOnCorruptedLogFiles)
 {
     this._recoveryService         = recoveryService;
     this._monitor                 = monitor;
     this._logsTruncator           = logsTruncator;
     this._schemaLife              = schemaLife;
     this._progressReporter        = progressReporter;
     this._failOnCorruptedLogFiles = failOnCorruptedLogFiles;
 }
Esempio n. 4
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());
        }