static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Console.WriteLine("Milestone SDK evidence lock demo (XProtect Corporate only)"); Console.WriteLine("Creates 2 new evidence locks and retrieves them using "); Console.WriteLine(" 1) MarkedDataGet"); Console.WriteLine(" 2) MarkedDataSearch"); Console.WriteLine("And then deletes them again"); Console.WriteLine(""); // Initialize the SDK - must be done in stand alone VideoOS.Platform.SDK.Environment.Initialize(); VideoOS.Platform.SDK.UI.Environment.Initialize(); // Initialize ActiveX references, e.g. usage of ImageViewerActiveX etc #region Connect to the server var loginForm = new VideoOS.Platform.SDK.UI.LoginDialog.DialogLoginForm(SetLoginResult, IntegrationId, IntegrationName, Version, ManufacturerName); Application.Run(loginForm); // Show and complete the form and login to server if (!_connected) { Console.WriteLine("Failed to connect or login"); Console.ReadKey(); return; } if (EnvironmentManager.Instance.MasterSite.ServerId.ServerType != ServerId.CorporateManagementServerType) { Console.WriteLine("Evidence locks are not supported on this product."); Console.ReadKey(); return; } #endregion #region Select a camera Item selectedItem = null; var form = new VideoOS.Platform.UI.ItemPickerForm { KindFilter = Kind.Camera, AutoAccept = true }; form.Init(Configuration.Instance.GetItems()); if (form.ShowDialog() == DialogResult.OK) { selectedItem = form.SelectedItem; } if (selectedItem == null) { Console.WriteLine("Failed to pick a camera"); Console.ReadKey(); return; } if (selectedItem.FQID.ServerId.ServerType != ServerId.CorporateRecordingServerType) { Console.WriteLine("Evidence locks are not supported on this product."); Console.ReadKey(); return; } #endregion var loginSettings = LoginSettingsCache.GetLoginSettings(EnvironmentManager.Instance.MasterSite); using (var client = CreateWcfClient(loginSettings)) { // Get token needed for calls to manipulate evidence locks. var token = loginSettings.Token; var devicesToCreateLockOn = new[] { selectedItem.FQID.ObjectId }; DateTime timeNow = DateTime.UtcNow; #region create first evidence lock Console.WriteLine("Creating the first evidence lock"); var timeBegin1 = timeNow.AddMinutes(-60); var markedDataId1 = Guid.NewGuid(); try { var markedDataCreateResult = client.MarkedDataCreate( token, markedDataId1, devicesToCreateLockOn, timeBegin1, timeBegin1.AddMinutes(5), timeBegin1.AddMinutes(10), string.Format("MyEvidenceLock-{0}", timeBegin1.ToLongTimeString()), string.Format("AutoEvidenceLock-{0}", timeBegin1.ToLongTimeString()), string.Format("AutoEvidenceLock-{0} set for a duration of 10 minutes", timeBegin1.ToLongTimeString()), 2, // 2 is used for evidence locks true, // This must be set to true to actual lock data! DateTime.MaxValue, // We never expire the the evidence lock new RetentionOption { RetentionOptionType = RetentionOptionType.Indefinite, RetentionUnits = -1 } ); Console.WriteLine("{0} when creating evidence lock 1 with ID = {1}", markedDataCreateResult.Status, markedDataCreateResult.MarkedData.Id); } catch (Exception ex) { Console.WriteLine("EvidenceLock 1 failed: " + ex.Message); Console.WriteLine("Press any Key"); Console.ReadKey(); return; } #endregion #region Create a second evidence lock Console.WriteLine("Creating a second evidence lock - 20 minutes after the first evidence lock"); DateTime timeBegin2 = timeBegin1.AddMinutes(20); var markedDataId2 = Guid.NewGuid(); try { var markedDataCreateResult = client.MarkedDataCreate( token, markedDataId2, devicesToCreateLockOn, timeBegin2, timeBegin2.AddMinutes(5), timeBegin2.AddMinutes(10), string.Format("MyEvidenceLock-{0}", timeBegin2.ToLongTimeString()), string.Format("AutoEvidenceLock-{0}", timeBegin2.ToLongTimeString()), string.Format("AutoEvidenceLock-{0} set for a duration of 10 minutes", timeBegin2.ToLongTimeString()), 2, // 2 is used for evidence locks true, // This must be set to true to actual lock data! DateTime.MaxValue, // We never expire the the evidence lock new RetentionOption { RetentionOptionType = RetentionOptionType.Indefinite, RetentionUnits = -1 } ); Console.WriteLine("{0} when creating evidence lock 2 with ID = {1}", markedDataCreateResult.Status, markedDataCreateResult.MarkedData.Id); } catch (Exception ex) { Console.WriteLine("EvidenceLock 2 failed: " + ex.Message); Console.WriteLine("Press any Key"); Console.ReadKey(); return; } #endregion #region MarkedDataSearch Console.WriteLine("Searching for evidence locks ..."); var searchResult = client.MarkedDataSearch( token, devicesToCreateLockOn, // use empty array to search on all devices null, // Use null to not search for text null, // Use null to search for all users DateTime.MinValue.ToUniversalTime(), DateTime.MinValue.ToUniversalTime(), DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddSeconds(-10), DateTime.MinValue.ToUniversalTime(), DateTime.MinValue.ToUniversalTime(), DateTime.MinValue.ToUniversalTime(), DateTime.MinValue.ToUniversalTime(), 0, 100, SortOrderOption.CreateTime, true ); Console.WriteLine("-> Found {0} evidence lock{1}", searchResult.Length, searchResult.Length == 1 ? string.Empty : "s"); if (searchResult.Length > 0) { int counter = 1; foreach (var markedData in searchResult) { Console.WriteLine("{0}:", counter); PrintMarkedData(markedData); counter++; } } Console.WriteLine(""); #endregion #region MarkedDataGet // Get first created evidence lock Console.WriteLine( "Looking for the first evidence lock using MarkedDataGet (finding the first of the 2 newly created)"); var markedDataGet = client.MarkedDataGet(token, markedDataId1); if (markedDataGet != null) { Console.WriteLine("-> An evidence lock was found"); PrintMarkedData(markedDataGet); } else { Console.WriteLine("Sorry no evidence lock found"); } Console.WriteLine(""); #endregion #region Deleting evidence locks Console.WriteLine("Deleting the two newly created evidence locks"); var deleteResult = client.MarkedDataDelete(token, new[] { markedDataId1, markedDataId2 }); foreach (var markedDataResult in deleteResult) { Console.WriteLine("Deleting marked data {0} was a {1}", markedDataResult.MarkedData.Id, markedDataResult.Status); } #endregion Console.WriteLine(""); Console.WriteLine("Press any key"); Console.Out.Flush(); Console.ReadKey(); } }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Console.WriteLine("Milestone SDK Bookmarks demo (XProtect Corporate only)"); Console.WriteLine("Creates 2 new bookmarks and retrieves them using "); Console.WriteLine(" 1) BookmarkSearchTime "); Console.WriteLine(" 2) BookmarkSearchFromBookmark"); Console.WriteLine(" 3) BookmarkGet"); Console.WriteLine(""); // Initialize the SDK - must be done in stand alone VideoOS.Platform.SDK.Environment.Initialize(); VideoOS.Platform.SDK.UI.Environment.Initialize(); // Initialize ActiveX references, e.g. usage of ImageViewerActiveX etc #region Connect to the server VideoOS.Platform.SDK.UI.LoginDialog.DialogLoginForm loginForm = new VideoOS.Platform.SDK.UI.LoginDialog.DialogLoginForm(SetLoginResult, IntegrationId, IntegrationName, Version, ManufacturerName); Application.Run(loginForm); // Show and complete the form and login to server if (!Connected) { Console.WriteLine("Failed to connect or login"); Console.ReadKey(); return; } if (EnvironmentManager.Instance.MasterSite.ServerId.ServerType == ServerId.EnterpriseServerType) { Console.WriteLine("Bookmark is not supported on this product."); Console.ReadKey(); return; } #endregion #region Select a camera Item _selectItem1 = null; VideoOS.Platform.UI.ItemPickerForm form = new VideoOS.Platform.UI.ItemPickerForm(); form.KindFilter = Kind.Camera; form.AutoAccept = true; form.Init(Configuration.Instance.GetItems()); if (form.ShowDialog() == DialogResult.OK) { _selectItem1 = form.SelectedItem; } if (_selectItem1 == null) { Console.WriteLine("Failed to pick a camera"); Console.ReadKey(); return; } if (_selectItem1.FQID.ServerId.ServerType == ServerId.EnterpriseServerType) { Console.WriteLine("Bookmark is not supported on this product."); Console.ReadKey(); return; } FQID cameraFqid = _selectItem1.FQID; #endregion DateTime timeNow = DateTime.Now; // get cameras for each recording server // now-5:10min: BookmarkSearchTime start // now-5:00min: (beginTime) | BookmarkGet // now-4:59min: start recording 1 | // now-4:55min: start bookmark 1 | // now-4:45min: end bookmark 1 | // | BookmarkSearchFromBookmark // now-2:00min: | | // now-1:59min: start recording 2 | | // now-1:55min: start bookmark 2 (trigger time) | | // now-1:45min: end bookmark 2 | | // now v V Guid[] mediaDeviceTypes = new Guid[3]; mediaDeviceTypes[0] = Kind.Camera; mediaDeviceTypes[1] = Kind.Microphone; mediaDeviceTypes[2] = Kind.Speaker; #region get bookmark reference Console.WriteLine("Asking for a new Bookmark Reference:"); BookmarkReference bookmarkReference = BookmarkService.Instance.BookmarkGetNewReference(cameraFqid, true); Console.WriteLine(".... Received:" + bookmarkReference.Reference); #endregion #region create first bookmark Console.WriteLine("Creating the first bookmark"); DateTime timeBegin = timeNow.AddMinutes(-5); StringBuilder bookmarkref = new StringBuilder(); StringBuilder bookmarkHeader = new StringBuilder(); StringBuilder bookmarkDesc = new StringBuilder(); bookmarkref.AppendFormat("Mybookmark-{0}", timeBegin.ToLongTimeString()); bookmarkHeader.AppendFormat("AutoBookmark-{0}", timeBegin.ToLongTimeString()); bookmarkDesc.AppendFormat("AutoBookmark-{0} set for a duration of {1} seconds", timeBegin.ToLongTimeString(), (timeBegin.AddSeconds(10) - timeBegin.AddSeconds(1)).Seconds); Bookmark bookmark1 = null; try { bookmark1 = BookmarkService.Instance.BookmarkCreate( cameraFqid, timeBegin.AddSeconds(1), timeBegin.AddSeconds(5), timeBegin.AddSeconds(10), bookmarkref.ToString(), bookmarkHeader.ToString(), bookmarkDesc.ToString()); Console.WriteLine("Created bookmark 1 = " + bookmark1.BookmarkFQID.ToString()); } catch (Exception ex) { Console.WriteLine("BookmarkCreate 1 failed: " + ex.Message); Console.WriteLine("Press any Key"); Console.ReadKey(); } #endregion Console.WriteLine(""); Console.WriteLine("Waiting 20sec ...."); Console.WriteLine(""); System.Threading.Thread.Sleep(20000); #region Create a second bookmark Console.WriteLine("Creating a second bookmark - 2 minutes after the first bookmark"); DateTime timeBegin2 = timeBegin.AddMinutes(2); bookmarkHeader.Length = 0; bookmarkDesc.Length = 0; StringBuilder bookmarkref2 = new StringBuilder(); bookmarkref2.AppendFormat("Mybookmark-{0}", timeBegin2.ToLongTimeString()); bookmarkHeader.AppendFormat("AutoBookmark-{0}", timeBegin2.ToLongTimeString()); bookmarkDesc.AppendFormat("AutoBookmark-{0} set for a duration of {1} seconds", timeBegin2.ToLongTimeString(), (timeBegin2.AddSeconds(10) - timeBegin2.AddSeconds(1)).Seconds); Bookmark bookmark2 = null; try { bookmark2 = BookmarkService.Instance.BookmarkCreate( cameraFqid, timeBegin2.AddSeconds(1), timeBegin2.AddSeconds(5), timeBegin2.AddSeconds(10), bookmarkref2.ToString(), bookmarkHeader.ToString(), bookmarkDesc.ToString()); Console.WriteLine("Created bookmark 2 " + bookmark2.BookmarkFQID.ToString()); } catch (Exception ex) { Console.WriteLine("BookmarkCreate 2 failed: " + ex.Message); Console.WriteLine("Press any Key"); Console.ReadKey(); } Console.WriteLine("-> trigger time = {0}", bookmark2.TimeTrigged); Console.WriteLine(""); #endregion #region BookmarkSearchTime // Get max 10 the bookmarks created after the specified time Console.WriteLine(""); Console.WriteLine("Looking for bookmarks using BookmarkSearchTime (finding the 2 newly created)"); Bookmark[] bookmarkList = BookmarkService.Instance.BookmarkSearchTime( cameraFqid.ServerId, bookmark1.TimeBegin.AddSeconds(-10), 1800000000, 10, mediaDeviceTypes, null, null, null); if (bookmarkList.Length > 0) { Console.WriteLine("-> Found {0} bookmark(s)", bookmarkList.Length); int counter = 1; foreach (Bookmark bookmark in bookmarkList) { Console.WriteLine("{0}:", counter); Item camera = Configuration.Instance.GetItem(bookmark.BookmarkFQID.ParentId, Kind.Camera); FQID parent = bookmark.BookmarkFQID.GetParent(); Item camera2 = Configuration.Instance.GetItem(parent); Console.WriteLine(" Id ={0} ", bookmark.BookmarkFQID.ToString()); Console.WriteLine(" Name={0} ", bookmark.Header); Console.WriteLine(" Desc={0} ", bookmark.Description); Console.WriteLine(" user={0} ", bookmark.User); Console.WriteLine(" Device={0} Start={1} Stop={2} ", bookmark.GetDeviceItem().FQID.ObjectId, bookmark.TimeBegin, bookmark.TimeEnd); counter++; } } else { Console.WriteLine("sorry no bookmarks found"); } Console.WriteLine(""); #endregion #region BookmarkSearchFromBookmark // Get the next (max 10) bookmarks after the first Console.WriteLine("Looking for bookmarks using BookmarSearchFromBookmark (finding the last of the 2 newly created)"); Bookmark[] bookmarkListsFromBookmark = BookmarkService.Instance.BookmarkSearchFromBookmark( bookmark1.BookmarkFQID, 1800000000, 10, mediaDeviceTypes, null, null, null); if (bookmarkListsFromBookmark.Length > 0) { Console.WriteLine("-> Found {0} bookmark(s)", bookmarkListsFromBookmark.Length); int counter = 1; foreach (Bookmark bookmark in bookmarkListsFromBookmark) { Console.WriteLine("{0}:", counter); Console.WriteLine(" Id ={0} ", bookmark.BookmarkFQID.ToString()); Console.WriteLine(" Name={0} ", bookmark.Header); Console.WriteLine(" Desc={0} ", bookmark.Description); Console.WriteLine(" user={0} ", bookmark.User); Console.WriteLine(" Device={0} Start={1} Stop={2} ", bookmark.GetDeviceItem().FQID.ObjectId, bookmark.TimeBegin, bookmark.TimeEnd); counter++; } } else { Console.WriteLine("sorry no bookmarks found"); } Console.WriteLine(""); #endregion #region SearchTimeAsync Console.WriteLine("Looking for bookmarks using bookmarkSearchTimeAsync (finding the last of the 2 newly created)"); _hasBeenCalledBack = false; BookmarkService.Instance.BookmarkSearchTimeAsync( cameraFqid.ServerId, bookmark2.TimeBegin.AddSeconds(-10), 1800000000, 10, mediaDeviceTypes, null, null, null, MyAsyncCallbackHandler, null); while (!_hasBeenCalledBack) { //Do something usefull while waiting System.Threading.Thread.Sleep(100); } #endregion #region SearchBookmarkAsync Console.WriteLine("Looking for bookmarks using BookmarkSearchFromBookmarkAsync (finding the last of the 2 newly created)"); _hasBeenCalledBack = false; BookmarkService.Instance.BookmarkSearchFromBookmarkAsync( bookmark1.BookmarkFQID, 1800000000, 10, mediaDeviceTypes, null, null, null, MyAsyncCallbackHandler, null); while (!_hasBeenCalledBack) { //Do something usefull while waiting System.Threading.Thread.Sleep(100); } #endregion #region BookmarkGet // Get first created bookmark Console.WriteLine("Looking for the first bookmarks using BookmarkGet (finding the first of the 2 newly created)"); Bookmark newbookmarkFetched = BookmarkService.Instance.BookmarkGet(bookmark1.BookmarkFQID); if (newbookmarkFetched != null) { Console.WriteLine("-> A bookmarks is found"); Console.WriteLine(" Id ={0} ", newbookmarkFetched.BookmarkFQID.ToString()); Console.WriteLine(" Name={0} ", newbookmarkFetched.Header); Console.WriteLine(" Desc={0} ", newbookmarkFetched.Description); Console.WriteLine(" user={0} ", newbookmarkFetched.User); Console.WriteLine(" Device={0} Start={1} Stop={2} ", newbookmarkFetched.GetDeviceItem().FQID.ObjectId, newbookmarkFetched.TimeBegin, newbookmarkFetched.TimeEnd); } else { Console.WriteLine("Sorry no bookmarks found"); } Console.WriteLine(""); #endregion #region Update Bookmark1 Console.WriteLine("Updating the bookmark just fetched using BookmarkUpdate"); newbookmarkFetched.Description = "Now I have updated the description of this bookmark"; Bookmark newbookmark1 = BookmarkService.Instance.BookmarkUpdate(newbookmarkFetched); if (newbookmarkFetched != null) { Console.WriteLine("-> Result ="); Console.WriteLine(" Id ={0} ", newbookmarkFetched.BookmarkFQID.ToString()); Console.WriteLine(" Name={0} ", newbookmarkFetched.Header); Console.WriteLine(" Desc={0} ", newbookmarkFetched.Description); Console.WriteLine(" user={0} ", newbookmarkFetched.User); Console.WriteLine(" Device={0} Start={1} Stop={2} ", newbookmarkFetched.GetDeviceItem().FQID.ObjectId, newbookmarkFetched.TimeBegin, newbookmarkFetched.TimeEnd); } else { Console.WriteLine("Sorry. Failed to update the bookmark"); } Console.WriteLine(""); #endregion #region Deleting bookmarks Console.WriteLine("Deleting 2 newly created bookmarks"); BookmarkService.Instance.BookmarkDelete(bookmark1.BookmarkFQID); Console.WriteLine(" -> first deleted"); BookmarkService.Instance.BookmarkDelete(bookmark2); Console.WriteLine(" -> second deleted"); #endregion Console.WriteLine(""); Console.WriteLine("Press any key"); Console.ReadKey(); }