本文整理汇总了C#中CameraType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# CameraType.ToString方法的具体用法?C# CameraType.ToString怎么用?C# CameraType.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CameraType
的用法示例。
在下文中一共展示了CameraType.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCameras
/// <summary>
/// Gets the cameras.
/// </summary>
/// <param name="cameraType">Type of the camera.</param>
/// <param name="name">The name.</param>
/// <returns></returns>
public IObservable<Camera> GetCameras(CameraType cameraType, string name)
{
var cachedCameras = new CachedEntity<List<Camera>>(string.Format("Services.Camera.{0}.{1}", cameraType, name));
return new AnonymousObservable<Camera>(observer =>
{
if (!cachedCameras.Value.Any() || !cachedCameras.CachedDateTime.HasValue || cachedCameras.CachedDateTime.Value <= DateTime.Now.AddDays(-1))
{
Uri cameraListUri = null;
if (cameraType == CameraType.Regional)
{
cameraListUri = new Uri(string.Format("{0}?roadway={1}", DfwTranstarUri.CamerasRegionalUri, name.Replace(' ', '_')));
}
else
{
cameraListUri = new Uri(string.Format("{0}?list={1}&roadway={2}", DfwTranstarUri.CamerasUri, cameraType.ToString().ToLower(), name.Replace(' ', '_')));
}
IObservable<string> observable = ObservableHelper.TextFromUri(cameraListUri);
var svc = observable.Subscribe(result =>
{
int tableStart = result.IndexOf("<table id=\"ListTable\"");
int tableEnd = result.IndexOf("</table>", tableStart);
XElement xmlDoc = XElement.Parse(result.Substring(tableStart, (tableEnd + 8) - tableStart));
var cameras = from item in xmlDoc.Element("tr").Element("td").Element("ul").Elements("li")
select new Camera
{
ID = this.GetCameraID(cameraType, item.Element("a").Attribute("href").Value),
Name = item.Value,
EnableThumbnails = ProfileCommon.UserSettings.ShowCameraThumbnails,
ImageUri = cameraType == CameraType.Regional ?
string.Format(DfwTranstarUri.CameraDetailRegionalUri, name.ToLower()
.Replace(" north", "")
.Replace(" south", "")
.Replace(" east", "")
.Replace(" west", ""),
this.GetCameraID(cameraType, item.Element("a").Attribute("href").Value)) :
string.Format(DfwTranstarUri.CameraDetailUri, this.GetCameraID(cameraType, item.Element("a").Attribute("href").Value))
};
cachedCameras.Value = cameras.ToList();
cachedCameras.Cache();
cachedCameras.Value.ToList().ForEach(c => observer.OnNext(c));
observer.OnCompleted();
},
ex =>
{
observer.OnError(new Exception("Unable to retrieve traffic data.", ex));
});
}
else
{
cachedCameras.Value.ToList().ForEach(c => observer.OnNext(c));
observer.OnCompleted();
}
return Disposable.Empty;
});
}
示例2: GetRoadwayCameras
/// <summary>
/// Gets the roadway cameras.
/// </summary>
/// <param name="cameraType">Type of the camera.</param>
/// <returns></returns>
public IObservable<Roadway> GetRoadwayCameras(CameraType cameraType)
{
var cachedRoadways = new CachedEntity<List<Roadway>>("Services.RoadwayCameras." + cameraType.ToString());
return new AnonymousObservable<Roadway>(observer =>
{
if (!cachedRoadways.Value.Any() || cachedRoadways.CachedDateTime <= DateTime.Now.AddDays(-1))
{
Uri uri = null;
switch (cameraType)
{
case CameraType.Freeway:
uri = new Uri(DfwTranstarUri.CamerasUri);
break;
case CameraType.Street:
uri = new Uri(DfwTranstarUri.CamerasUri + "?list=street");
break;
case CameraType.Regional:
uri = new Uri(DfwTranstarUri.CamerasRegionalUri);
break;
}
IObservable<string> observable = ObservableHelper.TextFromUri(uri);
var svc = observable.Subscribe(result =>
{
int tableStart = result.IndexOf("<table id=\"ListTable\"");
int tableEnd = result.IndexOf("</table>", tableStart);
XElement xmlDoc = XElement.Parse(result.Substring(tableStart, (tableEnd + 8) - tableStart));
var roadways = from item in xmlDoc.Element("tr").Element("td").Element("ul").Elements("li")
select new Roadway
{
Name = item.Value,
IconUri = cameraType == CameraType.Freeway ?
this.GetRoadwayIconUri(item.Value) : "/Resources/Images/empty_svg_small.png"
};
cachedRoadways.Value = roadways.ToList();
cachedRoadways.Cache();
cachedRoadways.Value.ToList().ForEach(r => observer.OnNext(r));
observer.OnCompleted();
}, ex =>
{
observer.OnError(new Exception("Unable to retrieve traffic data.", ex));
});
}
else
{
cachedRoadways.Value.ToList().ForEach(r => observer.OnNext(r));
observer.OnCompleted();
}
return Disposable.Empty;
});
}