public void Bookmark() { // 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 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; 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(); }
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(); } }
private void buttonTrigger_Click(object sender, EventArgs e) { Item item = dumpConfigurationUserControl1.GetSelectedItem(); if (item == null) { MessageBox.Show("Select an item"); return; } // Kind.TriggerEvent // If the serverType is CorporateManagementServerType and it is user-defined event // triggering an event with a camera FQID (as a releatedFQID) is supported. // This is useful because you can then create and use rules "Use devices from metadata" // to determine on which device to do the action. // If you do not need a parameter with the trigger you can leave it out, the trigger // command will work without a releatedFQID. if (item.FQID.Kind == Kind.TriggerEvent && item.FQID.ServerId.ServerType == ServerId.CorporateManagementServerType) { var form = new VideoOS.Platform.UI.ItemPickerForm(); form.KindFilter = Kind.Camera; form.Init(); DialogResult dr = form.ShowDialog(); if (dr == DialogResult.OK) { EnvironmentManager.Instance.SendMessage( new VideoOS.Platform.Messaging.Message( VideoOS.Platform.Messaging.MessageId.Control.TriggerCommand, form.SelectedItem.FQID), item.FQID); return; } else // if cancel trigger without relatedFQID { EnvironmentManager.Instance.SendMessage( new VideoOS.Platform.Messaging.Message( VideoOS.Platform.Messaging.MessageId.Control.TriggerCommand), item.FQID); return; } } // For More information see "Introduction to Controlling Output, PTZ and Matrix" in the MIP SDK Documentation // Kind.Matrix // Trigger of Matrix only makes sense with a relatedFQID, // the relatedFQID will identify the camera being pushed to the matrix if (item.FQID.Kind == Kind.Matrix) { var form = new VideoOS.Platform.UI.ItemPickerForm(); form.KindFilter = Kind.Camera; form.Init(); DialogResult dr = form.ShowDialog(); if (dr == DialogResult.OK) { EnvironmentManager.Instance.SendMessage( new VideoOS.Platform.Messaging.Message( VideoOS.Platform.Messaging.MessageId.Control.TriggerCommand, form.SelectedItem.FQID), item.FQID); return; } else { MessageBox.Show("To trigger matrix without a camera is not useful."); return; } } // Kind.Output and Kind.Preset (and Kind.TriggerEvent in E-code) // If not user defined event (triggerEvent) or matrix a relatedFQID is not relevant and not supported. // Trigger of outputs and PTZ Presets are the items that can be triggered which are not already mentioned. EnvironmentManager.Instance.SendMessage( new VideoOS.Platform.Messaging.Message( VideoOS.Platform.Messaging.MessageId.Control.TriggerCommand), item.FQID); }