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); } }
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())); }); }
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); }); }
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); }); }
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); }); } }
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); } }