Example #1
0
        public static string ToText(this MonsterAttackType attack, string delimiter)
        {
            var sb = new StringBuilder();
            if (attack.IsEmpty) {
                return String.Empty;
            }
            else if (attack.Damage.IsEmpty) {
                sb.Append(attack.Description);
            }
            else {
                sb.AppendIfNotEmpty(attack.ToString());
            }

            for (int i = 0; i < attack.FailedSavingThrows.Count; ++i) {
                var failed = attack.FailedSavingThrows[i];
                sb.AppendFormat("{0}    {1} Failed Saving Throw: {2}", delimiter, (i + 1).ToIteration(), failed); // failed.ToHtml(power));
            }
            foreach (var sustain in attack.Sustains) {
                sb.AppendFormat("{0}    Sustain", delimiter);
                sb.AppendFormatIfNotEmpty(" {0}", sustain.Action);
                sb.AppendFormat(": {0}", sustain.Description); //sustain.ToHtml(power));
            }

            foreach (var attackInner in attack.Attacks) {
                sb.AppendFormat("{0}    {1}: {2}", delimiter, attackInner.Name, attackInner.Effect);
            }

            if (!attack.Damage.IsEmpty) {
                foreach (var after in attack.AfterEffects) {
                    sb.AppendFormat("{0}    Aftereffect: {1}", delimiter, after); //after.ToHtml(power));
                }
            }

            return sb.ToString();
        }
        /// <summary>
        /// Returns the header parameter to be put into the HTTP WWW-Authenticate header. The field ts has the timestamp
        /// in UNIX time corresponding to the server clock and the field tsm is the MAC calculated for the normalized
        /// timestamp data using the shared symmetric key and the algorithm agreed upon.
        /// </summary>
        /// <returns></returns>
        internal string ToWwwAuthenticateHeaderParameter()
        {
            Hasher hasher = new Hasher(credential.Algorithm);

            byte[] data = this.ToString().ToBytesFromUtf8();

            string tsm = hasher.ComputeHmac(data, credential.Key).ToBase64String();

            char trailer = ',';

            StringBuilder result = new StringBuilder();
            result.AppendIfNotEmpty(TS, fresh.ToString(), trailer)
                .AppendIfNotEmpty(TSM, tsm, trailer);

            return result.ToString().Trim().Trim(trailer);
        }
        /// <summary>
        /// Returns the serialized form of this object.
        /// </summary>
        /// <param name="includeClientArtifacts">If true, the client supplied artifacts of id, timestamp, and nonce are included.</param>
        /// <returns></returns>
        private string ToHeaderParameter(bool includeClientArtifacts)
        {
            char trailer = ',';
            StringBuilder result = new StringBuilder();

            if (includeClientArtifacts)
            {
                result
                    .AppendIfNotEmpty(ID, this.Id, trailer)
                    .AppendIfNotEmpty(TS, (this.Timestamp > 0 ? this.Timestamp.ToString() : String.Empty), trailer)
                    .AppendIfNotEmpty(NONCE, this.Nonce, trailer);
            }

            result
                .AppendIfNotEmpty(EXT, this.ApplicationSpecificData, trailer)
                .AppendIfNotEmpty(MAC, this.Mac == null ? null : this.Mac.ToBase64String(), trailer)
                .AppendIfNotEmpty(HASH, this.PayloadHash == null ? null : this.PayloadHash.ToBase64String(), trailer);

            return result.ToString()
                .Trim().Trim(trailer); // Remove the trailing trailer and space for the last pair
        }
Example #4
0
 private static void JoinCore(StringBuilder builder, IEnumerable<string> collection, string separator)
 {
     using (var enumerator = collection.GetEnumerator())
         if (enumerator.MoveNext())
         {
             builder.AppendIfNotEmpty(enumerator.Current);
             while (enumerator.MoveNext())
                 builder
                     .Append(separator)
                     .AppendIfNotEmpty(enumerator.Current);
         }
 }
Example #5
0
 private static void JoinCore(StringBuilder builder, IEnumerable<string> collection)
 {
     foreach (string item in collection)
         builder.AppendIfNotEmpty(item);
 }
Example #6
0
        /// <summary>Concatenates the specified separator between each element of the specified collection of strings,
        /// with an optional prefix and suffix, yielding a single concatenated string.</summary>
        /// <param name="collection">The collection of elements to join.</param>
        /// <param name="prefix">The optional prefix to concatenate before the first element.</param>
        /// <param name="separator">The separator to concatenate between each element.</param>
        /// <param name="suffix">The optional suffix to concatenate after the last element.</param>
        /// <returns>The single concatenated string.</returns>
        public static string Join(
            this IEnumerable<string> collection,
            string prefix,
            string separator,
            string suffix)
        {
            if (collection == null) throw new ArgumentNullException("collection");

            StringBuilder builder = new StringBuilder();

            builder.AppendIfNotEmpty(prefix);

            if (separator.IsNullOrEmpty())
                JoinCore(builder, collection);
            else JoinCore(builder, collection, separator);

            return builder.AppendIfNotEmpty(suffix).ToString();
        }
        // internal to allow unit testing
        internal StringBuilder CreateWhereClause(EntityParameterCollection parameters)
        {
            Debug.Assert(parameters != null, "parameters != null");

            var whereClause = new StringBuilder();
            foreach (var alias in _filterAliases)
            {
                var allows = new StringBuilder();
                var excludes = new StringBuilder();
                foreach (var entry in _filters)
                {
                    if (entry.Effect == EntityStoreSchemaFilterEffect.Allow)
                    {
                        AppendFilterEntry(allows, alias, entry, parameters);
                    }
                    else
                    {
                        Debug.Assert(entry.Effect == EntityStoreSchemaFilterEffect.Exclude, "did you add new value?");
                        AppendFilterEntry(excludes, alias, entry, parameters);
                    }
                }

                if (allows.Length != 0)
                {
                    // AND appended if this is not the first condition
                    whereClause
                        .AppendIfNotEmpty(Environment.NewLine)
                        .AppendIfNotEmpty("AND")
                        .AppendIfNotEmpty(Environment.NewLine);

                    whereClause
                        .Append("(")
                        .Append(allows)
                        .Append(")");
                }

                if (excludes.Length != 0)
                {
                    // AND appended if this is not the first condition
                    whereClause
                        .AppendIfNotEmpty(Environment.NewLine)
                        .AppendIfNotEmpty("AND")
                        .AppendIfNotEmpty(Environment.NewLine);

                    whereClause
                        .Append("NOT (")
                        .Append(excludes)
                        .Append(")");
                }
            }
            return whereClause;
        }
        private static void AppendComparisonFragment(
            StringBuilder filterFragment, string alias, string propertyName, string parameterName)
        {
            Debug.Assert(filterFragment != null, "filterFragment != null");
            Debug.Assert(alias != null, "alias != null");
            Debug.Assert(propertyName != null, "propertyName != null");

            filterFragment
                .AppendIfNotEmpty(" AND ")
                .Append(alias)
                .Append(".")
                .Append(propertyName)
                .Append(" LIKE @")
                .Append(parameterName);
        }
        // internal to allow unit testing
        internal static StringBuilder AppendFilterEntry(
            StringBuilder segment, string alias, EntityStoreSchemaFilterEntry entry, EntityParameterCollection parameters)
        {
            Debug.Assert(segment != null, "segment != null");
            Debug.Assert(alias != null, "alias != null");
            Debug.Assert(entry != null, "entry != null");
            Debug.Assert(parameters != null, "parameters != null");

            var filterText = new StringBuilder();
            AppendComparison(filterText, alias, "CatalogName", entry.Catalog, parameters);
            AppendComparison(filterText, alias, "SchemaName", entry.Schema, parameters);
            AppendComparison(
                filterText, alias, "Name",
                entry.Catalog == null && entry.Schema == null && entry.Name == null ? "%" : entry.Name,
                parameters);
            segment
                .AppendIfNotEmpty(" OR ")
                .Append("(")
                .Append(filterText)
                .Append(")");

            return segment;
        }
Example #10
0
        public override string ToString()
        {
            var sb = new StringBuilder();
            sb.AppendLine( "     Type: " + Type );
            sb.AppendLine( "SaveIndex: " + SaveIndex );
            sb.AppendLine( "     Name: " + Name );
            sb.AppendLine( "   Gender: " + Gender );
            sb.AppendLine( "Public ID: " + PublicId );
            sb.AppendLine( "Secret ID: " + SecretId );
            sb.AppendLine( "      Key: " + SecurityKey );
            sb.AppendLine( "     Time: " + TimePlayed );
            sb.AppendLine( " Gamecode: " + GameCode );
            sb.AppendLine( "    Money: " + Money );
            sb.AppendLine( "    Rival: " + Rival );

            sb.AppendLine( "Teamsize:\t" + TeamSize );
            for( int i = 0; i < Team.Count; i++ )
                sb.AppendIfNotEmpty( Team[i].Brief(), i );

            sb.AppendLine( "PC Items:" );
            for( int i = 0; i < PCItems.Count; i++ )
                sb.AppendIfNotEmpty( PCItems[i].ToString(), i );

            sb.AppendLine( "Bag Items:" );
            for( int i = 0; i < Items.Count; i++ )
                sb.AppendIfNotEmpty( Items[i].ToString(), i );

            sb.AppendLine( "Key Items:" );
            for( int i = 0; i < KeyItems.Count; i++ )
                sb.AppendIfNotEmpty( KeyItems[i].ToString(), i );

            sb.AppendLine( "Ball pocket:" );
            for( int i = 0; i < BallPocket.Count; i++ )
                sb.AppendIfNotEmpty( BallPocket[i].ToString(), i );

            sb.AppendLine( "TM case:" );
            for( int i = 0; i < TMCase.Count; i++ )
                sb.AppendIfNotEmpty( TMCase[i].ToString(), i );

            sb.AppendLine( "Berries:" );
            for( int i = 0; i < Berries.Count; i++ )
                sb.AppendIfNotEmpty( Berries[i].ToString(), i );

            sb.AppendLine( "PC buffer:" );
            string pre = string.Empty;
            for( int i = 0; i < PcBuffer.Count; i++ )
            {
                if( i % 30 == 0 )
                    pre = "PC Box #" + Math.Floor( i / 30.0 );
                if( sb.AppendIfNotEmpty( PcBuffer[i].Brief(), i, pre ) )
                    pre = string.Empty;
            }
            return sb.ToString();
        }