/// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack)
            {
                ShowDetail(PageParameter("BinaryFileId").AsInteger(), PageParameter("BinaryFileTypeId").AsIntegerOrNull());

                ddlBinaryFileType.Visible = GetAttributeValue("ShowBinaryFileType").AsBoolean();
            }
            else
            {
                if (pnlDetails.Visible)
                {
                    var binaryFile = new BinaryFile {
                        BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt() ?? 0
                    };
                    if (binaryFile.BinaryFileTypeId > 0)
                    {
                        binaryFile.LoadAttributes();
                        phAttributes.Controls.Clear();
                        Rock.Attribute.Helper.AddEditControls(binaryFile, phAttributes, false, BlockValidationGroup);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Handles the FileUploaded event of the fsFile control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void fsFile_FileUploaded(object sender, EventArgs e)
        {
            using (new Rock.Data.UnitOfWorkScope())
            {
                var        binaryFileService = new BinaryFileService();
                BinaryFile binaryFile        = null;
                if (fsFile.BinaryFileId.HasValue)
                {
                    binaryFile = binaryFileService.Get(fsFile.BinaryFileId.Value);
                }

                if (binaryFile != null)
                {
                    if (!string.IsNullOrWhiteSpace(tbName.Text))
                    {
                        binaryFile.FileName = tbName.Text;
                    }

                    // set binaryFile.Id to original id since the UploadedFile is a temporary binaryFile with a different id
                    binaryFile.Id               = hfBinaryFileId.ValueAsInt();
                    binaryFile.Description      = tbDescription.Text;
                    binaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt();
                    if (binaryFile.BinaryFileTypeId.HasValue)
                    {
                        binaryFile.BinaryFileType = new BinaryFileTypeService().Get(binaryFile.BinaryFileTypeId.Value);
                    }

                    binaryFile.LoadAttributes();
                    Rock.Attribute.Helper.GetEditValues(phAttributes, binaryFile);

                    // Process uploaded file using an optional workflow
                    Guid workflowTypeGuid = Guid.NewGuid();
                    if (Guid.TryParse(GetAttributeValue("Workflow"), out workflowTypeGuid))
                    {
                        var workflowTypeService = new WorkflowTypeService();
                        var workflowType        = workflowTypeService.Get(workflowTypeGuid);
                        if (workflowType != null)
                        {
                            var workflow = Workflow.Activate(workflowType, binaryFile.FileName);

                            List <string> workflowErrors;
                            if (workflow.Process(binaryFile, out workflowErrors))
                            {
                                binaryFile = binaryFileService.Get(binaryFile.Id);

                                if (workflowType.IsPersisted)
                                {
                                    var workflowService = new Rock.Model.WorkflowService();
                                    workflowService.Add(workflow, CurrentPersonId);
                                    workflowService.Save(workflow, CurrentPersonId);
                                }
                            }
                        }
                    }

                    ShowBinaryFileDetail(binaryFile);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack)
            {
                string itemId = PageParameter("BinaryFileId");
                string typeId = PageParameter("BinaryFileTypeId");
                if (!string.IsNullOrWhiteSpace(itemId))
                {
                    if (string.IsNullOrWhiteSpace(typeId))
                    {
                        ShowDetail("BinaryFileId", int.Parse(itemId));
                    }
                    else
                    {
                        ShowDetail("BinaryFileId", int.Parse(itemId), int.Parse(typeId));
                    }
                }
                else
                {
                    pnlDetails.Visible = false;
                }

                bool showBinaryFileType = false;
                if (Boolean.TryParse(GetAttributeValue("ShowBinaryFileType"), out showBinaryFileType) && showBinaryFileType)
                {
                    ddlBinaryFileType.Visible = true;
                }
                else
                {
                    ddlBinaryFileType.Visible = false;
                }
            }
            else
            {
                if (pnlDetails.Visible)
                {
                    var binaryFile = new BinaryFile {
                        BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt() ?? 0
                    };
                    if (binaryFile.BinaryFileTypeId > 0)
                    {
                        binaryFile.LoadAttributes();
                        phAttributes.Controls.Clear();
                        Rock.Attribute.Helper.AddEditControls(binaryFile, phAttributes, false);
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            BinaryFile        BinaryFile;
            BinaryFileService BinaryFileService = new BinaryFileService();
            AttributeService  attributeService  = new AttributeService();

            int BinaryFileId = int.Parse(hfBinaryFileId.Value);

            if (BinaryFileId == 0)
            {
                BinaryFile = new BinaryFile();
                BinaryFileService.Add(BinaryFile, CurrentPersonId);
            }
            else
            {
                BinaryFile = BinaryFileService.Get(BinaryFileId);
            }

            BinaryFile.IsTemporary      = false;
            BinaryFile.FileName         = tbName.Text;
            BinaryFile.Description      = tbDescription.Text;
            BinaryFile.MimeType         = tbMimeType.Text;
            BinaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt();

            BinaryFile.LoadAttributes();
            Rock.Attribute.Helper.GetEditValues(phAttributes, BinaryFile);

            if (!Page.IsValid)
            {
                return;
            }

            if (!BinaryFile.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            RockTransactionScope.WrapTransaction(() =>
            {
                BinaryFileService.Save(BinaryFile, CurrentPersonId);
                Rock.Attribute.Helper.SaveAttributeValues(BinaryFile, CurrentPersonId);
            });

            NavigateToParentPage();
        }
Exemple #5
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="binaryFile">The binary file.</param>
        public void ShowBinaryFileDetail(BinaryFile binaryFile)
        {
            pnlDetails.Visible = true;
            hfBinaryFileId.SetValue(binaryFile.Id);

            if (binaryFile.BinaryFileTypeId.HasValue)
            {
                fsFile.BinaryFileTypeGuid = new BinaryFileTypeService().Get(binaryFile.BinaryFileTypeId ?? 0).Guid;
            }

            tbName.Text        = binaryFile.FileName;
            tbDescription.Text = binaryFile.Description;
            tbMimeType.Text    = binaryFile.MimeType;
            ddlBinaryFileType.SetValue(binaryFile.BinaryFileTypeId);

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized("Edit"))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(BinaryFile.FriendlyTypeName);
            }

            phAttributes.Controls.Clear();
            binaryFile.LoadAttributes();

            if (readOnly)
            {
                lActionTitle.Text = ActionTitle.View(BinaryFile.FriendlyTypeName);
                btnCancel.Text    = "Close";
                Rock.Attribute.Helper.AddDisplayControls(binaryFile, phAttributes);
            }
            else
            {
                Rock.Attribute.Helper.AddEditControls(binaryFile, phAttributes, true);
            }

            tbName.ReadOnly           = readOnly;
            tbDescription.ReadOnly    = readOnly;
            tbMimeType.ReadOnly       = readOnly;
            ddlBinaryFileType.Enabled = !readOnly;

            btnSave.Visible = !readOnly;
        }
Exemple #6
0
        /// <summary>
        /// Handles the FileUploaded event of the fsFile control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void fsFile_FileUploaded(object sender, EventArgs e)
        {
            var        rockContext       = new RockContext();
            var        binaryFileService = new BinaryFileService(rockContext);
            BinaryFile binaryFile        = null;

            if (fsFile.BinaryFileId.HasValue)
            {
                binaryFile = binaryFileService.Get(fsFile.BinaryFileId.Value);
            }

            if (binaryFile != null)
            {
                if (!string.IsNullOrWhiteSpace(tbName.Text))
                {
                    binaryFile.FileName = tbName.Text;
                }

                // set binaryFile.Id to original id since the UploadedFile is a temporary binaryFile with a different id
                binaryFile.Id               = hfBinaryFileId.ValueAsInt();
                binaryFile.Description      = tbDescription.Text;
                binaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt();
                if (binaryFile.BinaryFileTypeId.HasValue)
                {
                    binaryFile.BinaryFileType = new BinaryFileTypeService(rockContext).Get(binaryFile.BinaryFileTypeId.Value);
                }

                var tempList = OrphanedBinaryFileIdList;
                tempList.Add(fsFile.BinaryFileId.Value);
                OrphanedBinaryFileIdList = tempList;

                // load attributes, then get the attribute values from the UI
                binaryFile.LoadAttributes();
                Rock.Attribute.Helper.GetEditValues(phAttributes, binaryFile);

                LaunchFileUploadWorkflow(binaryFile, binaryFileService);

                ShowBinaryFileDetail(binaryFile);
            }
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad( EventArgs e )
        {
            base.OnLoad( e );

            if ( !Page.IsPostBack )
            {
                string itemId = PageParameter( "BinaryFileId" );
                string typeId = PageParameter( "BinaryFileTypeId" );
                if ( !string.IsNullOrWhiteSpace( itemId ) )
                {
                    if ( string.IsNullOrWhiteSpace( typeId ) )
                    {
                        ShowDetail( "BinaryFileId", int.Parse( itemId ) );
                    }
                    else
                    {
                        ShowDetail( "BinaryFileId", int.Parse( itemId ), int.Parse( typeId ) );
                    }
                }
                else
                {
                    pnlDetails.Visible = false;
                }

                ddlBinaryFileType.Visible = GetAttributeValue( "ShowBinaryFileType" ).AsBoolean();
            }
            else
            {
                if ( pnlDetails.Visible )
                {
                    var binaryFile = new BinaryFile { BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt() ?? 0 };
                    if ( binaryFile.BinaryFileTypeId > 0 )
                    {
                        binaryFile.LoadAttributes();
                        phAttributes.Controls.Clear();
                        Rock.Attribute.Helper.AddEditControls( binaryFile, phAttributes, false );
                    }
                }
            }
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad( EventArgs e )
        {
            base.OnLoad( e );

            if ( !Page.IsPostBack )
            {
                ShowDetail( PageParameter( "BinaryFileId" ).AsInteger(), PageParameter( "BinaryFileTypeId" ).AsIntegerOrNull() );

                ddlBinaryFileType.Visible = GetAttributeValue( "ShowBinaryFileType" ).AsBoolean();
            }
            else
            {
                if ( pnlDetails.Visible )
                {
                    var binaryFile = new BinaryFile { BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt() ?? 0 };
                    if ( binaryFile.BinaryFileTypeId > 0 )
                    {
                        binaryFile.LoadAttributes();
                        phAttributes.Controls.Clear();
                        Rock.Attribute.Helper.AddEditControls( binaryFile, phAttributes, false, BlockValidationGroup );
                    }
                }
            }
        }
        /// <summary>
        /// Handles the FileUploaded event of the fsFile control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void fsFile_FileUploaded(object sender, EventArgs e)
        {
            var        rockContext       = new RockContext();
            var        binaryFileService = new BinaryFileService(rockContext);
            BinaryFile binaryFile        = null;

            if (fsFile.BinaryFileId.HasValue)
            {
                binaryFile = binaryFileService.Get(fsFile.BinaryFileId.Value);
            }

            if (binaryFile != null)
            {
                if (!string.IsNullOrWhiteSpace(tbName.Text))
                {
                    binaryFile.FileName = tbName.Text;
                }

                // set binaryFile.Id to original id since the UploadedFile is a temporary binaryFile with a different id
                binaryFile.Id               = hfBinaryFileId.ValueAsInt();
                binaryFile.Description      = tbDescription.Text;
                binaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt();
                if (binaryFile.BinaryFileTypeId.HasValue)
                {
                    binaryFile.BinaryFileType = new BinaryFileTypeService(rockContext).Get(binaryFile.BinaryFileTypeId.Value);
                }

                var tempList = OrphanedBinaryFileIdList;
                tempList.Add(fsFile.BinaryFileId.Value);
                OrphanedBinaryFileIdList = tempList;

                // load attributes, then get the attribute values from the UI
                binaryFile.LoadAttributes();
                Rock.Attribute.Helper.GetEditValues(phAttributes, binaryFile);

                // Process uploaded file using an optional workflow (which will probably populate attribute values)
                Guid workflowTypeGuid = Guid.NewGuid();
                if (Guid.TryParse(GetAttributeValue("Workflow"), out workflowTypeGuid))
                {
                    try
                    {
                        // temporarily set the binaryFile.Id to the uploaded binaryFile.Id so that workflow can do stuff with it
                        binaryFile.Id = fsFile.BinaryFileId ?? 0;

                        // create a rockContext for the workflow so that it can save it's changes, without
                        var workflowRockContext = new RockContext();
                        var workflowTypeService = new WorkflowTypeService(workflowRockContext);
                        var workflowType        = workflowTypeService.Get(workflowTypeGuid);
                        if (workflowType != null)
                        {
                            var workflow = Workflow.Activate(workflowType, binaryFile.FileName);

                            List <string> workflowErrors;
                            if (new Rock.Model.WorkflowService(workflowRockContext).Process(workflow, binaryFile, out workflowErrors))
                            {
                                binaryFile = binaryFileService.Get(binaryFile.Id);
                            }
                        }
                    }
                    finally
                    {
                        // set binaryFile.Id to original id again since the UploadedFile is a temporary binaryFile with a different id
                        binaryFile.Id = hfBinaryFileId.ValueAsInt();
                    }
                }

                ShowBinaryFileDetail(binaryFile);
            }
        }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="binaryFile">The binary file.</param>
        public void ShowBinaryFileDetail( BinaryFile binaryFile )
        {
            pnlDetails.Visible = true;
            hfBinaryFileId.SetValue( binaryFile.Id );
            
            if ( binaryFile.BinaryFileTypeId.HasValue )
            {
                fsFile.BinaryFileTypeGuid = new BinaryFileTypeService().Get( binaryFile.BinaryFileTypeId ?? 0).Guid;
            }

            tbName.Text = binaryFile.FileName;
            tbDescription.Text = binaryFile.Description;
            tbMimeType.Text = binaryFile.MimeType;
            ddlBinaryFileType.SetValue( binaryFile.BinaryFileTypeId );

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if ( !IsUserAuthorized( "Edit" ) )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( BinaryFile.FriendlyTypeName );
            }

            phAttributes.Controls.Clear();
            binaryFile.LoadAttributes();

            if ( readOnly )
            {
                lActionTitle.Text = ActionTitle.View( BinaryFile.FriendlyTypeName );
                btnCancel.Text = "Close";
                Rock.Attribute.Helper.AddDisplayControls( binaryFile, phAttributes );
            }
            else
            {
                Rock.Attribute.Helper.AddEditControls( binaryFile, phAttributes, true );
            }

            tbName.ReadOnly = readOnly;
            tbDescription.ReadOnly = readOnly;
            tbMimeType.ReadOnly = readOnly;
            ddlBinaryFileType.Enabled = !readOnly;

            btnSave.Visible = !readOnly;
        }