Пример #1
0
        public override void Saved(HttpRequest request, string actualPath, string vpath)
        {
            #region arguments

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            #endregion

            // add an entry to media
            Document document = new Document();
            document.Url = vpath;

            try
            {
                document.Owner = AuthenticationUtility.Instance.GetLoggedUser();
                document.Name = Path.GetFileName(actualPath);

                //save the media
                BaseMedia media = MediaStore.Instance.Save(document);

                Dictionary<string, object> properties = new Dictionary<string, object>(1);
                properties["Id"] = media.Id;
                properties["name"] = media.Name;
                this.Properties = properties;

                this.Success = true;
            }
            catch
            {
                // failure mapping the image.
                this.Success = false;
                this.DeleteUploaded = true;
            }
        }
Пример #2
0
        public string Save(string url, string name, string tags, string mediaType)
        {
            // make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (!(IsAccessAllowed(user)))
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(url))
            {

                try
                {
                    BaseMedia media = null;

                    if (MediaStore.Instance.TryGetMedia(url, out media))
                    {
                        string mname = name ?? string.Empty;
                        if (!mname.Equals(media.Name, StringComparison.OrdinalIgnoreCase))
                        {
                            media.Name = mname;
                        }

                        if (!string.IsNullOrEmpty(tags))
                        {
                            // update the tags
                            media.AddTags(tags);
                        }

                        media.Update();
                    }
                    else
                    {
                        // create a new media type
                        MediaType mType;

                        if (Enum.TryParse<MediaType>(mediaType, true, out mType))
                        {
                            switch (mType)
                            {
                                case MediaType.Photo:

                                    //try to get the width and height of the image
                                    Tuple<int, int> size = Jardalu.Ratna.Web.Utility.GetImageSize(url);

                                    Photo photo = new Photo();
                                    photo.Width = size.Item1;
                                    photo.Height = size.Item2;
                                    media = photo;

                                    output.AddOutput("width", photo.Width);
                                    output.AddOutput("height", photo.Height);
                                    break;
                                case MediaType.Video:
                                    media = new Video();
                                    break;
                                case MediaType.Document:
                                    media = new Document();
                                    break;
                            }
                        }

                        if (media != null)
                        {
                            media.Owner = user;
                            media.Url = url;
                            media.Name = name ?? string.Empty;
                            if (!string.IsNullOrEmpty(tags))
                            {
                                media.AddTags(tags);
                            }
                            media.Update();

                            output.AddOutput("location", url);
                        }
                    }

                    output.Success = true;

                }
                catch (MessageException me)
                {
                    // error saving the media
                    output.AddOutput(Constants.Json.Error, me.Message);
                }
                catch (Exception ex)
                {
                    // all other failures
                    logger.Log(LogLevel.Error, "Unable to save media, exception : {0}", ex);
                }
            }

            return output.GetJson();
        }