예제 #1
0
        public override System.Windows.Forms.DialogResult CreateContent(System.Windows.Forms.IWin32Window dialogOwner, ref string newContent)
        {
            DialogResult       result;
            DoWorkEventHandler handler = null;

            FlickrNet.Auth validAuthToken = null;
            FlickrContext  context        = new FlickrContext(base.Options);

            token = context.FlickrAuthToken;

            // we have a token saved already and
            // need to verify it with Flickr
            if (!string.IsNullOrEmpty(token))
            {
                using (VerifyAuth vauth = new VerifyAuth())
                {
                    if (handler == null)
                    {
                        handler = delegate(object sender, DoWorkEventArgs args)
                        {
                            FlickrNet.Flickr fp = FlickrPluginHelper.GetFlickrProxy();
                            validAuthToken = fp.AuthCheckToken(token);
                            if (validAuthToken != null)
                            {
                                token = validAuthToken.Token;
                            }
                        };
                    }
                    vauth.DoWork += handler;
                    result        = vauth.ShowDialog(dialogOwner);
                    if (result != DialogResult.OK)
                    {
                        return(result);
                    }
                }
            }

            /* we didn't get a valid auth token
             * it might have expired or is just invalid/revoked
             * prompt the user to re-auth
             * OR
             * we don't have a saved token and know
             * we need to get one first so show the auth process
             */
            if (string.IsNullOrEmpty(token) || (validAuthToken == null))
            {
                token = AuthManager.Authenticate(dialogOwner, context);
            }

            if (string.IsNullOrEmpty(token))
            {
                return(DialogResult.Cancel);
            }

            using (InsertFlickrImageForm flickr = new InsertFlickrImageForm(new FlickrContext(base.Options)))
            {
                System.Windows.Forms.DialogResult formResult = flickr.ShowDialog(dialogOwner);

                context.FlickrUserId     = flickr.FlickrUserId.Trim();
                context.FlickrUserName   = flickr.FlickrUserName.Trim();
                context.FlickrAuthUserId = flickr.FlickrAuthUserId.Trim();

                if (formResult == System.Windows.Forms.DialogResult.OK)
                {
                    ImageSize imgsize = flickr.SelectedImageSize;

                    foreach (FlickrNet.Photo photo in flickr.SelectedPhotos)
                    {
                        newContent += FlickrPluginHelper.GenerateFlickrHtml(photo, GetImageUrl(photo, imgsize), flickr.CssClass, flickr.BorderThickness, flickr.VerticalPadding, flickr.HorizontalPadding, flickr.Alignment, flickr.EnableHyperLink, flickr.FlickrUserId);
                    }
                }
                return(formResult);
            }
        }
예제 #2
0
 public override void EditOptions(System.Windows.Forms.IWin32Window dialogOwner)
 {
     // authenticate as needed
     token = AuthManager.Authenticate(dialogOwner, new FlickrContext(base.Options));
 }