System.Action.Invoke(WebRequestError)

Here are the examples of the csharp api System.Action.Invoke(WebRequestError) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

9 Examples 7

19 Source : ModManager_SubmitModOperation.cs
with MIT License
from modio

private void SubmissionComplete_Error(WebRequestError error)
        {
            if(this.onError != null)
            {
                this.onError.Invoke(error);
            }
        }

19 Source : ImageRequestManager.cs
with MIT License
from modio

public virtual void RequestModGalleryImage(int modId, GalleryImageLocator locator,
                                                   ModGalleryImageSize size,
                                                   Action<Texture2D> onImageReceived,
                                                   Action<Texture2D> onFallbackFound,
                                                   Action<WebRequestError> onError)
        {
            // - early outs -
            if(onImageReceived == null)
            {
                return;
            }
            if(locator == null)
            {
                if(onError != null)
                {
                    onError.Invoke(this.GenerateErrorForMissingLocator());
                }
                return;
            }

            string url = locator.GetSizeURL(size);
            string fileName = locator.GetFileName();

            // check url
            if(string.IsNullOrEmpty(url))
            {
                if(onError != null)
                {
                    onError.Invoke(this.GenerateErrorForMissingURL());
                }
                return;
            }

            // check cache and existing callbacks
            if(this.TryAddCallbacksToExisting(url, onImageReceived, onFallbackFound, onError))
            {
                return;
            }

            // - Start new request -
            Callbacks callbacks = this.CreateCallbacksEntry(url, onImageReceived, onError);

            // add save function to download callback
            if(this.storeIfSubscribed)
            {
                callbacks.onTextureDownloaded = (texture) =>
                {
                    if(LocalUser.SubscribedModIds.Contains(modId))
                    {
                        CacheClient.SaveModGalleryImage(modId, fileName, size, texture, null);
                    }
                };
            }

            // start process by checking the cache
            CacheClient.LoadModGalleryImage(modId, fileName, size, (texture) => {
                if(this == null)
                {
                    return;
                }

                if(texture != null)
                {
                    this.OnRequestSucceeded(url, texture);
                }
                else
                {
                    // do the download
                    this.DownloadImage(url);
                }
            });
        }

19 Source : ImageRequestManager.cs
with MIT License
from modio

public virtual void RequestUserAvatar(int userId, AvatarImageLocator locator,
                                              UserAvatarSize size,
                                              Action<Texture2D> onAvatarReceived,
                                              Action<Texture2D> onFallbackFound,
                                              Action<WebRequestError> onError)
        {
            // - early outs -
            if(onAvatarReceived == null)
            {
                return;
            }
            if(locator == null)
            {
                if(onError != null)
                {
                    onError.Invoke(this.GenerateErrorForMissingLocator());
                }
                return;
            }

            string url = locator.GetSizeURL(size);

            // check url
            if(string.IsNullOrEmpty(url))
            {
                if(onError != null)
                {
                    onError.Invoke(this.GenerateErrorForMissingURL());
                }
                return;
            }

            if(url == ImageRequestManager.GUEST_AVATAR_URL)
            {
                if(onAvatarReceived != null)
                {
                    onAvatarReceived.Invoke(this.guestAvatar);
                }
                return;
            }

            // check cache and existing callbacks
            if(this.TryAddCallbacksToExisting(url, onAvatarReceived, onFallbackFound, onError))
            {
                return;
            }

            // - Start new request -
            Callbacks callbacks = this.CreateCallbacksEntry(url, onAvatarReceived, onError);

            // start process by checking the cache
            CacheClient.LoadUserAvatar(userId, size, (texture) => {
                if(this == null)
                {
                    return;
                }

                if(texture != null)
                {
                    this.OnRequestSucceeded(url, texture);
                }
                else
                {
                    // do the download
                    this.DownloadImage(url);
                }
            });
        }

19 Source : ImageRequestManager.cs
with MIT License
from modio

public virtual void RequestYouTubeThumbnail(int modId, string youTubeId,
                                                    Action<Texture2D> onThumbnailReceived,
                                                    Action<WebRequestError> onError)
        {
            // - early outs -
            if(onThumbnailReceived == null)
            {
                return;
            }

            string url = Utility.GenerateYouTubeThumbnailURL(youTubeId);

            // check url
            if(string.IsNullOrEmpty(url))
            {
                if(onError != null)
                {
                    onError.Invoke(this.GenerateErrorForMissingURL());
                }
                return;
            }

            // check cache and existing callbacks
            if(this.TryAddCallbacksToExisting(url, onThumbnailReceived, null, onError))
            {
                return;
            }

            // - Start new request -
            Callbacks callbacks = this.CreateCallbacksEntry(url, onThumbnailReceived, onError);

            // add save function to download callback
            if(this.storeIfSubscribed)
            {
                callbacks.onTextureDownloaded = (texture) =>
                {
                    if(LocalUser.SubscribedModIds.Contains(modId))
                    {
                        CacheClient.SaveModYouTubeThumbnail(modId, youTubeId, texture, null);
                    }
                };
            }

            // start process by checking the cache
            CacheClient.LoadModYouTubeThumbnail(modId, youTubeId, (texture) => {
                if(this == null)
                {
                    return;
                }

                if(texture != null)
                {
                    this.OnRequestSucceeded(url, texture);
                }
                else
                {
                    // do the download
                    this.DownloadImage(url);
                }
            });
        }

19 Source : ImageRequestManager.cs
with MIT License
from modio

public virtual void RequestImage(string url, Action<Texture2D> onSuccess,
                                         Action<WebRequestError> onError)
        {
            // - early outs -
            if(onSuccess == null)
            {
                return;
            }
            if(string.IsNullOrEmpty(url))
            {
                if(onError != null)
                {
                    onError.Invoke(this.GenerateErrorForMissingURL());
                }
                return;
            }

            // check cache and existing callbacks
            if(this.TryAddCallbacksToExisting(url, onSuccess, null, onError))
            {
                return;
            }

            // - Start new request -
            this.CreateCallbacksEntry(url, onSuccess, onError);

            // do the download
            this.DownloadImage(url);
        }

19 Source : ImageRequestManager.cs
with MIT License
from modio

protected virtual void OnRequestFailed(string url, WebRequestError error)
        {
            if(this == null || string.IsNullOrEmpty(url))
            {
                return;
            }

            if(this.m_callbackMap.ContainsKey(url))
            {
                foreach(var errorCallback in this.m_callbackMap[url].failed)
                {
                    if(errorCallback != null)
                    {
                        errorCallback.Invoke(error);
                    }
                }

                // remove from "in progress"
                this.m_callbackMap.Remove(url);
            }
        }

19 Source : ImageRequestManager.cs
with MIT License
from modio

public virtual void RequestModLogo(int modId, LogoImageLocator locator, LogoSize size,
                                           Action<Texture2D> onLogoReceived,
                                           Action<Texture2D> onFallbackFound,
                                           Action<WebRequestError> onError)
        {
            // - early outs -
            if(onLogoReceived == null)
            {
                return;
            }
            if(locator == null)
            {
                if(onError != null)
                {
                    onError.Invoke(this.GenerateErrorForMissingLocator());
                }
                return;
            }

            string url = locator.GetSizeURL(size);
            string fileName = locator.GetFileName();

            // check url
            if(string.IsNullOrEmpty(url))
            {
                if(onError != null)
                {
                    onError.Invoke(this.GenerateErrorForMissingURL());
                }
                return;
            }

            // check cache and existing callbacks
            if(this.TryAddCallbacksToExisting(url, onLogoReceived, onFallbackFound, onError))
            {
                return;
            }

            // - Start new request -
            Callbacks callbacks = this.CreateCallbacksEntry(url, onLogoReceived, onError);

            // add save function to download callback
            if(this.storeIfSubscribed)
            {
                callbacks.onTextureDownloaded = (texture) =>
                {
                    if(LocalUser.SubscribedModIds.Contains(modId))
                    {
                        CacheClient.SaveModLogo(modId, fileName, size, texture, null);
                    }
                };
            }

            // start process by checking the cache
            CacheClient.LoadModLogo(modId, fileName, size, (texture) => {
                if(this == null)
                {
                    return;
                }

                if(texture != null)
                {
                    this.OnRequestSucceeded(url, texture);
                }
                else
                {
                    // do the download
                    this.DownloadImage(url);
                }
            });
        }

19 Source : UserAccountManagement.cs
with MIT License
from modio

public static void PullSubscriptionChanges(Action<List<ModProfile>> onSuccess,
                                                   Action<WebRequestError> onError)
        {
            // early out
            if(LocalUser.AuthenticationState == AuthenticationState.NoToken)
            {
                if(onSuccess != null)
                {
                    onSuccess(new List<ModProfile>(0));
                }
                return;
            }

            // holding vars
            string userToken = LocalUser.OAuthToken;
            List<ModProfile> remoteOnlySubscriptions = new List<ModProfile>();

            // set filter and initial pagination
            RequestFilter subscriptionFilter = new RequestFilter();
            subscriptionFilter.AddFieldFilter(ModIO.API.GetUserSubscriptionsFilterFields.gameId,
                                              new EqualToFilter<int>(PluginSettings.GAME_ID));

            APIPaginationParameters pagination = new APIPaginationParameters() {
                limit = APIPaginationParameters.LIMIT_MAX,
                offset = 0,
            };

            // define actions
            Action getNextPage = null;
            Action<RequestPage<ModProfile>> onPageReceived = null;
            Action onAllPagesReceived = null;

            getNextPage = () =>
            {
                APIClient.GetUserSubscriptions(
                    subscriptionFilter, pagination,
                    (response) => {
                        onPageReceived(response);

                        // check if all pages received
                        if(response != null && response.items != null && response.items.Length > 0
                           && response.resultTotal > response.size + response.resultOffset)
                        {
                            pagination.offset = response.resultOffset + response.size;

                            getNextPage();
                        }
                        else
                        {
                            onAllPagesReceived();

                            if(onSuccess != null)
                            {
                                onSuccess(remoteOnlySubscriptions);
                            }
                        }
                    },
                    (e) => {
                        if(onError != null)
                        {
                            onError(e);
                        }
                    });
            };


            onPageReceived = (r) =>
            {
                foreach(ModProfile profile in r.items)
                {
                    if(profile != null)
                    {
                        remoteOnlySubscriptions.Add(profile);
                    }
                }
            };

            onAllPagesReceived = () =>
            {
                if(userToken != LocalUser.OAuthToken)
                {
                    return;
                }

                List<int> localOnlySubs = new List<int>(LocalUser.SubscribedModIds);

                // NOTE(@jackson): Unsub actions *should not* be found in
                // activeUser.subscribedModIds
                foreach(int modId in LocalUser.QueuedUnsubscribes)
                {
#if DEBUG
                    if(localOnlySubs.Contains(modId))
                    {
                        Debug.LogWarning("[mod.io] A locally subscribed mod was found in the"
                                         + " queuedUnsubscribes. This should not occur - please"
                                         + " ensure that any mod ids added to"
                                         + " activeUser.queuedUnsubscribes are removed from"
                                         + " activeUser.subscribedModIds or use"
                                         + " UserAccountManagement.UnsubscribeFromMod() to handle"
                                         + " this automatically.");
                    }
#endif

                    localOnlySubs.Remove(modId);
                }

                List<int> newSubs = new List<int>();

                // build new subs list
                for(int i = 0; i < remoteOnlySubscriptions.Count; ++i)
                {
                    ModProfile profile = remoteOnlySubscriptions[i];

                    // remove if in queued subs
                    LocalUser.QueuedSubscribes.Remove(profile.id);

                    // if in unsub queue
                    if(LocalUser.QueuedUnsubscribes.Contains(profile.id))
                    {
                        remoteOnlySubscriptions.RemoveAt(i);
                        --i;
                    }
                    // if locally subbed
                    else if(localOnlySubs.Remove(profile.id))
                    {
                        remoteOnlySubscriptions.RemoveAt(i);
                        --i;
                    }
                    // if not locally subbed && if not in unsub queue
                    else
                    {
                        newSubs.Add(profile.id);
                    }
                }

                // -- update locally --
                // remove new unsubs
                foreach(int modId in localOnlySubs)
                {
                    // if not in sub queue
                    if(!LocalUser.QueuedSubscribes.Contains(modId))
                    {
                        LocalUser.SubscribedModIds.Remove(modId);
                    }
                }

                LocalUser.SubscribedModIds.AddRange(newSubs);

                // save
                LocalUser.Save();
            };

            // get pages
            getNextPage();
        }

19 Source : UserAccountManagement.cs
with MIT License
from modio

public static void ReauthenticateWithStoredExternalAuthData(bool hasUserAcceptedTerms,
                                                                    Action<UserProfile> onSuccess,
                                                                    Action<WebRequestError> onError)
        {
            ExternalAuthenticationData authData = LocalUser.ExternalAuthentication;

            Debug.replacedert(!string.IsNullOrEmpty(authData.ticket));
            Debug.replacedert(authData.portal != UserPortal.None);

            Action<string> onSuccessWrapper = (t) =>
            {
                LocalUser.OAuthToken = t;
                LocalUser.WasTokenRejected = false;
                LocalUser.Save();

                if(onSuccess != null)
                {
                    UserAccountManagement.UpdateUserProfile(onSuccess, onError);
                }
            };

            switch(LocalUser.ExternalAuthentication.portal)
            {
                case UserPortal.Steam:
                {
                    APIClient.RequestSteamAuthentication(authData.ticket, hasUserAcceptedTerms,
                                                         onSuccessWrapper, onError);
                }
                break;

                case UserPortal.GOG:
                {
                    APIClient.RequestGOGAuthentication(authData.ticket, hasUserAcceptedTerms,
                                                       onSuccessWrapper, onError);
                }
                break;

                case UserPortal.itchio:
                {
                    APIClient.RequesreplacedchIOAuthentication(authData.ticket, hasUserAcceptedTerms,
                                                          onSuccessWrapper, onError);
                }
                break;

                case UserPortal.Oculus:
                {
                    string token = authData.ticket;
                    string nonce = null;
                    string userIdString = null;
                    int userId = -1;
                    string errorMessage = null;

                    if(authData.additionalData == null)
                    {
                        errorMessage = "The user id and nonce are missing.";
                    }
                    else if(!authData.additionalData.TryGetValue(
                                ExternalAuthenticationData.OculusRiftKeys.NONCE, out nonce)
                            || string.IsNullOrEmpty(nonce))
                    {
                        errorMessage = "The nonce is missing.";
                    }
                    else if(!authData.additionalData.TryGetValue(
                                ExternalAuthenticationData.OculusRiftKeys.USER_ID, out userIdString)
                            || string.IsNullOrEmpty(userIdString))
                    {
                        errorMessage = "The user id is missing.";
                    }
                    else if(!int.TryParse(userIdString, out userId))
                    {
                        errorMessage = "The user id is not parseable as an integer.";
                    }

                    if(errorMessage != null)
                    {
                        Debug.LogWarning(
                            "[mod.io] Unable to authenticate using stored Oculus Rift user data.\n"
                            + errorMessage);

                        if(onError != null)
                        {
                            var error = WebRequestError.GenerateLocal(errorMessage);
                            onError(error);
                        }

                        return;
                    }
                    else
                    {
                        APIClient.RequestOculusRiftAuthentication(
                            nonce, userId, token, hasUserAcceptedTerms, onSuccessWrapper, onError);
                    }
                }
                break;

                case UserPortal.XboxLive:
                {
                    APIClient.RequestXboxLiveAuthentication(authData.ticket, hasUserAcceptedTerms,
                                                            onSuccessWrapper, onError);
                }
                break;

                default:
                {
                    throw new System.NotImplementedException();
                }
            }
        }