Ejemplo n.º 1
0
    public void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SiteMapDataAttribute sitemapdata = new SiteMapDataAttribute();
            sitemapdata.Add(new SiteMapDataAttributeNode("System Preferences", Request, "SystemPreferencesManage.aspx"));
            sitemapdata.Add(new SiteMapDataAttributeNode("Pictures", Request, "SystemPicturesManage.aspx"));

            inputType.DataSource = SessionManager.ObjectService.GetPictureTypes(
                SessionManager.Ticket, null);

            inputType.DataBind();

            if (RequestId > 0)
            {
                TransitPicture t = SessionManager.ObjectService.GetPictureById(
                    SessionManager.Ticket, RequestId);
                inputName.Text        = t.Name;
                inputDescription.Text = t.Description;
                ListItemManager.TrySelect(inputType, t.Type);
                imageThumbnail.ImageUrl = string.Format("SystemPictureThumbnail.aspx?id={0}&CacheDuration=0", t.Id);
                sitemapdata.Add(new SiteMapDataAttributeNode(t.Name, Request.Url));
            }
            else
            {
                sitemapdata.Add(new SiteMapDataAttributeNode("New Picture", Request.Url));
            }

            StackSiteMap(sitemapdata);
        }

        SetDefaultButton(manageAdd);
    }
Ejemplo n.º 2
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        string url = Request["Src"];

        if (string.IsNullOrEmpty(url))
        {
            throw new Exception("Invalid url.");
        }

        string key = string.Format("AccountFeedItemPicture:{0}", url.GetHashCode());
        TransitPicture result = (TransitPicture) Cache[key];

        if (result != null)
            return result;

        // fetch the image to get its size
        WebClient client = new WebClient();
        client.Headers["Accept"] = "*/*";
        client.Headers["User-Agent"] = SessionManager.GetCachedConfiguration("SnCore.Web.UserAgent", "SnCore/1.0");
        result = new TransitPicture();
        result.Name = url;

        try
        {
            byte[] data = client.DownloadData(url);

            if (data == null)
            {
                throw new Exception("Missing file data.");
            }

            result.Bitmap = new ThumbnailBitmap(new MemoryStream(data), new Size(0, 0), 
                ThumbnailBitmap.s_FullSize, ThumbnailBitmap.s_ThumbnailSize).Bitmap;

            string created = (string)client.ResponseHeaders["Created"];
            if (string.IsNullOrEmpty(created)) created = (string)client.ResponseHeaders["Date"];
            if (string.IsNullOrEmpty(created) || !DateTime.TryParse(created, out result.Created))
                result.Created = DateTime.Now;

            string modified = (string)client.ResponseHeaders["Modified"];
            if (string.IsNullOrEmpty(modified) || !DateTime.TryParse(modified, out result.Modified))
                result.Modified = DateTime.Now;
        }
        catch(Exception ex)
        {
            string message = string.Format("This image cannot be displayed.\n{0}\n{1}",
                ex.Message, url);
            result.Bitmap = ThumbnailBitmap.GetBitmapDataFromText(message, 8, 0, 0);
            result.Modified = result.Created = DateTime.Now;
        }

        Cache.Insert(key, result, null, Cache.NoAbsoluteExpiration,
            SessionManager.DefaultCacheTimeSpan);

        return result;
    }
Ejemplo n.º 3
0
 public void save_Click(object sender, EventArgs e)
 {
     TransitPicture t = new TransitPicture();
     t.Name = inputName.Text;
     t.Description = inputDescription.Text;
     t.Type = inputType.SelectedValue;
     t.Id = RequestId;
     SessionManager.CreateOrUpdate<TransitPicture>(
         t, SessionManager.ObjectService.CreateOrUpdatePicture);
     Redirect("SystemPicturesManage.aspx");
 }
Ejemplo n.º 4
0
    public void save_Click(object sender, EventArgs e)
    {
        TransitPicture t = new TransitPicture();

        t.Name        = inputName.Text;
        t.Description = inputDescription.Text;
        t.Type        = inputType.SelectedValue;
        t.Id          = RequestId;
        SessionManager.CreateOrUpdate <TransitPicture>(
            t, SessionManager.ObjectService.CreateOrUpdatePicture);
        Redirect("SystemPicturesManage.aspx");
    }
Ejemplo n.º 5
0
        public TransitPicture GetPictureIfModifiedSinceById(string ticket, int id, DateTime ifModifiedSince)
        {
            TransitPicture t_instance = WebServiceImpl <TransitPicture, ManagedPicture, Picture> .GetById(
                ticket, id);

            if (t_instance.Modified <= ifModifiedSince)
            {
                return(null);
            }

            return(t_instance);
        }
Ejemplo n.º 6
0
 public void Page_Load()
 {
     if (!IsPostBack)
     {
         TransitPicture p = SessionManager.ObjectService.GetPictureById(
             SessionManager.Ticket, RequestId);
         inputPicture.Src      = string.Format("SystemPicture.aspx?id={0}", RequestId);
         inputName.Text        = Renderer.Render(p.Name);
         inputDescription.Text = Renderer.Render(p.Description);
         inputCreated.Text     = Adjust(p.Created).ToString();
         inputType.Text        = Renderer.Render(p.Type);
     }
 }
Ejemplo n.º 7
0
    public override TransitPicture GetPictureWithBitmap(int id, DateTime ifModifiedSince)
    {
        TransitAccountStoryPicture p = SessionManager.GetInstance<TransitAccountStoryPicture, int, DateTime>(
            id, ifModifiedSince, SessionManager.StoryService.GetAccountStoryPictureIfModifiedSinceById);

        if (p == null)
            return null;

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.Picture;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
Ejemplo n.º 8
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        TransitAccountGroupPicture p = SessionManager.GroupService.GetAccountGroupPictureById(
            SessionManager.Ticket, id);

        if (p == null)
            return null;

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.Bitmap;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
Ejemplo n.º 9
0
    public override TransitPicture GetPictureWithThumbnail(int id, DateTime ifModifiedSince)
    {
        TransitAccountGroupPicture p = SessionManager.GroupService.GetAccountGroupPictureIfModifiedSinceById(
            SessionManager.Ticket, id, ifModifiedSince);

        if (p == null)
            return null;

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.Thumbnail;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
Ejemplo n.º 10
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        TransitAttribute p = SessionManager.GetInstance<TransitAttribute, int>(
            id, SessionManager.ObjectService.GetAttributeById);

        if (p == null)
            return null;

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.Bitmap;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
Ejemplo n.º 11
0
    public override TransitPicture GetPictureWithThumbnail(int id)
    {
        TransitBookmark p = SessionManager.GetInstance<TransitBookmark, int>(
            id, SessionManager.ObjectService.GetBookmarkById);

        if (p == null)
            return null;

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.LinkBitmap;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
Ejemplo n.º 12
0
    public override TransitPicture GetPictureWithThumbnail(int id, DateTime ifModifiedSince)
    {
        TransitAccountPicture p = SessionManager.GetInstance<TransitAccountPicture, AccountService.ServiceQueryOptions, int, DateTime>(
            id, ifModifiedSince, SessionManager.AccountService.GetAccountPictureIfModifiedSinceById);

        if (p == null)
            return null;

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.Thumbnail;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
Ejemplo n.º 13
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        TransitAccountPicture p = SessionManager.GetInstance<TransitAccountPicture, AccountService.ServiceQueryOptions, int>(
            id, SessionManager.AccountService.GetAccountPictureById);

        if (p == null)
            return null;

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.Bitmap;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
Ejemplo n.º 14
0
    public override TransitPicture GetPictureWithBitmap(int id, DateTime ifModifiedSince)
    {
        TransitBookmark p = SessionManager.GetInstance<TransitBookmark, int, DateTime>(
            id, ifModifiedSince, SessionManager.ObjectService.GetBookmarkIfModifiedSinceById);

        if (p == null)
            return null;

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.FullBitmap;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
Ejemplo n.º 15
0
    public override TransitPicture GetPictureWithThumbnail(int id)
    {
        TransitPlacePicture p = SessionManager.GetInstance<TransitPlacePicture, int>(
            id, SessionManager.PlaceService.GetPlacePictureById);

        if (p == null)
            return null;

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.Thumbnail;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
    public override TransitPicture GetPictureWithThumbnail(int id)
    {
        TransitAccountFeedItemImg p = SessionManager.GetInstance<TransitAccountFeedItemImg, int>(
            id, SessionManager.SyndicationService.GetAccountFeedItemImgById);

        if (p == null)
            return null;

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.Thumbnail;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Url;
        return result;
    }
Ejemplo n.º 17
0
    public override TransitPicture GetPictureWithThumbnail(int id, DateTime ifModifiedSince)
    {
        TransitAccountWebsite p = SessionManager.GetInstance<TransitAccountWebsite, int, DateTime>(
            id, ifModifiedSince, SessionManager.AccountService.GetAccountWebsiteIfModifiedSinceById);

        if (p == null || p.Bitmap == null)
        {
            return GetRandomPictureWithThumbnail();
        }

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.Thumbnail;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
Ejemplo n.º 18
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        TransitPlaceWebsite p = SessionManager.GetInstance<TransitPlaceWebsite, int>(
            id, SessionManager.PlaceService.GetPlaceWebsiteById);

        if (p == null || p.Bitmap == null)
        {
            return GetRandomPictureWithThumbnail();
        }

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.Bitmap;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
Ejemplo n.º 19
0
    public override TransitPicture GetPictureWithThumbnail(int id, DateTime ifModifiedSince)
    {
        TransitPlaceWebsite p = SessionManager.GetInstance <TransitPlaceWebsite, int, DateTime>(
            id, ifModifiedSince, SessionManager.PlaceService.GetPlaceWebsiteIfModifiedSinceById);

        if (p == null || p.Bitmap == null)
        {
            return(GetRandomPictureWithThumbnail());
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Thumbnail;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
    public override TransitPicture GetPictureWithThumbnail(int id)
    {
        TransitAccountFeedItemImg p = SessionManager.GetInstance <TransitAccountFeedItemImg, int>(
            id, SessionManager.SyndicationService.GetAccountFeedItemImgById);

        if (p == null)
        {
            return(null);
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Thumbnail;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Url;
        return(result);
    }
Ejemplo n.º 21
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        SnCore.Services.TransitPicture p = SessionManager.GetInstance <SnCore.Services.TransitPicture, int>(
            id, SessionManager.ObjectService.GetPictureById);

        if (p == null)
        {
            return(null);
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Bitmap;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 22
0
    public override TransitPicture GetPictureWithBitmap(int id, DateTime ifModifiedSince)
    {
        TransitPlacePicture p = SessionManager.GetInstance <TransitPlacePicture, PlaceService.ServiceQueryOptions, int, DateTime>(
            id, ifModifiedSince, SessionManager.PlaceService.GetPlacePictureIfModifiedSinceById);

        if (p == null)
        {
            return(null);
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Bitmap;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 23
0
    public override TransitPicture GetPictureWithThumbnail(int id, DateTime ifModifiedSince)
    {
        TransitBookmark p = SessionManager.GetInstance <TransitBookmark, int, DateTime>(
            id, ifModifiedSince, SessionManager.ObjectService.GetBookmarkIfModifiedSinceById);

        if (p == null)
        {
            return(null);
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.LinkBitmap;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 24
0
    public override TransitPicture GetPictureWithThumbnail(int id)
    {
        TransitPlacePicture p = SessionManager.GetInstance <TransitPlacePicture, PlaceService.ServiceQueryOptions, int>(
            id, SessionManager.PlaceService.GetPlacePictureById);

        if (p == null)
        {
            return(null);
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Thumbnail;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 25
0
    public override TransitPicture GetPictureWithThumbnail(int id, DateTime ifModifiedSince)
    {
        TransitAccountGroupPicture p = SessionManager.GroupService.GetAccountGroupPictureIfModifiedSinceById(
            SessionManager.Ticket, id, ifModifiedSince);

        if (p == null)
        {
            return(null);
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Thumbnail;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 26
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        TransitAccountGroupPicture p = SessionManager.GroupService.GetAccountGroupPictureById(
            SessionManager.Ticket, id);

        if (p == null)
        {
            return(null);
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Bitmap;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 27
0
    public override TransitPicture GetPictureWithThumbnail(int id)
    {
        TransitAccountWebsite p = SessionManager.GetInstance <TransitAccountWebsite, int>(
            id, SessionManager.AccountService.GetAccountWebsiteById);

        if (p == null || p.Bitmap == null)
        {
            return(GetRandomPictureWithThumbnail());
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Thumbnail;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 28
0
    public override TransitPicture GetRandomPictureWithThumbnail()
    {
        SnCore.Services.TransitPicture p = SessionManager.GetInstance <SnCore.Services.TransitPicture, string>(
            "AccountStory", SessionManager.ObjectService.GetRandomPictureByType);

        if (p == null)
        {
            return(null);
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Thumbnail;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 29
0
    public override PicturePage.TransitPicture GetRandomPictureWithThumbnail()
    {
        ObjectService.TransitPicture p = SessionManager.GetInstance <ObjectService.TransitPicture, ObjectService.ServiceQueryOptions, string>(
            "Place", SessionManager.ObjectService.GetRandomPictureByType);

        if (p == null)
        {
            return(null);
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Thumbnail;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 30
0
    public override TransitPicture GetPictureWithThumbnail(int id)
    {
        TransitAttribute p = SessionManager.GetInstance <TransitAttribute, int>(
            id, SessionManager.ObjectService.GetAttributeById);

        if (p == null)
        {
            return(null);
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Bitmap;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 31
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        TransitAccountStoryPicture p = SessionManager.GetInstance <TransitAccountStoryPicture, int>(
            id, SessionManager.StoryService.GetAccountStoryPictureById);

        if (p == null)
        {
            return(null);
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Picture;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 32
0
    public override TransitPicture GetPictureWithThumbnail(int id, DateTime ifModifiedSince)
    {
        TransitAccountStoryPicture p = SessionManager.GetInstance <TransitAccountStoryPicture, int, DateTime>(
            id, ifModifiedSince, SessionManager.StoryService.GetAccountStoryPictureIfModifiedSinceById);

        if (p == null)
        {
            return(null);
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Thumbnail;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 33
0
    protected void files_FilesPosted(object sender, FilesPostedEventArgs e)
    {
        try
        {
            if (e.PostedFiles.Count == 0)
            {
                return;
            }

            ExceptionCollection exceptions = new ExceptionCollection();
            foreach (HttpPostedFile file in e.PostedFiles)
            {
                try
                {
                    TransitPicture  p = new TransitPicture();
                    ThumbnailBitmap t = new ThumbnailBitmap(file.InputStream);
                    p.Bitmap      = t.Bitmap;
                    p.Name        = Path.GetFileName(file.FileName);
                    p.Type        = selectPictureType.SelectedValue;
                    p.Description = string.Empty;

                    SessionManager.CreateOrUpdate <TransitPicture>(
                        p, SessionManager.ObjectService.CreateOrUpdatePicture);
                }
                catch (Exception ex)
                {
                    exceptions.Add(new Exception(string.Format("Error processing {0}: {1}",
                                                               Renderer.Render(file.FileName), ex.Message), ex));
                }
            }

            gridManage.CurrentPageIndex = 0;
            gridManage_OnGetDataSource(sender, e);
            gridManage.DataBind();
            exceptions.Throw();
        }
        catch (Exception ex)
        {
            ReportException(ex);
        }
    }
Ejemplo n.º 34
0
    public override PicturePage.TransitPicture GetRandomPictureWithThumbnail()
    {
        SnCore.Services.TransitPicture p = SessionManager.GetInstance <SnCore.Services.TransitPicture, string>(
            "AccountWebsite", SessionManager.ObjectService.GetRandomPictureByType);

        if (p == null || p.Bitmap == null)
        {
            p = new SnCore.Services.TransitPicture();
            const string s_Unavailable = "Thumbnail\nQueued";
            // flip the bitmaps horizontally
            p.Bitmap    = ThumbnailBitmap.GetBitmapDataFromText(s_Unavailable, 10, ThumbnailBitmap.s_FullSize.Height, ThumbnailBitmap.s_FullSize.Width);
            p.Thumbnail = ThumbnailBitmap.GetBitmapDataFromText(s_Unavailable, 10, ThumbnailBitmap.s_ThumbnailSize.Height, ThumbnailBitmap.s_ThumbnailSize.Width);
            p.Created   = p.Modified = DateTime.UtcNow;
        }

        TransitPicture result = new TransitPicture();

        result.Id       = p.Id;
        result.Bitmap   = p.Thumbnail;
        result.Created  = p.Created;
        result.Modified = p.Modified;
        result.Name     = p.Name;
        return(result);
    }
Ejemplo n.º 35
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            Nullable<Size> resize = Size;
            Nullable<DateTime> ims = IfModifiedSince;

            if (ims.HasValue)
            {
                if (ims.Value.ToUniversalTime().AddSeconds(CacheDuration) > DateTime.UtcNow)
                {
                    Response.StatusCode = 304;
                    return;
                }
            }

            TransitPicture p = null;

            switch (PageType)
            {
                case PicturePageType.Thumbnail:
                    
                    if (RequestId == 0)
                    {
                        p = GetRandomPictureWithThumbnail();

                        if (p == null)
                        {
                            p = new TransitPicture();
                            p.Id = 0;
                            p.Created = p.Modified = DateTime.Now;
                            p.Name = Guid.NewGuid().ToString();
                            if (!resize.HasValue) resize = new Size(100, 150);
                            p.Bitmap = ThumbnailBitmap.GetBitmapDataFromText("?", 72, 
                                resize.Value.Width, resize.Value.Height);
                        }
                    }
                    else
                    {
                        p = ims.HasValue ?
                                GetPictureWithThumbnail(RequestId, ims.Value) :
                                GetPictureWithThumbnail(RequestId);
                    }

                    break;
                case PicturePageType.Bitmap:
                    
                    p = ims.HasValue ?
                            GetPictureWithBitmap(RequestId, ims.Value) :
                            GetPictureWithBitmap(RequestId);

                    break;
            }

            if (p == null)
            {
                if (ims.HasValue)
                {
                    Response.StatusCode = 304;
                    return;
                }
                else
                {
                    throw new Exception("Invalid picture id.");
                }
            }

            Response.Cache.SetLastModified(p.Modified.ToLocalTime());
            Response.Cache.SetCacheability(HttpCacheability.Private);

            p.Name = (string.IsNullOrEmpty(p.Name)) ? p.Id.ToString() + ".jpg" : p.Id.ToString() + "-" + p.Name;

            if (resize.HasValue)
            {
                ThumbnailBitmap resized = new ThumbnailBitmap(new MemoryStream(p.Bitmap), new Size(0, 0),
                    resize.Value, resize.Value);

                switch (PageType)
                {
                    case PicturePageType.Bitmap:
                        p.Bitmap = resized.Bitmap;
                        break;
                    case PicturePageType.Thumbnail:
                        p.Bitmap = resized.Thumbnail;
                        break;
                }
            }

            switch (PageType)
            {
                case PicturePageType.Thumbnail:
                    p.Name.Insert(0, "thumbnail-");
                    break;
            }

            Response.ContentType = "image/" + Path.GetExtension(p.Name).TrimStart(".".ToCharArray());
            Response.AddHeader("Content-disposition", "attachment; filename=" + p.Name);
            Response.AddHeader("Created", p.Created.ToString("r"));
            Response.AddHeader("Modified", p.Modified.ToString("r"));
            Response.BinaryWrite(p.Bitmap);
            Response.End();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
Ejemplo n.º 36
0
    public override PicturePage.TransitPicture GetRandomPictureWithThumbnail()
    {
        SnCore.Services.TransitPicture p = SessionManager.GetInstance<SnCore.Services.TransitPicture, string>(
            "PlaceWebsite", SessionManager.ObjectService.GetRandomPictureByType);

        if (p == null || p.Bitmap == null)
        {
            p = new SnCore.Services.TransitPicture();
            const string s_Unavailable = "Thumbnail\nQueued";
            // flip the bitmaps horizontally
            p.Bitmap = ThumbnailBitmap.GetBitmapDataFromText(s_Unavailable, 10, ThumbnailBitmap.s_FullSize.Height, ThumbnailBitmap.s_FullSize.Width);
            p.Thumbnail = ThumbnailBitmap.GetBitmapDataFromText(s_Unavailable, 10, ThumbnailBitmap.s_ThumbnailSize.Height, ThumbnailBitmap.s_ThumbnailSize.Width);
            p.Created = p.Modified = DateTime.UtcNow;
        }

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.Thumbnail;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
Ejemplo n.º 37
0
 public int CreateOrUpdatePicture(string ticket, TransitPicture picture)
 {
     return WebServiceImpl<TransitPicture, ManagedPicture, Picture>.CreateOrUpdate(
         ticket, picture);
 }
Ejemplo n.º 38
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        ChartEngine engine = new ChartEngine();
        engine.Size = new Size(570, 300);
        engine.GridLines = WebChart.GridLines.None;
        engine.ShowXValues = true;
        engine.ShowYValues = true;
        engine.LeftChartPadding = 50;
        engine.BottomChartPadding = 50;
        engine.XAxisFont.StringFormat.LineAlignment = StringAlignment.Center;
        engine.XAxisFont.StringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
        engine.XAxisFont.ForeColor = engine.YAxisFont.ForeColor = Color.Black;

        ChartCollection charts = new ChartCollection(engine);
        engine.Charts = charts;

        List<List<TransitSummarizedCounter>> counters = new List<List<TransitSummarizedCounter>>();
        string format;
        string title = RequestType.ToString();

        switch (RequestType)
        {
            case ChartType.DailyNew:
                counters.Add(Summary.NewDaily);
                format = "MMM d";
                title = "New Daily";
                break;
            case ChartType.DailyReturning:
                counters.Add(Summary.ReturningDaily);
                format = "MMM d";
                title = "Returning Daily";
                break;
            case ChartType.Daily:
                counters.Add(Summary.Daily);
                format = "MMM d";
                break;
            case ChartType.Hourly:
                counters.Add(Summary.Hourly);
                format = "htt";
                break;
            case ChartType.MonthlyUnique:
                counters.Add(Summary.UniqueMonthly);
                format = "MMM";
                title = "Monthly Unique";
                break;
            case ChartType.Monthly:
                counters.Add(Summary.Monthly);
                format = "MMM";
                break;
            case ChartType.Weekly:
                counters.Add(Summary.Weekly);
                format = "MMM dd";
                break;
            case ChartType.Yearly:
                counters.Add(Summary.Yearly);
                format = "yyyy";
                break;
            case ChartType.AccountDaily:
                counters.Add(Summary.AccountDaily);
                format = "MMM d";
                title = "New Daily";
                break;
            case ChartType.AccountMonthly:
                counters.Add(Summary.AccountMonthly);
                format = "MMM";
                title = "New Monthly";
                break;
            case ChartType.AccountWeekly:
                counters.Add(Summary.AccountWeekly);
                format = "MMM dd";
                title = "New Weekly";
                break;
            case ChartType.AccountYearly:
                counters.Add(Summary.AccountYearly);
                format = "yyyy";
                title = "New Yearly";
                break;
            default:
                throw new ArgumentOutOfRangeException("type");
        }

        long total = 0;
        long count = 0;
        Color fill = Color.FromArgb(0x9F, 0x6, 0x15);
        foreach (List<TransitSummarizedCounter> clist in counters)
        {
            ColumnChart chart = new ColumnChart();
            chart.ShowLineMarkers = false;
            chart.ShowLegend = true;
            chart.Line.Color = Color.White;
            chart.Line.Width = 2;
            chart.Fill.Color = engine.Border.Color = fill;
            chart.Fill.LinearGradientMode = System.Drawing.Drawing2D.LinearGradientMode.Vertical;
            chart.MaxColumnWidth = 100;

            count += clist.Count;

            foreach (TransitSummarizedCounter counter in clist)
            {                
                total += counter.Total;
                chart.Data.Add(new ChartPoint(counter.Timestamp.ToString(format), counter.Total));
            }

            charts.Add(chart);
            fill = Color.FromArgb(fill.R + 0x30, fill.G + 0x30, fill.B + 0x30);
        }

        engine.Title = new ChartText();
        double average = count > 0 ? total / count : 0;
        engine.Title.Text = string.Format("{0} (average: {1})", RequestType, average);

        TransitPicture picture = new TransitPicture();
        picture.Id = 0;
        picture.Modified = picture.Created = DateTime.UtcNow;
        picture.Name = RequestType.ToString();

        MemoryStream ds = new MemoryStream();
        engine.GetBitmap().Save(ds, System.Drawing.Imaging.ImageFormat.Png);
        picture.Bitmap = new byte[ds.Length];
        MemoryStream ms = new MemoryStream(picture.Bitmap);
        ds.WriteTo(ms);

        return picture;
    }
Ejemplo n.º 39
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        string url = Request["Src"];

        if (string.IsNullOrEmpty(url))
        {
            throw new Exception("Invalid url.");
        }

        string         key    = string.Format("AccountFeedItemPicture:{0}", url.GetHashCode());
        TransitPicture result = (TransitPicture)Cache[key];

        if (result != null)
        {
            return(result);
        }

        // fetch the image to get its size
        WebClient client = new WebClient();

        client.Headers["Accept"]     = "*/*";
        client.Headers["User-Agent"] = SessionManager.GetCachedConfiguration("SnCore.Web.UserAgent", "SnCore/1.0");
        result      = new TransitPicture();
        result.Name = url;

        try
        {
            byte[] data = client.DownloadData(url);

            if (data == null)
            {
                throw new Exception("Missing file data.");
            }

            result.Bitmap = new ThumbnailBitmap(new MemoryStream(data), new Size(0, 0),
                                                ThumbnailBitmap.s_FullSize, ThumbnailBitmap.s_ThumbnailSize).Bitmap;

            string created = (string)client.ResponseHeaders["Created"];
            if (string.IsNullOrEmpty(created))
            {
                created = (string)client.ResponseHeaders["Date"];
            }
            if (string.IsNullOrEmpty(created) || !DateTime.TryParse(created, out result.Created))
            {
                result.Created = DateTime.Now;
            }

            string modified = (string)client.ResponseHeaders["Modified"];
            if (string.IsNullOrEmpty(modified) || !DateTime.TryParse(modified, out result.Modified))
            {
                result.Modified = DateTime.Now;
            }
        }
        catch (Exception ex)
        {
            string message = string.Format("This image cannot be displayed.\n{0}\n{1}",
                                           ex.Message, url);
            result.Bitmap   = ThumbnailBitmap.GetBitmapDataFromText(message, 8, 0, 0);
            result.Modified = result.Created = DateTime.Now;
        }

        Cache.Insert(key, result, null, Cache.NoAbsoluteExpiration,
                     SessionManager.DefaultCacheTimeSpan);

        return(result);
    }
Ejemplo n.º 40
0
    public override TransitPicture GetPictureWithBitmap(int id)
    {
        ChartEngine engine = new ChartEngine();

        engine.Size               = new Size(570, 300);
        engine.GridLines          = WebChart.GridLines.None;
        engine.ShowXValues        = true;
        engine.ShowYValues        = true;
        engine.LeftChartPadding   = 50;
        engine.BottomChartPadding = 50;
        engine.XAxisFont.StringFormat.LineAlignment = StringAlignment.Center;
        engine.XAxisFont.StringFormat.FormatFlags   = StringFormatFlags.DirectionVertical;
        engine.XAxisFont.ForeColor = engine.YAxisFont.ForeColor = Color.Black;

        ChartCollection charts = new ChartCollection(engine);

        engine.Charts = charts;

        List <List <TransitSummarizedCounter> > counters = new List <List <TransitSummarizedCounter> >();
        string format;
        string title = RequestType.ToString();

        switch (RequestType)
        {
        case ChartType.DailyNew:
            counters.Add(Summary.NewDaily);
            format = "MMM d";
            title  = "New Daily";
            break;

        case ChartType.DailyReturning:
            counters.Add(Summary.ReturningDaily);
            format = "MMM d";
            title  = "Returning Daily";
            break;

        case ChartType.Daily:
            counters.Add(Summary.Daily);
            format = "MMM d";
            break;

        case ChartType.Hourly:
            counters.Add(Summary.Hourly);
            format = "htt";
            break;

        case ChartType.MonthlyUnique:
            counters.Add(Summary.UniqueMonthly);
            format = "MMM";
            title  = "Monthly Unique";
            break;

        case ChartType.Monthly:
            counters.Add(Summary.Monthly);
            format = "MMM";
            break;

        case ChartType.Weekly:
            counters.Add(Summary.Weekly);
            format = "MMM dd";
            break;

        case ChartType.Yearly:
            counters.Add(Summary.Yearly);
            format = "yyyy";
            break;

        case ChartType.AccountDaily:
            counters.Add(Summary.AccountDaily);
            format = "MMM d";
            title  = "New Daily";
            break;

        case ChartType.AccountMonthly:
            counters.Add(Summary.AccountMonthly);
            format = "MMM";
            title  = "New Monthly";
            break;

        case ChartType.AccountWeekly:
            counters.Add(Summary.AccountWeekly);
            format = "MMM dd";
            title  = "New Weekly";
            break;

        case ChartType.AccountYearly:
            counters.Add(Summary.AccountYearly);
            format = "yyyy";
            title  = "New Yearly";
            break;

        default:
            throw new ArgumentOutOfRangeException("type");
        }

        long  total = 0;
        long  count = 0;
        Color fill  = Color.FromArgb(0x9F, 0x6, 0x15);

        foreach (List <TransitSummarizedCounter> clist in counters)
        {
            ColumnChart chart = new ColumnChart();
            chart.ShowLineMarkers         = false;
            chart.ShowLegend              = true;
            chart.Line.Color              = Color.White;
            chart.Line.Width              = 2;
            chart.Fill.Color              = engine.Border.Color = fill;
            chart.Fill.LinearGradientMode = System.Drawing.Drawing2D.LinearGradientMode.Vertical;
            chart.MaxColumnWidth          = 100;

            count += clist.Count;

            foreach (TransitSummarizedCounter counter in clist)
            {
                total += counter.Total;
                chart.Data.Add(new ChartPoint(counter.Timestamp.ToString(format), counter.Total));
            }

            charts.Add(chart);
            fill = Color.FromArgb(fill.R + 0x30, fill.G + 0x30, fill.B + 0x30);
        }

        engine.Title = new ChartText();
        double average = count > 0 ? total / count : 0;

        engine.Title.Text = string.Format("{0} (average: {1})", RequestType, average);

        TransitPicture picture = new TransitPicture();

        picture.Id       = 0;
        picture.Modified = picture.Created = DateTime.UtcNow;
        picture.Name     = RequestType.ToString();

        MemoryStream ds = new MemoryStream();

        engine.GetBitmap().Save(ds, System.Drawing.Imaging.ImageFormat.Png);
        picture.Bitmap = new byte[ds.Length];
        MemoryStream ms = new MemoryStream(picture.Bitmap);

        ds.WriteTo(ms);

        return(picture);
    }
Ejemplo n.º 41
0
    protected void files_FilesPosted(object sender, FilesPostedEventArgs e)
    {
        try
        {
            if (e.PostedFiles.Count == 0)
                return;

            ExceptionCollection exceptions = new ExceptionCollection();
            foreach (HttpPostedFile file in e.PostedFiles)
            {
                try
                {
                    TransitPicture p = new TransitPicture();
                    ThumbnailBitmap t = new ThumbnailBitmap(file.InputStream);
                    p.Bitmap = t.Bitmap;
                    p.Name = Path.GetFileName(file.FileName);
                    p.Type = selectPictureType.SelectedValue;
                    p.Description = string.Empty;

                    SessionManager.CreateOrUpdate<TransitPicture>(
                        p, SessionManager.ObjectService.CreateOrUpdatePicture);
                }
                catch (Exception ex)
                {
                    exceptions.Add(new Exception(string.Format("Error processing {0}: {1}",
                        Renderer.Render(file.FileName), ex.Message), ex));
                }
            }

            gridManage.CurrentPageIndex = 0;
            gridManage_OnGetDataSource(sender, e);
            gridManage.DataBind();
            exceptions.Throw();
        }
        catch (Exception ex)
        {
            ReportException(ex);
        }
    }
Ejemplo n.º 42
0
    public override PicturePage.TransitPicture GetRandomPictureWithThumbnail()
    {
        SnCore.Services.TransitPicture p = SessionManager.GetInstance<SnCore.Services.TransitPicture, string>(
            "Place", SessionManager.ObjectService.GetRandomPictureByType);

        if (p == null)
            return null;

        TransitPicture result = new TransitPicture();
        result.Id = p.Id;
        result.Bitmap = p.Thumbnail;
        result.Created = p.Created;
        result.Modified = p.Modified;
        result.Name = p.Name;
        return result;
    }
Ejemplo n.º 43
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            Nullable <Size>     resize = Size;
            Nullable <DateTime> ims    = IfModifiedSince;

            if (ims.HasValue)
            {
                if (ims.Value.ToUniversalTime().AddSeconds(CacheDuration) > DateTime.UtcNow)
                {
                    Response.StatusCode = 304;
                    return;
                }
            }

            TransitPicture p = null;

            switch (PageType)
            {
            case PicturePageType.Thumbnail:

                if (RequestId == 0)
                {
                    p = GetRandomPictureWithThumbnail();

                    if (p == null)
                    {
                        p         = new TransitPicture();
                        p.Id      = 0;
                        p.Created = p.Modified = DateTime.Now;
                        p.Name    = Guid.NewGuid().ToString();
                        if (!resize.HasValue)
                        {
                            resize = new Size(100, 150);
                        }
                        p.Bitmap = ThumbnailBitmap.GetBitmapDataFromText("?", 72,
                                                                         resize.Value.Width, resize.Value.Height);
                    }
                }
                else
                {
                    p = ims.HasValue ?
                        GetPictureWithThumbnail(RequestId, ims.Value) :
                        GetPictureWithThumbnail(RequestId);
                }

                break;

            case PicturePageType.Bitmap:

                p = ims.HasValue ?
                    GetPictureWithBitmap(RequestId, ims.Value) :
                    GetPictureWithBitmap(RequestId);

                break;
            }

            if (p == null)
            {
                if (ims.HasValue)
                {
                    Response.StatusCode = 304;
                    return;
                }
                else
                {
                    throw new Exception("Invalid picture id.");
                }
            }

            Response.Cache.SetLastModified(p.Modified.ToLocalTime());
            Response.Cache.SetCacheability(HttpCacheability.Private);

            p.Name = (string.IsNullOrEmpty(p.Name)) ? p.Id.ToString() + ".jpg" : p.Id.ToString() + "-" + p.Name;

            if (resize.HasValue)
            {
                ThumbnailBitmap resized = new ThumbnailBitmap(new MemoryStream(p.Bitmap), new Size(0, 0),
                                                              resize.Value, resize.Value);

                switch (PageType)
                {
                case PicturePageType.Bitmap:
                    p.Bitmap = resized.Bitmap;
                    break;

                case PicturePageType.Thumbnail:
                    p.Bitmap = resized.Thumbnail;
                    break;
                }
            }

            switch (PageType)
            {
            case PicturePageType.Thumbnail:
                p.Name.Insert(0, "thumbnail-");
                break;
            }

            Response.ContentType = "image/" + Path.GetExtension(p.Name).TrimStart(".".ToCharArray());
            Response.AddHeader("Content-disposition", "attachment; filename=" + p.Name);
            Response.AddHeader("Created", p.Created.ToString("r"));
            Response.AddHeader("Modified", p.Modified.ToString("r"));
            Response.BinaryWrite(p.Bitmap);
            Response.End();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
Ejemplo n.º 44
0
 public int CreateOrUpdatePicture(string ticket, TransitPicture picture)
 {
     return(WebServiceImpl <TransitPicture, ManagedPicture, Picture> .CreateOrUpdate(
                ticket, picture));
 }