예제 #1
0
        public static PictureAd parseJSONString(string jsonString, string localCachePath)
        {
            PictureAd pictureAd = new PictureAd();

            pictureAd.setImageSpace(ImageType.Base, defaultBaseSpace);
            pictureAd.setImageSpace(ImageType.Close, defaultCloseButtonSpace);
            pictureAd.setImageSpace(ImageType.Frame, defaultFrameSpace);
            pictureAd.closeButtonDelay = defaultCloseButtonDelay;

            if (jsonString == null || jsonString.Length == 0)
            {
                return(pictureAd);
            }

            var dict = Json.Deserialize(jsonString) as Dictionary <string, object>;

            if (dict == null)
            {
                return(pictureAd);
            }

            if (!dict.ContainsKey("data"))
            {
                return(pictureAd);
            }

            Dictionary <string, object> dict2 = (Dictionary <string, object>)dict["data"];

            foreach (string assetKey in dict2.Keys)
            {
                if (assetKey == game__KEY)
                {
                    var gameDict = (Dictionary <string, object>)dict2[assetKey];
                    if (gameDict == null)
                    {
                        return(pictureAd);
                    }

                    if (gameDict.ContainsKey(landscapeFramePicture__KEY))
                    {
                        setupPathsForAd(pictureAd, localCachePath, (string)gameDict[landscapeFramePicture__KEY], ImageOrientation.Landscape, ImageType.Frame);
                    }

                    if (gameDict.ContainsKey(portraitFramePicture__KEY))
                    {
                        setupPathsForAd(pictureAd, localCachePath, (string)gameDict[portraitFramePicture__KEY], ImageOrientation.Portrait, ImageType.Frame);
                    }

                    if (gameDict.ContainsKey(closeButtonPicture__KEY))
                    {
                        setupPathsForAd(pictureAd, localCachePath, (string)gameDict[closeButtonPicture__KEY], ImageOrientation.Landscape, ImageType.Close);
                        pictureAd.setImageURL(localPathForResource(localCachePath, (string)gameDict[closeButtonPicture__KEY]),
                                              ImageURLType.Local, ImageOrientation.Portrait, ImageType.Close);
                    }

                    if (gameDict.ContainsKey(closeButtonDelay__KEY))
                    {
                        pictureAd.closeButtonDelay = stringToInt((string)gameDict[closeButtonDelay__KEY].ToString());
                    }

                    setImageSpace(pictureAd, ImageType.Frame, gameDict);
                    setImageSpace(pictureAd, ImageType.Close, gameDict);
                }

                if (assetKey == campaign__KEY)
                {
                    var campaignDict = (Dictionary <string, object>)dict2[assetKey];
                    if (campaignDict == null)
                    {
                        return(pictureAd);
                    }

                    if (campaignDict.ContainsKey(landscapePicture__KEY))
                    {
                        setupPathsForAd(pictureAd, localCachePath, (string)campaignDict[landscapePicture__KEY], ImageOrientation.Landscape, ImageType.Base);
                    }

                    if (campaignDict.ContainsKey(portraitPicture__KEY))
                    {
                        setupPathsForAd(pictureAd, localCachePath, (string)campaignDict[portraitPicture__KEY], ImageOrientation.Portrait, ImageType.Base);
                    }

                    if (campaignDict.ContainsKey(id__KEY))
                    {
                        pictureAd.id = (string)campaignDict[id__KEY];
                    }

                    if (campaignDict.ContainsKey(clickActionUrl__KEY))
                    {
                        pictureAd.clickActionUrl = (string)campaignDict[clickActionUrl__KEY];
                    }

                    setImageSpace(pictureAd, ImageType.Base, campaignDict);
                }

                if (assetKey == hasMoreCampaigns__KEY)
                {
                    bool.TryParse((string)dict2[assetKey].ToString(), out pictureAd.hasMoreCampaigns);
                }
            }

            return(pictureAd);
        }
예제 #2
0
		public static PictureAd parseJSONString(string jsonString, string localCachePath) {
			PictureAd pictureAd = new PictureAd();
			pictureAd.setImageSpace(ImageType.Base, defaultBaseSpace);
			pictureAd.setImageSpace(ImageType.Close, defaultCloseButtonSpace);
			pictureAd.setImageSpace(ImageType.Frame, defaultFrameSpace);
			pictureAd.closeButtonDelay = defaultCloseButtonDelay;
			
			if(jsonString == null || jsonString.Length == 0) return pictureAd;
			
			var dict = Json.Deserialize(jsonString) as Dictionary<string, object>;
			
			if(dict == null) return pictureAd;
			
			if(!dict.ContainsKey("data")) return pictureAd;
			
			Dictionary<string, object> dict2 = (Dictionary<string, object>)dict["data"];
			
			foreach(string assetKey in dict2.Keys) {
				if(assetKey == game__KEY) {
					var gameDict = (Dictionary <string, object>)dict2[assetKey];
					if(gameDict == null) return pictureAd;
					
					if(gameDict.ContainsKey(landscapeFramePicture__KEY))
						setupPathsForAd(pictureAd, localCachePath, (string)gameDict[landscapeFramePicture__KEY], ImageOrientation.Landscape, ImageType.Frame);
					
					if(gameDict.ContainsKey(portraitFramePicture__KEY))
						setupPathsForAd(pictureAd, localCachePath, (string)gameDict[portraitFramePicture__KEY], ImageOrientation.Portrait, ImageType.Frame);
					
					if(gameDict.ContainsKey(closeButtonPicture__KEY)) {
						setupPathsForAd(pictureAd, localCachePath, (string)gameDict[closeButtonPicture__KEY], ImageOrientation.Landscape, ImageType.Close);
						pictureAd.setImageURL(localPathForResource(localCachePath,(string)gameDict[closeButtonPicture__KEY]), 
						                      ImageURLType.Local, ImageOrientation.Portrait, ImageType.Close);
					}
					
					if(gameDict.ContainsKey(closeButtonDelay__KEY))
						pictureAd.closeButtonDelay = stringToInt((string)gameDict[closeButtonDelay__KEY].ToString());
					
					setImageSpace(pictureAd, ImageType.Frame, gameDict);
					setImageSpace(pictureAd, ImageType.Close, gameDict);
				}
				
				if(assetKey == campaign__KEY) {
					var campaignDict = (Dictionary <string, object>)dict2[assetKey];
					if(campaignDict == null) return pictureAd;
					
					if(campaignDict.ContainsKey(landscapePicture__KEY))
						setupPathsForAd(pictureAd, localCachePath, (string)campaignDict[landscapePicture__KEY], ImageOrientation.Landscape, ImageType.Base);
					
					if(campaignDict.ContainsKey(portraitPicture__KEY))
						setupPathsForAd(pictureAd, localCachePath, (string)campaignDict[portraitPicture__KEY], ImageOrientation.Portrait, ImageType.Base);
					
					if(campaignDict.ContainsKey(id__KEY))
						pictureAd.id = (string)campaignDict[id__KEY];
					
					if(campaignDict.ContainsKey(clickActionUrl__KEY))
						pictureAd.clickActionUrl = (string)campaignDict[clickActionUrl__KEY];
					
					setImageSpace(pictureAd, ImageType.Base, campaignDict);
				}
				
				if (assetKey == hasMoreCampaigns__KEY)
					bool.TryParse((string)dict2[assetKey].ToString(), out pictureAd.hasMoreCampaigns);
				
			}
			
			return pictureAd;
		}
예제 #3
0
 static void setupPathsForAd(PictureAd ad, string localCachePath, string remotePath, ImageOrientation orientation, ImageType imageType)
 {
     ad.setImageURL(remotePath, ImageURLType.Remote, orientation, imageType);
     ad.setImageURL(localPathForResource(localCachePath, remotePath), ImageURLType.Local, orientation, imageType);
 }
예제 #4
0
		static void setupPathsForAd(PictureAd ad, string localCachePath, string remotePath, ImageOrientation orientation, ImageType imageType) {
			ad.setImageURL(remotePath, ImageURLType.Remote, orientation, imageType);
			ad.setImageURL(localPathForResource(localCachePath, remotePath), ImageURLType.Local, orientation, imageType);
		}