本文整理汇总了C#中System.Variant.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Variant.ToString方法的具体用法?C# Variant.ToString怎么用?C# Variant.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Variant
的用法示例。
在下文中一共展示了Variant.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConcurrencyTest
public ConcurrencyTest(Variant variant, string description)
: base(variant.ToString() + ": " + description)
{
this.variant = variant;
startThreadsEvent = new ManualResetEvent(false);
endTestEvent = new ManualResetEvent(false);
}
示例2: TestDateTime
public void TestDateTime()
{
DateTime arg = new DateTime(2010, 1, 2, 3, 4, 5, 6);
Variant v1 = new Variant(arg);
Assert.AreEqual(v1.Type, Variant.EnumType.DateTime);
Assert.IsTrue(v1.Is(Variant.EnumType.DateTime));
Assert.IsTrue(v1.Is<DateTime>());
Assert.AreEqual(v1.As<DateTime>(), arg);
Assert.AreEqual(Convert.ToDateTime(v1), arg);
Assert.AreEqual(v1.ToString(), "2010-01-02T03:04:05.006");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}
示例3: TestBoolean
public void TestBoolean()
{
Variant vTrue = new Variant(true);
Assert.AreEqual(vTrue.Type, Variant.EnumType.Boolean);
Assert.IsTrue(vTrue.Is(Variant.EnumType.Boolean));
Assert.IsTrue(vTrue.Is<bool>());
Assert.IsTrue(vTrue.As<bool>());
Assert.IsTrue(Convert.ToBoolean(vTrue));
Assert.AreEqual(vTrue.ToString(), "true");
Variant vFalse = new Variant(false);
Assert.AreEqual(vFalse.Type, Variant.EnumType.Boolean);
Assert.IsTrue(vFalse.Is(Variant.EnumType.Boolean));
Assert.IsTrue(vFalse.Is<bool>());
Assert.IsFalse(vFalse.As<bool>());
Assert.IsFalse(Convert.ToBoolean(vFalse));
Assert.AreEqual(vFalse.ToString(), "false");
Variant v1 = new Variant(vTrue);
Assert.IsTrue(v1.Equals(vTrue));
Variant v2 = new Variant(vFalse);
Assert.IsTrue(v2.Equals(vFalse));
}
示例4: TestUInt64
public void TestUInt64()
{
Variant v1 = new Variant((UInt64)4);
Assert.AreEqual(v1.Type, Variant.EnumType.UInt64);
Assert.IsTrue(v1.Is(Variant.EnumType.UInt64));
Assert.IsTrue(v1.Is<UInt64>());
Assert.AreEqual(v1.As<UInt64>(), 4);
Assert.AreEqual(Convert.ToUInt64(v1), 4);
Assert.AreEqual(v1.ToString(), "4");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}
示例5: TestTime
public void TestTime()
{
TimeSpan arg = new TimeSpan(0, 2, 3, 4, 5);
Variant v1 = new Variant(arg);
Assert.AreEqual(v1.Type, Variant.EnumType.Time);
Assert.IsTrue(v1.Is(Variant.EnumType.Time));
Assert.IsTrue(v1.Is<TimeSpan>());
Assert.AreEqual(v1.As<TimeSpan>(), arg);
Assert.AreEqual(v1.ToString(), "02:03:04.005");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}
示例6: TestInt64
public void TestInt64()
{
Variant v1 = new Variant((Int64)3);
Assert.AreEqual(v1.Type, Variant.EnumType.Int64);
Assert.IsTrue(v1.Is(Variant.EnumType.Int64));
Assert.IsTrue(v1.Is<Int64>());
Assert.AreEqual(v1.As<Int64>(), 3);
Assert.AreEqual(Convert.ToInt64(v1), 3);
Assert.AreEqual(v1.ToString(), "3");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}
示例7: TestInt32
public void TestInt32()
{
Variant v1 = new Variant((Int32)1);
Assert.AreEqual(v1.Type, Variant.EnumType.Int32);
Assert.IsTrue(v1.Is(Variant.EnumType.Int32));
Assert.IsTrue(v1.Is<Int32>());
Assert.AreEqual(v1.As<Int32>(), 1);
Assert.AreEqual(Convert.ToInt32(v1), 1);
Assert.AreEqual(v1.ToString(), "1");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}
示例8: HandleRTSPResponse200Setup
private bool HandleRTSPResponse200Setup(RtspProtocol rtspProtocol, Variant requestHeaders, ref string requestContent, Variant responseHeaders, ref string responseContent)
{
if (rtspProtocol.CustomParameters["connectionType"] == "pull")
{
if (responseHeaders[RTSP_FIRST_LINE, RTSP_STATUS_CODE] != 200)
{
FATAL("request {0} failed with response {1}",
(requestHeaders.ToString()),
(responseHeaders.ToString()));
return false;
}
if (rtspProtocol.CustomParameters["pendingTracks"].ArrayLength != 0)
return SendSetupTrackMessages(rtspProtocol);
//2. Do the play command
var uri = rtspProtocol.CustomParameters["uri", "fullUri"];
//3. prepare the play command
rtspProtocol.PushRequestFirstLine(RTSP_METHOD_PLAY, uri, RTSP_VERSION_1_0);
return rtspProtocol.SendRequestMessage();
}
else
{
if (responseHeaders[RTSP_HEADERS, RTSP_HEADERS_TRANSPORT] == null)
{
FATAL("RTSP {0} request doesn't have {1} header line",
RTSP_METHOD_SETUP,
RTSP_HEADERS_TRANSPORT);
return false;
}
//3. get the transport header line
var raw = responseHeaders[RTSP_HEADERS, RTSP_HEADERS_TRANSPORT];
var transport = Variant.Get();
if (!SDP.ParseTransportLine(raw, transport))
{
FATAL("Unable to parse transport line {0}", (raw));
return false;
}
bool forceTcp;
if (transport["server_port"] != null &&
(transport["rtp/avp/udp"] != null || transport["rtp/avp"] != null))
{
forceTcp = false;
}else if (transport["interleaved"] != null && transport["rtp/avp/tcp"] != null)
{
forceTcp = true;
}
else
{
FATAL("Invalid transport line: {0}", (transport.ToString()));
return false;
}
if (forceTcp != (bool)rtspProtocol.CustomParameters["forceTcp"])
{
FATAL("Invalid transport line: {0}", (transport.ToString()));
return false;
}
var pConnectivity = GetOutboundConnectivity(rtspProtocol, forceTcp);
if (pConnectivity == null)
{
FATAL("Unable to get outbound connectivity");
return false;
}
var param = rtspProtocol.CustomParameters;
param[param["lastSetup"] == "audio" ? "audioTransport" : "videoTransport"] = transport;
var variantUri = param["uri"];
string trackId = "";
bool isAudio = false;
if (param["audioTrackId"] != null)
{
trackId = param["audioTrackId"];
param["audioTrackId"] = null;
param["lastSetup"] = "audio";
isAudio = true;
pConnectivity.HasAudio = true;
}
else
{
if (param["videoTrackId"] != null)
{
trackId = param["videoTrackId"];
param["videoTrackId"] = null;
param["lastSetup"] = "video";
pConnectivity.HasVideo = true;
}
}
if (trackId != "")
{
var uri = variantUri["fullUri"] + "/trackID=" + trackId;
rtspProtocol.PushRequestFirstLine(RTSP_METHOD_SETUP, uri, RTSP_VERSION_1_0);
transport = forceTcp ? $"RTP/AVP/TCP;unicast;interleaved={(isAudio ? pConnectivity.AudioChannels : pConnectivity.VideoChannels)};mode=record" : $"RTP/AVP;unicast;client_port={(isAudio ? pConnectivity.AudioChannels : pConnectivity.VideoChannels)};mode=record";
rtspProtocol.PushRequestHeader(RTSP_HEADERS_TRANSPORT, transport);
return rtspProtocol.SendRequestMessage();
}
else
{
rtspProtocol.PushRequestFirstLine(RTSP_METHOD_RECORD,variantUri["fullUri"],RTSP_VERSION_1_0);
return rtspProtocol.SendRequestMessage();
}
}
//.........这里部分代码省略.........
示例9: CreateIFS
//public void SignalONS(BaseOutNetRTMPStream pONS)
//{
// if (_pSignaledRTMPOutNetStream.Contains(pONS)) return;
// _pSignaledRTMPOutNetStream.AddLast(pONS);
//}
public InFileRTMPStream CreateIFS(Variant metadata)
{
var pRtmpInFileStream = InFileRTMPStream.GetInstance(this, Application.StreamsManager, metadata);
if (pRtmpInFileStream == null)
{
WARN("Unable to get file stream. Metadata:\n{0}", metadata.ToString());
return null;
}
if (!pRtmpInFileStream.Initialize(metadata[CONF_APPLICATION_CLIENTSIDEBUFFER]))
{
WARN("Unable to initialize file inbound stream");
pRtmpInFileStream.Dispose();
return null;
}
// _inFileStreams.Add(pRtmpInFileStream);
return pRtmpInFileStream;
}
示例10: TestBuildVariant
static void TestBuildVariant()
{
Variant v = new Variant();
string format = v.GetVariantStringFormat();
Console.WriteLine("VariantStringFormat = {0}", format);
string value = v.ToString();
Console.WriteLine("VariantString = {0}", value);
string options = v.GetVariantStringOptions("\t");
Console.WriteLine("VariantStringOptions = \n{0}", options);
Variant v2 = new Variant();
v2.FromString("Develop.x64.NopeNotThisTime");
Console.WriteLine("FromString,ToString = {0}", v2.ToString());
}
示例11: HandleRTSPResponse
private bool HandleRTSPResponse(RtspProtocol rtspProtocol, Variant requestHeaders,ref string requestContent, Variant responseHeaders,ref string responseContent)
{
switch ((uint)responseHeaders[RTSP_FIRST_LINE, RTSP_STATUS_CODE])
{
case 200:
switch ((string)requestHeaders[RTSP_FIRST_LINE,RTSP_METHOD])
{
case RTSP_METHOD_OPTIONS:
return HandleRTSPResponse200Options(rtspProtocol,requestHeaders,ref requestContent, responseHeaders,ref responseContent);
case RTSP_METHOD_DESCRIBE:
return HandleRTSPResponse200Describe(rtspProtocol, requestHeaders, ref requestContent, responseHeaders, ref responseContent);
case RTSP_METHOD_SETUP:
return HandleRTSPResponse200Setup(rtspProtocol, requestHeaders, ref requestContent, responseHeaders, ref responseContent);
case RTSP_METHOD_PLAY:
return HandleRTSPResponse200Play(rtspProtocol, requestHeaders, ref requestContent, responseHeaders, ref responseContent);
case RTSP_METHOD_ANNOUNCE:
return HandleRTSPResponse200Announce(rtspProtocol, requestHeaders, ref requestContent, responseHeaders, ref responseContent);
case RTSP_METHOD_RECORD:
return HandleRTSPResponse200Record(rtspProtocol, requestHeaders, ref requestContent, responseHeaders, ref responseContent);
case RTSP_METHOD_TEARDOWN:
return true;
default:
return false;
}
case 401:
var username = rtspProtocol.CustomParameters["uri", "userName"];
var password = rtspProtocol.CustomParameters["uri", "password"];
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
{
FATAL("No username/password provided");
return false;
}
string auth = responseHeaders[RTSP_HEADERS, HTTP_HEADERS_WWWAUTHENTICATE];
if (string.IsNullOrEmpty(auth))
{
FATAL("Invalid 401 response: {0}", (responseHeaders.ToString()));
return false;
}
if (!rtspProtocol.SetAuthentication(auth, username, password))
{
FATAL("Unable to authenticate: request headers:\n{0}\nresponseHeaders:\n{1}",
(requestHeaders.ToString()),
(responseHeaders.ToString()));
return false;
}
return true;
case 404:
switch ((string)requestHeaders[RTSP_FIRST_LINE, RTSP_METHOD])
{
case RTSP_METHOD_PLAY:
FATAL("PLAY: Resource not found: "+(requestHeaders[RTSP_FIRST_LINE][RTSP_URL]));
return false;
case RTSP_METHOD_DESCRIBE:
FATAL("DESCRIBE: Resource not found: "+(requestHeaders[RTSP_FIRST_LINE][RTSP_URL]));
return false;
default:
FATAL("Response for method {0} not implemented yet\n{1}", ((string)requestHeaders[RTSP_FIRST_LINE, RTSP_METHOD]),
(responseHeaders.ToString()));
return false;
}
default:
return false;
}
}
示例12: HandleRTSPRequestAnnounce
private bool HandleRTSPRequestAnnounce(RtspProtocol pFrom, Variant requestHeaders, string requestContent)
{
//1. Make sure we ONLY handle application/sdp
if ((string)requestHeaders[RTSP_HEADERS,RTSP_HEADERS_CONTENT_TYPE]!= RTSP_HEADERS_ACCEPT_APPLICATIONSDP)
{
FATAL("Invalid ANNOUNCE request:\n{0}", (requestHeaders.ToString()));
return false;
}
//2. Get the SDP
var sdp = pFrom.InboundSDP;
//3. Parse the SDP
if (!SDP.ParseSDP(sdp, requestContent))
{
FATAL("Unable to parse the SDP");
return false;
}
//4. Get the first video track
var videoTrack = sdp.GetVideoTrack(0,requestHeaders[RTSP_FIRST_LINE,RTSP_URL]);
var audioTrack = sdp.GetAudioTrack(0,requestHeaders[RTSP_FIRST_LINE,RTSP_URL]);
//5. Store the tracks inside the session for later use
if (audioTrack != VariantType.Null)
{
pFrom.CustomParameters["pendingTracks",audioTrack["globalTrackIndex"]] = audioTrack;
}
if (videoTrack != VariantType.Null)
{
pFrom.CustomParameters["pendingTracks",videoTrack["globalTrackIndex"]] = videoTrack;
}
//6. Mark this connection as inbound connection
pFrom.CustomParameters["isInbound"] = true;
//7. Save the streamName
string streamName = sdp.GetStreamName();
if (streamName == "")
{
streamName = $"rtsp_stream_{pFrom.Id}";
}
pFrom.CustomParameters["sdpStreamName"] = streamName;
streamName = new Uri(requestHeaders[RTSP_FIRST_LINE, RTSP_URL],UriKind.Absolute).Segments.Last();
//8. Save the bandwidth hint
pFrom.CustomParameters["sdpBandwidthHint"] = sdp.GetTotalBandwidth();
//9. Get the inbound connectivity
InboundConnectivity pInboundConnectivity = pFrom.GetInboundConnectivity(
streamName,
sdp.GetTotalBandwidth(),Application.Configuration[CONF_APPLICATION_RTCPDETECTIONINTERVAL]);
if (pInboundConnectivity == null)
{
FATAL("Unable to create inbound connectivity");
return false;
}
//8. Send back the response
pFrom.PushResponseFirstLine(RTSP_VERSION_1_0, 200, "OK");
return pFrom.SendResponseMessage();
}
示例13: HandleRTSPResponse200Options
private bool HandleRTSPResponse200Options(RtspProtocol rtspProtocol, Variant requestHeaders, ref string requestContent, Variant responseHeaders, ref string responseContent)
{
if (rtspProtocol.HasConnectivity) return true;
if (rtspProtocol.CustomParameters["connectionType"] == null)
{
FATAL("Bogus connection");
rtspProtocol.EnqueueForDelete();
return false;
}
//1. Sanitize
if (responseHeaders[RTSP_HEADERS, RTSP_HEADERS_PUBLIC] == null)
{
FATAL("Invalid response:\n{0}", (responseHeaders.ToString()));
return false;
}
//2. get the raw options
string raw = responseHeaders[RTSP_HEADERS, RTSP_HEADERS_PUBLIC];
//3. split and normalize the options
var parts = raw.Split(',').Select(x => x.Split(':')).ToDictionary(x => x[0], x => x[1]);
string url = requestHeaders[RTSP_FIRST_LINE, RTSP_URL];
switch ((string)rtspProtocol.CustomParameters["connectionType"])
{
case "pull":
//4. Test the presence of the wanted methods
if (!parts.ContainsKey(RTSP_METHOD_DESCRIBE) || !parts.ContainsKey(RTSP_METHOD_SETUP) ||
!parts.ContainsKey(RTSP_METHOD_PLAY))
{
FATAL("Some of the supported methods are missing: {0}", (raw));
return false;
}
rtspProtocol.PushRequestFirstLine(RTSP_METHOD_DESCRIBE, url, RTSP_VERSION_1_0);
rtspProtocol.PushRequestHeader(RTSP_HEADERS_ACCEPT, RTSP_HEADERS_ACCEPT_APPLICATIONSDP);
return rtspProtocol.SendRequestMessage();
case "push":
//4. Test the presence of the wanted methods
if (!parts.ContainsKey(RTSP_METHOD_ANNOUNCE) || !parts.ContainsKey(RTSP_METHOD_SETUP) ||
!parts.ContainsKey(RTSP_METHOD_RECORD))
{
FATAL("Some of the supported methods are missing: {0}", (raw));
return false;
}
var parameters = rtspProtocol.CustomParameters;
rtspProtocol.PushRequestFirstLine(RTSP_METHOD_ANNOUNCE,url,RTSP_VERSION_1_0);
var sdp = ComputeSDP(rtspProtocol,
parameters["customParameters","localStreamConfig","localStreamName"],
parameters["customParameters","localStreamConfig","targetStreamName"],
parameters["customParameters","localStreamConfig","targetUri","host"]);
if (sdp == "")
{
FATAL("Unable to compute sdp");
return false;
}
rtspProtocol.PushRequestHeader(RTSP_HEADERS_CONTENT_TYPE, RTSP_HEADERS_ACCEPT_APPLICATIONSDP);
rtspProtocol.PushRequestContent(sdp,false);
return rtspProtocol.SendRequestMessage();
default:
FATAL("Bogus connection");
rtspProtocol.EnqueueForDelete();
return false;
}
}
示例14: HandleRTSPResponse200Describe
private bool HandleRTSPResponse200Describe(RtspProtocol rtspProtocol, Variant requestHeaders, ref string requestContent, Variant responseHeaders, ref string responseContent)
{
//1. Make sure we ONLY handle application/sdp
if (responseHeaders[RTSP_HEADERS, RTSP_HEADERS_CONTENT_TYPE] == null)
{
FATAL("Invalid DESCRIBE response:\n{0}", (requestHeaders.ToString()));
return false;
}
if (responseHeaders[RTSP_HEADERS, RTSP_HEADERS_CONTENT_TYPE] == RTSP_HEADERS_ACCEPT_APPLICATIONSDP)
{
FATAL("Invalid DESCRIBE response:\n{0}", (requestHeaders.ToString()));
return false;
}
//2. Get the SDP
var sdp = rtspProtocol.InboundSDP;
//3. Parse the SDP
if (!SDP.ParseSDP(sdp, responseContent))
{
FATAL("Unable to parse the SDP");
return false;
}
//4. Get the first video track
var videoTrack = sdp.GetVideoTrack(0,requestHeaders[RTSP_FIRST_LINE,RTSP_URL]);
var audioTrack = sdp.GetAudioTrack(0,requestHeaders[RTSP_FIRST_LINE,RTSP_URL]);
if ((videoTrack == VariantType.Null) && (audioTrack == VariantType.Null))
{
FATAL("No compatible tracks found");
return false;
}
var forceTcp = rtspProtocol.CustomParameters["forceTcp"];
var rtcpDetectionInterval = Application.Configuration[CONF_APPLICATION_RTCPDETECTIONINTERVAL];
if (rtspProtocol.CustomParameters[CONF_APPLICATION_RTCPDETECTIONINTERVAL]!=null)
rtcpDetectionInterval = (byte)rtspProtocol.CustomParameters[CONF_APPLICATION_RTCPDETECTIONINTERVAL];
//5. Store the tracks inside the session for later use
if (audioTrack != VariantType.Null)
{
audioTrack["isTcp"] = (bool)forceTcp;
rtspProtocol.CustomParameters["pendingTracks"][(int)audioTrack["globalTrackIndex"]] = audioTrack;
}
if (videoTrack != VariantType.Null)
{
videoTrack["isTcp"] = (bool)forceTcp;
rtspProtocol.CustomParameters["pendingTracks"][(int)videoTrack["globalTrackIndex"]] = videoTrack;
}
//6. Save the streamName
string streamName = sdp.GetStreamName();
if (streamName == "")
{
streamName = "rtsp_stream_"+rtspProtocol.Id;
}
rtspProtocol.CustomParameters["sdpStreamName"] = streamName;
//7. Save the bandwidth hint
rtspProtocol.CustomParameters["sdpBandwidthHint"] = sdp.GetTotalBandwidth();
//8. Get the inbound connectivity
var pInboundConnectivity = rtspProtocol.GetInboundConnectivity(streamName, sdp.GetTotalBandwidth(),
rtcpDetectionInterval);
if (pInboundConnectivity == null)
{
FATAL("Unable to create inbound connectivity");
return false;
}
//9. Start sending the setup commands on the pending tracks;
return SendSetupTrackMessages(rtspProtocol);
}
示例15: TestDouble
public void TestDouble()
{
Variant v1 = new Variant((double)5.0);
Assert.AreEqual(v1.Type, Variant.EnumType.Double);
Assert.IsTrue(v1.Is(Variant.EnumType.Double));
Assert.IsTrue(v1.Is<double>());
Assert.AreEqual(v1.As<double>(), 5.0);
Assert.AreEqual(Convert.ToDouble(v1), 5.0);
Assert.AreEqual(v1.ToString(), "5");
Variant vNaN = new Variant(double.NaN);
Assert.AreEqual(vNaN.ToString(), "NaN");
Variant vINF = new Variant(double.PositiveInfinity);
Assert.AreEqual(vINF.ToString(), "INF");
Variant vNEGINF = new Variant(double.NegativeInfinity);
Assert.AreEqual(vNEGINF.ToString(), "-INF");
Variant v2 = new Variant(v1);
Assert.IsTrue(v1.Equals(v2));
}