Facade class to provide intaraction with NuGet internals
コード例 #1
0
        /// <summary>
        /// Handles the Click event of the lbImport 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 lbImport_Click( object sender, EventArgs e )
        {
            var page = PageCache.Read( _pageId ?? 0 );
            if ( page != null )
            {
                var extension = fuImport.FileName.Substring( fuImport.FileName.LastIndexOf( '.' ) );

                if ( fuImport.PostedFile == null && extension != ".nupkg" )
                {
                    var errors = new List<string> { "Please attach an export file when trying to import a package." };
                    rptImportErrors.DataSource = errors;
                    rptImportErrors.DataBind();
                    rptImportErrors.Visible = true;
                    pnlImportSuccess.Visible = false;
                    return;
                }

                var packageService = new PackageService();
                bool importResult;

                importResult = packageService.ImportPage( fuImport.FileBytes, fuImport.FileName, page.Id, page.Layout.SiteId );

                if ( !importResult )
                {
                    rptImportErrors.DataSource = packageService.ErrorMessages;
                    rptImportErrors.DataBind();
                    rptImportErrors.Visible = true;
                    pnlImportSuccess.Visible = false;
                }
                else
                {
                    pnlImportSuccess.Visible = true;
                    rptImportWarnings.Visible = false;
                    rptImportErrors.Visible = false;

                    if ( packageService.WarningMessages.Count > 0 )
                    {
                        rptImportErrors.DataSource = packageService.WarningMessages;
                        rptImportErrors.DataBind();
                        rptImportWarnings.Visible = true;
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Handles the Click event of the lbExport 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 lbExport_Click( object sender, EventArgs e )
 {
     if ( _pageId.HasValue )
     {
         var pageService = new PageService( new RockContext() );
         var page = pageService.Get( _pageId.Value );
         var packageService = new PackageService();
         var pageName = page.InternalName.Replace( " ", "_" ) + ( cbExportChildren.Checked ? "_wChildPages" : string.Empty );
         using ( var stream = packageService.ExportPage( page, cbExportChildren.Checked ) )
         {
             EnableViewState = false;
             Response.Clear();
             Response.ContentType = "application/octet-stream";
             Response.AddHeader( "content-disposition", "attachment; filename=" + pageName + ".nupkg" );
             Response.Charset = string.Empty;
             Response.BinaryWrite( stream.ToArray() );
             Response.Flush();
             Response.End();
         }
     }
 }