Commit 5019b706 by ozekiltd

Build commit version: 11.1.2

parents

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Onvif IP Camera Manager", "Onvif IP Camera Manager\Onvif IP Camera Manager.csproj", "{AA392C81-E16E-4595-8585-AE1E36913F22}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AA392C81-E16E-4595-8585-AE1E36913F22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA392C81-E16E-4595-8585-AE1E36913F22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA392C81-E16E-4595-8585-AE1E36913F22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA392C81-E16E-4595-8585-AE1E36913F22}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>
<Application x:Class="Onvif_IP_Camera_Manager.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="View/MainWindow.xaml">
<Application.Resources>
<Style x:Key="{x:Type Label}" TargetType="Label">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Height" Value="30"/>
</Style>
</Application.Resources>
</Application>
using System;
using System.Windows;
using System.Windows.Threading;
namespace Onvif_IP_Camera_Manager
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
base.OnStartup(e);
}
void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show(string.Format("Error occurred: {0}, {1}, {2}", e.Exception.GetType(), e.Exception.Message, e.Exception.StackTrace), "Error");
e.Handled = true;
}
}
}
using System;
namespace Onvif_IP_Camera_Manager.LOG
{
public class DetectionEventArgs : EventArgs
{
public string Path;
public DetectionEventArgs(string path)
{
Path = path;
}
}
}
using System;
using Onvif_IP_Camera_Manager.Model.Data;
namespace Onvif_IP_Camera_Manager.LOG
{
class Log
{
public static ObservableList<string> LogList { get; set; }
public static ObservableList<string> MotionLogList { get; set; }
static object sync = new object();
static Log()
{
LogList = new ObservableList<string>();
MotionLogList = new ObservableList<string>();
}
private static int Counter;
public static void Write(string logMessage)
{
string logMsg;
lock (sync)
{
Counter++;
logMsg = "(" + Counter + ") " + DateTime.Now + " | " + logMessage;
LogList.Add(logMsg);
}
}
private static int MotionCounter;
public static void Motion(string logMessage)
{
string logMsg;
lock (sync)
{
Write(logMessage);
MotionCounter++;
logMsg = "(" + MotionCounter + ") " + DateTime.Now + " | " + logMessage;
MotionLogList.Add(logMsg);
}
}
}
}
using System;
namespace Onvif_IP_Camera_Manager.LOG
{
class LogEventArgs : EventArgs
{
public string LogMessage;
public LogEventArgs(string log)
{
LogMessage = log;
}
}
}

namespace Onvif_IP_Camera_Manager.Model
{
public class AccountModel
{
public string DisplayName { get; set; }
public string UserName { get; set; }
public string RegisterName { get; set; }
public string Password { get; set; }
public string Domain { get; set; }
public string OutboundProxy { get; set; }
public bool RegistrationRequired { get; set; }
}
}
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using Onvif_IP_Camera_Manager.Model.Data;
using Onvif_IP_Camera_Manager.Model.Helpers;
namespace Onvif_IP_Camera_Manager.Model
{
public class AddCameraModel : INotifyPropertyChanged
{
string _cameraUrl;
string _userName;
string _password;
Window _addCameraWindow;
public string CameraUrl
{
get { return _cameraUrl; }
set
{
_cameraUrl = value;
OnPropertyChanged("CameraUrl");
}
}
public string UserName
{
get { return _userName; }
set
{
_userName = value;
OnPropertyChanged("UserName");
}
}
public string Password
{
get { return _password; }
set
{
_password = value;
OnPropertyChanged("Password");
}
}
public string Example1 { get; private set; }
public string Example2 { get; private set; }
public string Example3 { get; private set; }
public ConnectModel ConnectModel { get; set; }
public ICommand AddCameraCommand { get; private set; }
public ICommand ClearCommand { get; private set; }
public event PropertyChangedEventHandler PropertyChanged;
public event EventHandler<CameraAddedEventArgs> CameraAdded;
public AddCameraModel(Window addCameraWindow)
{
_addCameraWindow = addCameraWindow;
SetContents();
SetCommands();
}
void SetContents()
{
//ClearFields();
InvokeGui(() =>
{
if (ConnectModel.SelectedDevice.IpCameraInfo != null)
CameraUrl = ConnectModel.SelectedDevice.IpCameraInfo.Uri.ToString();
else
CameraUrl = String.Empty;
Example1 = "192.168.115.98:8080";
OnPropertyChanged("Example1");
Example2 = "http://192.168.115.98:8080";
OnPropertyChanged("Example2");
Example3 = "rtsp://192.168.115.98:554/test.sdp";
OnPropertyChanged("Example3");
});
}
void ClearFields()
{
InvokeGui(() =>
{
CameraUrl = String.Empty;
UserName = String.Empty;
Password = String.Empty;
});
}
void SetCommands()
{
AddCameraCommand = new RelayCommand(() =>
{
AddCamera();
_addCameraWindow.Close();
});
ClearCommand = new RelayCommand(ClearFields);
}
void AddCamera()
{
if (String.IsNullOrEmpty(CameraUrl))
return;
var ipCamera = new IpCameraEngine(CameraUrl, UserName, Password);
if (!(CameraUrl.Trim().ToUpper().StartsWith("HTTP://") || CameraUrl.Trim().ToUpper().StartsWith("RTSP://")))
CameraUrl = String.Format("http://{0}", CameraUrl);
var ipCameraInfo = new IPVideoDeviceInfo
{
Uri = new Uri(CameraUrl)
};
var savedCamera = new SavedCamera
{
DeviceInfo = new CameraDeviceInfo
{
IpCameraInfo = ipCameraInfo
},
Camera = ipCamera,
UserName = UserName,
Password = Password
};
var deviceInfo = new CameraDeviceInfo
{
IpCameraInfo = ipCameraInfo
};
ConnectModel.CameraList.Add(ipCamera);
ConnectModel.SavedCameras.Add(savedCamera);
ConnectModel.DeviceList.Add(deviceInfo);
OnCameraAdded(ipCamera);
}
void InvokeGui(Action action)
{
Dispatcher.CurrentDispatcher.BeginInvoke(action);
}
void OnCameraAdded(Camera camera)
{
var handler = CameraAdded;
if (handler != null)
handler(this, new CameraAddedEventArgs(camera));
}
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Onvif_IP_Camera_Manager.Model.Data;
using Ozeki.Media.IPCamera;
using Ozeki.Media.IPCamera.Discovery;
using Ozeki.Media.MediaHandlers.Video;
namespace Onvif_IP_Camera_Manager.Model
{
public class ConnectModel : INotifyPropertyChanged
{
string _url;
public string User { get; set; }
public string Password { get; set; }
public ObservableList<CameraDeviceInfo> DeviceList { get; private set; }
public CameraDeviceInfo SelectedDevice { get; set; }
public List<SavedCamera> SavedCameras { get; private set; }
public List<Camera> CameraList { get; private set; }
public event EventHandler<DeviceAddedEventArgs> DeviceAdded;
public string Url
{
get { return _url; }
set
{
_url = value;
OnPropertyChanged("URL");
}
}
public ConnectModel()
{
Url = String.Empty;
User = String.Empty;
Password = String.Empty;
DeviceList = new ObservableList<CameraDeviceInfo>();
SavedCameras = new List<SavedCamera>();
CameraList = new List<Camera>();
IPCameraFactory.DeviceDiscovered += IPCamera_DeviceDiscovered;
}
internal void Close()
{
IPCameraFactory.DeviceDiscovered -= IPCamera_DeviceDiscovered;
}
void DiscoverUsbDevices()
{
var webCameras = WebCamera.GetDevices();
foreach (var camera in webCameras)
{
var deviceInfo = new CameraDeviceInfo { WebCameraInfo = camera };
AddDeviceToList(deviceInfo);
}
}
internal void DiscoverDevices()
{
DeviceList.Clear();
CameraList.Clear();
foreach (var userCamera in SavedCameras)
{
if (userCamera.DeviceInfo != null)
{
try
{
DeviceList.Add(userCamera.DeviceInfo);
}
catch (Exception ex)
{
}
}
if (userCamera.Camera != null)
{
try
{
CameraList.Add(userCamera.Camera);
}
catch (Exception ex)
{
}
}
}
DiscoverUsbDevices();
IPCameraFactory.DiscoverDevices();
}
void IPCamera_DeviceDiscovered(object sender, DiscoveryEventArgs e)
{
var deviceInfo = new CameraDeviceInfo { IpCameraInfo = new IPVideoDeviceInfo(e.Device) };
AddDeviceToList(deviceInfo);
}
void AddDeviceToList(CameraDeviceInfo info)
{
if (SelectedDevice == null)
{
SelectedDevice = info;
OnPropertyChanged("SelectedDevice");
}
if (info.IpCameraInfo != null)
{
foreach (var cameraDeviceInfo in SavedCameras)
{
if (String.IsNullOrEmpty(cameraDeviceInfo.Camera.DeviceInfo))
continue;
if (cameraDeviceInfo.DeviceInfo == null || cameraDeviceInfo.DeviceInfo.IpCameraInfo == null || info.IpCameraInfo.Uri == null)
continue;
if (cameraDeviceInfo.DeviceInfo.IpCameraInfo.Uri.ToString().Equals(info.IpCameraInfo.Uri.ToString()))
return;
}
}
else
{
foreach (var cameraDeviceInfo in SavedCameras)
{
if (String.IsNullOrEmpty(cameraDeviceInfo.Camera.DeviceInfo))
continue;
if (cameraDeviceInfo.DeviceInfo == null || cameraDeviceInfo.DeviceInfo.WebCameraInfo == null)
continue;
if (cameraDeviceInfo.DeviceInfo.WebCameraInfo.Name.Equals(info.WebCameraInfo.Name))
return;
}
}
DeviceList.Add(info);
try
{
OnDeviceAdded(info);
}
catch (Exception ex)
{
}
OnPropertyChanged("DeviceList");
}
public SavedCamera GetSavedCamera(string address)
{
if (String.IsNullOrEmpty(address))
return null;
foreach (var savedCamera in SavedCameras)
{
if (savedCamera.Camera != null
&& savedCamera.Camera.CameraInfo.Equals(address))
return savedCamera;
if (savedCamera.DeviceInfo != null
&& savedCamera.DeviceInfo.IpCameraInfo != null
&& savedCamera.DeviceInfo.IpCameraInfo.Uri.ToString().Equals(address))
return savedCamera;
}
return null;
}
public bool RemoveCamera(Camera camera)
{
for (var i = CameraList.Count - 1; i >= 0; i--)
{
if (CameraList[i].CameraInfo != camera.CameraInfo)
continue;
return CameraList.Remove(CameraList.FirstOrDefault(c=> c.CameraInfo.Equals(camera.CameraInfo)));
}
return false;
}
void OnDeviceAdded(CameraDeviceInfo info)
{
var handler = DeviceAdded;
if (handler != null)
handler(this, new DeviceAddedEventArgs(info));
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}
using System;
namespace Onvif_IP_Camera_Manager.Model.Data
{
public class CameraAddedEventArgs : EventArgs
{
public Camera Camera { get; private set; }
internal CameraAddedEventArgs(Camera camera)
{
Camera = camera;
}
}
}
using System;
using Ozeki.Media.Video;
namespace Onvif_IP_Camera_Manager.Model.Data
{
public class CameraDeviceInfo
{
public VideoDeviceInfo WebCameraInfo { get; set; }
//public DiscoveredDeviceInfo IpCameraInfo { get; set; }
public IPVideoDeviceInfo IpCameraInfo { get; set; }
public override string ToString()
{
if (WebCameraInfo != null)
return string.Format("[USB] {0}", WebCameraInfo.Name);
if (IpCameraInfo != null)
{
if (!String.IsNullOrEmpty(IpCameraInfo.Host))
return string.Format("[ONVIF] {0}:{1}", IpCameraInfo.Host, IpCameraInfo.Port);
if (IpCameraInfo.Uri != null && IpCameraInfo.Uri.ToString().Trim().ToUpper().StartsWith("RTSP://"))
return String.Format("[RTSP] {0}", IpCameraInfo.Uri);
return String.Format("[CUSTOM] {0}", IpCameraInfo.Uri);
}
return "Unknown";
}
}
}
using System;
namespace Onvif_IP_Camera_Manager.Model.Data
{
public class DeviceAddedEventArgs : EventArgs
{
public CameraDeviceInfo Info { get; private set; }
internal DeviceAddedEventArgs(CameraDeviceInfo info)
{
Info = info;
}
}
}
using System;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using Onvif_IP_Camera_Manager.LOG;
using System.IO;
namespace Onvif_IP_Camera_Manager.Model.Data
{
public class Email
{
public MailAddress FromAddress { get; set; }
public string FromPassword { get; set; }
public MailAddress ToAddress { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
public int PortNum { get; set; }
public SmtpClient Smtpclient { get; set; }
public Email(string fromAddress, string fromPassword, string toAddress, string subject, string body, int port)
{
FromAddress = new MailAddress(fromAddress, "Ozeki");
FromPassword = fromPassword;
ToAddress = new MailAddress(toAddress, "Ozeki");
Subject = subject;
Body = body;
PortNum = port;
}
public void SendEmail(string file)
{
var attachmentFilename = file;
var attachment = new Attachment(attachmentFilename, MediaTypeNames.Application.Octet);
if (attachmentFilename != null)
{
var disposition = attachment.ContentDisposition;
disposition.CreationDate = File.GetCreationTime(attachmentFilename);
disposition.ModificationDate = File.GetLastWriteTime(attachmentFilename);
disposition.ReadDate = File.GetLastAccessTime(attachmentFilename);
disposition.FileName = Path.GetFileName(attachmentFilename);
disposition.Size = new FileInfo(attachmentFilename).Length;
disposition.DispositionType = DispositionTypeNames.Attachment;
}
using (var message = new MailMessage(FromAddress, ToAddress)
{
Subject = Subject,
Body = Body
})
{
if (Smtpclient == null) return;
try
{
Smtpclient.Timeout = 300000000;
message.Attachments.Add(attachment);
Smtpclient.Send(message);
Log.Write(String.Format("Email has been sent from {0} to {1}", FromAddress.Address, ToAddress.Address));
}
catch (Exception exception)
{
Log.Write("Error occured during e-mail sending: " + exception.Message);
}
}
}
public void CreateSmtpClient(string address)
{
Smtpclient = new SmtpClient
{
Host = address,
Port = PortNum,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(FromAddress.Address, FromPassword)
};
}
}
}
using System;
using System.IO;
using System.Net;
using Onvif_IP_Camera_Manager.LOG;
namespace Onvif_IP_Camera_Manager.Model.Data
{
public class Ftp
{
public string Host { get; set; }