Exemplo n.º 1
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Add Transparency" <see
        /// cref="CheckBox"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="RoutedEventArgs"/> object containing event data.</param>
        /// <remarks><para>
        /// Checking the "Add Transparency" check box calls <see cref="OnColorChange"/> to let the
        /// user select a valid masking color. The check box is cleared again if the <see
        /// cref="ImageSection.MaskColor"/> of the current <see cref="ImageSection"/> remains at
        /// <see cref="Colors.Transparent"/>.
        /// </para><para>
        /// Unchecking "Add Transparency" resets <see cref="ImageSection.MaskColor"/> to <see
        /// cref="Colors.Transparent"/>, calls <see cref="Initialize"/> to reload all image file
        /// bitmaps and redisplay all images, and sets the <see cref="SectionTabItem.DataChanged"/>
        /// flag.</para></remarks>

        private void OnTransparency(object sender, RoutedEventArgs args)
        {
            args.Handled = true;
            ImageSection images = MasterSection.Instance.Images;

            if (ColorToggle.IsChecked == true)
            {
                // select valid masking color
                if (images.MaskColor == Colors.Transparent)
                {
                    OnColorChange(sender, args);
                }

                // uncheck option if no masking color selected
                if (images.MaskColor == Colors.Transparent)
                {
                    ColorToggle.IsChecked = false;
                }

                return;
            }

            // reset to embedded color and broadcast changes
            if (images.MaskColor != Colors.Transparent)
            {
                images.MaskColor = Colors.Transparent;
                Initialize();
                SectionTab.DataChanged = true;
            }
        }
Exemplo n.º 2
0
 private void ExecuteAddImageInfoCommand(ImageSection section)
 {
     if (section != null)
     {
         section.ImageList.Add(new ImageInfo());
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes the section-specific controls of the tab page.</summary>
        /// <remarks><para>
        /// <b>Initialize</b> initializes all controls that are specific to the "Images" tab page.
        /// </para><para>
        /// <b>Initialize</b> attempts to load all disk files defined by the items of the "Image
        /// File" list view but allows this operation to fail for any or all list view items. The
        /// user is notified of the failure. Clients should take care not to assume that any given
        /// <see cref="ImageFile"/> bitmap is valid.</para></remarks>

        public void Initialize()
        {
            ImageSection images = MasterSection.Instance.Images;

            // check custom color option if not transparent
            ColorToggle.IsChecked = (images.MaskColor != Colors.Transparent);

            // reload image files from scenario section
            if (FileList.ItemsSource != images.ImageFiles.Values)
            {
                FileList.ItemsSource = images.ImageFiles.Values;
            }
            else
            {
                FileList.Items.Refresh();
            }

            // select first item by default
            if (FileList.Items.Count > 0)
            {
                FileList.SelectedIndex = 0;
            }

            // try loading image files from disk
            foreach (ImageFile file in images.ImageFiles.Values)
            {
                LoadImageFile(file, images.MaskColor);
            }

            // acquire polygon geometry
            UpdateGeometry();

            // remember selected index in image list
            int selectedIndex = ImageList.SelectedIndex;

            // reload images from scenario section
            ImageList.Items.Clear();
            foreach (EntityImage image in images.Collection.Values)
            {
                ImageList.Insert(new ImageListBoxItem(image));
            }
            ImageList.Items.Refresh();

            // reselect previously selected index, if possible
            if (selectedIndex >= 0 && selectedIndex < ImageList.Items.Count)
            {
                ImageList.SelectAndShow(selectedIndex);
            }
            else if (ImageList.Items.Count > 0)
            {
                ImageList.SelectedIndex = 0;
            }

            // update list button status
            EnableListButtons();
        }
Exemplo n.º 4
0
        public static ImageSection ConvertToImageSection(HeadImage x)
        {
            ImageSection image = new ImageSection
            {
                ImageSectionActive    = true,
                ImageSectionColorText = x.HeadImageColorText,
                ImageSectionImage     = x.HeadImageImage,
                ImageSectionPageName  = x.HeadImagePageName,
                ImageSectionText      = x.HeadImageText,
                Link = x.HeaderLink
            };

            image.ImageSectionPageId = x.HeadImagePageName == "FosePromocion" || x.HeadImagePageName == "BlogNews" ? x.HeadImagePageId : 0;

            return(image);
        }
Exemplo n.º 5
0
 double CalcSectionSize(ImageFrame frame, ImageSection sec, double totalVariable, double stretchableSize, ref double remainingVariable)
 {
     if (sec.Mode != RenderMode.Fixed)
     {
         double sw = Math.Round(totalVariable * (sec.Size / stretchableSize));
         if (sw > remainingVariable)
         {
             sw = remainingVariable;
         }
         remainingVariable -= sw;
         return(sw);
     }
     else
     {
         return(sec.Size / frame.ScaleFactor);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Change Color" <see
        /// cref="Button"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="RoutedEventArgs"/> object containing event data.</param>
        /// <remarks><para>
        /// <b>OnColorChange</b> displays a <see cref="CustomColorDialog"/> allowing the user to
        /// change the masking color.
        /// </para><para>
        /// If the user made any changes, <b>OnColorChange</b> sets the <see
        /// cref="ImageSection.MaskColor"/> of the current <see cref="ImageSection"/> to the new
        /// masking color, calls <see cref="Initialize"/> to reload all image file bitmaps and to
        /// redisplay all images with the new masking color, and sets the <see
        /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks>

        private void OnColorChange(object sender, RoutedEventArgs args)
        {
            args.Handled = true;
            ImageSection images = MasterSection.Instance.Images;

            // retrieve masking color and let user change it
            Color maskColor = images.MaskColor;
            bool  result    = CustomColorDialog.Show(MainWindow.Instance, ref maskColor);

            // update color and brodcast changes, if any
            if (result && images.MaskColor != maskColor)
            {
                images.MaskColor = maskColor;
                Initialize();
                SectionTab.DataChanged = true;
            }
        }
Exemplo n.º 7
0
        List <ImageSection> CreateSections(ImageFrame frame, IEnumerable <Color> pixels)
        {
            List <ImageSection> sections = new List <ImageSection> ();

            ImageSection section = null;
            int          n       = 0;

            foreach (var p in pixels)
            {
                RenderMode mode;
                // Don't compare exact colors. This is a workaround to make sure regions are properly detected when
                // there are small variations in colors.
                if (p.Red > 0.9 && p.Blue < 0.2 && p.Green < 0.2 && p.Alpha == 1)                 // Red-ish
                {
                    mode = RenderMode.Tile;
                }
                else if (p.Red < 0.2 && p.Blue < 0.2 && p.Green < 0.2 && p.Alpha == 1)                 // Black-ish
                {
                    mode = RenderMode.Stretch;
                }
                else
                {
                    mode = RenderMode.Fixed;
                }

                if (section == null || mode != section.Mode)
                {
                    section = new ImageSection {
                        Start = n,
                        Size  = 1,
                        Mode  = mode
                    };
                    sections.Add(section);
                }
                else
                {
                    section.Size++;
                }
                n++;
            }
            return(sections);
        }
Exemplo n.º 8
0
        public static void HandlePostMediaToThread(string mediaUrl, ButtonTypeEnum mediaType, string caption = null)
        {
            if (MainPageViewModel.CurrentInstance == null)
            {
                return;
            }

            Section section = null;

            switch (mediaType)
            {
            case ButtonTypeEnum.GetImage:
                section = new ImageSection
                {
                    Url     = mediaUrl,
                    Caption = caption
                };
                break;

            case ButtonTypeEnum.GetAudio:
                section = new AudioSection
                {
                    Url     = mediaUrl,
                    Caption = caption
                };
                break;

            case ButtonTypeEnum.GetVideo:
                section = new VideoSection
                {
                    Url = mediaUrl
                };
                break;

            default:
                return;
            }
            MainPageViewModel.CurrentInstance.AddOutgoingSection(section);
        }
Exemplo n.º 9
0
 double CalcSectionSize(ImageFrame frame, ImageSection sec, double totalVariable, double stretchableSize, ref double remainingVariable)
 {
     if (sec.Mode != RenderMode.Fixed) {
         double sw = Math.Round (totalVariable * (sec.Size / stretchableSize));
         if (sw > remainingVariable)
             sw = remainingVariable;
         remainingVariable -= sw;
         return sw;
     }
     else {
         return sec.Size / frame.ScaleFactor;
     }
 }
Exemplo n.º 10
0
        List<ImageSection> CreateSections(ImageFrame frame, IEnumerable<Color> pixels)
        {
            List<ImageSection> sections = new List<ImageSection> ();

            ImageSection section = null;
            int n = 0;

            foreach (var p in pixels) {
                RenderMode mode;
                // Don't compare exact colors. This is a workaround to make sure regions are properly detected when
                // there are small variations in colors.
                if (p.Red > 0.9 && p.Blue < 0.2 && p.Green < 0.2 && p.Alpha == 1) // Red-ish
                    mode = RenderMode.Tile;
                else if (p.Red < 0.2 && p.Blue < 0.2 && p.Green < 0.2 && p.Alpha == 1) // Black-ish
                    mode = RenderMode.Stretch;
                else
                    mode = RenderMode.Fixed;

                if (section == null || mode != section.Mode) {
                    section = new ImageSection {
                        Start = n,
                        Size = 1,
                        Mode = mode
                    };
                    sections.Add (section);
                } else
                    section.Size++;
                n++;
            }
            return sections;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Crops image on specific side.
        /// </summary>
        /// <param name="image">Image to be cropped.</param>
        /// <param name="side">Which side is going to be cropped.</param>
        /// <returns>Cropped bitmap.</returns>
        private Bitmap GetCroppedImage(Image image, ImageSection side)
        {
            Rectangle cropSection;
            if (side == ImageSection.Left)
                cropSection = new Rectangle(0, 0, cropWidth, image.Height);
            else
                cropSection = new Rectangle(image.Width - cropWidth, 0, cropWidth, image.Height);

            Bitmap sourceImage = new Bitmap(image);
            return sourceImage.Clone(cropSection, sourceImage.PixelFormat);
        }
Exemplo n.º 12
0
        private static Section GetSection(BsonDocument sectionBsonDocument)
        {
            Random rnd = new Random();

            Section sectObj;

            string sectionType = sectionBsonDocument.GetValue("SectionType")?.ToString();

            Debug.WriteLine("Section Type:" + sectionType);
            switch (sectionType?.ToLower())
            {
            case "image":
                ImageSection imgSectObj = BsonSerializer.Deserialize <ImageSection>(sectionBsonDocument);
                Content      imgContent = Contents.GetFor(imgSectObj);
                if (imgContent != null)
                {
                    imgSectObj.Title   = imgContent.Title;
                    imgSectObj.Caption = imgContent.Caption;
                }

                sectObj = imgSectObj;

                break;

            case "text":
                TextSection textSectObj = BsonSerializer.Deserialize <TextSection>(sectionBsonDocument);
                Content     textContent = Contents.GetFor(textSectObj);
                if (textContent != null)
                {
                    textSectObj.Text = textContent.SectionText;
                }
                sectObj = textSectObj;
                break;

            case "graph":

                GraphSection gphObj = BsonSerializer.Deserialize <GraphSection>(sectionBsonDocument);

                Content docContent = Contents.GetFor(gphObj);
                if (docContent != null)
                {
                    gphObj.Caption = docContent.Caption;

                    gphObj.X.Label = docContent.XLabel;
                    gphObj.Y.Label = docContent.YLabel;
                }
                gphObj.CoordinatesSet = new List <Coordinates>();
                BsonArray coordinateSetBsonArray = sectionBsonDocument.GetValue("CoordinatesSet").AsBsonArray;


                if (coordinateSetBsonArray != null)
                {
                    foreach (BsonDocument coordinateSetBsonDoc in coordinateSetBsonArray)
                    {
                        var coordinateListId = coordinateSetBsonDoc.GetValue("CoordinateListId")?.ToString();
                        if (!string.IsNullOrWhiteSpace(coordinateListId))
                        {
                            continue;
                        }

                        var coordinatesObj = new Coordinates()
                        {
                            CoordinateListId = coordinateListId
                        };

                        var coordinateContent = Contents.GetFor(coordinatesObj);
                        coordinatesObj.LegendName = coordinateContent?.CoordinateListLegend;

                        if (coordinateSetBsonDoc.TryGetValue("CoordinateList", out BsonValue tempCoordinateList))
                        {
                            BsonArray coordinateListBsonArray = tempCoordinateList?.AsBsonArray;
                            if (coordinateListBsonArray != null)
                            {
                                foreach (BsonDocument coordinateBsonDoc in coordinateListBsonArray)
                                {
                                    string x = coordinateBsonDoc.GetValue("X")?.AsString;
                                    string y = coordinateBsonDoc.GetValue("Y")?.AsString;

                                    string coordinateText = coordinateContent?.CoordinateText;

                                    if (string.IsNullOrWhiteSpace(coordinateText))
                                    {
                                        coordinatesObj.AddXYCoordinates(x, y);
                                    }
                                    else
                                    {
                                        coordinatesObj.AddXYCoordinates(x, y, coordinateText);
                                    }

                                    Debug.WriteLine(coordinatesObj.ToJson());
                                }
                            }
                        }
                        gphObj.CoordinatesSet.Add(coordinatesObj);
                    }
                }
                sectObj = gphObj;

                break;

            case "gif":
                GifSection gifObj     = BsonSerializer.Deserialize <GifSection>(sectionBsonDocument);
                Content    gifContent = Contents.GetFor(gifObj);
                if (gifContent != null)
                {
                    gifObj.Title   = gifContent.Title;
                    gifObj.Caption = gifContent.Caption;
                }
                sectObj = gifObj;
                break;

            case "audio":
                AudioSection audioObj     = BsonSerializer.Deserialize <AudioSection>(sectionBsonDocument);
                Content      audioContent = Contents.GetFor(audioObj);
                if (audioContent != null)
                {
                    audioObj.Title   = audioContent.Title;
                    audioObj.Caption = audioContent.Caption;
                }

                sectObj = audioObj;
                break;

            case "video":
                VideoSection videoObj     = BsonSerializer.Deserialize <VideoSection>(sectionBsonDocument);
                Content      videoContent = Contents.GetFor(videoObj);
                if (videoContent != null)
                {
                    videoObj.Title   = videoContent.Title;
                    videoObj.Caption = videoContent.Caption;
                }
                sectObj = videoObj;
                break;

            case "link":
                UrlSection urlObj = BsonSerializer.Deserialize <UrlSection>(sectionBsonDocument);
                sectObj = urlObj;
                break;

            case "embeddedhtml":
                EmbeddedHtmlSection embeddedHtmlObj     = BsonSerializer.Deserialize <EmbeddedHtmlSection>(sectionBsonDocument);
                Content             embeddedHtmlContent = Contents.GetFor(embeddedHtmlObj);
                if (embeddedHtmlContent != null)
                {
                    embeddedHtmlObj.Title   = embeddedHtmlContent.Title;
                    embeddedHtmlObj.Caption = embeddedHtmlContent.Caption;
                }
                sectObj = embeddedHtmlObj;
                break;

            default:
                sectObj = null;
                break;
            }
            return(sectObj);
        }
Exemplo n.º 13
0
        public void FromStream(Stream stream)
        {
            long fileStart = stream.Position;
            Header = NativeUtils.StreamToStructure<IMAGE_FILE_HEADER>(stream);

            OptionalHeader = new OptionalHeader();
            StringTable = new Dictionary<long, string>();

            if ((Header.Machine == IMAGE_FILE_MACHINE.IMAGE_FILE_MACHINE_UNKNOWN) && (Header.NumberOfSections == Constants.IMAGE_SYM_SECTION_ANON))
            {
                stream.Seek(fileStart, SeekOrigin.Begin);
                AnonHeader = NativeUtils.StreamToStructure<ANON_OBJECT_HEADER>(stream);

                if (AnonHeader.Version >= 2)
                {
                    stream.Seek(fileStart, SeekOrigin.Begin);
                    AnonHeaderV2 = NativeUtils.StreamToStructure<ANON_OBJECT_HEADER_V2>(stream);

                    if (AnonHeaderV2.ClassID == Constants.ANON_OBJECT_HEADER_BIGOBJ_CLASSID)
                    {
                        stream.Seek(fileStart, SeekOrigin.Begin);
                        AnonHeaderBigObj = NativeUtils.StreamToStructure<ANON_OBJECT_HEADER_BIGOBJ>(stream);
                    }
                }

                SectionData = new byte[0];

                Sections = new ImageSection[0];
                Symbols = new IMAGE_SYMBOL[0];

                return;
            }

            // Optional header
            if (Header.SizeOfOptionalHeader != 0)
            {
                OptionalHeader.FromStream(stream, Header.SizeOfOptionalHeader);
            }

            if (Header.NumberOfSections > Constants.IMAGE_SYM_SECTION_MAX)
            {
                throw new InvalidDataException("Can't parse object file");
            }

            Sections = new ImageSection[Header.NumberOfSections];
            Symbols = new IMAGE_SYMBOL[Header.NumberOfSymbols];

            // Section table
            for (int i = 0; i < Header.NumberOfSections; ++i)
            {
                IMAGE_SECTION_HEADER sectionHeader = NativeUtils.StreamToStructure<IMAGE_SECTION_HEADER>(stream);
                Sections[i].Header = sectionHeader;
            }

            // Section data
            for (int i = 0; i < Header.NumberOfSections; ++i)
            {
                Sections[i].RawOffset = stream.Position - fileStart;
                uint size = Sections[i].Header.SizeOfRawData;
                Sections[i].RawData = new byte[size];
                stream.Read(Sections[i].RawData, 0, (int)size);
            }

            // Symbol table
            if (Header.NumberOfSymbols != 0)
            {
                long offset = fileStart + Header.PointerToSymbolTable;
                stream.Seek(offset, SeekOrigin.Begin);

                long count = Header.NumberOfSymbols;
                for (int i = 0; i < count; ++i)
                {
                    Symbols[i] = NativeUtils.StreamToStructure<IMAGE_SYMBOL>(stream);
                }
            }

            {
                BinaryReader reader = new BinaryReader(stream, Encoding.ASCII);

                long start = stream.Position;
                uint stringTableSize = reader.ReadUInt32();

                long end = start + stringTableSize;

                StringBuilder sb = new StringBuilder(1024);

                while (stream.Position < end)
                {
                    long offset = stream.Position - start;
                    char c;
                    while ((stream.Position < end) && ((c = reader.ReadChar()) != 0))
                    {
                        sb.Append(c);
                    }

                    StringTable.Add(offset, sb.ToString());
                    sb.Clear();
                }
            }

            for (int i = 0; i < Sections.Length; ++i)
            {
                ImageSection section = Sections[i];
                section.Relocations = new IMAGE_RELOCATION[section.Header.NumberOfRelocations];

                if (section.Header.PointerToRelocations != 0)
                {
                    stream.Seek(fileStart + section.Header.PointerToRelocations, SeekOrigin.Begin);

                    for (int r = 0; r < section.Header.NumberOfRelocations; ++r)
                    {
                        section.Relocations[r] = NativeUtils.StreamToStructure<IMAGE_RELOCATION>(stream);
                    }
                }
            }
        }
Exemplo n.º 14
0
        internal Pixelmap GetFrameData(int index, out AdvImageData imageData, out AdvStatusData statusData, out Bitmap displayBitmap)
        {
            imageData = null;

            if (index < NumberOfFrames)
            {
                byte layoutId;
                AdvImageLayout.GetByteMode byteMode;

                GetFrameImageSectionHeader(index, out layoutId, out byteMode);

                AdvImageLayout layout = ImageSection.GetImageLayoutFromLayoutId(layoutId);

                if (layout.IsDiffCorrLayout && byteMode == AdvImageLayout.GetByteMode.DiffCorrBytes && prevFrameNo != index - 1)
                {
                    // Move back and find the nearest previous key frame
                    int keyFrameIdx = index;
                    do
                    {
                        keyFrameIdx--;
                        GetFrameImageSectionHeader(keyFrameIdx, out layoutId, out byteMode);
                    }while (keyFrameIdx > 0 && byteMode != AdvImageLayout.GetByteMode.KeyFrameBytes);

                    object[] keyFrameData = GetFrameSectionData(keyFrameIdx, null);
                    prevFramePixels = ((AdvImageData)keyFrameData[0]).ImageData;

                    if (layout.DiffCorrFrame == DiffCorrFrameMode.PrevFrame)
                    {
                        for (int i = keyFrameIdx + 1; i < index; i++)
                        {
                            object[] frameData = GetFrameSectionData(i, prevFramePixels);

                            prevFramePixels = ((AdvImageData)frameData[0]).ImageData;
                        }
                    }
                }

                object[] data;

                data = GetFrameSectionData(index, prevFramePixels);

                imageData  = (AdvImageData)data[0];
                statusData = (AdvStatusData)data[1];

                if (prevFramePixels == null)
                {
                    prevFramePixels = new ushort[ImageSection.Width, ImageSection.Height];
                }

                if (layout.IsDiffCorrLayout)
                {
                    for (int x = 0; x < ImageSection.Width; x++)
                    {
                        for (int y = 0; y < ImageSection.Height; y++)
                        {
                            prevFramePixels[x, y] = imageData.ImageData[x, y];
                        }
                    }
                }

                prevFrameNo = index;

                Pixelmap rv = ImageSection.CreatePixelmap(imageData);

                //Pixelmap rv = new Pixelmap((int)m_AdvFile.ImageSection.Width, (int)m_AdvFile.ImageSection.Height, m_AdvFile.ImageSection.BitsPerPixel, null, null, null);
                //rv.Width = (int) m_AdvFile.ImageSection.Width;
                //rv.Height = (int) m_AdvFile.ImageSection.Height;
                //rv.BitPixCamera = m_AdvFile.ImageSection.BitsPerPixel;
                //rv.Array = new uint[Width * Height];
                //rv.CopyPixelsFrom(imageData.ImageData, imageData.Bpp);
                //displayBitmap = PixelmapFactory.ConstructBitmapFrom12BitPixelmap(rv);

                displayBitmap = rv.DisplayBitmap;

                return(rv);
            }
            else
            {
                displayBitmap = null;
                statusData    = null;
                return(null);
            }
        }
Exemplo n.º 15
0
        private static Section GetSection(BsonDocument sectionBsonDocument)
        {
            Section sectObj;

            string sectionType = sectionBsonDocument.GetValue("SectionType")?.ToString();

            Debug.WriteLine("Section Type:" + sectionType);
            switch (sectionType?.ToLower())
            {
            case "image":
                ImageSection imgSectObj = BsonSerializer.Deserialize <ImageSection>(sectionBsonDocument);
                Content      imgContent = Contents.GetFor(imgSectObj);
                if (imgContent != null)
                {
                    imgSectObj.Title   = imgContent.Title;
                    imgSectObj.Caption = imgContent.Caption;
                }
                sectObj = imgSectObj;
                break;

            case "text":
                TextSection textSectObj = BsonSerializer.Deserialize <TextSection>(sectionBsonDocument);
                Content     textContent = Contents.GetFor(textSectObj);
                if (textContent != null)
                {
                    textSectObj.Text = textContent.SectionText;
                    if (textSectObj.DelayInMs == 0)
                    {
                        textSectObj.DelayInMs = Math.Min(Utils.Settings.MaxCapTimeTakenToType, textSectObj.Text.Length * (Utils.Settings.BaseTimeTakenToTypePerChar + rand.Next(0, Utils.Settings.VariableTimeTakenToTypePerChar)));
                    }
                }
                sectObj = textSectObj;
                break;

            case "graph":
            {
                GraphSection gphObj = BsonSerializer.Deserialize <GraphSection>(sectionBsonDocument);

                Content docContent = Contents.GetFor(gphObj);
                if (docContent != null)
                {
                    gphObj.Caption = docContent.Caption;

                    gphObj.X.Label = docContent.XLabel;
                    gphObj.Y.Label = docContent.YLabel;
                }
                gphObj.CoordinatesSet = new List <Coordinates>();
                BsonArray coordinateSetBsonArray = sectionBsonDocument.GetValue("CoordinatesSet").AsBsonArray;


                if (coordinateSetBsonArray != null)
                {
                    foreach (BsonDocument coordinateSetBsonDoc in coordinateSetBsonArray)
                    {
                        var coordinateListId = coordinateSetBsonDoc.GetValue("CoordinateListId")?.ToString();
                        if (!string.IsNullOrWhiteSpace(coordinateListId))
                        {
                            continue;
                        }

                        var coordinatesObj = new Coordinates()
                        {
                            CoordinateListId = coordinateListId
                        };

                        var coordinateContent = Contents.GetFor(coordinatesObj);
                        coordinatesObj.LegendName = coordinateContent?.CoordinateListLegend;

                        if (coordinateSetBsonDoc.TryGetValue("CoordinateList", out BsonValue tempCoordinateList))
                        {
                            BsonArray coordinateListBsonArray = tempCoordinateList?.AsBsonArray;
                            if (coordinateListBsonArray != null)
                            {
                                foreach (BsonDocument coordinateBsonDoc in coordinateListBsonArray)
                                {
                                    string x = coordinateBsonDoc.GetValue("X")?.AsString;
                                    string y = coordinateBsonDoc.GetValue("Y")?.AsString;

                                    string coordinateText = coordinateContent?.CoordinateText;

                                    if (string.IsNullOrWhiteSpace(coordinateText))
                                    {
                                        coordinatesObj.AddXYCoordinates(x, y);
                                    }
                                    else
                                    {
                                        coordinatesObj.AddXYCoordinates(x, y, coordinateText);
                                    }

                                    Debug.WriteLine(coordinatesObj.ToJson());
                                }
                            }
                        }
                        gphObj.CoordinatesSet.Add(coordinatesObj);
                    }
                }
                sectObj = gphObj;
            }

            break;

            case "gif":
                GifSection gifObj     = BsonSerializer.Deserialize <GifSection>(sectionBsonDocument);
                Content    gifContent = Contents.GetFor(gifObj);
                if (gifContent != null)
                {
                    gifObj.Title   = gifContent.Title;
                    gifObj.Caption = gifContent.Caption;
                }
                sectObj = gifObj;
                break;

            case "audio":
                AudioSection audioObj     = BsonSerializer.Deserialize <AudioSection>(sectionBsonDocument);
                Content      audioContent = Contents.GetFor(audioObj);
                if (audioContent != null)
                {
                    audioObj.Title   = audioContent.Title;
                    audioObj.Caption = audioContent.Caption;
                }

                sectObj = audioObj;
                break;

            case "video":
                VideoSection videoObj     = BsonSerializer.Deserialize <VideoSection>(sectionBsonDocument);
                Content      videoContent = Contents.GetFor(videoObj);
                if (videoContent != null)
                {
                    videoObj.Title   = videoContent.Title;
                    videoObj.Caption = videoContent.Caption;
                }
                sectObj = videoObj;
                break;

            case "link":
                UrlSection urlObj = BsonSerializer.Deserialize <UrlSection>(sectionBsonDocument);
                sectObj = urlObj;
                break;

            case "embeddedhtml":
                EmbeddedHtmlSection embeddedHtmlObj     = BsonSerializer.Deserialize <EmbeddedHtmlSection>(sectionBsonDocument);
                Content             embeddedHtmlContent = Contents.GetFor(embeddedHtmlObj);
                if (embeddedHtmlContent != null)
                {
                    embeddedHtmlObj.Title   = embeddedHtmlContent.Title;
                    embeddedHtmlObj.Caption = embeddedHtmlContent.Caption;
                }
                sectObj = embeddedHtmlObj;
                break;

            case "carousel":
                var carouselObj = BsonSerializer.Deserialize <CarouselSection>(sectionBsonDocument);
                var carContent  = Contents.GetFor(carouselObj);
                if (carContent != null)
                {
                    carouselObj.Title   = carContent.Title;
                    carouselObj.Caption = carContent.Caption;
                }
                if (carouselObj.Items != null)
                {
                    foreach (var carItem in carouselObj.Items)
                    {
                        var content = Contents.GetFor(carItem);
                        if (content != null)
                        {
                            carItem.Title   = content.Title;
                            carItem.Caption = content.Caption;
                        }
                        if (carItem.Buttons != null)
                        {
                            foreach (var carBtn in carItem.Buttons)
                            {
                                var carBtnContent = Contents.GetFor(carBtn);
                                carBtn.Text = carBtnContent?.ButtonText;
                            }
                        }
                    }
                }
                sectObj = carouselObj;
                break;

            case "printotp":
                PrintOTPSection printOTPSection = BsonSerializer.Deserialize <PrintOTPSection>(sectionBsonDocument);
                //No content to load for Section Type: PrintOTP
                sectObj = printOTPSection;
                break;

            default:
                sectObj = null;
                break;
            }
            return(sectObj);
        }
Exemplo n.º 16
0
 private bool CanExecuteAddImageInfoCommand(ImageSection arg)
 {
     return(true);
 }
Exemplo n.º 17
0
 public void AddSection(ImageSection section)
 {
     _sectionHeaderTable.Segments.Add(section.Header);
     _sectionTable.Segments.Add(section);
 }