Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Guid?           uploadSession   = null;
            string          tagWords        = null;
            ObjectStatus?   objectStatus    = null;
            ObjectShowState?objectShowState = null;
            FriendType?     friendType      = null;
            int?            copyright       = null;
            double          geoLat          = double.MinValue;
            double          geoLong         = double.MinValue;
            string          geoZip          = null;
            string          geoCity         = null;
            string          geoStreet       = null;
            string          geoCountry      = null;

            if (!string.IsNullOrEmpty(Request.QueryString["UploadSession"]))
            {
                uploadSession = Request.QueryString["UploadSession"].ToGuid();
            }
            if (!string.IsNullOrEmpty(Request.QueryString["TG"]))
            {
                tagWords = Server.UrlDecode(Request.QueryString["TG"]);
            }
            if (!string.IsNullOrEmpty(Request.QueryString["OS"]))
            {
                objectStatus = (ObjectStatus)int.Parse(Request.QueryString["OS"]);
            }
            if (!string.IsNullOrEmpty(Request.QueryString["SS"]))
            {
                objectShowState = (ObjectShowState)int.Parse(Request.QueryString["SS"]);
            }
            if (!string.IsNullOrEmpty(Request.QueryString["FT"]))
            {
                friendType = (FriendType)int.Parse(Request.QueryString["FT"]);
            }
            if (!string.IsNullOrEmpty(Request.QueryString["CR"]))
            {
                copyright = int.Parse(Request.QueryString["CR"]);
            }
            if (!string.IsNullOrEmpty(Request.QueryString["GC"]))
            {
                string[] geoLatLong = Request.QueryString["GC"].Split(',');
                if (geoLatLong.Length == 2)
                {
                    double.TryParse(geoLatLong[0], out geoLat);
                    double.TryParse(geoLatLong[1], out geoLong);
                }
            }
            if (!string.IsNullOrEmpty(Request.QueryString["ZP"]))
            {
                geoZip = Server.UrlDecode(Request.QueryString["ZP"]);
            }
            if (!string.IsNullOrEmpty(Request.QueryString["CI"]))
            {
                geoCity = Server.UrlDecode(Request.QueryString["CI"]);
            }
            if (!string.IsNullOrEmpty(Request.QueryString["RE"]))
            {
                geoStreet = Server.UrlDecode(Request.QueryString["RE"]);
            }
            if (!string.IsNullOrEmpty(Request.QueryString["CO"]))
            {
                geoCountry = Server.UrlDecode(Request.QueryString["CO"]);
            }

            picture = DataObject.Load <DataObjectPicture>(ObjectID, null, true);

            if (picture.State != ObjectState.Added) // Changing an existing object
            {
                if (tagWords != null)
                {
                    picture.TagList = tagWords;
                }
                if (objectStatus.HasValue)
                {
                    picture.Status = objectStatus.Value;
                }
                if (objectShowState.HasValue)
                {
                    picture.ShowState = objectShowState.Value;
                }
                if (friendType.HasValue)
                {
                    picture.FriendVisibility = friendType.Value;
                }
                if (copyright.HasValue)
                {
                    picture.Copyright = copyright.Value;
                }
                if (uploadSession != null)
                {
                    picture.GroupID = uploadSession;
                }
                if (geoLat != double.MinValue)
                {
                    picture.Geo_Lat = geoLat;
                }
                if (geoLong != double.MinValue)
                {
                    picture.Geo_Long = geoLong;
                }
                if (geoZip != null)
                {
                    picture.Zip = geoZip;
                }
                if (geoCity != null)
                {
                    picture.City = geoCity;
                }
                if (geoStreet != null)
                {
                    picture.Street = geoStreet;
                }
                if (geoCountry != null)
                {
                    picture.CountryCode = geoCountry;
                }

                // Don't save yet - save on SaveStep()

                FillEditForm();
            }
            else if (uploadSession.HasValue) // Creating an new object
            {
                try
                {
                    string cutFileName = FileInfo.Name.Substring(32);
                    picture.ObjectID    = Guid.NewGuid();
                    picture.Title       = cutFileName.Substring(0, cutFileName.LastIndexOf(".")).Replace("_", " ").CropString(100);
                    picture.CommunityID = CommunityID;
                    if (tagWords != null)
                    {
                        picture.TagList = tagWords;
                    }
                    if (objectStatus.HasValue)
                    {
                        picture.Status = objectStatus.Value;
                    }
                    if (objectShowState.HasValue)
                    {
                        picture.ShowState = objectShowState.Value;
                    }
                    if (friendType.HasValue)
                    {
                        picture.FriendVisibility = friendType.Value;
                    }
                    if (copyright.HasValue)
                    {
                        picture.Copyright = copyright.Value;
                    }
                    if (uploadSession != null)
                    {
                        picture.GroupID = uploadSession;
                    }
                    if (geoLat != double.MinValue)
                    {
                        picture.Geo_Lat = geoLat;
                    }
                    if (geoLong != double.MinValue)
                    {
                        picture.Geo_Long = geoLong;
                    }
                    if (geoZip != null)
                    {
                        picture.Zip = geoZip;
                    }
                    if (geoCity != null)
                    {
                        picture.City = geoCity;
                    }
                    if (geoStreet != null)
                    {
                        picture.Street = geoStreet;
                    }
                    if (geoCountry != null)
                    {
                        picture.CountryCode = geoCountry;
                    }

                    _4screen.CSB.ImageHandler.Business.ImageHandler imageHandler = new _4screen.CSB.ImageHandler.Business.ImageHandler(_4screen.CSB.Common.SiteConfig.MediaDomainName, ConfigurationManager.AppSettings["ConverterRootPath"], UserProfile.Current.UserId.ToString(), picture.ObjectID.Value.ToString(), false, Server.MapPath("/Configurations"));
                    Helper.SetActions(Helper.GetPictureFormatFromFilename(FileInfo.Name), picture.ObjectType, out saveOriginalAction, out saveLargeAction, out saveMediumAction, out saveSmallAction, out saveExtraSmallAction, out saveCropAction, imageTypes);

                    imageHandler.DoConvert(FileInfo.FullName, saveOriginalAction, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url);
                    string originalImagePath = imageHandler.TargetImage;

                    imageHandler.DoConvert(originalImagePath, saveLargeAction, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url);
                    picture.SizeByte = imageHandler.ImageInfo.SizeDisk;
                    picture.Width    = imageHandler.ImageInfo.Width;
                    picture.Height   = imageHandler.ImageInfo.Height;

                    if (saveMediumAction != null)
                    {
                        imageHandler.DoConvert(originalImagePath, saveMediumAction, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url);
                    }
                    imageHandler.DoConvert(originalImagePath, saveSmallAction, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url);
                    imageHandler.DoConvert(originalImagePath, saveExtraSmallAction, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url);

                    picture.Image = imageHandler.ImageName;
                    foreach (var imageType in imageTypes)
                    {
                        picture.SetImageType(imageType.Key, imageType.Value);
                    }

                    if (picture.Height > 0)
                    {
                        picture.AspectRatio = Math.Round((decimal)picture.Width / (decimal)picture.Height, 3);
                    }

                    picture.Insert(UserDataContext.GetUserDataContext());

                    FillEditForm();
                }
                catch (Exception ex)
                {
                    this.LitMsg.Text = string.Format("{0}: ", language.GetString("MessageSaveError")) + ex.Message;
                }
            }
        }
Example #2
0
        public static void GetImages(WebServiceLogEntry log, DataObjectNews receivedNews, DataObject news)
        {
            DataObject dataObject = news ?? receivedNews;

            DataObjectList <DataObjectPicture> newsPictures = DataObjects.Load <DataObjectPicture>(new QuickParameters()
            {
                Udc            = UserDataContext.GetUserDataContext(dataObject.Nickname),
                RelationParams = new RelationParams()
                {
                    ParentObjectID   = dataObject.ObjectID,
                    ParentObjectType = dataObject.ObjectType,
                    ChildObjectType  = Common.Helper.GetObjectType("Picture").NumericId
                },
                IgnoreCache   = true,
                DisablePaging = true
            });

            foreach (DataObjectPicture newsPicture in newsPictures)
            {
                newsPicture.Delete(UserDataContext.GetUserDataContext(OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name));
            }
            DataObject.RelDelete(new RelationParams()
            {
                ParentObjectID = dataObject.ObjectID, ParentObjectType = dataObject.ObjectType, ChildObjectType = Common.Helper.GetObjectType("Picture").NumericId
            });

            if (!string.IsNullOrEmpty(receivedNews.Image))
            {
                string  imageName = dataObject.ObjectID.ToString();
                int     width, height;
                decimal aspectRatio;
                if (GetImage(log, receivedNews.Image, Common.Helper.GetObjectType("News").NumericId, dataObject.UserID.Value, imageName, out width, out height, out aspectRatio))
                {
                    dataObject.Image = imageName;
                    dataObject.SetImageType(PictureVersion.XS, PictureFormat.Jpg);
                    dataObject.SetImageType(PictureVersion.S, PictureFormat.Jpg);
                    dataObject.SetImageType(PictureVersion.L, PictureFormat.Jpg);
                    dataObject.SetImageType(PictureVersion.A, PictureFormat.Jpg);
                    log.FilesDownload++;
                }
            }

            if (receivedNews.LargePictures.Count > 0)
            {
                List <string> newsImages   = receivedNews.LargePictures;
                List <string> newsCaptions = receivedNews.PictureCaptions;
                for (int i = 0; i < newsImages.Count; i++)
                {
                    Guid    newsPictureId = Guid.NewGuid();
                    int     width, height;
                    decimal aspectRatio;
                    if (GetImage(log, newsImages[i], Common.Helper.GetObjectType("News").NumericId, dataObject.UserID.Value, newsPictureId.ToString(), out width, out height, out aspectRatio))
                    {
                        DataObjectPicture newsPicture = new DataObjectPicture(UserDataContext.GetUserDataContext(dataObject.Nickname));
                        newsPicture.ObjectID    = newsPictureId;
                        newsPicture.Title       = !string.IsNullOrEmpty(newsCaptions[i]) ? newsCaptions[i].CropString(100) : " ";
                        newsPicture.PartnerID   = dataObject.PartnerID;
                        newsPicture.Description = newsCaptions[i];
                        newsPicture.TagList     = dataObject.TagList;
                        newsPicture.StartDate   = dataObject.StartDate;
                        newsPicture.EndDate     = dataObject.EndDate;
                        newsPicture.CommunityID = dataObject.CommunityID;
                        newsPicture.Status      = dataObject.Status;
                        newsPicture.Copyright   = dataObject.Copyright;
                        newsPicture.Image       = newsPictureId.ToString();
                        newsPicture.Width       = width;
                        newsPicture.Height      = height;
                        newsPicture.AspectRatio = aspectRatio;
                        newsPicture.SetImageType(PictureVersion.XS, PictureFormat.Jpg);
                        newsPicture.SetImageType(PictureVersion.S, PictureFormat.Jpg);
                        newsPicture.SetImageType(PictureVersion.L, PictureFormat.Jpg);
                        newsPicture.SetImageType(PictureVersion.A, PictureFormat.Jpg);
                        newsPicture.Insert(UserDataContext.GetUserDataContext(OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name));

                        DataObject.RelInsert(new RelationParams()
                        {
                            ParentObjectID = dataObject.ObjectID, ParentObjectType = dataObject.ObjectType, ChildObjectID = newsPicture.ObjectID, ChildObjectType = newsPicture.ObjectType
                        }, i);

                        log.FilesDownload++;
                    }
                }
            }
        }