예제 #1
0
        void RequestSharePhoto(Dictionary <string, object> paramsDictionary)
        {
            if (paramsDictionary != null && paramsDictionary.ContainsKey("photo"))
            {
                UIImage image = null;

                var imageBytes = paramsDictionary["photo"] as byte[];

                if (imageBytes != null)
                {
                    using (var data = NSData.FromArray(imageBytes))
                        image = UIImage.LoadFromData(data);
                }


                SharePhoto photo = Facebook.ShareKit.SharePhoto.From(image, true);

                if (paramsDictionary.ContainsKey("caption"))
                {
                    photo.Caption = $"{paramsDictionary["caption"]}";
                }


                var photoContent = new SharePhotoContent()
                {
                    Photos = new SharePhoto[] { photo }
                };

                ShareAPI.Share(photoContent, this);
            }
        }
        public void ShareImageOnFacebook(string caption, string imagePath)
        {
            SharePhoto tt = SharePhoto.From(new UIImage(imagePath), true);

            tt.Caption = caption;
            SharePhotoContent content = new SharePhotoContent();

            content.Photos = new SharePhoto[] { tt };
            content.SetContentUrl(new NSUrl(imagePath));

            var shareDelegate = new FbDelegate();

            var dialog = new ShareDialog();

            dialog.Mode = ShareDialogMode.FeedBrowser;
            dialog.SetDelegate(shareDelegate);
            dialog.SetShareContent(content);
            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;

            bool isInstalled = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(urlString: "fb://"));

            if (isInstalled)
            {
                dialog.Mode = ShareDialogMode.Native;
                dialog.Show();
            }
            else
            {
                ShareAPI.Share(content, shareDelegate);
            }
        }
        public void ShareLinkOnFacebook(string text, string description, string link)
        {
            ShareLinkContent link1 = new ShareLinkContent();

            link1.SetContentUrl(new NSUrl(link));
            var shareDelegate = new FbDelegate();

            var dialog = new ShareDialog();

            dialog.Mode = ShareDialogMode.FeedBrowser;
            dialog.SetDelegate(shareDelegate);
            dialog.SetShareContent(link1);
            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
            bool isInstalled = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(urlString: "fb://"));

            if (isInstalled)
            {
                dialog.Mode = ShareDialogMode.Native;
                dialog.Show();
            }
            else
            {
                ShareAPI.Share(link1, shareDelegate);
            }
        }
예제 #4
0
        private void ShowDetails()
        {
            Console.Clear();
            Console.Write("Enter Ticker: ");
            string input_ticker = (Console.ReadLine()).ToUpper();
            var    shareAPI     = new ShareAPI();
            var    infoResult   = shareAPI.GetShareInfo(input_ticker);
            var    values       = infoResult.values;
            string errorMessage = infoResult.errorMessage;

            if (errorMessage != "")
            {
                Console.WriteLine($"\n{errorMessage}");
                return;
            }

            double   open          = double.Parse(values.open);
            double   close         = double.Parse(values.close);
            double   low           = double.Parse(values.low);
            double   high          = double.Parse(values.high);
            DateTime dateTime      = DateTime.Parse(values.datetime);
            double   percentChange = (close - open) / close * 100;

            Console.Clear();
            Console.WriteLine("");

            Console.WriteLine($"{input_ticker} \n" +
                              $"Time: {dateTime.ToString("dddd, MM/dd/yyy HH:mm tt")} \n" +
                              $"Open: ${Math.Round(open, 2)} \n" +
                              $"Volume: {values.volume}/shares per minute \n" +
                              $"Low: ${Math.Round(low, 2)} \n" +
                              $"High: ${Math.Round(high, 2)}");

            if (percentChange < 0)
            {
                Console.WriteLine($"{input_ticker} has gone down {Math.Round(percentChange, 4)}% since the open this morning.", Console.ForegroundColor = ConsoleColor.Red);
            }
            else
            {
                Console.WriteLine($"{input_ticker} has gone up {Math.Round(percentChange, 4)}% since the open this morning!", Console.ForegroundColor = ConsoleColor.Green);
            }
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.ReadLine();
        }
예제 #5
0
        private void ShowPrice()
        {
            Console.Clear();

            Console.Write("Enter Ticker: ");
            string input_ticker = (Console.ReadLine()).ToUpper();
            var    shareAPI     = new ShareAPI();
            var    priceResult  = shareAPI.GetSharePrice(input_ticker);
            var    infoResult   = shareAPI.GetShareInfo(input_ticker);
            double price        = priceResult.price;
            var    values       = infoResult.values;

            string errorMessage = priceResult.errorMessage;

            if (errorMessage != "")
            {
                Console.WriteLine($"\n{errorMessage}");
                return;
            }
            double open = double.Parse(values.open);

            Console.Clear();
            Console.WriteLine($" \n" +
                              $"{ input_ticker}");

            if (price > open)
            {
                Console.WriteLine($"Current Price: ${Math.Round(price, 2)} \n" +
                                  $"The price of {input_ticker} has gone up since the open this morning!", Console.ForegroundColor = ConsoleColor.Green);
            }
            else
            {
                Console.WriteLine($"Current Price: ${Math.Round(price, 2)} \n" +
                                  $"The price of {input_ticker} has gone down since the open this morning.", Console.ForegroundColor = ConsoleColor.Red);
            }
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.ReadLine();
        }
예제 #6
0
        void RequestShare(Dictionary <string, object> paramsDictionary)
        {
            if (paramsDictionary.TryGetValue("content", out object shareContent) && shareContent is FacebookShareContent)
            {
                ISharingContent content = null;
                if (shareContent is FacebookShareLinkContent)
                {
                    FacebookShareLinkContent linkContent  = shareContent as FacebookShareLinkContent;
                    ShareLinkContent         sLinkContent = new ShareLinkContent();


                    if (linkContent.Quote != null)
                    {
                        sLinkContent.Quote = linkContent.Quote;
                    }

                    if (linkContent.ContentLink != null)
                    {
                        sLinkContent.SetContentUrl(linkContent.ContentLink);
                    }

                    if (!string.IsNullOrEmpty(linkContent.Hashtag))
                    {
                        var shareHashTag = new Hashtag();
                        shareHashTag.StringRepresentation = linkContent.Hashtag;
                        sLinkContent.Hashtag = shareHashTag;
                    }

                    if (linkContent.PeopleIds != null && linkContent.PeopleIds.Length > 0)
                    {
                        sLinkContent.SetPeopleIds(linkContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(linkContent.PlaceId))
                    {
                        sLinkContent.SetPlaceId(linkContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(linkContent.Ref))
                    {
                        sLinkContent.SetRef(linkContent.Ref);
                    }

                    content = sLinkContent;
                }
                else if (shareContent is FacebookSharePhotoContent)
                {
                    FacebookSharePhotoContent photoContent = shareContent as FacebookSharePhotoContent;

                    SharePhotoContent sharePhotoContent = new SharePhotoContent();

                    if (photoContent.Photos != null && photoContent.Photos.Length > 0)
                    {
                        List <SharePhoto> photos = new List <SharePhoto>();
                        foreach (var p in photoContent.Photos)
                        {
                            if (p.ImageUrl != null && !string.IsNullOrEmpty(p.ImageUrl.AbsoluteUri))
                            {
                                SharePhoto photoFromUrl = SharePhoto.From(p.ImageUrl, true);

                                if (!string.IsNullOrEmpty(p.Caption))
                                {
                                    photoFromUrl.Caption = p.Caption;
                                }

                                photos.Add(photoFromUrl);
                            }

                            if (p.Image != null)
                            {
                                UIImage image = null;

                                var imageBytes = p.Image as byte[];

                                if (imageBytes != null)
                                {
                                    using (var data = NSData.FromArray(imageBytes))
                                        image = UIImage.LoadFromData(data);

                                    SharePhoto sPhoto = Facebook.ShareKit.SharePhoto.From(image, true);

                                    if (!string.IsNullOrEmpty(p.Caption))
                                    {
                                        sPhoto.Caption = p.Caption;
                                    }


                                    photos.Add(sPhoto);
                                }
                            }
                        }

                        if (photos.Count > 0)
                        {
                            sharePhotoContent.Photos = photos.ToArray();
                        }
                    }

                    if (photoContent.ContentLink != null)
                    {
                        sharePhotoContent.SetContentUrl(photoContent.ContentLink);
                    }

                    if (!string.IsNullOrEmpty(photoContent.Hashtag))
                    {
                        var shareHashTag = new Hashtag();
                        shareHashTag.StringRepresentation = photoContent.Hashtag;
                        sharePhotoContent.SetHashtag(shareHashTag);
                    }

                    if (photoContent.PeopleIds != null && photoContent.PeopleIds.Length > 0)
                    {
                        sharePhotoContent.SetPeopleIds(photoContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(photoContent.PlaceId))
                    {
                        sharePhotoContent.SetPlaceId(photoContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(photoContent.Ref))
                    {
                        sharePhotoContent.SetRef(photoContent.Ref);
                    }

                    content = sharePhotoContent;
                }
                else if (shareContent is FacebookShareVideoContent)
                {
                    FacebookShareVideoContent videoContent      = shareContent as FacebookShareVideoContent;
                    ShareVideoContent         shareVideoContent = new ShareVideoContent();


                    if (videoContent.PreviewPhoto != null)
                    {
                        if (videoContent.PreviewPhoto.ImageUrl != null && !string.IsNullOrEmpty(videoContent.PreviewPhoto.ImageUrl.AbsoluteUri))
                        {
                            SharePhoto photoFromUrl = Facebook.ShareKit.SharePhoto.From(videoContent.PreviewPhoto.ImageUrl, true);

                            if (!string.IsNullOrEmpty(videoContent.PreviewPhoto.Caption))
                            {
                                photoFromUrl.Caption = videoContent.PreviewPhoto.Caption;
                            }

                            shareVideoContent.PreviewPhoto = photoFromUrl;
                        }

                        if (videoContent.PreviewPhoto.Image != null)
                        {
                            UIImage image = null;

                            var imageBytes = videoContent.PreviewPhoto.Image as byte[];

                            if (imageBytes != null)
                            {
                                using (var data = NSData.FromArray(imageBytes))
                                    image = UIImage.LoadFromData(data);

                                SharePhoto photo = Facebook.ShareKit.SharePhoto.From(image, true);

                                if (!string.IsNullOrEmpty(videoContent.PreviewPhoto.Caption))
                                {
                                    photo.Caption = videoContent.PreviewPhoto.Caption;
                                }


                                shareVideoContent.PreviewPhoto = photo;
                            }
                        }
                    }

                    if (videoContent.Video != null)
                    {
                        if (videoContent.Video.LocalUrl != null)
                        {
                            shareVideoContent.Video = ShareVideo.From(videoContent.Video.LocalUrl);
                        }
                    }

                    if (videoContent.ContentLink != null)
                    {
                        shareVideoContent.SetContentUrl(videoContent.ContentLink);
                    }

                    if (!string.IsNullOrEmpty(videoContent.Hashtag))
                    {
                        var shareHashTag = new Hashtag();
                        shareHashTag.StringRepresentation = videoContent.Hashtag;
                        shareVideoContent.SetHashtag(shareHashTag);
                    }

                    if (videoContent.PeopleIds != null && videoContent.PeopleIds.Length > 0)
                    {
                        shareVideoContent.SetPeopleIds(videoContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(videoContent.PlaceId))
                    {
                        shareVideoContent.SetPlaceId(videoContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(videoContent.Ref))
                    {
                        shareVideoContent.SetRef(videoContent.Ref);
                    }

                    content = shareVideoContent;
                }

                if (content != null)
                {
                    ShareAPI.Share(content, this);
                }
            }
        }