Esempio n. 1
0
        public long Send(int groupId)
        {
            MediaId mediaId = UploadMessage();
            var     msg     = new GroupMpNewsMassMessage(groupId, mediaId.Id);

            return(msg.Send());
        }
Esempio n. 2
0
        public long Send(IEnumerable <string> users)
        {
            MediaId mediaId = UploadMessage();
            var     msg     = new UserMpNewsMassMessage(users, mediaId.Id);

            return(msg.Send());
        }
Esempio n. 3
0
        public override int GetHashCode()
        {
            int hash = 13;

            hash += (hash * 43) + MediaId.GetHashCode();

            return(hash);
        }
Esempio n. 4
0
        public static MpNewsArticle CreateArticle(string title, string content, string path)
        {
            TkDebug.AssertArgumentNullOrEmpty(path, "path", null);

            MediaId media = WeUtil.UploadFile(MediaType.Image, path);

            return(new MpNewsArticle(title, media.Id, content));
        }
Esempio n. 5
0
        public static MpNewsArticle CreateArticle(string title, string content, int appId, string path)
        {
            TkDebug.AssertArgumentNullOrEmpty(path, "path", null);

            string  secret = WeixinSettings.Current.GetCorpSecret(appId);
            MediaId media  = WeCorpUtil.UploadFile(secret, MediaType.Image, path);

            return(new MpNewsArticle(title, media.Id, content));
        }
Esempio n. 6
0
 private void marketplace_go_btn_Click(object sender, EventArgs e)
 {
     try
     {
         MediaId temp = (MediaId)cat_select.SelectedValue;
         cat_sync_label.Text = temp.Name;
         _helper.SubmitQuery();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
Esempio n. 7
0
        public override string ToString()
        {
            StringBuilder strBuild = new StringBuilder();

            strBuild.Append("MediaItem:{");
            strBuild.Append("MediaId=" + MediaId.ToString());
            strBuild.Append(", Class=" + MediaClass);
            strBuild.Append(", FileType=" + FileType);
            strBuild.Append(", URL=" + MediaURL);
            strBuild.Append(", Index=" + MediaIndex.ToString());
            strBuild.Append("}");

            return(strBuild.ToString());
        }
        public async Task <ActionResult> AddPost(ViewModels.Wall.Form form, IFormFile mediaFile)
        {
            if (ModelState.IsValid)
            {
                MediaId mediaId = null;
                if (mediaFile != null)
                {
                    using (var mediaStream = mediaFile.OpenReadStream())
                    {
                        var memoryStream = new MemoryStream();
                        mediaStream.CopyTo(memoryStream);

                        UploadImageResponse uploadResponse = await clientProvider.MediaClient.UploadImageAsync(new UploadImageRequest
                        {
                            Image = new Image
                            {
                                Data     = ByteString.CopyFrom(memoryStream.ToArray()),
                                Mimetype = mediaFile.ContentType
                            }
                        });

                        mediaId = uploadResponse.Id;
                    }
                }

                await clientProvider.WallClient.PostToWallAsync(new PostToWallRequest
                {
                    Post = new WallPost
                    {
                        Username = Constants.DemoUsername,
                        Caption  = form.Caption,
                        MediaId  = mediaId
                    }
                });

                return(RedirectToAction("Index"));
            }
            return(ViewForm());
        }
Esempio n. 9
0
        public MediaId GetWeCorpMediaId(string secret, MediaType type, string path)
        {
            DataRow row = TrySelectRowWithKeys(type.ToString(), path);

            if (row == null)
            {
                SetCommands(AdapterCommand.Insert);
                MediaId mediaId = WeCorpUtil.UploadFile(secret, type, path);
                row = NewRow();
                row.BeginEdit();
                row["MediaType"] = type.ToString();
                row["MediaKey"]  = path;
                SetMediaRow(row, mediaId);
                row["CorpSecret"] = secret;
                row.EndEdit();
                UpdateDatabase();

                return(mediaId);
            }
            else
            {
                DateTime validDate = row["ValidDate"].Value <DateTime>();
                if (validDate > DateTime.Now)
                {
                    return(new MediaId(row["MediaId"].ToString()));
                }
                else
                {
                    SetCommands(AdapterCommand.Update);
                    MediaId mediaId = WeCorpUtil.UploadFile(secret, type, path);
                    row.BeginEdit();
                    SetMediaRow(row, mediaId);
                    row.EndEdit();
                    UpdateDatabase();

                    return(mediaId);
                }
            }
        }
Esempio n. 10
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Id.Length != 0)
            {
                hash ^= Id.GetHashCode();
            }
            if (StartUTC != 0L)
            {
                hash ^= StartUTC.GetHashCode();
            }
            if (EndUTC != 0L)
            {
                hash ^= EndUTC.GetHashCode();
            }
            if (MediaId.Length != 0)
            {
                hash ^= MediaId.GetHashCode();
            }
            if (duration_ != null)
            {
                hash ^= Duration.GetHashCode();
            }
            if (MediaLenghtInSec != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(MediaLenghtInSec);
            }
            if (FromDevice.Length != 0)
            {
                hash ^= FromDevice.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Esempio n. 11
0
 public Movie(MediaId id)
 {
     this.Id = id;
 }
 private static void SetMediaRow(DataRow row, MediaId mediaId)
 {
     row["MediaId"] = mediaId.Id;
     row["CreateDate"] = mediaId.CreateTime;
     row["ValidDate"] = mediaId.CreateTime + VALID_TIME;
 }
Esempio n. 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            MOTD.InnerHtml = System.Configuration.ConfigurationManager.AppSettings["MOTD"];

            if (string.IsNullOrEmpty(Data.DeviceType))
            {
                Response.Redirect("get_device_info?url=home");
            }

            myUser = Account.PublicPage(this, Data.DeviceType);

            NewMenu.SelectedPage = PageIndex.Home;
            if (myUser != null)
            {
                NewMenu.LoggedInUser = myUser;
                NewMenu.Upload       = true;
            }

            Page httpHandler = (Page)HttpContext.Current.Handler;

            if (myUser == null)
            {
            }
            //LoginNudge.Visible = true;
            else
            {
                UploadMediaControl.Initialise(myUser, this);
                if (myUser.AccountType == "admin" || myUser.AccountType == "member" || myUser.AccountType == "media")
                {
                    uploadForm.Visible          = true;
                    UploadButtonPadding.Visible = true;
                }
            }

            new LogEntry(Log.Debug)
            {
                Text = string.Format("The home page was accessed by {0} from {1} {2} device.",
                                     myUser == null ? "someone who was not logged in" : myUser.Forename,
                                     myUser == null ? "their" : myUser.PosessivePronoun, Data.DeviceType)
            };

            //WelcomeLabel.Text =
            //    string.Format("Hiya {0} to the parsnip website!", myUser == null ?
            //    "stranger, welcome" : myUser.Forename + ", welcome back");

            if (myUser == null)
            {
                MediaTagContainer.InnerHtml = "<label style=\"color:red \">You must <a href=\"login\" style=\"color:blue\">login</a> to see tags!</label>";
            }
            else
            {
                List <ViewTagControl> ViewTagControls = new List <ViewTagControl>();
                foreach (MediaTag mediaTag in MediaTag.GetAllTags())
                {
                    ViewTagControl mediaTagPairViewControl = (ViewTagControl)httpHandler.LoadControl("~/Custom_Controls/Media/ViewTagControl.ascx");
                    mediaTagPairViewControl.MyTag = mediaTag;
                    mediaTagPairViewControl.UpdateLink();
                    MediaTagContainer.Controls.Add(mediaTagPairViewControl);
                    ViewTagControls.Add(mediaTagPairViewControl);
                }

                foreach (ParsnipData.Accounts.User user in ParsnipData.Accounts.User.GetAllUsers())
                {
                    ViewTagControl mediaUserPairViewControl = (ViewTagControl)httpHandler.LoadControl("~/Custom_Controls/Media/ViewTagControl.ascx");
                    mediaUserPairViewControl.MyUser = user;
                    mediaUserPairViewControl.UpdateLink();
                    MediaTagContainer.Controls.Add(mediaUserPairViewControl);
                    ViewTagControls.Add(mediaUserPairViewControl);
                }

                foreach (ViewTagControl control in ViewTagControls.OrderBy(x => x.Name))
                {
                    MediaTagContainer.Controls.Add(control);
                }
            }



            var myImage = new ParsnipData.Media.Image();

            myImage.Id          = MediaId.NewMediaId();
            myImage.Compressed  = "Resources/Media/Images/Local/Dirt_On_You.jpg";
            myImage.Placeholder = "Resources/Media/Images/Local/Dirt_On_You.jpg";

            if (myUser != null)
            {
                myImage.Title = $"Hey {myUser.Forename}, what DIRT do we have on YOU? 😜";
            }
            else
            {
                myImage.Title = $"What DIRT do we have on YOU? 😜";
            }

            var MySeeYourselfControl = (MediaControl)Page.LoadControl("~/Custom_Controls/Media/MediaControl.ascx");

            MySeeYourselfControl.MyMedia    = myImage;
            MySeeYourselfControl.AnchorLink = $"{Request.Url.GetLeftPart(UriPartial.Authority)}/me";

            //seeYourself.Controls.Add(MySeeYourselfControl);
            //seeYourself.Visible = true;

            int   userId      = myUser == null ? 0 : myUser.Id;
            Media latestVideo = Media.SelectLatestVideo(userId);

            if (latestVideo != null)
            {
                var MyVideoControl = (MediaControl)Page.LoadControl("~/Custom_Controls/Media/MediaControl.ascx");


                latestVideo.Title      = "LATEST VIDEO: " + latestVideo.Title;
                MyVideoControl.MyMedia = latestVideo;

                //LatestVideo.Controls.Add(MyVideoControl);
            }
        }
Esempio n. 14
0
 public Episode(MediaId showId, int season, int number)
 {
     this.ShowId = showId;
     this.Season = season;
     this.Number = number;
 }
Esempio n. 15
0
 public override bool Equals(object obj)
 {
     return(MediaId.Equals(obj));
 }
Esempio n. 16
0
 public override int GetHashCode()
 {
     return(MediaId.GetHashCode());
 }
Esempio n. 17
0
        static void GenerateAndUploadThumbnails(Video video, bool UseCompressedVideo = false)
        {
            var originalsDir   = $"{RelativeLocalThumbnailsDir}\\{video.Id}\\AutoGen\\Originals";
            var compressedDir  = $"{RelativeLocalThumbnailsDir}\\{video.Id}\\AutoGen\\Compressed";
            var placeholderDir = $"{RelativeLocalThumbnailsDir}\\{video.Id}\\AutoGen\\Placeholders";
            var segment        = new TimeSpan(video.VideoData.Duration.Ticks / NumberOfGeneratedThumbnails);

            CreateLocalDirectories();
            GenerateAndUploadThumbnails();
            InsertThumbnailData();

            void CreateLocalDirectories()
            {
                if (Directory.Exists(originalsDir))
                {
                    Directory.Delete(originalsDir, true);
                }

                if (Directory.Exists(compressedDir))
                {
                    Directory.Delete(compressedDir, true);
                }

                if (Directory.Exists(placeholderDir))
                {
                    Directory.Delete(placeholderDir, true);
                }

                Directory.CreateDirectory(originalsDir);
                Directory.CreateDirectory(compressedDir);
                Directory.CreateDirectory(placeholderDir);
            }

            void GenerateAndUploadThumbnails()
            {
                for (int i = 0; i < NumberOfGeneratedThumbnails; i++)
                {
                    var    timeStamp                   = new TimeSpan(segment.Ticks * i);
                    string thumbnailIdentifier         = MediaId.NewMediaId().ToString();
                    var    videoThumbnail              = new VideoThumbnail();
                    System.Drawing.Image originalImage = null;

                    InitialiseThumbnail();
                    GenerateImages();
                    UploadThumbnail(videoThumbnail, thumbnailIdentifier);
                    video.Thumbnails.Add(videoThumbnail);

                    void GenerateImages()
                    {
                        originalImage = GenerateOriginal();
                        UpdateVideoThumbnailScale();
                        GenerateCompressed();
                        GeneratePlaceholder();

                        System.Drawing.Image GenerateOriginal()
                        {
                            var     thumbnailDir = $"{RelativeLocalThumbnailsDir}\\{videoThumbnail.MediaId}\\AutoGen\\Originals\\{videoThumbnail.MediaId}_{thumbnailIdentifier}.png";
                            var     videoDir     = UseCompressedVideo ? $"{RelativeLocalCompressedVideosDir}\\{video.Id}{video.VideoData.CompressedFileExtension}" : $"{RelativeLocalOriginalVideosDir}\\{video.Id}{video.VideoData.OriginalFileExtension}";
                            Process process      = new Process();

                            process.StartInfo.FileName    = "GenerateThumbnail.bat";
                            process.StartInfo.Arguments   = $"{thumbnailDir} {videoDir} {timeStamp}";
                            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                            process.Start();
                            process.WaitForExit();
                            int exitCode = process.ExitCode;

                            process.Close();
                            return(Bitmap.FromFile(thumbnailDir));
                        }

                        void UpdateVideoThumbnailScale()
                        {
                            int scale = Media.GetAspectScale(originalImage.Width, originalImage.Height);

                            videoThumbnail.XScale = Convert.ToInt16(originalImage.Width / scale);
                            videoThumbnail.YScale = Convert.ToInt16(originalImage.Height / scale);
                        }

                        void GenerateCompressed()
                        {
                            var    localDir = $"{RelativeLocalThumbnailsDir}\\{videoThumbnail.MediaId}\\AutoGen\\Compressed\\{videoThumbnail.MediaId}_{thumbnailIdentifier}.jpg";
                            Bitmap bitmap   = Media.GenerateBitmapOfSize(originalImage, 1280, 200);

                            Media.SaveBitmapWithCompression(bitmap, 85L, localDir);
                        }

                        void GeneratePlaceholder()
                        {
                            var    localDir = $"{RelativeLocalThumbnailsDir}\\{videoThumbnail.MediaId}\\AutoGen\\Placeholders\\{videoThumbnail.MediaId}_{thumbnailIdentifier}.jpg";
                            Bitmap bitmap   = Media.GenerateBitmapOfSize(originalImage, 250, 0);

                            Media.SaveBitmapWithCompression(bitmap, 15L, localDir);
                        }
                    }

                    void InitialiseThumbnail()
                    {
                        videoThumbnail.MediaId     = video.Id;
                        videoThumbnail.Placeholder = $"{RemoteThumbnailsDir}/Placeholders/{video.Id}_{thumbnailIdentifier}.jpg";
                        videoThumbnail.Compressed  = $"{RemoteThumbnailsDir}/Compressed/{video.Id}_{thumbnailIdentifier}.jpg";
                        videoThumbnail.Original    = $"{RemoteThumbnailsDir}/Originals/{video.Id}_{thumbnailIdentifier}.png";
                    }
                }
            }

            void InsertThumbnailData()
            {
                foreach (var videoThumbnail in video.Thumbnails)
                {
                    videoThumbnail.Insert();
                }
            }
        }
 /// <summary>
 /// Filter by the media id of the list entry.
 /// </summary>
 public GraphQueryArgument <int> MediaIdQueryArgument(int value)
 {
     return(MediaId.GetQueryArgumentAndSetValue(value));
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            Page httpHandler = (Page)HttpContext.Current.Handler;

            myUser = Account.SecurePage(this, Data.DeviceType);

            NewMenu.LoggedInUser = myUser;
            NewMenu.Upload       = true;
            NewMenu.HighlightButtonsForPage(PageIndex.MyUploads, "My Uploads");

            UploadMediaControl.Initialise(myUser, this);
            if (myUser.AccountType == "admin" || myUser.AccountType == "member" || myUser.AccountType == "media")
            {
                uploadForm.Visible = true;
            }

            var mediaControls = MediaControl.GetUserMediaAsMediaControls(myUser.Id, myUser.Id);

            if (mediaControls.Count != default)
            {
                UploadPrompt.Visible = false;
            }

            foreach (MediaControl mc in mediaControls)
            {
                MyMediaContainer.Controls.Add(mc);
            }



            if (string.IsNullOrEmpty(Data.DeviceType))
            {
                Response.Redirect("get_device_info?url=home");
            }

            new LogEntry(Log.Debug)
            {
                Text = string.Format("The home page was accessed by {0} from {1} {2} device.",
                                     myUser == null ? "someone who was not logged in" : myUser.Forename,
                                     myUser == null ? "their" : myUser.PosessivePronoun, Data.DeviceType)
            };

            //WelcomeLabel.Text =
            //    string.Format("Hiya {0} to the parsnip website!", myUser == null ?
            //    "stranger, welcome" : myUser.Forename + ", welcome back");

            var myImage = new ParsnipData.Media.Image();

            myImage.Id          = MediaId.NewMediaId();
            myImage.Compressed  = "Resources/Media/Images/Local/Dirt_On_You.jpg";
            myImage.Placeholder = "Resources/Media/Images/Local/Dirt_On_You.jpg";

            if (myUser != null)
            {
                myImage.Title = $"Hey {myUser.Forename}, what DIRT do we have on YOU? 😜";
            }
            else
            {
                myImage.Title = $"What DIRT do we have on YOU? 😜";
            }

            var MySeeYourselfControl = (MediaControl)Page.LoadControl("~/Custom_Controls/Media/MediaControl.ascx");

            MySeeYourselfControl.MyMedia    = myImage;
            MySeeYourselfControl.AnchorLink = $"{Request.Url.GetLeftPart(UriPartial.Authority)}/me";

            //seeYourself.Controls.Add(MySeeYourselfControl);
            //seeYourself.Visible = true;

            int   userId      = myUser == null ? 0 : myUser.Id;
            Media latestVideo = Media.SelectLatestVideo(userId);

            if (latestVideo != null)
            {
                var MyVideoControl = (MediaControl)Page.LoadControl("~/Custom_Controls/Media/MediaControl.ascx");


                latestVideo.Title      = "LATEST VIDEO: " + latestVideo.Title;
                MyVideoControl.MyMedia = latestVideo;

                //LatestVideo.Controls.Add(MyVideoControl);
            }
        }
Esempio n. 20
0
 private static void SetMediaRow(DataRow row, MediaId mediaId)
 {
     row["MediaId"]    = mediaId.Id;
     row["CreateDate"] = mediaId.CreateTime;
     row["ValidDate"]  = mediaId.CreateTime + VALID_TIME;
 }
        public override IDictionary <string, object> GetSerializedValue()
        {
            var val = new Dictionary <string, object>();

            //generate an id if we need one
            if (MediaId == Guid.Empty)
            {
                MediaId = Guid.NewGuid();
            }

            //add the media id to be saved
            val.Add("MediaId", MediaId.ToString("N"));

            // Check to see if we should delete the current file
            // either becuase remove file is checked, or we have a replacement file
            if (RemoveFile || HasFile())
            {
                if (!Value.IsNullValueOrEmpty())
                {
                    // delete entire property folder (deletes image and any thumbnails stored)
                    //var folderHiveId = HiveId.Parse("storage://file-uploader/string/" + MediaId.ToString("N"));
                    var folderHiveId = new HiveId("storage", "file-uploader", new HiveIdValue(MediaId.ToString("N")));

                    using (var uow = _hive.Create())
                    {
                        uow.Repositories.Delete <File>(Value); // Must delete file entity so that relations are deleted
                        uow.Repositories.Delete <File>(folderHiveId);
                        uow.Complete();
                    }
                }
            }

            // If we've received a File from the binding, we need to save it
            if (HasFile())
            {
                // Open a new unit of work to write the file
                using (var uow = _hive.Create())
                {
                    // Create main file
                    var file = new File
                    {
                        RootedPath = MediaId.ToString("N") + "/" + Path.GetFileName(NewFile.FileName).Replace(" ", "")
                    };

                    var stream = NewFile.InputStream;
                    if (stream.CanRead && stream.CanSeek)
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        using (var mem = new MemoryStream())
                        {
                            stream.CopyTo(mem);
                            file.ContentBytes = mem.ToArray();
                        }
                    }

                    uow.Repositories.AddOrUpdate(file);

                    // Create thumbnails (TODO: Need to encapsulate this so it can be reused in other places?)
                    if (file.IsImage())
                    {
                        var img = Image.FromFile(file.RootedPath);

                        // Create default thumbnail
                        CreateThumbnail(uow, file, img, MediaId.ToString("N"), 100);

                        // Create additional thumbnails
                        if (!string.IsNullOrEmpty(PreValueModel.Sizes))
                        {
                            var sizes = PreValueModel.Sizes.Split(',');
                            foreach (var size in sizes)
                            {
                                var intSize = 0;
                                if (Int32.TryParse(size, out intSize))
                                {
                                    CreateThumbnail(uow, file, img, MediaId.ToString("N"), intSize);
                                }
                            }
                        }
                    }

                    uow.Complete();

                    val.Add("Value", file.Id);
                }
            }
            else if (!Value.IsNullValueOrEmpty() && !RemoveFile)
            {
                val.Add("Value", Value);
            }
            else
            {
                val.Add("Value", HiveId.Empty);
            }

            return(val);
        }