Example #1
0
        /// <summary>
        /// Raises the load event.
        /// </summary>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        /// <remarks>
        /// This method notifies the server control that it should perform actions common to each HTTP
        /// request for the page it is associated with, such as setting up a database query. At this
        /// stage in the page lifecycle, server controls in the hierarchy are created and initialized,
        /// view state is restored, and form controls reflect client-side data. Use the IsPostBack
        /// property to determine whether the page is being loaded in response to a client postback,
        /// or if it is being loaded and accessed for the first time.
        /// </remarks>
        /// <exception cref="ApplicationException">Sitecore Analytics is disabled.</exception>
        /// <exception cref="AccessDeniedException">Application access denied.</exception>
        protected override void OnLoad([NotNull] EventArgs e)
        {
            Assert.ArgumentNotNull(e, "e");

            Assert.CanRunApplication("Dialogs/Segment Builder");


            base.OnLoad(e);
            InitializeServices();
            if (Context.ClientPage.IsEvent)
            {
                return;
            }

            UrlHandle handle;

            if (!UrlHandle.TryGetHandle(out handle))
            {
                throw new AccessDeniedException("Application access denied.");
            }

            Initialize(handle["value"]);
        }
Example #2
0
 public bool TryGetHandle(out UrlHandle handle)
 {
     return(UrlHandle.TryGetHandle(out handle));
 }
        protected override void OnLoad(EventArgs e)
        {
            Assert.ArgumentNotNull(e, "e");
            Assert.IsTrue(ServiceAuthorizationManager.IsUserAuthorized(WebServiceSettings.ServiceExecution, Context.User.Name, false), "Application access denied.");
            base.OnLoad(e);

            Context.ClientPage.ClientResponse.SetDialogValue(Hidden.Value);
            if (Context.ClientPage.IsEvent)
            {
                return;
            }

            UrlHandle handle = null;

            if (!UrlHandle.TryGetHandle(out handle))
            {
                FileNameLabel.Text =
                    "Invalid dialog invocation.";
                SizeLabel.Visible     = false;
                PathPrefix.Visible    = false;
                SizePrefix.Visible    = false;
                OK.Visible            = false;
                DownloadImage.Visible = false;
                ErrorImage.Visible    = true;
                return;
            }

            FileName = handle["fn"];

            ItemUri = handle["uri"];
            ItemDb  = handle["db"];

            bool showFullPath;

            if (!bool.TryParse(handle["fp"], out showFullPath))
            {
                showFullPath = false;
            }

            Text.Text = handle["te"];

            if (!string.IsNullOrEmpty(ItemUri))
            {
                var item = Factory.GetDatabase(ItemDb).GetItem(new DataUri(ItemUri));
                if (MediaManager.HasMediaContent(item))
                {
                    FileNameLabel.Text = (showFullPath ? item.GetProviderPath() : item.Name)
                                         + "." + item["Extension"];
                    long size;
                    SizeLabel.Text = Int64.TryParse(item["size"], out size) ? ToFileSize(size) : "unknown";
                }
                else
                {
                    SheerResponse.Alert("There is no file attached.");
                }
            }
            else if (!string.IsNullOrEmpty(FileName))
            {
                // check if file in approved location
                var filePath    = FileUtil.MapPath(FileName);
                var webSitePath = FileUtil.MapPath("/");
                var dataPath    = FileUtil.MapPath(Settings.DataFolder);

                if (!filePath.StartsWith(webSitePath, StringComparison.InvariantCultureIgnoreCase) &&
                    !filePath.StartsWith(dataPath, StringComparison.InvariantCultureIgnoreCase))
                {
                    FileNameLabel.Text =
                        "Files from outside of the Sitecore Data and Website folders cannot be downloaded.\n\n" +
                        "Copy the file to the Sitecore Data folder and try again.";
                    SizeLabel.Visible     = false;
                    PathPrefix.Visible    = false;
                    SizePrefix.Visible    = false;
                    OK.Visible            = false;
                    DownloadImage.Visible = false;
                    ErrorImage.Visible    = true;
                    return;
                }

                FileNameLabel.Text = showFullPath ? FileName : Path.GetFileName(FileName);
                SheerResponse.Download(FileName);
                Hidden.Value = "downloaded";
                var file = new FileInfo(FileName);
                SizeLabel.Text = ToFileSize(file.Length);
            }

            var caption = handle["cp"];

            Context.ClientPage.Title = caption;
            Assert.ArgumentNotNull(e, "e");
            base.OnLoad(e);
            Text.Text    = handle["te"];
            Hidden.Value = "cancelled";
            Context.ClientPage.ClientResponse.SetDialogValue(Hidden.Value);
            UrlHandle.DisposeHandle(handle);
        }