当前位置: 首页>>代码示例>>C#>>正文


C# Dictionary.AddOrReplace方法代码示例

本文整理汇总了C#中Dictionary.AddOrReplace方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.AddOrReplace方法的具体用法?C# Dictionary.AddOrReplace怎么用?C# Dictionary.AddOrReplace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dictionary的用法示例。


在下文中一共展示了Dictionary.AddOrReplace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BalanceSheet

        public BalanceSheet(IEnumerable<OrderedBalanceChange> changes, ChainBase chain)
        {
            if (chain == null)
                throw new ArgumentNullException("chain");
            _Chain = chain;

            var all = changes
                        .Where(c => c.SpentCoins != null) //Remove line whose previous coins have not been loadedcould not be deduced
                        .Where(c => c.MempoolEntry || chain.GetBlock(c.BlockId) != null) //Take only mempool entry, or confirmed one
                        .Where(c => !(c.IsCoinbase && c.MempoolEntry)) //There is no such thing as a Coinbase unconfirmed, by definition a coinbase appear in a block
                        .ToList(); 
            var confirmed = all.Where(o => o.BlockId != null).ToDictionary(o => o.TransactionId);
            Dictionary<uint256, OrderedBalanceChange> unconfirmed = new Dictionary<uint256, OrderedBalanceChange>();

            foreach(var item in all.Where(o => o.MempoolEntry && !confirmed.ContainsKey(o.TransactionId)))
            {
                unconfirmed.AddOrReplace(item.TransactionId, item);
            }

            _Prunable = all.Where(o => o.BlockId == null && confirmed.ContainsKey(o.TransactionId)).ToList();
            _All = all.Where(o => 
                (unconfirmed.ContainsKey(o.TransactionId) || confirmed.ContainsKey(o.TransactionId)) 
                    &&
                    !(o.BlockId == null && confirmed.ContainsKey(o.TransactionId))
                ).ToList();
            _Confirmed = _All.Where(o => o.BlockId != null && confirmed.ContainsKey(o.TransactionId)).ToList();
            _Unconfirmed = _All.Where(o => o.BlockId == null && unconfirmed.ContainsKey(o.TransactionId)).ToList();
        }
开发者ID:bijakatlykkex,项目名称:NBitcoin.Indexer,代码行数:28,代码来源:BalanceSheet.cs

示例2: ParseScript

		public static Script ParseScript(string s)
		{
			MemoryStream result = new MemoryStream();
			if(mapOpNames.Count == 0)
			{
				mapOpNames = new Dictionary<string, OpcodeType>(Op._OpcodeByName);
				foreach(var kv in mapOpNames.ToArray())
				{
					if(kv.Key.StartsWith("OP_", StringComparison.Ordinal))
					{
						var name = kv.Key.Substring(3, kv.Key.Length - 3);
						mapOpNames.AddOrReplace(name, kv.Value);
					}
				}
			}

			var words = s.Split(' ', '\t', '\n');

			foreach(string w in words)
			{
				if(w == "")
					continue;
				if(w.All(l => l.IsDigit()) ||
					(w.StartsWith("-") && w.Substring(1).All(l => l.IsDigit())))
				{

					// Number
					long n = long.Parse(w);
					Op.GetPushOp(new BigInteger(n)).WriteTo(result);
				}
				else if(w.StartsWith("0x") && HexEncoder.IsWellFormed(w.Substring(2)))
				{
					// Raw hex data, inserted NOT pushed onto stack:
					var raw = Encoders.Hex.DecodeData(w.Substring(2));
					result.Write(raw, 0, raw.Length);
				}
				else if(w.Length >= 2 && w.StartsWith("'") && w.EndsWith("'"))
				{
					// Single-quoted string, pushed as data. NOTE: this is poor-man's
					// parsing, spaces/tabs/newlines in single-quoted strings won't work.
					var b = TestUtils.ToBytes(w.Substring(1, w.Length - 2));
					Op.GetPushOp(b).WriteTo(result);
				}
				else if(mapOpNames.ContainsKey(w))
				{
					// opcode, e.g. OP_ADD or ADD:
					result.WriteByte((byte)mapOpNames[w]);
				}
				else
				{
					Assert.True(false, "Invalid test");
					return null;
				}
			}

			return new Script(result.ToArray());
		}
开发者ID:knocte,项目名称:NBitcoin,代码行数:57,代码来源:script_tests.cs

示例3: EquipmentSets

		static EquipmentSets()
		{
			CMOptions = new EquipmentSetsOptions();

			SetTypes = TypeOfEquipmentSet.GetConstructableChildren();

			Sets = new Dictionary<Type, EquipmentSet>(SetTypes.Length);

			foreach (var t in SetTypes)
			{
				Sets.AddOrReplace(t, set => set ?? t.CreateInstanceSafe<EquipmentSet>());
			}
		}
开发者ID:Ravenwolfe,项目名称:Core,代码行数:13,代码来源:EquipmentSets_Init.cs

示例4: BindGrid

        /// <summary>
        /// Shows the preview.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="gReport">The g report.</param>
        /// <param name="currentPerson">The current person.</param>
        /// <param name="databaseTimeoutSeconds">The database timeout seconds.</param>
        /// <param name="errorMessage">The error message.</param>
        public static void BindGrid( Report report, Grid gReport, Person currentPerson, int? databaseTimeoutSeconds, out string errorMessage )
        {
            errorMessage = null;
            if ( report != null )
            {
                var errors = new List<string>();

                if ( !report.EntityTypeId.HasValue )
                {
                    gReport.Visible = false;
                    return;
                }

                var rockContext = new RockContext();

                if ( !report.IsAuthorized( Authorization.VIEW, currentPerson ) )
                {
                    gReport.Visible = false;
                    return;
                }

                Type entityType = EntityTypeCache.Read( report.EntityTypeId.Value, rockContext ).GetEntityType();
                if ( entityType == null )
                {
                    errorMessage = string.Format( "Unable to determine entityType for {0}", report.EntityType );
                    return;
                }

                gReport.EntityTypeId = report.EntityTypeId;

                bool isPersonDataSet = report.EntityTypeId == EntityTypeCache.Read( typeof( Rock.Model.Person ), true, rockContext ).Id;

                if ( isPersonDataSet )
                {
                    gReport.PersonIdField = "Id";
                    gReport.DataKeyNames = new string[] { "Id" };
                }
                else
                {
                    gReport.PersonIdField = null;
                }

                if ( report.EntityTypeId.HasValue )
                {
                    gReport.RowItemText = EntityTypeCache.Read( report.EntityTypeId.Value, rockContext ).FriendlyName;
                }

                List<EntityField> entityFields = Rock.Reporting.EntityHelper.GetEntityFields( entityType, true, false );

                var selectedEntityFields = new Dictionary<int, EntityField>();
                var selectedAttributes = new Dictionary<int, AttributeCache>();
                var selectedComponents = new Dictionary<int, ReportField>();

                // if there is a selectField, keep it to preserve which items are checked
                var selectField = gReport.Columns.OfType<SelectField>().FirstOrDefault();
                gReport.Columns.Clear();
                int columnIndex = 0;

                if ( !string.IsNullOrWhiteSpace( gReport.PersonIdField ) )
                {
                    // if we already had a selectField, use it (to preserve checkbox state)
                    gReport.Columns.Add( selectField ?? new SelectField() );
                    columnIndex++;
                }

                var reportFieldSortExpressions = new Dictionary<Guid, string>();

                foreach ( var reportField in report.ReportFields.OrderBy( a => a.ColumnOrder ) )
                {
                    columnIndex++;
                    if ( reportField.ReportFieldType == ReportFieldType.Property )
                    {
                        var entityField = entityFields.FirstOrDefault( a => a.Name == reportField.Selection );
                        if ( entityField != null )
                        {
                            selectedEntityFields.Add( columnIndex, entityField );

                            BoundField boundField = entityField.GetBoundFieldType();
                            boundField.DataField = string.Format( "Entity_{0}_{1}", entityField.Name, columnIndex );
                            boundField.HeaderText = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? entityField.Title : reportField.ColumnHeaderText;
                            boundField.SortExpression = boundField.DataField;
                            reportFieldSortExpressions.AddOrReplace( reportField.Guid, boundField.SortExpression );
                            boundField.Visible = reportField.ShowInGrid;
                            gReport.Columns.Add( boundField );
                        }
                    }
                    else if ( reportField.ReportFieldType == ReportFieldType.Attribute )
                    {
                        Guid? attributeGuid = reportField.Selection.AsGuidOrNull();
                        if ( attributeGuid.HasValue )
                        {
                            var attribute = AttributeCache.Read( attributeGuid.Value, rockContext );
//.........这里部分代码省略.........
开发者ID:NewSpring,项目名称:Rock,代码行数:101,代码来源:ReportingHelper.cs

示例5: LoadChart

        /// <summary>
        /// Loads the chart.
        /// </summary>
        public void LoadChart()
        {
            lcAttendance.ShowTooltip = true;
            if ( this.DetailPageGuid.HasValue )
            {
                lcAttendance.ChartClick += lcAttendance_ChartClick;
            }

            var dataSourceUrl = "~/api/Attendances/GetChartData";
            var dataSourceParams = new Dictionary<string, object>();
            var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues( drpSlidingDateRange.DelimitedValues );

            if ( dateRange.Start.HasValue )
            {
                dataSourceParams.AddOrReplace( "startDate", dateRange.Start.Value.ToString( "o" ) );
            }

            if ( dateRange.End.HasValue )
            {
                dataSourceParams.AddOrReplace( "endDate", dateRange.End.Value.ToString( "o" ) );
            }

            var groupBy = hfGroupBy.Value.ConvertToEnumOrNull<AttendanceGroupBy>() ?? AttendanceGroupBy.Week;
            lcAttendance.TooltipFormatter = null;
            switch ( groupBy )
            {
                case AttendanceGroupBy.Week:
                    {
                        lcAttendance.Options.xaxis.tickSize = new string[] { "7", "day" };
                        lcAttendance.TooltipFormatter = @"
            function(item) {
            var itemDate = new Date(item.series.chartData[item.dataIndex].DateTimeStamp);
            var dateText = 'Weekend of <br />' + itemDate.toLocaleDateString();
            var seriesLabel = item.series.label;
            var pointValue = item.series.chartData[item.dataIndex].YValue || item.series.chartData[item.dataIndex].YValueTotal;
            return dateText + '<br />' + seriesLabel + ': ' + pointValue;
            }
            ";
                    }

                    break;
                case AttendanceGroupBy.Month:
                    {
                        lcAttendance.Options.xaxis.tickSize = new string[] { "1", "month" };
                        lcAttendance.TooltipFormatter = @"
            function(item) {
            var month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
            var itemDate = new Date(item.series.chartData[item.dataIndex].DateTimeStamp);
            var dateText = month_names[itemDate.getMonth()] + ' ' + itemDate.getFullYear();
            var seriesLabel = item.series.label;
            var pointValue = item.series.chartData[item.dataIndex].YValue || item.series.chartData[item.dataIndex].YValueTotal;
            return dateText + '<br />' + seriesLabel + ': ' + pointValue;
            }
            ";
                    }

                    break;
                case AttendanceGroupBy.Year:
                    {
                        lcAttendance.Options.xaxis.tickSize = new string[] { "1", "year" };
                        lcAttendance.TooltipFormatter = @"
            function(item) {
            var itemDate = new Date(item.series.chartData[item.dataIndex].DateTimeStamp);
            var dateText = itemDate.getFullYear();
            var seriesLabel = item.series.label;
            var pointValue = item.series.chartData[item.dataIndex].YValue || item.series.chartData[item.dataIndex].YValueTotal;
            return dateText + '<br />' + seriesLabel + ': ' + pointValue;
            }
            ";
                    }

                    break;
            }

            dataSourceParams.AddOrReplace( "groupBy", hfGroupBy.Value.AsInteger() );
            dataSourceParams.AddOrReplace( "graphBy", hfGraphBy.Value.AsInteger() );

            dataSourceParams.AddOrReplace( "campusIds", cpCampuses.SelectedCampusIds.AsDelimited( "," ) );
            dataSourceParams.AddOrReplace( "groupIds", GetSelectedGroupIds().AsDelimited( "," ) );

            SaveSettingsToUserPreferences();

            dataSourceUrl += "?" + dataSourceParams.Select( s => string.Format( "{0}={1}", s.Key, s.Value ) ).ToList().AsDelimited( "&" );

            lcAttendance.DataSourceUrl = this.ResolveUrl( dataSourceUrl );

            if ( pnlGrid.Visible )
            {
                BindGrid();
            }
        }
开发者ID:Ganon11,项目名称:Rock,代码行数:94,代码来源:AttendanceReporting.ascx.cs

示例6: LoadChartAndGrids

        /// <summary>
        /// Loads the chart and any visible grids
        /// </summary>
        public void LoadChartAndGrids()
        {
            pnlUpdateMessage.Visible = false;
            pnlResults.Visible = true;

            lcAttendance.ShowTooltip = true;
            if ( this.DetailPageGuid.HasValue )
            {
                lcAttendance.ChartClick += lcAttendance_ChartClick;
            }

            bcAttendance.ShowTooltip = true;
            if ( this.DetailPageGuid.HasValue )
            {
                bcAttendance.ChartClick += lcAttendance_ChartClick;
            }

            var lineChartDataSourceUrl = "~/api/Attendances/GetChartData";
            var dataSourceParams = new Dictionary<string, object>();
            var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues( drpSlidingDateRange.DelimitedValues );

            if ( !dateRange.Start.HasValue || !dateRange.End.HasValue )
            {
                nbDateRangeWarning.Visible = true;
                return;
            }

            nbDateRangeWarning.Visible = false;

            if ( dateRange.Start.HasValue )
            {
                dataSourceParams.AddOrReplace( "startDate", dateRange.Start.Value.ToString( "o" ) );
            }

            if ( dateRange.End.HasValue )
            {
                dataSourceParams.AddOrReplace( "endDate", dateRange.End.Value.ToString( "o" ) );
            }

            var groupBy = hfGroupBy.Value.ConvertToEnumOrNull<ChartGroupBy>() ?? ChartGroupBy.Week;
            lcAttendance.TooltipFormatter = null;
            switch ( groupBy )
            {
                case ChartGroupBy.Week:
                    {
                        lcAttendance.Options.xaxis.tickSize = new string[] { "7", "day" };
                        lcAttendance.TooltipFormatter = @"
            function(item) {
            var itemDate = new Date(item.series.chartData[item.dataIndex].DateTimeStamp);
            var dateText = 'Weekend of <br />' + itemDate.toLocaleDateString();
            var seriesLabel = item.series.label || ( item.series.labels ? item.series.labels[item.dataIndex] : null );
            var pointValue = item.series.chartData[item.dataIndex].YValue || item.series.chartData[item.dataIndex].YValueTotal || '-';
            return dateText + '<br />' + seriesLabel + ': ' + pointValue;
            }
            ";
                    }

                    break;

                case ChartGroupBy.Month:
                    {
                        lcAttendance.Options.xaxis.tickSize = new string[] { "1", "month" };
                        lcAttendance.TooltipFormatter = @"
            function(item) {
            var month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
            var itemDate = new Date(item.series.chartData[item.dataIndex].DateTimeStamp);
            var dateText = month_names[itemDate.getMonth()] + ' ' + itemDate.getFullYear();
            var seriesLabel = item.series.label || ( item.series.labels ? item.series.labels[item.dataIndex] : null );
            var pointValue = item.series.chartData[item.dataIndex].YValue || item.series.chartData[item.dataIndex].YValueTotal || '-';
            return dateText + '<br />' + seriesLabel + ': ' + pointValue;
            }
            ";
                    }

                    break;

                case ChartGroupBy.Year:
                    {
                        lcAttendance.Options.xaxis.tickSize = new string[] { "1", "year" };
                        lcAttendance.TooltipFormatter = @"
            function(item) {
            var itemDate = new Date(item.series.chartData[item.dataIndex].DateTimeStamp);
            var dateText = itemDate.getFullYear();
            var seriesLabel = item.series.label || ( item.series.labels ? item.series.labels[item.dataIndex] : null );
            var pointValue = item.series.chartData[item.dataIndex].YValue || item.series.chartData[item.dataIndex].YValueTotal || '-';
            return dateText + '<br />' + seriesLabel + ': ' + pointValue;
            }
            ";
                    }

                    break;
            }

            string groupByTextPlural = groupBy.ConvertToString().ToLower().Pluralize();
            lPatternXFor.Text = string.Format( " {0} for the selected date range", groupByTextPlural );
            lPatternAndMissedXBetween.Text = string.Format( " {0} between", groupByTextPlural );

//.........这里部分代码省略.........
开发者ID:RMRDevelopment,项目名称:Rockit,代码行数:101,代码来源:AttendanceAnalytics.ascx.cs

示例7: FilterValueControl

 /// <summary>
 /// Gets the filter value control.
 /// </summary>
 /// <param name="configurationValues">The configuration values.</param>
 /// <param name="id">The identifier.</param>
 /// <param name="required">if set to <c>true</c> [required].</param>
 /// <returns></returns>
 public override Control FilterValueControl( Dictionary<string, ConfigurationValue> configurationValues, string id, bool required )
 {
     var overrideConfigValues = new Dictionary<string, ConfigurationValue>();
     foreach ( var keyVal in configurationValues )
     {
         overrideConfigValues.Add( keyVal.Key, keyVal.Value );
     }
     overrideConfigValues.AddOrReplace( ALLOW_MULTIPLE_KEY, new ConfigurationValue( "false" ) );
     
     return  base.FilterValueControl( overrideConfigValues, id, required );
 }
开发者ID:tcavaletto,项目名称:Rock-CentralAZ,代码行数:18,代码来源:AttributeFieldType.cs

示例8: ParseMarkup

        /// <summary>
        /// Parses the markup.
        /// </summary>
        /// <param name="markup">The markup.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">No parameters were found in your command. The syntax for a parameter is parmName:'' (note that you must use single quotes).</exception>
        private Dictionary<string, string> ParseMarkup( string markup, Context context )
        {
            // first run lava across the inputted markup
            var internalMergeFields = new Dictionary<string, object>();

            // get variables defined in the lava source
            foreach ( var scope in context.Scopes )
            {
                foreach ( var item in scope )
                {
                    internalMergeFields.AddOrReplace( item.Key, item.Value );
                }
            }

            // get merge fields loaded by the block or container
            if ( context.Environments.Count > 0 )
            {
                foreach ( var item in context.Environments[0] )
                {
                    internalMergeFields.AddOrReplace( item.Key, item.Value );
                }
            }
            var resolvedMarkup = markup.ResolveMergeFields( internalMergeFields );

            var parms = new Dictionary<string, string>();
            parms.Add( "iterator", "results" );

            var markupItems = Regex.Matches( resolvedMarkup, "(.*?:'[^']+')" )
                .Cast<Match>()
                .Select( m => m.Value )
                .ToList();

            if ( markupItems.Count == 0 )
            {
                throw new Exception( "No parameters were found in your command. The syntax for a parameter is parmName:'' (note that you must use single quotes)." );
            }

            foreach ( var item in markupItems )
            {
                var itemParts = item.ToString().Split( new char[] { ':' }, 2 );
                if ( itemParts.Length > 1 )
                {
                    parms.AddOrReplace( itemParts[0].Trim().ToLower(), itemParts[1].Trim().Substring( 1, itemParts[1].Length - 2 ) );
                }
            }
            return parms;
        }
开发者ID:NewSpring,项目名称:Rock,代码行数:54,代码来源:Search.cs

示例9: OnInit


//.........这里部分代码省略.........
                            site.RedirectToLoginPage( true );
                        }
                        else
                        {
                            FormsAuthentication.RedirectToLoginPage();
                        }
                    }
                    else
                    {
                        // If not authorized, and the user has logged in, redirect to error page
                        Page.Trace.Warn( "Redirecting to error page" );

                        Response.Redirect( "~/error.aspx?type=security", false );
                        Context.ApplicationInstance.CompleteRequest();
                    }
                }
                else
                {
                    // Set current models (context)
                    Page.Trace.Warn( "Checking for Context" );
                    ModelContext = new Dictionary<string, Data.KeyEntity>();
                    try
                    {

                        // first search cookies, but pageContext can replace it
                        GetCookieContext( GetContextCookieName( false ) );      // Site
                        GetCookieContext( GetContextCookieName( true ) );       // Page (will replace any site values)

                        foreach ( var pageContext in _pageCache.PageContexts )
                        {
                            int? contextId = PageParameter( pageContext.Value ).AsIntegerOrNull();
                            if ( contextId.HasValue )
                            {
                                ModelContext.AddOrReplace( pageContext.Key, new Data.KeyEntity( contextId.Value ) );
                            }
                        }

                        char[] delim = new char[1] { ',' };
                        foreach ( string param in PageParameter( "context", true ).Split( delim, StringSplitOptions.RemoveEmptyEntries ) )
                        {
                            string contextItem = Rock.Security.Encryption.DecryptString( param );
                            string[] parts = contextItem.Split( '|' );
                            if ( parts.Length == 2 )
                            {
                                ModelContext.AddOrReplace( parts[0], new Data.KeyEntity( parts[1] ) );
                            }
                        }

                    }
                    catch
                    {
                        // intentionally ignore exception
                    }

                    // set viewstate on/off
                    this.EnableViewState = _pageCache.EnableViewState;

                    // Cache object used for block output caching
                    Page.Trace.Warn( "Getting memory cache" );
                    ObjectCache cache = MemoryCache.Default;

                    Page.Trace.Warn( "Checking if user can administer" );
                    bool canAdministratePage = _pageCache.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson );

                    // Create a javascript object to store information about the current page for client side scripts to use
                    Page.Trace.Warn( "Creating JS objects" );
开发者ID:Ganon11,项目名称:Rock,代码行数:67,代码来源:RockPage.cs

示例10: GetInChain

        //Do not get all entries, but only the one you can generate with spent/unspent.
        public AccountEntry[] GetInChain(Chain chain, bool value)
        {
            Dictionary<OutPoint, AccountEntry> entries = new Dictionary<OutPoint, AccountEntry>();
            foreach(var entry in AccountEntries)
            {
                if(entry.Block == null)
                    continue;

                if(chain.Contains(entry.Block, false) == value)
                {
                    if(entry.Reason == AccountEntryReason.Income && _Unspent.ContainsKey(entry.Spendable.OutPoint))
                        entries.AddOrReplace(entry.Spendable.OutPoint, entry);
                    if(entry.Reason == AccountEntryReason.ChainBlockChanged && !_Unspent.ContainsKey(entry.Spendable.OutPoint))
                        entries.AddOrReplace(entry.Spendable.OutPoint, entry);
                }
            }
            return entries.Values.ToArray();
        }
开发者ID:royosherove,项目名称:NBitcoin,代码行数:19,代码来源:Account.cs

示例11: ShowView

        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void ShowView()
        {
            nbContentError.Visible = false;
            upnlContent.Update();

            var pageRef = CurrentPageReference;
            pageRef.Parameters.AddOrReplace( "Page", "PageNum" );

            Dictionary<string, object> linkedPages = new Dictionary<string, object>();
            linkedPages.Add( "DetailPage", LinkedPageRoute( "DetailPage" ) );

            var errorMessages = new List<string>();
            List<ContentChannelItem> content;
            try
            {
                content = GetContent( errorMessages ) ?? new List<ContentChannelItem>();
            }
            catch (Exception ex)
            {
                this.LogException( ex );
                Exception exception = ex;
                while ( exception != null )
                {
                    errorMessages.Add( exception.Message );
                    exception = exception.InnerException;
                }
                
                content = new List<ContentChannelItem>();
            }

            if (errorMessages.Any())
            {
                nbContentError.Text = "ERROR: There was a problem getting content...<br/> ";
                nbContentError.NotificationBoxType = NotificationBoxType.Danger;
                nbContentError.Details = errorMessages.AsDelimited( "<br/>" );
                nbContentError.Visible = true;
            }

            var pagination = new Pagination();
            pagination.ItemCount = content.Count();
            pagination.PageSize = GetAttributeValue( "Count" ).AsInteger();
            pagination.CurrentPage = PageParameter( "Page" ).AsIntegerOrNull() ?? 1;
            pagination.UrlTemplate = pageRef.BuildUrl();
            var currentPageContent = pagination.GetCurrentPageItems( content );

            var commonMergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( this.RockPage, this.CurrentPerson );

            // Merge content and attribute fields if block is configured to do so.
            if ( GetAttributeValue( "MergeContent" ).AsBoolean() )
            {
                var itemMergeFields = new Dictionary<string, object>();
                if ( CurrentPerson != null )
                {
                    // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line
                    itemMergeFields.Add( "Person", CurrentPerson );
                }

                commonMergeFields.ToList().ForEach( d => itemMergeFields.Add( d.Key, d.Value ) );

                foreach ( var item in currentPageContent )
                {
                    itemMergeFields.AddOrReplace( "Item", item );
                    var enabledCommands = GetAttributeValue( "EnabledLavaCommands" );
                    item.Content = item.Content.ResolveMergeFields( itemMergeFields, enabledCommands );

                    foreach ( var attributeValue in item.AttributeValues )
                    {
                        attributeValue.Value.Value = attributeValue.Value.Value.ResolveMergeFields( itemMergeFields, enabledCommands );
                    }
                }
            }

            var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( this.RockPage, this.CurrentPerson );
            mergeFields.Add( "Pagination", pagination );
            mergeFields.Add( "LinkedPages", linkedPages );
            mergeFields.Add( "Items", currentPageContent );
            mergeFields.Add( "RockVersion", Rock.VersionInfo.VersionInfo.GetRockProductVersionNumber() );

            // enable showing debug info
            if ( GetAttributeValue( "EnableDebug" ).AsBoolean() && IsUserAuthorized( Authorization.EDIT ) )
            {
                mergeFields["Items"] = currentPageContent.Take( 5 ).ToList();

                lDebug.Visible = true;
                
                lDebug.Text = mergeFields.lavaDebugInfo();

                mergeFields["Items"] = currentPageContent;
            }
            else
            {
                lDebug.Visible = false;
                lDebug.Text = string.Empty;
            }

            // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line
            mergeFields.AddOrIgnore( "Person", CurrentPerson );
//.........这里部分代码省略.........
开发者ID:NewSpring,项目名称:Rock,代码行数:101,代码来源:ContentChannelView.ascx.cs

示例12: ParseMarkup

        /// <summary>
        /// Parses the markup.
        /// </summary>
        /// <param name="markup">The markup.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">No parameters were found in your command. The syntax for a parameter is parmName:'' (note that you must use single quotes).</exception>
        private Dictionary<string, string> ParseMarkup( string markup, Context context )
        {
            // first run lava across the inputted markup
            var internalMergeFields = new Dictionary<string, object>();

            // get variables defined in the lava source
            foreach ( var scope in context.Scopes )
            {
                foreach ( var item in scope )
                {
                    internalMergeFields.AddOrReplace( item.Key, item.Value );
                }
            }

            // get merge fields loaded by the block or container
            foreach( var environment in context.Environments )
            {
                foreach ( var item in environment )
                {
                    internalMergeFields.AddOrReplace( item.Key, item.Value );
                }
            }

            var resolvedMarkup = markup.ResolveMergeFields( internalMergeFields );

            var parms = new Dictionary<string, string>();
            parms.Add( "method", "GET" );
            parms.Add( "return", "results" );
            parms.Add( "basicauth", "" );
            parms.Add( "parameters", "" );
            parms.Add( "headers", "" );
            parms.Add( "responsecontenttype", "json" );
            parms.Add( "body", "" );
            parms.Add( "requesttype", "text/plain" );

            var markupItems = Regex.Matches( resolvedMarkup, "(.*?:'[^']+')" )
                .Cast<Match>()
                .Select( m => m.Value )
                .ToList();

            foreach ( var item in markupItems )
            {
                var itemParts = item.ToString().Split( new char[] { ':' }, 2 );
                if ( itemParts.Length > 1 )
                {
                    parms.AddOrReplace( itemParts[0].Trim().ToLower(), itemParts[1].Trim().Substring( 1, itemParts[1].Length - 2 ) );
                }
            }
            return parms;
        }
开发者ID:NewSpring,项目名称:Rock,代码行数:57,代码来源:WebRequest.cs

示例13: ShowDetail

        private void ShowDetail()
        {
            _mode = "VIEW";

            pnlEdit.Visible = false;

            string json = GetAttributeValue( "Forms" );
            if ( string.IsNullOrWhiteSpace( json ) )
            {
                FormState = new List<AttributeForm>();
            }
            else
            {
                FormState = JsonConvert.DeserializeObject<List<AttributeForm>>( json );
            }

            if ( FormState.Count > 0 )
            {
                pnlView.Visible = true;

                AttributeValueState = new Dictionary<int, string>();
                if ( CurrentPerson != null )
                {
                    if ( CurrentPerson.Attributes == null )
                    {
                        CurrentPerson.LoadAttributes();
                    }

                    foreach ( var form in FormState )
                    {
                        foreach ( var field in form.Fields
                            .Where( a =>
                                a.AttributeId.HasValue &&
                                a.ShowCurrentValue == true ) )
                        {
                            var attributeCache = AttributeCache.Read( field.AttributeId.Value );
                            if ( attributeCache != null )
                            {
                                AttributeValueState.AddOrReplace( field.AttributeId.Value, CurrentPerson.GetAttributeValue( attributeCache.Key ) );
                            }
                        }
                    }
                }

                ProgressBarSteps = FormState.Count();
                CurrentPageIndex = 0;
                ShowPage();
            }
            else
            {
                nbMain.Title = "No Forms/Fields";
                nbMain.Text = "No forms or fields have been configured. Use the Block Configuration to add new forms and fields.";
                nbMain.NotificationBoxType = NotificationBoxType.Warning;
                nbMain.Visible = true;
            }
        }
开发者ID:NewPointe,项目名称:Rockit,代码行数:56,代码来源:PersonAttributeForms.ascx.cs

示例14: BindGrid

        /// <summary>
        /// Shows the preview.
        /// </summary>
        /// <param name="entityTypeId">The entity type id.</param>
        /// <param name="filter">The filter.</param>
        private void BindGrid( Report report )
        {
            if ( report != null )
            {
                var errors = new List<string>();

                if ( !report.EntityTypeId.HasValue )
                {
                    gReport.Visible = false;
                    return;
                }

                var rockContext = new RockContext();

                if ( !report.IsAuthorized( Authorization.VIEW, this.CurrentPerson ) )
                {
                    gReport.Visible = false;
                    return;
                }

                Type entityType = EntityTypeCache.Read( report.EntityTypeId.Value, rockContext ).GetEntityType();

                bool isPersonDataSet = report.EntityTypeId == EntityTypeCache.Read( typeof( Rock.Model.Person ), true, rockContext ).Id;

                if ( isPersonDataSet )
                {
                    gReport.PersonIdField = "Id";
                    gReport.DataKeyNames = new string[] { "Id" };
                }
                else
                {
                    gReport.PersonIdField = null;
                }

                if ( report.EntityTypeId.HasValue )
                {
                    gReport.RowItemText = EntityTypeCache.Read( report.EntityTypeId.Value, rockContext ).FriendlyName;
                }

                List<EntityField> entityFields = Rock.Reporting.EntityHelper.GetEntityFields( entityType );

                var selectedEntityFields = new Dictionary<int, EntityField>();
                var selectedAttributes = new Dictionary<int, AttributeCache>();
                var selectedComponents = new Dictionary<int, ReportField>();

                // if there is a selectField, keep it to preserve which items are checked
                var selectField = gReport.Columns.OfType<SelectField>().FirstOrDefault();
                gReport.Columns.Clear();
                int columnIndex = 0;

                if ( !string.IsNullOrWhiteSpace( gReport.PersonIdField ) )
                {
                    // if we already had a selectField, use it (to preserve checkbox state)
                    gReport.Columns.Add( selectField ?? new SelectField() );
                    columnIndex++;
                }

                var reportFieldSortExpressions = new Dictionary<Guid, string>();

                foreach ( var reportField in report.ReportFields.OrderBy( a => a.ColumnOrder ) )
                {
                    columnIndex++;
                    if ( reportField.ReportFieldType == ReportFieldType.Property )
                    {
                        var entityField = entityFields.FirstOrDefault( a => a.Name == reportField.Selection );
                        if ( entityField != null )
                        {
                            selectedEntityFields.Add( columnIndex, entityField );

                            BoundField boundField;
                            if ( entityField.FieldType.Guid.Equals( Rock.SystemGuid.FieldType.DEFINED_VALUE.AsGuid() ) )
                            {
                                boundField = new DefinedValueField();
                            }
                            else
                            {
                                boundField = Grid.GetGridField( entityField.PropertyType );
                            }

                            boundField.DataField = string.Format( "Entity_{0}_{1}", entityField.Name, columnIndex );
                            boundField.HeaderText = string.IsNullOrWhiteSpace( reportField.ColumnHeaderText ) ? entityField.Title : reportField.ColumnHeaderText;
                            boundField.SortExpression = boundField.DataField;
                            reportFieldSortExpressions.AddOrReplace( reportField.Guid, boundField.SortExpression );
                            boundField.Visible = reportField.ShowInGrid;
                            gReport.Columns.Add( boundField );
                        }
                    }
                    else if ( reportField.ReportFieldType == ReportFieldType.Attribute )
                    {
                        Guid? attributeGuid = reportField.Selection.AsGuidOrNull();
                        if ( attributeGuid.HasValue )
                        {
                            var attribute = AttributeCache.Read( attributeGuid.Value, rockContext );
                            if ( attribute != null )
                            {
//.........这里部分代码省略.........
开发者ID:Higherbound,项目名称:Higherbound-2016-website-upgrades,代码行数:101,代码来源:ReportDetail.ascx.cs

示例15: ParseMarkup

        /// <summary>
        /// Parses the markup.
        /// </summary>
        /// <param name="markup">The markup.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">No parameters were found in your command. The syntax for a parameter is parmName:'' (note that you must use single quotes).</exception>
        private Dictionary<string, string> ParseMarkup( string markup, Context context )
        {
            // first run lava across the inputted markup
            var internalMergeFields = new Dictionary<string, object>();

            // get variables defined in the lava source
            foreach ( var scope in context.Scopes )
            {
                foreach ( var item in scope )
                {
                    internalMergeFields.AddOrReplace( item.Key, item.Value );
                }
            }

            // get merge fields loaded by the block or container
            if ( context.Environments.Count > 0 )
            {
                foreach ( var item in context.Environments[0] )
                {
                    internalMergeFields.AddOrReplace( item.Key, item.Value );
                }
            }
            var resolvedMarkup = markup.ResolveMergeFields( internalMergeFields );

            var parms = new Dictionary<string, string>();
            parms.Add( "iterator", string.Format( "{0}Items", _entityName ) );

            var markupItems = Regex.Matches( resolvedMarkup, "(.*?:'[^']+')" )
                .Cast<Match>()
                .Select( m => m.Value )
                .ToList();

            if ( markupItems.Count == 0 )
            {
                throw new Exception( "No parameters were found in your command. The syntax for a parameter is parmName:'' (note that you must use single quotes)." );
            }

            foreach ( var item in markupItems )
            {
                var itemParts = item.ToString().Split( new char[] { ':' }, 2 );
                if ( itemParts.Length > 1 )
                {
                    parms.AddOrReplace( itemParts[0].Trim().ToLower(), itemParts[1].Trim().Substring( 1, itemParts[1].Length - 2 ) );
                }
            }

            // override any dynamic parameters
            List<string> dynamicFilters = new List<string>(); // will be used to process dynamic filters
            if ( parms.ContainsKey( "dynamicparameters" ) )
            {
                var dynamicParms = parms["dynamicparameters"];
                var dynamicParmList = dynamicParms.Split( ',' )
                                        .Select( x => x.Trim() )
                                        .Where( x => !string.IsNullOrWhiteSpace( x ) )
                                        .ToList();

                foreach ( var dynamicParm in dynamicParmList )
                {
                    if ( HttpContext.Current.Request[dynamicParm] != null )
                    {
                        var dynamicParmValue = HttpContext.Current.Request[dynamicParm].ToString();

                        switch ( dynamicParm )
                        {
                            case "id":
                            case "limit":
                            case "offset":
                            case "dataview":
                            case "expression":
                            case "sort":
                            case "iterator":
                            case "checksecurity":
                            case "includedeceased":
                                {
                                    parms.AddOrReplace( dynamicParm, dynamicParmValue );
                                    break;
                                }
                            default:
                                {
                                    dynamicFilters.Add( dynamicParm );
                                    break;
                                }
                        }
                    }
                }

                parms.AddOrReplace( "dynamicparameters", string.Join( ",", dynamicFilters ) );
            }

            return parms;
        }
开发者ID:NewSpring,项目名称:Rock,代码行数:98,代码来源:RockEntity.cs


注:本文中的Dictionary.AddOrReplace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。