示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
0
        public ThemeFile(byte[] Data)
        {
            EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(Data), Endianness.LittleEndian);

            try
            {
                header = new ThemeHeader(er);

                topHeight    = 256;
                bottomHeight = 256;

                switch (header.topScreenDrawType)
                {
                case 1:                                                            //solid color
                    er.BaseStream.Position = header.topScreenSolidColorDataOffset; //7 bytes here, first 4 is rgba, other 3 unknown (possible overlay colour ??)
                    Byte r  = er.ReadByte();
                    Byte g  = er.ReadByte();
                    Byte b  = er.ReadByte();
                    Byte a1 = er.ReadByte();    //alpha makes the colours appear lighter because the 3ds does blending
                    topSolidColor = Color.FromArgb(a1, r, g, b);
                    break;

                case 2:                        //wierd 64x64 overlay mode
                    topWidth       = 64;
                    topHeight      = 64;
                    topClampWidth  = 64;
                    topClampHeight = 64;
                    break;

                case 3:    //texture
                    switch (header.topScreenFrameType)
                    {
                    case 0:        //tex1
                    case 3:        //tex1
                        topWidth       = 1024;
                        topClampWidth  = 1008;
                        topClampHeight = 240;
                        break;

                    case 1:        //tex0
                        topWidth       = 512;
                        topClampWidth  = 412;
                        topClampHeight = 240;
                        break;
                    }
                    break;
                }

                switch (header.bottomScreenDrawType)
                {
                case 1:                                                               //solid color
                    er.BaseStream.Position = header.bottomScreenSolidOrTextureOffset; //7 bytes here, first 4 is rgba, other 3 unknown (possible overlay colour ??)
                    Byte r  = er.ReadByte();
                    Byte g  = er.ReadByte();
                    Byte b  = er.ReadByte();
                    Byte a1 = er.ReadByte();    //alpha makes the colours appear lighter because the 3ds does blending

                    bottomSolidColor = Color.FromArgb(a1, r, g, b);
                    break;

                case 3:    //texture
                    switch (header.bottomScreenFrameType)
                    {
                    case 0:        //tex4
                    case 3:        //tex4
                        bottomWidth       = 1024;
                        bottomClampWidth  = 1008;
                        bottomClampHeight = 240;
                        break;

                    case 1:        //tex2
                        bottomWidth       = 512;
                        bottomClampWidth  = 320;
                        bottomClampHeight = 240;
                        break;

                    case 4:        //tex3 //both animated.?
                    case 2:        //tex3
                        bottomWidth       = 1024;
                        bottomClampWidth  = 960;
                        bottomClampHeight = 240;
                        break;
                    }
                    break;
                }



                er.BaseStream.Position = header.topScreenTextureOffset;
                if (header.topScreenDrawType == 2)                // in draw type 2 theyre are 2 alpha images, one at topscreentextureoffset and the other at the colour offset, they need to be drawn onto the gradient background
                {
                    topOverlayAlphaTexture    = er.ReadBytes(alphaTextureWidth * alphaTextureHeight);
                    er.BaseStream.Position    = header.topScreenAdditionalTextureOffset;
                    topBackgroundAlphaTexture = er.ReadBytes(alphaTextureWidth * alphaTextureHeight);

                    //TODO figure out colour data for gradients etc
                    er.BaseStream.Position = header.topScreenSolidColorDataOffset;
                    Byte type = er.ReadByte();
                    Byte r1   = er.ReadByte();
                    Byte g1   = er.ReadByte();
                    Byte b1   = er.ReadByte();

                    Byte r2 = er.ReadByte();
                    Byte g2 = er.ReadByte();
                    Byte b2 = er.ReadByte();

                    Console.WriteLine("type? " + type);
                    Console.WriteLine("color " + r1 + " " + g1 + " " + b1);
                    Console.WriteLine("color " + r2 + " " + g2 + " " + b2);
                }
                else
                {
                    topScreenTexture = er.ReadBytes((topHeight * topWidth) * 2);
                }

                er.BaseStream.Position = header.bottomScreenSolidOrTextureOffset;
                bottomScreenTexture    = er.ReadBytes((bottomHeight * bottomWidth) * 2);

                er.BaseStream.Position = header.openedFolderTextureOffset;
                openFolderTexture      = er.ReadBytes((folderWidth * folderHeight) * 4);
                er.BaseStream.Position = header.closedFolderTextureOffset;
                closedFolderTexture    = er.ReadBytes((folderWidth * folderHeight) * 4);

                er.BaseStream.Position = header.iconBorder48pxOffset;
                iconBorder48pxTexture  = er.ReadBytes((iconBorder48pxWidth * iconBorder48pxHeight) * 4);
                er.BaseStream.Position = header.iconBorder24pxOffset;
                iconBorder24pxTexture  = er.ReadBytes((iconBorder24pxWidth * iconBorder24pxHeight) * 4);

                er.BaseStream.Position = header.audioSectionOffset;
                audioSection           = new AudioSection(er);
            }
            finally
            {
                er.Close();
            }
        }