public BloomLinkArgs(string url)
        {
            if (!url.StartsWith(kBloomUrlPrefix))
            {
                throw new ArgumentException(String.Format("unrecognized BloomLinkArgs URL string: {0}", url));
            }
            // I think we can't use the standard HttpUtility because we are trying to stick to the .NET 4.0 Client profile
            var queryData = url.Substring(kBloomUrlPrefix.Length);
            var qparams   = queryData.Split('&');
            var parts     = qparams[0].Split('=');

            if (parts.Length != 2 || parts[0] != kOrderFile)
            {
                throw new ArgumentException(String.Format("badly formed BloomLinkArgs URL string: {0}", url));
            }
            OrderUrl = HttpUtilityFromMono.UrlDecode(parts[1]);
            if (qparams.Length > 1 && qparams[1].StartsWith("title="))
            {
                Title = HttpUtilityFromMono.UrlDecode(qparams[1].Substring("title=".Length));
            }
            else
            {
                // Make up a title from the book order. This should be obsolete once all instances of Bloom Library
                // are supplying titles.
                var indexOfSlash = OrderUrl.LastIndexOf('/');
                var bookOrder    = OrderUrl.Substring(indexOfSlash + 1);
                Title = Path.GetFileNameWithoutExtension(bookOrder);
            }
        }
Example #2
0
        /// <summary>
        /// Builds a context descriptor with the given parameters that will provide a url link to the correct area in FLEx.
        /// </summary>
        internal static ContextDescriptor GenerateContextDescriptor(string filePath, string guid, string label)
        {
            var appId         = "FLEx";
            var directory     = Path.GetDirectoryName(filePath);
            var lastDirectory = Path.GetFileName(directory);

            if (lastDirectory == "Scripture")
            {
                appId = "TE";
            }
            // figure out here which we need.
            var fwAppArgs = new FwAppArgs(appId, "current", "", "default", guid);

            // Add the "label" information which the Chorus Notes browser extracts to identify the object in the UI.
            // This is just for a label and we can't have & or = in the value. So replace them if they occur.
            fwAppArgs.AddProperty("label", label.Replace("&", " and ").Replace("=", " equals "));
            // The FwUrl has all the query part encoded.
            // Chorus needs it unencoded so it can extract the label.
            var fwUrl      = fwAppArgs.ToString();
            var hostLength = fwUrl.IndexOf("?", StringComparison.Ordinal);
            var host       = fwUrl.Substring(0, hostLength);
            var query      = HttpUtilityFromMono.UrlDecode(fwUrl.Substring(hostLength + 1));
            var url        = host + "?" + query;

            return(new ContextDescriptor(label, url));
        }
Example #3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Use the explicit type tag to parse parameters into the right type
 /// </summary>
 /// <param name="value">The value.</param>
 /// ------------------------------------------------------------------------------------
 protected object Decode(string value)
 {
     if (value.IndexOf("bool:") > -1)
     {
         value = value.Substring(5);
         return(bool.Parse(value));
     }
     return(HttpUtilityFromMono.UrlDecode(value));
 }
Example #4
0
 public virtual void InitFromUri(string url)
 {
     SetServerLabelFromUrl(url);
     Password    = HttpUtilityFromMono.UrlDecode(UrlHelper.GetPassword(url));
     AccountName = HttpUtilityFromMono.UrlDecode(UrlHelper.GetUserName(url));
     ProjectId   = HttpUtilityFromMono.UrlDecode(UrlHelper.GetPathAfterHost(url));
     CustomUrl   = UrlHelper.GetPathOnly(url);
     //CustomUrlSelected = true;
 }
Example #5
0
        public string DownloadFromOrderUrl(string orderUrl, string destPath)
        {
            var decoded     = HttpUtilityFromMono.UrlDecode(orderUrl);
            var bucketStart = decoded.IndexOf(_s3Client.BucketName, StringComparison.InvariantCulture);

            if (bucketStart == -1)
            {
#if DEBUG
                if (decoded.StartsWith(("BloomLibraryBooks")))
                {
                    Palaso.Reporting.ErrorReport.NotifyUserOfProblem(
                        "The book is from bloomlibrary.org, but you are running the DEBUG version of Bloom, which can only use dev.bloomlibrary.org.");
                }
                else
                {
                    throw new ApplicationException("Can't match URL of bucket of the book being downloaded, and I don't know why.");
                }
#else
                if (decoded.StartsWith(("BloomLibraryBooks-Sandbox")))
                {
                    Palaso.Reporting.ErrorReport.NotifyUserOfProblem(
                        "The book is from the testing version of the bloomlibrary, but you are running the RELEASE version of Bloom. The RELEASE build cannot use the 'dev.bloomlibrary.org' site. If you need to do that for testing purposes, set the windows Environment variable 'BloomSandbox' to 'true'.", decoded);
                }
                else
                {
                    throw new ApplicationException(string.Format("Can't match URL of bucket of the book being downloaded {0}, and I don't know why.", decoded));
                }
#endif
                return(null);
            }

            var    s3orderKey = decoded.Substring(bucketStart + _s3Client.BucketName.Length + 1);
            string url        = "unknown";
            string title      = "unknown";
            try
            {
                var metadata = BookMetaData.FromString(_s3Client.DownloadFile(s3orderKey));
                url   = metadata.DownloadSource;
                title = metadata.Title;
                if (_progressDialog != null)
                {
                    _progressDialog.Invoke((Action)(() => { _progressDialog.Progress = 1; }));
                }
                // downloading the metadata is considered step 1.
                var destinationPath = DownloadBook(metadata.DownloadSource, destPath);
                LastBookDownloadedPath = destinationPath;

                Analytics.Track("DownloadedBook-Success",
                                new Dictionary <string, string>()
                {
                    { "url", url }, { "title", title }
                });
                return(destinationPath);
            }
            catch (WebException e)
            {
                DisplayNetworkDownloadProblem(e);
                Analytics.Track("DownloadedBook-Failure",
                                new Dictionary <string, string>()
                {
                    { "url", url }, { "title", title }
                });
                Analytics.ReportException(e);
                return("");
            }
            catch (AmazonServiceException e)
            {
                DisplayNetworkDownloadProblem(e);
                Analytics.Track("DownloadedBook-Failure",
                                new Dictionary <string, string>()
                {
                    { "url", url }, { "title", title }
                });
                Analytics.ReportException(e);
                return("");
            }
            catch (Exception e)
            {
                ShellWindow.Invoke((Action)(() =>
                                            Palaso.Reporting.ErrorReport.NotifyUserOfProblem(e,
                                                                                             LocalizationManager.GetString("PublishTab.Upload.DownloadProblem",
                                                                                                                           "There was a problem downloading your book. You may need to restart Bloom or get technical help."))));
                Analytics.Track("DownloadedBook-Failure",
                                new Dictionary <string, string>()
                {
                    { "url", url }, { "title", title }
                });
                Analytics.ReportException(e);
                return("");
            }
        }