コード例 #1
0
    // picks random ad from given list for given type
    public static Ad_S1 GetAdd(List <Ad_S1> _ads, AddType _type)
    {
        bool _contains = false;

        // check that list contains type
        foreach (Ad_S1 _ad in _ads)
        {
            if (_ad.Type == _type)
            {
                _contains = true;
                break;
            }
        }

        if (!_contains)
        {
            throw new ArgumentException(string.Format("List of ads does not contain given type \"{0}\"", _type.ToString()));
        }

        // pick a random ad
        while (true)
        {
            Random _rand  = new Random();
            int    _index = _rand.Next(_ads.Count);

            Ad_S1 _ad = _ads[_index];
            if (_ad.Type == _type)
            {
                return(_ad);
            }
        }
    }
コード例 #2
0
    // loads advertisement banners
    private void loadAds()
    {
        // get list of adds
        List <Ad_S1> _ads;

        try {
            _ads = GetAds();
        } catch (Exception _e) {
            Trace.Warn("Shop", "Failed to get ads", _e);
            return;
        }

        // get random horizontal and vertical ads
        try {
            Ad_S1 _adH = Ad_S1.GetAdd(_ads, Ad_S1.AddType.Horizontal);
            SetAdHorizontal(_adH);
        }catch (Exception _e) {
            Trace.Warn("Shop", "Failed to set horizontal ad", _e);
        }

        try {
            Ad_S1 _adV = Ad_S1.GetAdd(_ads, Ad_S1.AddType.Vertical);
            SetAdVertical(_adV);
        } catch (Exception _e) {
            Trace.Warn("Shop", "Failed to set vertical ad", _e);
        }
    }
コード例 #3
0
    // sets horizontal ad
    private void SetAdHorizontal(Ad_S1 _ad)
    {
        // get image name
        string _imagePath = GetImagePath(_ad.ImageName);

        // get control for image
        Control   _topBanner = FindControl("bannerTop");
        HyperLink _image     = (HyperLink)FindControl("bannerTopImg");

        if (_image == null)
        {
            _image    = new HyperLink();
            _image.ID = "bannerTopImg";

            // add to bannerTop
            _topBanner.Controls.Add(_image);
        }

        // setup image
        _image.ImageUrl    = _imagePath;
        _image.NavigateUrl = string.Format("http://{0}", _ad.Link);
    }