Beispiel #1
0
        public ActionResult Compare(VirtualTemplatesCompareModel model)
        {
            var viewModel = SaveTemplate(model.VirtualPath, model.LeftContents);

            if (model.Button == "Save and close")
            {
                return(View("Index", viewModel));
            }
            else
            {
                model.ConfirmMessage =
                    string.Format(
                        _localizationService.GetString("/virtualtemplatesystem/messages/saveconfirm",
                                                       "Template: <strong>{0}</strong> successfully saved"), model.VirtualPath);
                return(View(model));
            }
        }
Beispiel #2
0
        private VirtualTemplatesCompareModel GetCompareModel(string virtualPath, string leftVersion, string rightVersion, bool populateHistory)
        {
            var model = new VirtualTemplatesCompareModel()
            {
                VirtualPath = virtualPath
            };

            // Set up references for content
            ContentReference leftReference;
            ContentReference rightReference = ContentReference.EmptyReference;

            if (!string.IsNullOrEmpty(leftVersion))
            {
                leftReference = ContentReference.Parse(leftVersion);
                ContentReference.TryParse(rightVersion, out rightReference);
            }
            else
            {
                leftReference = _viewPersistenceService.GetContentReference(virtualPath);
            }

            // Left panel content
            var leftTemplateContent = _versionRepository.GetVersion(leftReference);

            model.LeftContents    = leftTemplateContent.FileContents;
            model.LeftVersionText = leftTemplateContent.StatusText + ": " +
                                    leftTemplateContent.ChangedDate.ToString("dd-MMM-yy, hh:mm") + " by " +
                                    leftTemplateContent.ChangedBy;

            // Right panel content
            if (rightReference == null || rightReference == ContentReference.EmptyReference)
            {
                // Comparing original deployed version
                model.RightContents    = _fileReader.ReadFile(Server.MapPath("~" + leftTemplateContent.VirtualPath));
                model.RightVersionText = "Original version";
            }
            else
            {
                var rightTemplateContent = _versionRepository.GetVersion(rightReference);
                model.RightContents    = rightTemplateContent.FileContents;
                model.RightVersionText = rightTemplateContent.StatusText + ": " +
                                         rightTemplateContent.ChangedDate.ToString("dd-MMM-yy, hh:mm") + " by " +
                                         rightTemplateContent.ChangedBy;
            }

            model.TemplateIsChanged =
                _templateComparer.TemplateIsChanged(leftTemplateContent.FileContents, virtualPath);

            if (populateHistory)
            {
                var allVersions = _versionRepository.GetAllVersions(leftReference, virtualPath);
                allVersions.Add(new UiTemplateVersion()
                {
                    ChangedBy   = "-",
                    VirtualPath = virtualPath,
                    Reference   = leftReference,
                    Status      = VersionStatus.Published,
                    StatusText  = "Original version"
                });
                model.Versions = allVersions;
            }
            return(model);
        }