本文整理汇总了C#中SteamKit2.KeyValue类的典型用法代码示例。如果您正苦于以下问题:C# KeyValue类的具体用法?C# KeyValue怎么用?C# KeyValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyValue类属于SteamKit2命名空间,在下文中一共展示了KeyValue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetAppManifestValue
private static KeyValue GetAppManifestValue(string manifestPath, string key)
{
var acfKeys = new KeyValue();
var reader = new StreamReader(manifestPath);
var acfReader = new KVTextReader(acfKeys, reader.BaseStream);
reader.Close();
return acfKeys.Children.FirstOrDefault(k => k.Name == key);
}
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:8,代码来源:GUIDCalculator.cs
示例2: KeyValueInitializesCorrectly
public void KeyValueInitializesCorrectly()
{
KeyValue kv = new KeyValue( "name", "value" );
Assert.Equal( "name", kv.Name );
Assert.Equal( "value", kv.Value );
Assert.Empty( kv.Children );
}
开发者ID:RaptorFactor,项目名称:SteamKit,代码行数:9,代码来源:KeyValueFacts.cs
示例3: KeyValueIndexerReturnsValidAndInvalid
public void KeyValueIndexerReturnsValidAndInvalid()
{
KeyValue kv = new KeyValue();
kv.Children.Add( new KeyValue( "exists", "value" ) );
Assert.Equal( kv["exists"].Value, "value" );
Assert.Equal( kv["thiskeydoesntexist"], KeyValue.Invalid );
}
开发者ID:logtcn,项目名称:SteamKit,代码行数:9,代码来源:KeyValueFacts.cs
示例4: Convert
static string Convert(KeyValue kv, bool compactJSON)
{
var jo = new JObject();
var rootNode = new JObject();
jo[kv.Name] = ConvertRecursive(kv);
StringWriter textWriter = new StringWriter();
JsonWriter jsonWriter = new JsonTextWriter(textWriter);
jsonWriter.Formatting = compactJSON ? Formatting.None : Formatting.Indented;
jo.WriteTo(jsonWriter);
return textWriter.GetStringBuilder().ToString();
}
开发者ID:sy1989,项目名称:Dota2DroplistJson,代码行数:11,代码来源:vdf2json.cs
示例5: PrintBinary
private static void PrintBinary(CommandArguments command, KeyValue kv, string key)
{
if (kv[key].Children.Count == 0)
{
return;
}
kv = kv[key];
CommandHandler.ReplyToCommand(command, "{0}{1} {2}({3} MB)", CDN, kv["file"].AsString(), Colors.DARKGRAY, (kv["size"].AsLong() / 1048576.0).ToString("0.###"));
}
开发者ID:TheFighter,项目名称:SteamDatabaseBackend,代码行数:11,代码来源:Binaries.cs
示例6: GetPackageInfo
public bool GetPackageInfo( uint packageId, out KeyValue packageInfo )
{
packageInfo = KeyValue.LoadAsBinary( GetPackageCachePath( packageId ) );
if ( packageInfo == null )
return false;
packageInfo = packageInfo.Children
.FirstOrDefault();
return packageInfo != null;
}
开发者ID:Netshroud,项目名称:steam-irc-bot,代码行数:12,代码来源:SteamAppInfoHandler.cs
示例7: GCClientNotificationHandler
public GCClientNotificationHandler( GCManager manager )
: base(manager)
{
new GCCallback<CMsgGCClientDisplayNotification>( ClientNotification, OnNotification, manager );
tfEnglish = KeyValue.LoadAsText( Path.Combine( Application.StartupPath, "tf_english.txt" ) );
if ( tfEnglish == null )
{
Log.WriteWarn( "GCClientNotificationHandler", "Unable to load tf_english.txt, localizations will be unavailable!" );
}
}
开发者ID:Netshroud,项目名称:steam-irc-bot,代码行数:12,代码来源:TF2GCHandlers.cs
示例8: KeyValueIndexerUpdatesKey
public void KeyValueIndexerUpdatesKey()
{
KeyValue kv = new KeyValue();
KeyValue subkey = new KeyValue();
Assert.Null( subkey.Name );
kv["subkey"] = subkey;
Assert.Equal( subkey.Name, "subkey" );
Assert.Equal( kv["subkey"].Name, "subkey" );
}
开发者ID:logtcn,项目名称:SteamKit,代码行数:13,代码来源:KeyValueFacts.cs
示例9: KVTextReader
public KVTextReader( KeyValue kv, Stream input )
: base( input )
{
bool wasQuoted;
bool wasConditional;
KeyValue currentKey = kv;
do
{
bool bAccepted = true;
string s = ReadToken( out wasQuoted, out wasConditional );
if ( string.IsNullOrEmpty( s ) )
break;
if ( currentKey == null )
{
currentKey = new KeyValue( s );
}
else
{
currentKey.Name = s;
}
s = ReadToken( out wasQuoted, out wasConditional );
if ( wasConditional )
{
bAccepted = ( s == "[$WIN32]" );
// Now get the '{'
s = ReadToken( out wasQuoted, out wasConditional );
}
if ( s.StartsWith( "{" ) && !wasQuoted )
{
// header is valid so load the file
currentKey.RecursiveLoadFromBuffer( this );
}
else
{
throw new Exception( "LoadFromBuffer: missing {" );
}
currentKey = null;
}
while ( !EndOfStream );
}
开发者ID:Redflameman0,项目名称:SteamKit2,代码行数:50,代码来源:KeyValue.cs
示例10: JsonifyKeyValue
public static string JsonifyKeyValue(KeyValue keys)
{
string value = string.Empty;
using (var sw = new StringWriter(new StringBuilder()))
{
using (JsonWriter w = new JsonTextWriter(sw))
{
DbWorker.JsonifyKeyValue(w, keys.Children);
}
value = sw.ToString();
}
return value;
}
开发者ID:RJacksonm1,项目名称:SteamDatabaseBackend,代码行数:16,代码来源:DbWorker.cs
示例11: KeyValueIndexerDoesntallowDuplicates
public void KeyValueIndexerDoesntallowDuplicates()
{
KeyValue kv = new KeyValue();
kv["key"] = new KeyValue();
Assert.Equal( kv.Children.Count, 1 );
kv["key"] = new KeyValue();
Assert.Equal( kv.Children.Count, 1 );
kv["key2"] = new KeyValue();
Assert.Equal( kv.Children.Count, 2 );
}
开发者ID:logtcn,项目名称:SteamKit,代码行数:16,代码来源:KeyValueFacts.cs
示例12: ConvertRecursive
static JToken ConvertRecursive(KeyValue kv)
{
var jo = new JObject();
if (kv.Children.Count > 0)
{
foreach (var child in kv.Children)
{
jo[child.Name] = ConvertRecursive(child);
}
return jo;
}
else
{
return (JToken)kv.Value;
}
}
开发者ID:sy1989,项目名称:Dota2DroplistJson,代码行数:17,代码来源:vdf2json.cs
示例13: GetAppInfo
public bool GetAppInfo( uint appId, out KeyValue appInfo )
{
appInfo = KeyValue.LoadAsText( GetAppCachePath( appId ) );
// cache off the name
if ( appInfo != null )
{
string name = appInfo[ "common" ][ "name" ].AsString();
string type = appInfo[ "common" ][ "type" ].AsString();
bool isGame = string.Equals( type, "game", StringComparison.OrdinalIgnoreCase );
if ( name != null )
{
appNameCache[ name ] = new AppCacheEntry { AppID = appId, IsGame = isGame };
}
}
return appInfo != null;
}
开发者ID:Markusyatina,项目名称:steam-irc-bot,代码行数:20,代码来源:SteamAppInfoHandler.cs
示例14: OnCommand
public override void OnCommand(CommandArguments command)
{
using (var webClient = new WebClient())
{
webClient.DownloadDataCompleted += delegate(object sender, DownloadDataCompletedEventArgs e)
{
var kv = new KeyValue();
using (var ms = new MemoryStream(e.Result))
{
try
{
kv.ReadAsText(ms);
}
catch
{
CommandHandler.ReplyToCommand(command, "Something went horribly wrong and keyvalue parser died.");
return;
}
}
if (kv["bins_osx"].Children.Count == 0)
{
CommandHandler.ReplyToCommand(command, "Failed to find binaries in parsed response.");
return;
}
kv = kv["bins_osx"];
CommandHandler.ReplyToCommand(command, "You're on your own:{0} {1}{2} {3}({4} MB)", Colors.DARKBLUE, CDN, kv["file"].AsString(), Colors.DARKGRAY, (kv["size"].AsLong() / 1048576.0).ToString("0.###"));
};
webClient.DownloadDataAsync(new Uri(string.Format("{0}steam_client_publicbeta_osx?_={1}", CDN, DateTime.UtcNow.Ticks)));
}
}
开发者ID:RJacksonm1,项目名称:SteamDatabaseBackend,代码行数:37,代码来源:Binaries.cs
示例15: DoCommand
KeyValue DoCommand( Server server, string command, string data = null, string method = WebRequestMethods.Http.Get, bool doAuth = false, string args = "" )
{
byte[] resultData = DoRawCommand( server, command, data, method, doAuth, args );
var dataKv = new KeyValue();
using ( MemoryStream ms = new MemoryStream( resultData ) )
{
try
{
dataKv.ReadAsText( ms );
}
catch ( Exception ex )
{
throw new InvalidDataException( "An internal error occurred while attempting to parse the response from the CS server.", ex );
}
}
return dataKv;
}
开发者ID:suzaku91,项目名称:SteamKit,代码行数:20,代码来源:CDNClient.cs
示例16: KeyValuesFailsToReadTruncatedBinary
public void KeyValuesFailsToReadTruncatedBinary()
{
// Test every possible truncation boundary we have.
for ( int i = 0; i < TestObjectHex.Length; i += 2 )
{
var binary = Utils.DecodeHexString( TestObjectHex.Substring( 0, i ) );
var kv = new KeyValue();
bool success;
using ( var ms = new MemoryStream( binary ) )
{
success = kv.TryReadAsBinary( ms );
Assert.Equal( ms.Length, ms.Position );
}
Assert.False( success, "Should not have read test object." );
}
}
开发者ID:RaptorFactor,项目名称:SteamKit,代码行数:17,代码来源:KeyValueFacts.cs
示例17: Call
/// <summary>
/// Manually calls the specified Web API function with the provided details.
/// </summary>
/// <param name="func">The function name to call.</param>
/// <param name="version">The version of the function to call.</param>
/// <param name="args">A dictionary of string key value pairs representing arguments to be passed to the API.</param>
/// <param name="method">The http request method. Either "POST" or "GET".</param>
/// <param name="secure">if set to <c>true</c> this method will be called through the secure API.</param>
/// <returns>A <see cref="Task{T}"/> that contains a <see cref="KeyValue"/> object representing the results of the Web API call.</returns>
/// <exception cref="ArgumentNullException">The function name or request method provided were <c>null</c>.</exception>
/// <exception cref="WebException">An network error occurred when performing the request.</exception>
/// <exception cref="InvalidDataException">An error occured when parsing the response from the WebAPI.</exception>
public Task<KeyValue> Call( string func, int version = 1, Dictionary<string, string> args = null, string method = WebRequestMethods.Http.Get, bool secure = false )
{
if ( func == null )
throw new ArgumentNullException( "func" );
if ( args == null )
args = new Dictionary<string, string>();
if ( method == null )
throw new ArgumentNullException( "method" );
StringBuilder urlBuilder = new StringBuilder();
StringBuilder paramBuilder = new StringBuilder();
urlBuilder.Append( secure ? "https://" : "http://" );
urlBuilder.Append( API_ROOT );
urlBuilder.AppendFormat( "/{0}/{1}/v{2}", iface, func, version );
bool isGet = method.Equals( WebRequestMethods.Http.Get, StringComparison.OrdinalIgnoreCase );
if ( isGet )
{
// if we're doing a GET request, we'll build the params onto the url
paramBuilder = urlBuilder;
paramBuilder.Append( "/?" ); // start our GET params
}
args.Add( "format", "vdf" );
if ( !string.IsNullOrEmpty( apiKey ) )
{
args.Add( "key", apiKey );
}
// append any args
paramBuilder.Append( string.Join( "&", args.Select( kvp =>
{
// TODO: the WebAPI is a special snowflake that needs to appropriately handle url encoding
// this is in contrast to the steam3 content server APIs which use an entirely different scheme of encoding
string key = WebHelpers.UrlEncode( kvp.Key );
string value = kvp.Value; // WebHelpers.UrlEncode( kvp.Value );
return string.Format( "{0}={1}", key, value );
} ) ) );
var task = Task.Factory.StartNew<KeyValue>( () =>
{
byte[] data = null;
if ( isGet )
{
data = webClient.DownloadData( urlBuilder.ToString() );
}
else
{
byte[] postData = Encoding.Default.GetBytes( paramBuilder.ToString() );
webClient.Headers.Add( HttpRequestHeader.ContentType, "application/x-www-form-urlencoded" );
data = webClient.UploadData( urlBuilder.ToString(), postData );
}
KeyValue kv = new KeyValue();
using ( var ms = new MemoryStream( data ) )
{
try
{
kv.ReadAsText( ms );
}
catch ( Exception ex )
{
throw new InvalidDataException(
"An internal error occurred when attempting to parse the response from the WebAPI server. This can indicate a change in the VDF format.",
ex
);
}
}
return kv;
} );
task.ContinueWith( t =>
{
// we need to observe the exception in this OnlyOnFaulted continuation if our task throws an exception but we're not able to observe it
// (such as when waiting for the task times out, and an exception is thrown later)
// see: http://msdn.microsoft.com/en-us/library/dd997415.aspx
//.........这里部分代码省略.........
开发者ID:JustHev,项目名称:SteamKit,代码行数:101,代码来源:WebAPI.cs
示例18: Package
internal Package( CMsgClientPackageInfoResponse.Package pack, Package.PackageStatus status )
{
Status = status;
PackageID = pack.package_id;
ChangeNumber = pack.change_number;
Hash = pack.sha;
Data = new KeyValue();
using ( var ms = new MemoryStream( pack.buffer ) )
using ( var br = new BinaryReader( ms ) )
{
// steamclient checks this value == 1 before it attempts to read the KV from the buffer
// see: CPackageInfo::UpdateFromBuffer(CSHA const&,uint,CUtlBuffer &)
// todo: we've apparently ignored this with zero ill effects, but perhaps we want to respect it?
br.ReadUInt32();
Data.TryReadAsBinary( ms );
}
}
开发者ID:Jwsonic,项目名称:SteamKit,代码行数:21,代码来源:Callbacks.cs
示例19: GuestPassListCallback
internal GuestPassListCallback( MsgClientUpdateGuestPassesList msg, Stream payload )
{
Result = msg.Result;
CountGuestPassesToGive = msg.CountGuestPassesToGive;
CountGuestPassesToRedeem = msg.CountGuestPassesToRedeem;
GuestPasses = new List<KeyValue>();
for ( int i = 0; i < CountGuestPassesToGive + CountGuestPassesToRedeem; i++ )
{
var kv = new KeyValue();
kv.TryReadAsBinary( payload );
GuestPasses.Add( kv );
}
}
开发者ID:Jwsonic,项目名称:SteamKit,代码行数:14,代码来源:Callbacks.cs
示例20: Call
/// <summary>
/// Manually calls the specified Web API function with the provided details.
/// </summary>
/// <param name="func">The function name to call.</param>
/// <param name="version">The version of the function to call.</param>
/// <param name="args">A dictionary of string key value pairs representing arguments to be passed to the API.</param>
/// <param name="method">The http request method. Either "POST" or "GET".</param>
/// <param name="secure">if set to <c>true</c> this method will be called through the secure API.</param>
/// <returns>A <see cref="KeyValue"/> object representing the results of the Web API call.</returns>
/// <exception cref="ArgumentNullException">The function name or request method provided were <c>null</c>.</exception>
/// <exception cref="WebException">An network error occurred when performing the request.</exception>
/// <exception cref="InvalidDataException">An error occured when parsing the response from the WebAPI.</exception>
public KeyValue Call( string func, int version = 1, Dictionary<string, string> args = null, string method = WebRequestMethods.Http.Get, bool secure = false )
{
if ( func == null )
throw new ArgumentNullException( "func" );
if ( args == null )
args = new Dictionary<string, string>();
if ( method == null )
throw new ArgumentNullException( "method" );
StringBuilder urlBuilder = new StringBuilder();
StringBuilder paramBuilder = new StringBuilder();
urlBuilder.Append( secure ? "https://" : "http://" );
urlBuilder.Append( API_ROOT );
urlBuilder.AppendFormat( "/{0}/{1}/v{2}", iface, func, version );
bool isGet = method.Equals( WebRequestMethods.Http.Get, StringComparison.OrdinalIgnoreCase );
if ( isGet )
{
// if we're doing a GET request, we'll build the params onto the url
paramBuilder = urlBuilder;
paramBuilder.Append( "/?" ); // start our GET params
}
args.Add( "format", "vdf" );
if ( !string.IsNullOrEmpty( apiKey ) )
{
args.Add( "key", apiKey );
}
// append any args
paramBuilder.Append( string.Join( "&", args.Select( kvp =>
{
// TODO: the WebAPI is a special snowflake that needs to appropriately handle url encoding
// this is in contrast to the steam3 content server APIs which use an entirely different scheme of encoding
string key = WebHelpers.UrlEncode( kvp.Key );
string value = kvp.Value; // WebHelpers.UrlEncode( kvp.Value );
return string.Format( "{0}={1}", key, value );
} ) ) );
byte[] data = null;
if ( isGet )
{
data = webClient.DownloadData( urlBuilder.ToString() );
}
else
{
byte[] postData = Encoding.Default.GetBytes( paramBuilder.ToString() );
webClient.Headers.Add( HttpRequestHeader.ContentType, "application/x-www-form-urlencoded" );
data = webClient.UploadData( urlBuilder.ToString(), postData );
}
KeyValue kv = new KeyValue();
using ( var ms = new MemoryStream( data ) )
{
try
{
kv.ReadAsText( ms );
}
catch ( Exception ex )
{
throw new InvalidDataException(
"An internal error occurred when attempting to parse the response from the WebAPI server. This can indicate a change in the VDF format.",
ex
);
}
}
return kv;
}
开发者ID:Redflameman0,项目名称:SteamKit2,代码行数:92,代码来源:WebAPI.cs
注:本文中的SteamKit2.KeyValue类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论