Hi Bo,
Thanks for answering. Yes the unmodified view sample works.
The issue is not that I can’t get it working its just that the working code keeps failing with the error I mentioned and the only way I have found to fix it is copy the exact code into a new project and then it works for a while.
I’m just trying to identify what it is I’m doing that could be causing it. It has happened repeatedly and copying into a new project always fixes it but it’s a pain doing it.
I know it’s something I’m doing but I can’t work out what it could be.
Rob
<------------------------------------ Form Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using TrussCorp.Cameras;
using TrussCorp.Functions;
using VideoOS.Platform.Login;
namespace TestForm
{
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
Thread m_thread = null;
private readonly CFunctions CFn = new CFunctions();
private LoginSettings loginSettings;
private List<VideoOS.Platform.Item> filteredCameraList;
public RadForm1()
{
InitializeComponent();
}
private void RadForm1_Load(object sender, EventArgs e)
{
m_thread = new Thread(new ThreadStart(ThreadProc));
m_thread.Start();
}
public void ThreadProc()
{
Tuple<LoginSettings, string> Rtn = CFn.LoginToServer(“CameraServerURL”.GetSettings(), “CameraServerUsername”.GetSettings(), “CameraServerPassword”.GetSettings());
if (string.IsNullOrEmpty(Rtn.Item2))
{
loginSettings = Rtn.Item1;
}
else
{
Fn.SendSMS(Rtn.Item2 + @" Security Pedestrian Monitor App on " + Dns.GetHostName(), “04xxxxxxxx”, “04xxxxxxxx”);
return;
}
filteredCameraList = CFn.GetCameraList();
int interval = 500;
int elapsed = 0;
int waitTime = 50;
try
{
while (true)
{
if (interval >= elapsed)
{
elapsed = 0;
//GetCameraImages();
}
Thread.Sleep(waitTime);
elapsed += waitTime;
}
}
catch (ThreadAbortException)
{
// we want to eat the exception because we don’t care if the
// thread has aborted since we probably did it on purpose by
// stopping the service.
}
}
private void RadForm1_FormClosing(object sender, FormClosingEventArgs e)
{
CFn.LogOut();
Environment.Exit(Environment.ExitCode);
}
}
}
<------------------------------------------------------------- Camera Functions above
public class CFunctions
{
public Tuple<LoginSettings,string> LoginToServer(string Url, string Username, string Password)
{
LogOut();
string Message = “”;
VideoOS.Platform.SDK.Environment.Initialize();
VideoOS.Platform.EnvironmentManager.Instance.EnvironmentOptions[“UsePing”] = “No”;
Uri uri = new UriBuilder(Url).Uri;
CredentialCache credentialCache = Util.BuildCredentialCache(uri, Username, Password, “Basic”);
VideoOS.Platform.SDK.Environment.AddServer(uri, credentialCache);
LoginSettings loginSettings = null;
try
{
VideoOS.Platform.SDK.Environment.Login(uri);
loginSettings = LoginSettingsCache.GetLoginSettings(Url);
}
catch (ServerNotFoundMIPException snfe)
{
Message = "Server not found: " + snfe.Message;
VideoOS.Platform.SDK.Environment.RemoveServer(uri);
}
catch (InvalidCredentialsMIPException ice)
{
Message = "Invalid credentials for: " + ice.Message;
VideoOS.Platform.SDK.Environment.RemoveServer(uri);
}
catch (Exception)
{
Message = "Internal error connecting to: " + uri.DnsSafeHost;
VideoOS.Platform.SDK.Environment.RemoveServer(uri);
}
return new Tuple<LoginSettings, string> (loginSettings, Message);
}
public void LogOut()
{
try
{
VideoOS.Platform.SDK.Environment.Logout();
VideoOS.Platform.SDK.Environment.UnInitialize();
}
catch
{
// ignored
}
}
public List<VideoOS.Platform.Item> GetCameraList()
{
List<VideoOS.Platform.Item> cameraFolder = VideoOS.Platform.Configuration.Instance.GetItemsByKind(VideoOS.Platform.Kind.Camera);
List<VideoOS.Platform.Item> cameraList = FindAllCameras(cameraFolder);
List<VideoOS.Platform.Item> filteredCameraList = RemoveDuplicates(cameraList);
return filteredCameraList;
}
private List<VideoOS.Platform.Item> FindAllCameras(List<VideoOS.Platform.Item> folders)
{
List<VideoOS.Platform.Item> result = new List<VideoOS.Platform.Item>();
foreach (VideoOS.Platform.Item item in folders)
{
if (item.FQID.FolderType == VideoOS.Platform.FolderType.No)
{
if (item.FQID.Kind == VideoOS.Platform.Kind.Camera)
result.Add(item);
}
else
{
if (item.FQID.Kind == VideoOS.Platform.Kind.Server || item.FQID.Kind == VideoOS.Platform.Kind.Camera || item.FQID.Kind == VideoOS.Platform.Kind.Folder)
result.AddRange(FindAllCameras(item.GetChildren()));
}
}
return result;
}
private List<VideoOS.Platform.Item> RemoveDuplicates(List<VideoOS.Platform.Item> list)
{
Hashtable cameraObjectIds = new Hashtable();
List<VideoOS.Platform.Item> result = new List<VideoOS.Platform.Item>();
foreach (VideoOS.Platform.Item item in list)
{
if (cameraObjectIds[item.FQID.ObjectId] == null)
{
cameraObjectIds[item.FQID.ObjectId] = “AllReadyAdded”;
result.Add(item);
}
}
return result;
}
}