Skip to content

Conversation

@jholzer
Copy link
Contributor

@jholzer jholzer commented Jul 18, 2016

Processing in separate threat may cause racing condition and timeouts in browser.
By putting processing in original threat we get a more sequential processing and more stability.

Processing in separate threat may cause racing condition and timeouts in browser.
By putting processing in original threat we get a more sequential processing and more stability.
@JohnnyCrazy
Copy link
Owner

Isn't it blocking the UI Thread then?

Will have a look at it at the weekend
Thanks!

@jholzer
Copy link
Contributor Author

jholzer commented Jul 19, 2016

If the server is started on UI thread: yes!
But a server shouldn´t be started on UI-thread anyway...
Since it´s a library i wouldn´t make too much thoughts about this, since it´s in the applications´s responsibility to make the call on the right thread.

Small note: in my application i have a kind of "authentication factory" which delivers the authentication token in a awaitable call. The method takes care about starting the server, sending the request, handle the response and transform it into a result which is then returned to the user once it has completed.
I´m thinking about providing it to your library also. Would be easier for all...

jholzer added 3 commits July 19, 2016 21:14
+ New: AuthenticationFactory for awaitatble getting of fully initalized SpotifyWebApi
- Changed demo-app to usage of AuthenticationFactory
@jholzer
Copy link
Contributor Author

jholzer commented Jul 19, 2016

As mentioned above:
AuthenticationFactory is available now on my branch.
So 1 method call is sufficient to get a fully operational WebApi

@JohnnyCrazy
Copy link
Owner

JohnnyCrazy commented Jul 19, 2016

Nice, I like the idea @jholzer

Some thoughts:
Since we break the current version anyway, I think we should implement some abstraction into it. Imagine a abstract AuthFactory-class, which is the super-class of ImplicitAuthFactory, AuthorizationAuthFactory and CredentialsAuthFactory. Both parse the response and create their tokens. Both have to also implement a method like you already did SpotifyWebAPI WaitForAuth() which returns an async task etc... This way we support all 3 methods with abstraction and very easy handling.

What do you think about that? I could throw in a possible implementation next week 👍

Proper Re-Use is now possible
@jholzer
Copy link
Contributor Author

jholzer commented Jul 20, 2016

Hmmm... The problem is, that "AuthenticationFactory" in fact return a finished "SpotifyWebAPI" object while "ClientCredentials" just return a "Token", so does "AutorizationCodeAuth".
So what would be the common elements for the base-class?
It maybe would make sense for "ClientCredentials"and "AutorizationCodeAuth", since they both handle "Tokens"

Maybe the name "AuthenticationFactory" is a little missleading.
Should be named e.g. like "WebApiFactory".

jholzer added 2 commits July 22, 2016 21:38
So IDisposable is introduced which handles the above...
…: no more chance of deadlocks in StreamReadLine)

- Flush output stream and close it
@@ -1,112 +1,5 @@
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you restore this file? I guess VS accidently overwrote it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@JohnnyCrazy
Copy link
Owner

JohnnyCrazy commented Jul 23, 2016

WebApiFactory sounds good.

However, I still think we could add another 2 Factories for the other ones, since these could also provide a finished SpotifyWebAPI-object. Credential-auth needs to make a HTTP-Call --> Return a SpotifyWebAPI once finished. AutorizationCodeAuth is similar, but it has one more call to Spotify for the exchange-token.

But you're right, it's hard finding Common-elements since they behave very different. Maybe just start with SpotifyWebAPI BuildWebAPI() and maybe a flag if the internal HTTP-Server needs to run.

Gonna have a deeper look next week.

@jholzer
Copy link
Contributor Author

jholzer commented Jul 24, 2016

Yes,of course the other stuff should be wrapped in factories.
Just completed pushes of the first one incl. the requested restore and rename.

{
_rh = new RemoteHandler();

AttachTimer(50);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make this shorter with:

public SpotifyLocalAPI(int timerIntervall = 50)
{
    _rh = new RemoteHandler();
    AttachTimer(timerIntervall);
}

@JohnnyCrazy
Copy link
Owner

I added some comments mostly relating style-choices.
But it looks very good, gonna merge this after the comments have been cleared. 👍

Regarding other Factories:
You were right, the other auth-methods behave very differently. I would suggest we currently stay at one WebAPIFactory and may expand it in the future.


namespace SpotifyAPI.Web.Auth
{
public class WebApiFactory
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this should be WebAPIFactory (as well as the filename).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just commited the code style changes as requested. (Most were due to my ReSharper-settings... ;-) )

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mostly following the default ReSharper settings as well, but the API lasted from the beginning. 😜

Gonna merge this tomorrow 👍

@JohnnyCrazy JohnnyCrazy merged commit 409a444 into JohnnyCrazy:master Jul 31, 2016
@JohnnyCrazy
Copy link
Owner

Also added a note at the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants