示例#1
0
 public Task <IMapset> Import(FileInfo file, TaskListener <IMapset> listener = null)
 {
     return(Task.Run <IMapset>(async() =>
     {
         try
         {
             // Start importing the file
             Mapset mapset = await store.Import(file, listener: listener?.CreateSubListener <Mapset>());
             if (mapset != null)
             {
                 // Mapset must be fully loaded.
                 Mapset loadedMapset = store.LoadData(mapset);
                 if (loadedMapset != null)
                 {
                     // Dispatch mapset imported event on main thread.
                     UnityThread.Dispatch(() =>
                     {
                         // Add to all mapsets
                         allMapsets.AddOrReplace(loadedMapset);
                         // Reapply filter
                         Search(lastSearch);
                         OnImportMapset?.Invoke(loadedMapset);
                         return null;
                     });
                 }
                 else
                 {
                     notificationBox?.Add(new Notification()
                     {
                         Message = $"Failed to load imported mapset ({mapset.Metadata.Artist} - {mapset.Metadata.Title})",
                         Type = NotificationType.Error
                     });
                 }
             }
             else
             {
                 notificationBox?.Add(new Notification()
                 {
                     Message = $"Failed to import mapset at ({file.FullName})",
                     Type = NotificationType.Error
                 });
             }
             listener?.SetFinished(mapset);
             return mapset;
         }
         catch (Exception e)
         {
             Logger.LogError($"Error while importing mapset: {e.Message}\n{e.StackTrace}");
             listener?.SetFinished();
             return null;
         }
     }));
 }
示例#2
0
        /// <summary>
        /// Shows a notification for the specified api request.
        /// </summary>
        private void ShowNotification(IApiRequest request, TaskListener <IWebRequest> listener)
        {
            var notification = request.CreateNotification();

            if (notification == null)
            {
                return;
            }

            request.OnDisposing += () => notificationBox.Remove(notification);

            notification.Task     = request.InnerRequest;
            notification.Listener = listener;
            notificationBox.Add(notification);
        }
示例#3
0
        public void HandleResponse(IApiResponse response)
        {
            if (response == null)
            {
                return;
            }

            if (!response.IsSuccess)
            {
                notificationBox?.Add(new Notification()
                {
                    Scope   = NotificationScope.Stored,
                    Message = response.ErrorMessage,
                    Type    = NotificationType.Error
                });
            }
            else
            {
                if (response is AuthResponse authResponse)
                {
                    if (authResponse.Authentication != null)
                    {
                        authentication.Value = authResponse.Authentication;
                    }
                }
                else if (response is MeResponse meResponse)
                {
                    if (meResponse.User != null)
                    {
                        user.Value = meResponse.User;
                    }
                }
                else if (response is OAuthResponse oAuthResponse)
                {
                    if (!string.IsNullOrEmpty(oAuthResponse.OAuthUrl))
                    {
                        Application.OpenURL(oAuthResponse.OAuthUrl);
                    }
                }
            }
        }