本文整理汇总了C#中Properties.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# Properties.ContainsKey方法的具体用法?C# Properties.ContainsKey怎么用?C# Properties.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Properties
的用法示例。
在下文中一共展示了Properties.ContainsKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GateEntity
public GateEntity(Rectangle rect, Properties properties, GameScene gs)
{
position.X = rect.X;
position.Y = rect.Y;
spriteChoice.texture = gateTex;
animState.AnimationName = "closed";
Collidable = true;
Visible = true;
if (properties.ContainsKey ("any")) {
foreach (String identifier in ((String)properties["any"]).Split(',')) {
any.Add (identifier);
}
}
if (properties.ContainsKey ("require")) {
foreach (String identifier in ((String)properties["require"]).Split(',')) {
require.Add (identifier);
}
}
if (properties.ContainsKey ("forbid")) {
foreach (String identifier in ((String)properties["forbid"]).Split(',')) {
forbid.Add (identifier);
}
}
hitbox = new Rectangle(0,0,100,100);
Visible = true;
this.gs = gs;
}
示例2: NodeEntity
public NodeEntity(Rectangle position, Properties properties)
{
this.position = new Vector2(position.X, position.Y);
if (properties.ContainsKey("nodeName")) {
nodeName = (string)properties["nodeName"];
}
if (properties.ContainsKey ("next")) {
nextNodeName = (string)properties ["next"];
}
}
示例3: Init
public void Init()
{
try {
Properties properties = new Properties();
properties.Load(new FileStream("test-fixtures.properties", FileMode.Open));
if (properties.ContainsKey("goldSrcServerAddress")) goldSrcServerAddress = properties["goldSrcServerAddress"];
if (properties.ContainsKey("goldSrcServerPort")) goldSrcServerPort = int.Parse(properties["goldSrcServerPort"]);
if (properties.ContainsKey("goldSrcServerAuth")) goldSrcServerAuth = properties["goldSrcServerAuth"];
if (properties.ContainsKey("goldSrcServerTimeout")) goldSrcServerTimeout = int.Parse(properties["goldSrcServerTimeout"]);
if (properties.ContainsKey("sourceServerAddress")) sourceServerAddress = properties["sourceServerAddress"];
if (properties.ContainsKey("sourceServerPort")) sourceServerPort = int.Parse(properties["sourceServerPort"]);
if (properties.ContainsKey("sourceServerAuth")) sourceServerAuth = properties["sourceServerAuth"];
if (properties.ContainsKey("sourceServerTimeout")) sourceServerTimeout = int.Parse(properties["goldSrcServerTimeout"]);
} catch { }
}
示例4: DownloadJars
protected void DownloadJars()
{
Properties md5s = new Properties();
if (File.Exists(Path.Combine(Inst.BinDir, "md5s")))
md5s.Load(Path.Combine(Inst.BinDir, "md5s"));
State = EnumState.DOWNLOADING;
int[] fileSizes = new int[this.uriList.Length];
bool[] skip = new bool[this.uriList.Length];
// Get the headers and decide what files to skip downloading
for (int i = 0; i < uriList.Length; i++)
{
Console.WriteLine("Getting header " + uriList[i].ToString());
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uriList[i]);
request.Method = "HEAD";
string etagOnDisk = null;
if (md5s.ContainsKey(GetFileName(uriList[i])))
etagOnDisk = md5s[GetFileName(uriList[i])];
if (!forceUpdate && !string.IsNullOrEmpty(etagOnDisk))
request.Headers[HttpRequestHeader.IfNoneMatch] = etagOnDisk;
HttpWebResponse response = ((HttpWebResponse)request.GetResponse());
int code = (int)response.StatusCode;
if (code == 300)
skip[i] = true;
fileSizes[i] = (int)response.ContentLength;
this.totalDownloadSize += fileSizes[i];
Console.WriteLine("Got response: " + code + " and file size of " +
fileSizes[i] + " bytes");
}
int initialPercentage = Progress;
byte[] buffer = new byte[1024 * 10];
for (int i = 0; i < this.uriList.Length; i++)
{
if (skip[i])
{
Progress = (initialPercentage + fileSizes[i] * 45 / this.totalDownloadSize);
}
else
{
string currentFile = GetFileName(uriList[i]);
md5s.Remove(currentFile);
md5s.Save(Path.Combine(Inst.BinDir, "md5s"));
int failedAttempts = 0;
const int MAX_FAILS = 3;
bool downloadFile = true;
// Download the files
while (downloadFile)
{
downloadFile = false;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uriList[i]);
request.Headers[HttpRequestHeader.CacheControl] = "no-cache";
Console.WriteLine("Getting response");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.WriteLine("Done");
string etag = response.Headers[HttpResponseHeader.ETag];
etag = etag.TrimEnd('"').TrimStart('"');
Stream dlStream = response.GetResponseStream();
FileStream fos =
new FileStream(Path.Combine(Inst.BinDir, currentFile), FileMode.Create);
int fileSize = 0;
MD5 digest = MD5.Create();
digest.Initialize();
int readSize;
while ((readSize = dlStream.Read(buffer, 0, buffer.Length)) > 0)
{
// Console.WriteLine("Read " + readSize + " bytes");
fos.Write(buffer, 0, readSize);
this.currentDownloadSize += readSize;
fileSize += readSize;
digest.TransformBlock(buffer, 0, readSize, null, 0);
// Progress = fileSize / fileSizes[i];
Progress = (initialPercentage + this.currentDownloadSize
* 70 / this.totalDownloadSize);
}
digest.TransformFinalBlock(new byte[] {}, 0, 0);
dlStream.Close();
fos.Close();
string md5 = HexEncode(digest.Hash);
//.........这里部分代码省略.........
示例5: DownloadJars
protected void DownloadJars()
{
Properties md5s = new Properties();
if (File.Exists(Path.Combine(Inst.BinDir, "md5s")))
md5s.Load(Path.Combine(Inst.BinDir, "md5s"));
State = EnumState.DOWNLOADING;
int[] fileSizes = new int[this.uriList.Length];
bool[] skip = new bool[this.uriList.Length];
// Get the headers and decide what files to skip downloading
for (int i = 0; i < uriList.Length; i++)
{
Console.WriteLine("Getting header " + uriList[i].ToString());
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uriList[i]);
request.Timeout = 1000 * 15; // Set a 15 second timeout
request.Method = "HEAD";
string etagOnDisk = null;
if (md5s.ContainsKey(GetFileName(uriList[i])))
etagOnDisk = md5s[GetFileName(uriList[i])];
if (!forceUpdate && !string.IsNullOrEmpty(etagOnDisk))
request.Headers[HttpRequestHeader.IfNoneMatch] = etagOnDisk;
using (HttpWebResponse response = ((HttpWebResponse)request.GetResponse()))
{
int code = (int)response.StatusCode;
if (code == 300)
skip[i] = true;
fileSizes[i] = (int)response.ContentLength;
this.totalDownloadSize += fileSizes[i];
Console.WriteLine("Got response: " + code + " and file size of " +
fileSizes[i] + " bytes");
}
}
int initialPercentage = Progress;
byte[] buffer = new byte[1024 * 10];
for (int i = 0; i < this.uriList.Length; i++)
{
if (skip[i])
{
Progress = (initialPercentage + fileSizes[i] *
(100 - initialPercentage) / this.totalDownloadSize);
}
else
{
string currentFile = GetFileName(uriList[i]);
if (currentFile == "minecraft.jar" && File.Exists("mcbackup.jar"))
File.Delete("mcbackup.jar");
md5s.Remove(currentFile);
md5s.Save(Path.Combine(Inst.BinDir, "md5s"));
int failedAttempts = 0;
const int MAX_FAILS = 3;
bool downloadFile = true;
// Download the files
while (downloadFile)
{
downloadFile = false;
HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(uriList[i]);
request.Headers[HttpRequestHeader.CacheControl] = "no-cache";
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
string etag = "";
// If downloading from Mojang, use ETag.
if (uriList[i].ToString().StartsWith(Resources.MojangMCDLUri))
{
etag = response.Headers[HttpResponseHeader.ETag];
etag = etag.TrimEnd('"').TrimStart('"');
}
// If downloading from dropbox, ignore MD5s
else
{
// TODO add a way to verify integrity of files downloaded from dropbox
}
Stream dlStream = response.GetResponseStream();
using (FileStream fos =
new FileStream(Path.Combine(Inst.BinDir, currentFile), FileMode.Create))
{
int fileSize = 0;
using (MD5 digest = MD5.Create())
{
digest.Initialize();
int readSize;
while ((readSize = dlStream.Read(buffer, 0, buffer.Length)) > 0)
{
// Console.WriteLine("Read " + readSize + " bytes");
fos.Write(buffer, 0, readSize);
//.........这里部分代码省略.........