Ejemplo n.º 1
0
        public override System.Windows.Forms.DialogResult CreateContent(System.Windows.Forms.IWin32Window dialogOwner, ref string newContent)
        {
            using (InsertFlickrImageForm flickr = new InsertFlickrImageForm(new FlickrContext(base.Options)))
            {
                System.Windows.Forms.DialogResult formResult = flickr.ShowDialog(dialogOwner);

                FlickrContext context = new FlickrContext(base.Options);
                context.FlickrUserId = flickr.FlickrUserId.Trim();
                context.FlickrUserName = flickr.FlickrUserName.Trim();

                if (formResult == System.Windows.Forms.DialogResult.OK)
                {
                    newContent = FlickrPluginHelper.GenerateFlickrHtml(flickr.SelectedPhoto, flickr.ImageSourceUrl, flickr.CssClass, flickr.BorderThickness, flickr.VerticalPadding, flickr.HorizontalPadding, flickr.Alignment, flickr.EnableHyperLink, flickr.FlickrUserId);
                }
                return formResult;
            }
        }
Ejemplo n.º 2
0
        public override System.Windows.Forms.DialogResult CreateContent(System.Windows.Forms.IWin32Window dialogOwner, ref string newContent)
        {
            using (InsertFlickrImageForm flickr = new InsertFlickrImageForm(new FlickrContext(base.Options)))
            {
                System.Windows.Forms.DialogResult formResult = flickr.ShowDialog(dialogOwner);

                FlickrContext context = new FlickrContext(base.Options);
                context.FlickrUserId   = flickr.FlickrUserId.Trim();
                context.FlickrUserName = flickr.FlickrUserName.Trim();

                if (formResult == System.Windows.Forms.DialogResult.OK)
                {
                    newContent = FlickrPluginHelper.GenerateFlickrHtml(flickr.SelectedPhoto, flickr.ImageSourceUrl, flickr.CssClass, flickr.BorderThickness, flickr.VerticalPadding, flickr.HorizontalPadding, flickr.Alignment, flickr.EnableHyperLink, flickr.FlickrUserId);
                }
                return(formResult);
            }
        }
Ejemplo n.º 3
0
        internal static string Authenticate(IWin32Window dialogOwner, FlickrContext context)
        {
            object frob;

            FlickrNet.Flickr.CacheDisabled = true;

            System.Resources.ResourceManager mgr = new System.Resources.ResourceManager(typeof(Properties.Resources));
            FlickrNet.Flickr flickrProxy = new FlickrNet.Flickr(mgr.GetString("ApiKey"), mgr.GetString("SharedSecret"));

            // Leverage proxy settings if they are there.
            System.Net.WebProxy proxySettings = (System.Net.WebProxy)WindowsLive.Writer.Api.PluginHttpRequest.GetWriterProxy();
            if (proxySettings != null)
            {
                flickrProxy.Proxy = proxySettings;
            }

            using (AuthForm authf = new AuthForm(flickrProxy))
            {
                if (authf.ShowDialog(dialogOwner) != DialogResult.OK)
                {
                    return null;
                }

                frob = authf.Frob;
            }

            using (CompletedAuth complete = new CompletedAuth(flickrProxy, frob))
            {
                if (complete.ShowDialog(dialogOwner) != DialogResult.OK)
                {
                    // auth failed
                    MessageBox.Show(@"Authorization has failed.  Please try again", @"Authorization Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return null;
                }

                context.FlickrAuthToken = complete.AuthToken;
                context.FlickrAuthTokenSecret = complete.AuthTokenSecret;

                return complete.AuthToken;
            }
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
0
        internal static string Authenticate(System.Windows.Forms.IWin32Window dialogOwner, FlickrContext context)
        {
            string frob;

            FlickrNet.Flickr.CacheDisabled = true;
            FlickrNet.Flickr flickrProxy = null;

            System.Resources.ResourceManager mgr = new System.Resources.ResourceManager(typeof(SmilingGoat.WindowsLiveWriter.Flickr.Properties.Resources));
            flickrProxy = new FlickrNet.Flickr(mgr.GetString("ApiKey"), mgr.GetString("SharedSecret"));

            // Leverage proxy settings if they are there.
            System.Net.WebProxy proxySettings = (System.Net.WebProxy)WindowsLive.Writer.Api.PluginHttpRequest.GetWriterProxy();
            if (proxySettings != null)
            {
                flickrProxy.Proxy = proxySettings;
            }

            using (AuthForm authf = new AuthForm(flickrProxy))
            {
                if (authf.ShowDialog(dialogOwner) != System.Windows.Forms.DialogResult.OK)
                {
                    return(null);
                }

                frob = authf.Frob;
            }

            using (CompletedAuth complete = new CompletedAuth(flickrProxy, frob))
            {
                if (complete.ShowDialog(dialogOwner) != System.Windows.Forms.DialogResult.OK)
                {
                    // auth failed
                    MessageBox.Show("Authorization has failed.  Please try again", "Authorization Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }

                context.FlickrAuthToken = complete.AuthToken;

                return(complete.AuthToken);
            }
        }
Ejemplo n.º 6
0
        public override DialogResult CreateContent(IWin32Window dialogOwner, ref string newContent)
        {
            Auth validAuthToken = null;
            FlickrContext context = new FlickrContext(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())
                {
                    DoWorkEventHandler handler = delegate
                    {
                        FlickrNet.Flickr fp = FlickrPluginHelper.GetFlickrProxy();
                        fp.OAuthAccessTokenSecret = context.FlickrAuthTokenSecret;
                        fp.OAuthAccessToken = context.FlickrAuthToken;

                        Logger.DebugFormat("Auth Token: {0}", context.FlickrAuthToken);
                        Logger.DebugFormat("Auth Secret: {0}", context.FlickrAuthTokenSecret);

                        try
                        {
                            validAuthToken = fp.AuthOAuthCheckToken();
                        }
                        catch (FlickrNet.Exceptions.LoginFailedInvalidTokenException ex)
                        {
                            // token that was stored was bad -- re-auth
                            _token = AuthManager.Authenticate(dialogOwner, context);
                            fp.OAuthAccessToken = context.FlickrAuthToken;
                            fp.OAuthAccessTokenSecret = context.FlickrAuthTokenSecret;
                            validAuthToken = fp.AuthOAuthCheckToken();

                            PluginDiagnostics.LogException(ex, "Failure in Auth Verification");
                        }

                        if (validAuthToken != null)
                        {
                            _token = validAuthToken.Token;
                        }
                    };
                    vauth.DoWork += handler;
                    DialogResult 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(Options)))
            {
                DialogResult formResult = flickr.ShowDialog(dialogOwner);

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

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

                    foreach (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;
            }
        }
Ejemplo n.º 7
0
        public override void CreateContentFromUrl(string url, ref string title, ref string newContent)
        {
            Match m = Regex.Match(url, PHOTO_REGEX_URL);

            if (!m.Success)
            {
                base.CreateContentFromUrl(url, ref title, ref newContent);
            }
            else
            {
                string photoId = m.Groups["id"].Value;

                // get photo
                FlickrContext context = new FlickrContext(Options);
                FlickrNet.Flickr flickrProxy = FlickrPluginHelper.GetFlickrProxy();
                flickrProxy.OAuthAccessToken = context.FlickrAuthToken;
                flickrProxy.OAuthAccessTokenSecret = context.FlickrAuthTokenSecret;

                PhotoInfo photo = flickrProxy.PhotosGetInfo(photoId);

                title = photo.Title;
                newContent = string.Format("<p><a href=\"{0}\" title=\"{2}\"><img alt=\"{2}\" border=\"0\" src=\"{1}\"></a></p>", photo.WebUrl, photo.MediumUrl, HtmlServices.HtmlEncode(photo.Title));
            }
        }
Ejemplo n.º 8
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);
            }
        }