Esempio n. 1
0
        /// <summary>
        /// Converts template data model to template view model
        /// </summary>
        /// <param name="template">OmrTemplate to convert</param>
        /// <returns>Resulting TemplateViewModel</returns>
        public static TemplateViewModel ConvertModelToViewModel(OmrTemplate template)
        {
            TemplateViewModel templateViewModel = new TemplateViewModel("Loaded template");

            templateViewModel.TemplateId           = template.TemplateId;
            templateViewModel.FinalizationComplete = template.FinalizationComplete;

            OmrPage page = template.Pages[0];

            templateViewModel.TemplateImageName = page.ImageName;
            templateViewModel.ImageFileFormat   = page.ImageFormat;

            List <BaseQuestionViewModel> elements = new List <BaseQuestionViewModel>();

            foreach (OmrElement modelElement in page.Elements)
            {
                if (modelElement is ChoiceBoxElement)
                {
                    var choiceBoxViewModel = CreateChoiceBoxViewModel((ChoiceBoxElement)modelElement);
                    elements.Add(choiceBoxViewModel);
                }
                else if (modelElement is GridElement)
                {
                    var gridViewModel = CreateGridViewModel((GridElement)modelElement);
                    elements.Add(gridViewModel);
                }
            }

            templateViewModel.AddQuestions(elements);

            if (page.ImageData != null)
            {
                // loading from file
                double monitorWidth, monitorHeight;
                ResolutionUtility.GetMonitorResolution(out monitorWidth, out monitorHeight);

                var image = TemplateSerializer.DecompressImage(page.ImageData);

                templateViewModel.TemplateImage = image;
                templateViewModel.PageWidth     = page.Width;
                templateViewModel.PageHeight    = page.Height;

                TemplateViewModel.ZoomKoefficient = image.PixelWidth / page.Width < 1
                    ? image.PixelWidth / page.Width
                    : 1;
            }
            else
            {
                // processing server response
                templateViewModel.PageWidth  = page.Width;
                templateViewModel.PageHeight = page.Height;
            }

            return(templateViewModel);
        }
Esempio n. 2
0
        /// <summary>
        /// Converts template data model to template view model
        /// </summary>
        /// <param name="template">OmrTemplate to convert</param>
        /// <returns>Resulting TemplateViewModel</returns>
        public static TemplateViewModel ConvertModelToViewModel(OmrTemplate template)
        {
            TemplateViewModel templateViewModel = new TemplateViewModel(template.FinalizationComplete, template.TemplateId);

            templateViewModel.TemplateName        = template.Name;
            templateViewModel.IsGeneratedTemplate = template.IsGenerated;

            OmrPage page = template.Pages[0];

            templateViewModel.TemplateImageName = page.ImageName;
            templateViewModel.ImageFileFormat   = page.ImageFormat;

            templateViewModel.PageWidth  = page.Width;
            templateViewModel.PageHeight = page.Height;

            List <BaseQuestionViewModel> elements  = new List <BaseQuestionViewModel>();
            List <ReferencePointElement> refPoints = new List <ReferencePointElement>();

            foreach (OmrElement modelElement in page.Elements)
            {
                if (modelElement is ChoiceBoxElement)
                {
                    ChoiceBoxViewModel choiceBoxViewModel = CreateChoiceBoxViewModel((ChoiceBoxElement)modelElement, templateViewModel);
                    elements.Add(choiceBoxViewModel);
                }
                else if (modelElement is GridElement)
                {
                    GridViewModel gridViewModel = CreateGridViewModel((GridElement)modelElement, templateViewModel);
                    elements.Add(gridViewModel);
                }
                else if (modelElement is BarcodeElement)
                {
                    BarcodeViewModel barcodeViewModel = CreateBarcodeViewModel((BarcodeElement)modelElement, templateViewModel);
                    elements.Add(barcodeViewModel);
                }
                else if (modelElement is ClipAreaElement)
                {
                    ClipAreaViewModel clipViewModel = CreateClipAreaViewModel((ClipAreaElement)modelElement, templateViewModel);
                    elements.Add(clipViewModel);
                }
                else if (modelElement is ReferencePointElement)
                {
                    refPoints.Add((ReferencePointElement)modelElement);
                }
            }

            templateViewModel.AddQuestions(elements);
            templateViewModel.ReferencePointsModels = refPoints.ToArray();

            templateViewModel.IsDirty = false;
            return(templateViewModel);
        }