示例#1
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);
     }
 }
示例#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 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);
            });
        }
示例#5
0
 public void WindowActivated()
 {
     if (m_loginProcessData != null && !m_loginProcessData.IsTokenFlow)
     {
         LoginProcessData loginProcessData = m_loginProcessData;
         m_loginProcessData = null;
         TextBoxDialog dialog = new TextBoxDialog("输入用户登录Token:", "", 256, delegate(string s)
         {
             if (s != null)
             {
                 try
                 {
                     WebManager.Post(m_redirectUri + "/com/oauth2/token", new Dictionary <string, string>
                     {
                         {
                             "code",
                             s.Trim()
                         },
                         {
                             "client_id",
                             "1unnzwkb8igx70k"
                         },
                         {
                             "client_secret",
                             "3i5u3j3141php7u"
                         },
                         {
                             "grant_type",
                             "authorization_code"
                         }
                     }, null, new MemoryStream(), loginProcessData.Progress, delegate(byte[] result)
                     {
                         SettingsManager.ScpboxAccessToken = ((IDictionary <string, object>)WebManager.JsonFromBytes(result))["access_token"].ToString();
                         loginProcessData.Succeed(this);
                     }, delegate(Exception error)
                     {
                         loginProcessData.Fail(this, error);
                     });
                 }
                 catch (Exception error2)
                 {
                     loginProcessData.Fail(this, error2);
                 }
             }
             else
             {
                 loginProcessData.Fail(this, null);
             }
         });
         DialogsManager.ShowDialog(null, dialog);
     }
 }
示例#6
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);
            });
        }
示例#7
0
 public override void Update()
 {
     if (btna.IsClicked)
     {
         Dictionary <string, string> par = new Dictionary <string, string>();
         par.Add("user", txa.Text);
         par.Add("pass", txb.Text);
         WebManager.Post(SPMBoxExternalContentProvider.m_redirectUri + "/com/api/login", par, null, new MemoryStream(), new CancellableProgress(), succ, fail);
     }
     if (btnb.IsClicked)
     {
         WebBrowserManager.LaunchBrowser(SPMBoxExternalContentProvider.m_redirectUri + "/com/reg");
     }
     if (btnc.IsClicked)
     {
         DialogsManager.HideDialog(this);
     }
 }
示例#8
0
 public static void LogError(string message, Exception error)
 {
     try
     {
         double realTime = Time.RealTime;
         if (!(realTime - LastSendTime < 15.0))
         {
             LastSendTime = realTime;
             Dictionary <string, string> dictionary = new Dictionary <string, string>();
             dictionary.Add("Platform", VersionsManager.Platform.ToString());
             dictionary.Add("BuildConfiguration", VersionsManager.BuildConfiguration.ToString());
             dictionary.Add("DeviceModel", DeviceManager.DeviceModel);
             dictionary.Add("OSVersion", DeviceManager.OperatingSystemVersion);
             dictionary.Add("Is64bit", (Marshal.SizeOf <IntPtr>() == 8).ToString());
             dictionary.Add("FreeSpace", (Storage.FreeSpace / 1024 / 1024).ToString() + "MB");
             dictionary.Add("TotalAvailableMemory", (Utilities.GetTotalAvailableMemory() / 1024).ToString() + "kB");
             dictionary.Add("RealTime", Time.RealTime.ToString("0.000") + "s");
             dictionary.Add("WindowSize", Window.Size.ToString());
             dictionary.Add("FullErrorMessage", ExceptionManager.MakeFullErrorMessage(message, error));
             dictionary.Add("ExceptionType", error.GetType().ToString());
             dictionary.Add("ExceptionStackTrace", AbbreviateStackTrace(error.StackTrace));
             MemoryStream  memoryStream  = new MemoryStream();
             DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionLevel.Optimal, leaveOpen: true);
             BinaryWriter  binaryWriter  = new BinaryWriter(deflateStream);
             binaryWriter.Write(3735928559u);
             binaryWriter.Write((byte)dictionary.Count);
             foreach (KeyValuePair <string, string> item in dictionary)
             {
                 binaryWriter.Write(item.Key);
                 binaryWriter.Write(item.Value);
             }
             deflateStream.Dispose();
             memoryStream.Position = 0L;
             WebManager.Post(string.Format("{0}:{1}/{2}/{3}/{4}/{5}", "http://quality.kaalus.com", 30099, 1, "Survivalcraft", VersionsManager.Version, "Error"), null, null, memoryStream, null, null, null);
         }
     }
     catch
     {
     }
 }
示例#9
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);
     }
 }
示例#10
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);
     }
 }