Пример #1
0
 public void Login(CancellableProgress progress, Action success, Action <Exception> failure)
 {
     try
     {
         if (m_loginProcessData != null)
         {
             throw new InvalidOperationException("登陆已经在进程中");
         }
         if (!WebManager.IsInternetConnectionAvailable())
         {
             throw new InvalidOperationException("网络连接错误");
         }
         Logout();
         progress.Cancelled += delegate
         {
             if (m_loginProcessData != null)
             {
                 LoginProcessData loginProcessData = m_loginProcessData;
                 m_loginProcessData = null;
                 loginProcessData.Fail(this, null);
             }
         };
         m_loginProcessData          = new LoginProcessData();
         m_loginProcessData.Progress = progress;
         m_loginProcessData.Success  = success;
         m_loginProcessData.Failure  = failure;
         LoginLaunchBrowser();
     }
     catch (Exception obj)
     {
         failure(obj);
     }
 }
Пример #2
0
        public static void Delete(string address, string userId, CancellableProgress progress, Action success, Action <Exception> failure)
        {
            progress = (progress ?? new CancellableProgress());
            if (!WebManager.IsInternetConnectionAvailable())
            {
                failure(new InvalidOperationException("Internet connection is unavailable."));
                return;
            }
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary.Add("Action", "delete");
            dictionary.Add("UserId", userId);
            dictionary.Add("Url", address);
            dictionary.Add("Platform", VersionsManager.Platform.ToString());
            dictionary.Add("Version", VersionsManager.Version);
            WebManager.Post(m_scResDirAddress, null, null, WebManager.UrlParametersToStream(dictionary), progress, delegate
            {
                success();
                AnalyticsManager.LogEvent("[CommunityContentManager] Delete Success", new AnalyticsParameter("Name", address), new AnalyticsParameter("User", userId));
            }, delegate(Exception error)
            {
                failure(error);
                AnalyticsManager.LogEvent("[CommunityContentManager] Delete Failure", new AnalyticsParameter("Name", address), new AnalyticsParameter("User", userId), new AnalyticsParameter("Error", error.Message.ToString()));
            });
        }
Пример #3
0
 public void Upload(string path, Stream stream, CancellableProgress progress, Action <string> success, Action <Exception> failure)
 {
     try
     {
         VerifyLoggedIn();
         JsonObject jsonObject = new JsonObject();
         jsonObject.Add("path", NormalizePath(path));
         jsonObject.Add("mode", "add");
         jsonObject.Add("autorename", true);
         jsonObject.Add("mute", false);
         Dictionary <string, string> dictionary = new Dictionary <string, string>();
         dictionary.Add("Authorization", "Bearer " + SettingsManager.ScpboxAccessToken);
         dictionary.Add("Content-Type", "application/octet-stream");
         dictionary.Add("Dropbox-API-Arg", jsonObject.ToString());
         WebManager.Post(m_redirectUri + "/com/files/upload", null, dictionary, stream, progress, delegate
         {
             success(null);
         }, delegate(Exception error)
         {
             failure(error);
         });
     }
     catch (Exception obj)
     {
         failure(obj);
     }
 }
Пример #4
0
 public void Link(string path, CancellableProgress progress, Action <string> success, Action <Exception> failure)
 {
     try
     {
         VerifyLoggedIn();
         Dictionary <string, string> dictionary = new Dictionary <string, string>();
         dictionary.Add("Authorization", "Bearer " + SettingsManager.ScpboxAccessToken);
         dictionary.Add("Content-Type", "application/json");
         JsonObject jsonObject = new JsonObject();
         jsonObject.Add("path", NormalizePath(path));
         jsonObject.Add("short_url", false);
         MemoryStream data = new MemoryStream(Encoding.UTF8.GetBytes(jsonObject.ToString()));
         WebManager.Post(m_redirectUri + "/com/sharing/create_shared_link", null, dictionary, data, progress, delegate(byte[] result)
         {
             try
             {
                 JsonObject jsonObject2 = (JsonObject)WebManager.JsonFromBytes(result);
                 success(JsonObjectToLinkAddress(jsonObject2));
             }
             catch (Exception obj2)
             {
                 failure(obj2);
             }
         }, delegate(Exception error)
         {
             failure(error);
         });
     }
     catch (Exception obj)
     {
         failure(obj);
     }
 }
        public CancellableBusyDialog(string largeMessage, bool autoHideOnCancel)
        {
            XElement node = ContentManager.Get <XElement>("Dialogs/CancellableBusyDialog");

            LoadContents(this, node);
            m_largeLabelWidget   = Children.Find <LabelWidget>("CancellableBusyDialog.LargeLabel");
            m_smallLabelWidget   = Children.Find <LabelWidget>("CancellableBusyDialog.SmallLabel");
            m_cancelButtonWidget = Children.Find <ButtonWidget>("CancellableBusyDialog.CancelButton");
            Progress             = new CancellableProgress();
            m_autoHideOnCancel   = autoHideOnCancel;
            LargeMessage         = largeMessage;
        }
Пример #6
0
 public void Upload(string path, Stream stream, CancellableProgress progress, Action <string> success, Action <Exception> failure)
 {
     try
     {
         Dictionary <string, string> dictionary = new Dictionary <string, string>();
         dictionary.Add("Content-Type", "application/octet-stream");
         WebManager.Put("https://transfer.sh/" + path, null, dictionary, stream, progress, delegate(byte[] result)
         {
             string obj2 = Encoding.UTF8.GetString(result, 0, result.Length).Trim();
             success(obj2);
         }, delegate(Exception error)
         {
             failure(error);
         });
     }
     catch (Exception obj)
     {
         failure(obj);
     }
 }
Пример #7
0
 public void Download(string path, CancellableProgress progress, Action <Stream> success, Action <Exception> failure)
 {
     try
     {
         VerifyLoggedIn();
         JsonObject jsonObject = new JsonObject();
         jsonObject.Add("path", NormalizePath(path));
         Dictionary <string, string> dictionary = new Dictionary <string, string>();
         dictionary.Add("Authorization", "Bearer " + SettingsManager.ScpboxAccessToken);
         dictionary.Add("Dropbox-API-Arg", jsonObject.ToString());
         WebManager.Get(m_redirectUri + "/com/files/download", null, dictionary, progress, delegate(byte[] result)
         {
             success(new MemoryStream(result));
         }, delegate(Exception error)
         {
             failure(error);
         });
     }
     catch (Exception obj)
     {
         failure(obj);
     }
 }
Пример #8
0
 public void List(string path, CancellableProgress progress, Action <ExternalContentEntry> success, Action <Exception> failure)
 {
     try
     {
         VerifyLoggedIn();
         Dictionary <string, string> dictionary = new Dictionary <string, string>();
         dictionary.Add("Authorization", "Bearer " + SettingsManager.ScpboxAccessToken);
         dictionary.Add("Content-Type", "application/json");
         JsonObject jsonObject = new JsonObject();
         jsonObject.Add("path", NormalizePath(path));
         jsonObject.Add("recursive", false);
         jsonObject.Add("include_media_info", false);
         jsonObject.Add("include_deleted", false);
         jsonObject.Add("include_has_explicit_shared_members", false);
         MemoryStream data = new MemoryStream(Encoding.UTF8.GetBytes(jsonObject.ToString()));
         WebManager.Post(m_redirectUri + "/com/files/list_folder", null, dictionary, data, progress, delegate(byte[] result)
         {
             try
             {
                 JsonObject jsonObject2 = (JsonObject)WebManager.JsonFromBytes(result);
                 success(JsonObjectToEntry(jsonObject2));
             }
             catch (Exception obj2)
             {
                 failure(obj2);
             }
         }, delegate(Exception error)
         {
             failure(error);
         });
     }
     catch (Exception obj)
     {
         failure(obj);
     }
 }
Пример #9
0
        public static void Get(string address, Dictionary <string, string> parameters, Dictionary <string, string> headers, CancellableProgress progress, Action <byte[]> success, Action <Exception> failure)
        {
            MemoryStream targetStream = default(MemoryStream);
            Exception    e            = default(Exception);

            Task.Run(async delegate
            {
                _ = 3;
                try
                {
                    progress = (progress ?? new CancellableProgress());
                    if (!IsInternetConnectionAvailable())
                    {
                        throw new InvalidOperationException("Internet connection is unavailable.");
                    }
                    using (HttpClient client = new HttpClient())
                    {
                        System.Uri requestUri = (parameters != null && parameters.Count > 0) ? new System.Uri($"{address}?{UrlParametersToString(parameters)}") : new System.Uri(address);
                        client.DefaultRequestHeaders.Referrer = new System.Uri(address);
                        if (headers != null)
                        {
                            foreach (KeyValuePair <string, string> header in headers)
                            {
                                client.DefaultRequestHeaders.Add(header.Key, header.Value);
                            }
                        }
                        HttpResponseMessage responseMessage = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead, progress.CancellationToken);
                        await VerifyResponse(responseMessage);
                        long?contentLength = responseMessage.Content.Headers.ContentLength;
                        progress.Total     = contentLength.GetValueOrDefault();
                        using (Stream responseStream = await responseMessage.Content.ReadAsStreamAsync())
                        {
                            targetStream = new MemoryStream();
                            try
                            {
                                long written  = 0L;
                                byte[] buffer = new byte[1024];
                                int num;
                                do
                                {
                                    num = await responseStream.ReadAsync(buffer, 0, buffer.Length, progress.CancellationToken);
                                    if (num > 0)
                                    {
                                        targetStream.Write(buffer, 0, num);
                                        written           += num;
                                        progress.Completed = written;
                                    }
                                }while (num > 0);
                                if (success != null)
                                {
                                    Dispatcher.Dispatch(delegate
                                    {
                                        success(targetStream.ToArray());
                                    });
                                }
                            }
                            finally
                            {
                                if (targetStream != null)
                                {
                                    ((IDisposable)targetStream).Dispose();
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    e = ex;
                    Log.Error(ExceptionManager.MakeFullErrorMessage(e));
                    if (failure != null)
                    {
                        Dispatcher.Dispatch(delegate
                        {
                            failure(e);
                        });
                    }
                }
            });
        }
Пример #10
0
        public static void PutOrPost(bool isPost, string address, Dictionary <string, string> parameters, Dictionary <string, string> headers, Stream data, CancellableProgress progress, Action <byte[]> success, Action <Exception> failure)
        {
            byte[]    responseData = default(byte[]);
            Exception e            = default(Exception);

            Task.Run(async delegate
            {
                _ = 5;
                try
                {
                    if (!IsInternetConnectionAvailable())
                    {
                        throw new InvalidOperationException("Internet connection is unavailable.");
                    }
                    using (HttpClient client = new HttpClient())
                    {
                        Dictionary <string, string> dictionary = new Dictionary <string, string>();
                        if (headers != null)
                        {
                            foreach (KeyValuePair <string, string> header in headers)
                            {
                                if (!client.DefaultRequestHeaders.TryAddWithoutValidation(header.Key, header.Value))
                                {
                                    dictionary.Add(header.Key, header.Value);
                                }
                            }
                        }
                        System.Uri requestUri   = (parameters != null && parameters.Count > 0) ? new System.Uri($"{address}?{UrlParametersToString(parameters)}") : new System.Uri(address);
                        HttpContent httpContent = (progress != null) ? ((HttpContent) new ProgressHttpContent(data, progress)) : ((HttpContent) new StreamContent(data));
                        foreach (KeyValuePair <string, string> item in dictionary)
                        {
                            httpContent.Headers.Add(item.Key, item.Value);
                        }
                        HttpResponseMessage responseMessage = isPost ? ((progress == null) ? (await client.PostAsync(requestUri, httpContent)) : (await client.PostAsync(requestUri, httpContent, progress.CancellationToken))) : ((progress == null) ? (await client.PutAsync(requestUri, httpContent)) : (await client.PutAsync(requestUri, httpContent, progress.CancellationToken)));
                        await VerifyResponse(responseMessage);
                        responseData = await responseMessage.Content.ReadAsByteArrayAsync();
                        if (success != null)
                        {
                            Dispatcher.Dispatch(delegate
                            {
                                success(responseData);
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    e = ex;
                    Log.Error(ExceptionManager.MakeFullErrorMessage(e));
                    if (failure != null)
                    {
                        Dispatcher.Dispatch(delegate
                        {
                            failure(e);
                        });
                    }
                }
            });
        }
Пример #11
0
 public ProgressHttpContent(Stream sourceStream, CancellableProgress progress)
 {
     m_sourceStream = sourceStream;
     m_progress     = (progress ?? new CancellableProgress());
 }
Пример #12
0
 public static void Post(string address, Dictionary <string, string> parameters, Dictionary <string, string> headers, Stream data, CancellableProgress progress, Action <byte[]> success, Action <Exception> failure)
 {
     PutOrPost(isPost: true, address, parameters, headers, data, progress, success, failure);
 }
Пример #13
0
 public static void Publish(string address, string name, ExternalContentType type, string userId, CancellableProgress progress, Action success, Action <Exception> failure)
 {
     progress = (progress ?? new CancellableProgress());
     if (MarketplaceManager.IsTrialMode)
     {
         failure(new InvalidOperationException("Cannot publish links in trial mode."));
     }
     else if (!WebManager.IsInternetConnectionAvailable())
     {
         failure(new InvalidOperationException("Internet connection is unavailable."));
     }
     else
     {
         VerifyLinkContent(address, name, type, progress, delegate(byte[] data)
         {
             string value = CalculateContentHashString(data);
             WebManager.Post(m_scResDirAddress, null, null, WebManager.UrlParametersToStream(new Dictionary <string, string>
             {
                 {
                     "Action",
                     "publish"
                 },
                 {
                     "UserId",
                     userId
                 },
                 {
                     "Name",
                     name
                 },
                 {
                     "Url",
                     address
                 },
                 {
                     "Type",
                     type.ToString()
                 },
                 {
                     "Hash",
                     value
                 },
                 {
                     "Size",
                     data.Length.ToString(CultureInfo.InvariantCulture)
                 },
                 {
                     "Platform",
                     VersionsManager.Platform.ToString()
                 },
                 {
                     "Version",
                     VersionsManager.Version
                 }
             }), progress, delegate
             {
                 success();
                 AnalyticsManager.LogEvent("[CommunityContentManager] Publish Success", new AnalyticsParameter("Name", name), new AnalyticsParameter("Type", type.ToString()), new AnalyticsParameter("Size", data.Length.ToString()), new AnalyticsParameter("User", userId));
             }, delegate(Exception error)
             {
                 failure(error);
                 AnalyticsManager.LogEvent("[CommunityContentManager] Publish Failure", new AnalyticsParameter("Name", name), new AnalyticsParameter("Type", type.ToString()), new AnalyticsParameter("Size", data.Length.ToString()), new AnalyticsParameter("User", userId), new AnalyticsParameter("Error", error.Message.ToString()));
             });
         }, failure);
     }
 }
Пример #14
0
 public void List(string path, CancellableProgress progress, Action <ExternalContentEntry> success, Action <Exception> failure)
 {
     failure(new NotSupportedException());
 }
Пример #15
0
 public static void SendPlayTime(string address, string userId, double time, CancellableProgress progress, Action success, Action <Exception> failure)
 {
     Feedback(address, "PlayTime", MathUtils.Round(time).ToString(CultureInfo.InvariantCulture), null, 0L, userId, progress, success, failure);
 }
Пример #16
0
 public static void Report(string address, string userId, string report, CancellableProgress progress, Action success, Action <Exception> failure)
 {
     Feedback(address, "Report", report, null, 0L, userId, progress, success, failure);
 }
Пример #17
0
 public static void Rate(string address, string userId, int rating, CancellableProgress progress, Action success, Action <Exception> failure)
 {
     rating = MathUtils.Clamp(rating, 1, 5);
     Feedback(address, "Rating", rating.ToString(CultureInfo.InvariantCulture), null, 0L, userId, progress, success, failure);
 }
Пример #18
0
 public void Link(string path, CancellableProgress progress, Action <string> success, Action <Exception> failure)
 {
     failure(new NotSupportedException());
 }
Пример #19
0
 public void Download(string path, CancellableProgress progress, Action <Stream> success, Action <Exception> failure)
 {
     failure(new NotSupportedException());
 }
Пример #20
0
        public static void List(string cursor, string userFilter, string typeFilter, string moderationFilter, string sortOrder, CancellableProgress progress, Action <List <CommunityContentEntry>, string> success, Action <Exception> failure)
        {
            progress = (progress ?? new CancellableProgress());
            if (!WebManager.IsInternetConnectionAvailable())
            {
                failure(new InvalidOperationException("Internet connection is unavailable."));
                return;
            }
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary.Add("Action", "list");
            dictionary.Add("Cursor", cursor ?? string.Empty);
            dictionary.Add("UserId", userFilter ?? string.Empty);
            dictionary.Add("Type", typeFilter ?? string.Empty);
            dictionary.Add("Moderation", moderationFilter ?? string.Empty);
            dictionary.Add("SortOrder", sortOrder ?? string.Empty);
            dictionary.Add("Platform", VersionsManager.Platform.ToString());
            dictionary.Add("Version", VersionsManager.Version);
            WebManager.Post(m_scResDirAddress, null, null, WebManager.UrlParametersToStream(dictionary), progress, delegate(byte[] result)
            {
                try
                {
                    XElement xElement                 = XmlUtils.LoadXmlFromString(Encoding.UTF8.GetString(result, 0, result.Length), throwOnError: true);
                    string attributeValue             = XmlUtils.GetAttributeValue <string>(xElement, "NextCursor");
                    List <CommunityContentEntry> list = new List <CommunityContentEntry>();
                    foreach (XElement item in xElement.Elements())
                    {
                        try
                        {
                            list.Add(new CommunityContentEntry
                            {
                                Type           = XmlUtils.GetAttributeValue(item, "Type", ExternalContentType.Unknown),
                                Name           = XmlUtils.GetAttributeValue <string>(item, "Name"),
                                Address        = XmlUtils.GetAttributeValue <string>(item, "Url"),
                                UserId         = XmlUtils.GetAttributeValue <string>(item, "UserId"),
                                Size           = XmlUtils.GetAttributeValue <long>(item, "Size"),
                                ExtraText      = XmlUtils.GetAttributeValue(item, "ExtraText", string.Empty),
                                RatingsAverage = XmlUtils.GetAttributeValue(item, "RatingsAverage", 0f)
                            });
                        }
                        catch (Exception)
                        {
                        }
                    }
                    success(list, attributeValue);
                }
                catch (Exception obj)
                {
                    failure(obj);
                }
            }, delegate(Exception error)
            {
                failure(error);
            });
        }
Пример #21
0
 public static void VerifyLinkContent(string address, string name, ExternalContentType type, CancellableProgress progress, Action <byte[]> success, Action <Exception> failure)
 {
     progress = (progress ?? new CancellableProgress());
     WebManager.Get(address, null, null, progress, delegate(byte[] data)
     {
         ExternalContentManager.ImportExternalContent(new MemoryStream(data), type, "__Temp", delegate(string downloadedName)
         {
             ExternalContentManager.DeleteExternalContent(type, downloadedName);
             success(data);
         }, failure);
     }, failure);
 }
Пример #22
0
 public static void Download(string address, string name, ExternalContentType type, string userId, CancellableProgress progress, Action success, Action <Exception> failure)
 {
     progress = (progress ?? new CancellableProgress());
     if (!WebManager.IsInternetConnectionAvailable())
     {
         failure(new InvalidOperationException("Internet connection is unavailable."));
     }
     else
     {
         WebManager.Get(address, null, null, progress, delegate(byte[] data)
         {
             string hash = CalculateContentHashString(data);
             ExternalContentManager.ImportExternalContent(new MemoryStream(data), type, name, delegate(string downloadedName)
             {
                 m_idToAddressMap[MakeContentIdString(type, downloadedName)] = address;
                 Feedback(address, "Success", null, hash, data.Length, userId, progress, delegate
                 {
                 }, delegate
                 {
                 });
                 AnalyticsManager.LogEvent("[CommunityContentManager] Download Success", new AnalyticsParameter("Name", name));
                 success();
             }, delegate(Exception error)
             {
                 Feedback(address, "ImportFailure", null, hash, data.Length, userId, null, delegate
                 {
                 }, delegate
                 {
                 });
                 AnalyticsManager.LogEvent("[CommunityContentManager] Import Failure", new AnalyticsParameter("Name", name), new AnalyticsParameter("Error", error.Message.ToString()));
                 failure(error);
             });
         }, delegate(Exception error)
         {
             Feedback(address, "DownloadFailure", null, null, 0L, userId, null, delegate
             {
             }, delegate
             {
             });
             AnalyticsManager.LogEvent("[CommunityContentManager] Download Failure", new AnalyticsParameter("Name", name), new AnalyticsParameter("Error", error.Message.ToString()));
             failure(error);
         });
     }
 }
Пример #23
0
        public static void Feedback(string address, string feedback, string feedbackParameter, string hash, long size, string userId, CancellableProgress progress, Action success, Action <Exception> failure)
        {
            progress = (progress ?? new CancellableProgress());
            if (!WebManager.IsInternetConnectionAvailable())
            {
                failure(new InvalidOperationException("Internet connection is unavailable."));
                return;
            }

            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary.Add("Action", "feedback");
            dictionary.Add("Feedback", feedback);
            if (feedbackParameter != null)
            {
                dictionary.Add("FeedbackParameter", feedbackParameter);
            }
            dictionary.Add("UserId", userId);
            if (address != null)
            {
                dictionary.Add("Url", address);
            }
            if (hash != null)
            {
                dictionary.Add("Hash", hash);
            }
            if (size > 0)
            {
                dictionary.Add("Size", size.ToString(CultureInfo.InvariantCulture));
            }
            dictionary.Add("Platform", VersionsManager.Platform.ToString());
            dictionary.Add("Version", VersionsManager.Version);
            WebManager.Post(m_scResDirAddress, null, null, WebManager.UrlParametersToStream(dictionary), progress, delegate
            {
                string key = MakeFeedbackCacheKey(address, feedback, userId);
                if (m_feedbackCache.ContainsKey(key))
                {
                    Task.Run(delegate
                    {
                        Task.Delay(1500).Wait();
                        failure(new InvalidOperationException("Duplicate feedback."));
                    });
                    return;
                }
                m_feedbackCache[key] = true;
                success();
            }, delegate(Exception error)
            {
                failure(error);
            });
        }
Пример #24
0
 public void Login(CancellableProgress progress, Action success, Action <Exception> failure)
 {
     failure(new NotSupportedException());
 }