예제 #1
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);
 }
예제 #2
0
 public static void Update()
 {
     if (Time.PeriodicEvent(1.0, 0.0))
     {
         TimeSpan t   = TimeSpan.FromHours(SettingsManager.MotdUpdatePeriodHours);
         DateTime now = DateTime.Now;
         if (now >= SettingsManager.MotdLastUpdateTime + t)
         {
             SettingsManager.MotdLastUpdateTime = now;
             Log.Information("Downloading MOTD");
             AnalyticsManager.LogEvent("[MotdManager] Downloading MOTD", new AnalyticsParameter("Time", DateTime.Now.ToString("HH:mm:ss.fff")));
             string url = GetMotdUrl();
             WebManager.Get(url, null, null, null, delegate(byte[] result)
             {
                 try
                 {
                     string motdLastDownloadedData = UnpackMotd(result);
                     MessageOfTheDay = null;
                     SettingsManager.MotdLastDownloadedData = motdLastDownloadedData;
                     Log.Information("Downloaded MOTD");
                     AnalyticsManager.LogEvent("[MotdManager] Downloaded MOTD", new AnalyticsParameter("Time", DateTime.Now.ToString("HH:mm:ss.fff")), new AnalyticsParameter("Url", url));
                     SettingsManager.MotdUseBackupUrl = false;
                 }
                 catch (Exception ex)
                 {
                     Log.Error("Failed processing MOTD string. Reason: " + ex.Message);
                     SettingsManager.MotdUseBackupUrl = !SettingsManager.MotdUseBackupUrl;
                 }
             }, delegate(Exception error)
             {
                 Log.Error("Failed downloading MOTD. Reason: {0}", error.Message);
                 SettingsManager.MotdUseBackupUrl = !SettingsManager.MotdUseBackupUrl;
             });
         }
     }
     if (MessageOfTheDay == null && !string.IsNullOrEmpty(SettingsManager.MotdLastDownloadedData))
     {
         MessageOfTheDay = ParseMotd(SettingsManager.MotdLastDownloadedData);
         if (MessageOfTheDay == null)
         {
             SettingsManager.MotdLastDownloadedData = string.Empty;
         }
     }
 }
예제 #3
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);
         });
     }
 }
예제 #4
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);
     }
 }
        public override void Update()
        {
            string text = m_linkTextBoxWidget.Text.Trim();
            string name = m_nameTextBoxWidget.Text.Trim();

            m_typeLabelWidget.Text      = ExternalContentManager.GetEntryTypeDescription(m_type);
            m_typeIconWidget.Subtexture = ExternalContentManager.GetEntryTypeIcon(m_type);
            if (ExternalContentManager.DoesEntryTypeRequireName(m_type))
            {
                m_nameTextBoxWidget.IsEnabled    = true;
                m_downloadButtonWidget.IsEnabled = (text.Length > 0 && name.Length > 0 && m_type != ExternalContentType.Unknown);
                if (m_updateContentName)
                {
                    m_nameTextBoxWidget.Text = GetNameFromLink(m_linkTextBoxWidget.Text);
                    m_updateContentName      = false;
                }
            }
            else
            {
                m_nameTextBoxWidget.IsEnabled    = false;
                m_nameTextBoxWidget.Text         = string.Empty;
                m_downloadButtonWidget.IsEnabled = (text.Length > 0 && m_type != ExternalContentType.Unknown);
            }
            if (m_updateContentType)
            {
                m_type = GetTypeFromLink(m_linkTextBoxWidget.Text);
                m_updateContentType = false;
            }
            if (m_changeTypeButtonWidget.IsClicked)
            {
                DialogsManager.ShowDialog(base.ParentWidget, new SelectExternalContentTypeDialog("Select Content Type", delegate(ExternalContentType item)
                {
                    m_type = item;
                    m_updateContentName = true;
                }));
            }
            else if (base.Input.Cancel || m_cancelButtonWidget.IsClicked)
            {
                DialogsManager.HideDialog(this);
            }
            else if (m_downloadButtonWidget.IsClicked)
            {
                CancellableBusyDialog busyDialog = new CancellableBusyDialog("Downloading", autoHideOnCancel: false);
                DialogsManager.ShowDialog(base.ParentWidget, busyDialog);
                WebManager.Get(text, null, null, busyDialog.Progress, delegate(byte[] data)
                {
                    ExternalContentManager.ImportExternalContent(new MemoryStream(data), m_type, name, delegate
                    {
                        DialogsManager.HideDialog(busyDialog);
                        DialogsManager.HideDialog(this);
                    }, delegate(Exception error)
                    {
                        DialogsManager.HideDialog(busyDialog);
                        DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog("Error", error.Message, LanguageControl.Get("Usual", "ok"), null, null));
                    });
                }, delegate(Exception error)
                {
                    DialogsManager.HideDialog(busyDialog);
                    DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog("Error", error.Message, LanguageControl.Get("Usual", "ok"), null, null));
                });
            }
        }