private void OnCreate2x1(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(textBoxLayout.Text))
                {
                    MessageBox.Show("Please specifiy name of layout before creating");
                }
                else
                {
                    // Check that the name entered is not already used:
                    bool dup = false;
                    foreach (Item currentView in _groupItem.GetChildren())
                    {
                        if (textBoxLayout.Text == currentView.Name)
                        {
                            MessageBox.Show("Duplicate name - please select another");
                            dup = true;
                        }
                    }

                    if (!dup)
                    {
                        Rectangle[] rect = new Rectangle[3];
                        rect[0]                   = new Rectangle(000, 000, 999, 499);
                        rect[1]                   = new Rectangle(000, 499, 499, 499);
                        rect[2]                   = new Rectangle(499, 499, 499, 499);
                        _viewAndLayoutItem        = (ViewAndLayoutItem)_groupItem.AddChild(textBoxLayout.Text, Kind.View, FolderType.No);
                        textBoxCount.Text         = "3";
                        _viewAndLayoutItem.Icon   = Properties.Resources.UnknownLayout;
                        _viewAndLayoutItem.Layout = rect;
                        MakeIXList(3);
                    }
                }
            }
            catch (Exception ex)
            {
                EnvironmentManager.Instance.ExceptionDialog("OnCreate2x1", ex);
            }
        }
        /// <summary>
        /// This method is called when the user selects a camera and inserts the selected camera in a floating hotspot window
        /// </summary>
        /// <param name="message"></param>
        /// <param name="dest"></param>
        /// <param name="sender"></param>
        /// <returns></returns>
        private object ViewItemSelected(Message message, FQID dest, FQID sender)
        {
            if (sender != null && _myWindowFQID2 != null && sender.ObjectId == _myWindowFQID2.ObjectId)       // Ignore my own setup messages
            {
                return(null);
            }
            if (_myMessageInProgress)
            {
                return(null);
            }

            if (message.MessageId == MessageId.SmartClient.SelectedCameraChangedIndication)
            {
                FQID cameraFQID = message.RelatedFQID;

                if (_myWindowFQID2 != null)
                {
                    _myMessageInProgress = true;
                    EnvironmentManager.Instance.SendMessage(new Message(MessageId.SmartClient.SetCameraInViewCommand,
                                                                        new SetCameraInViewCommandData()
                    {
                        Index = _top?0:1, CameraFQID = cameraFQID
                    }), _myWindowFQID2);
                    _myMessageInProgress = false;
                    _top = !_top;
                    return(null);
                }

                if (cameraFQID == null)
                {
                    return(null);
                }

                _viewCounter++;
                // Make a new Temporary view group
                ConfigItem tempGroupItem = (ConfigItem)ClientControl.Instance.CreateTemporaryGroupItem("Floating Hotspot");
                // Make a group
                ConfigItem groupItem = tempGroupItem.AddChild("SCHotSpotGroup" + _viewCounter, Kind.View, FolderType.UserDefined);
                // Build a layout with wide ViewItems at the top and buttom, and 5 small ones in the middle
                Rectangle[] rect = new Rectangle[2];
                rect[0] = new Rectangle(000, 000, 999, 499);
                rect[1] = new Rectangle(000, 499, 999, 500);
                string            viewName          = "SCHotSpot" + _viewCounter;
                ViewAndLayoutItem viewAndLayoutItem = (ViewAndLayoutItem)groupItem.AddChild(viewName, Kind.View, FolderType.No);
                viewAndLayoutItem.Layout = rect;
                // Insert cameras
                Dictionary <String, String> cameraViewItemProperties = new Dictionary <string, string>();
                cameraViewItemProperties.Add("CameraId", cameraFQID != null?cameraFQID.ObjectId.ToString():Guid.Empty.ToString());
                viewAndLayoutItem.InsertBuiltinViewItem(0, ViewAndLayoutItem.CameraBuiltinId, cameraViewItemProperties);
                viewAndLayoutItem.Save();
                tempGroupItem.PropertiesModified();
                // Create floating window
                MultiWindowCommandData data    = new MultiWindowCommandData();
                List <Item>            screens = Configuration.Instance.GetItemsByKind(Kind.Screen);
                FQID screenFQID = GetFirstOfKind(screens, Kind.Screen);
                if (screenFQID != null)
                {
                    data.Screen = screenFQID;
                    List <Item> windows    = Configuration.Instance.GetItemsByKind(Kind.Window);
                    FQID        windowFQID = GetFirstOfKind(windows, Kind.Window);
                    if (windowFQID != null)
                    {
                        data.Window = windowFQID;
                        foreach (Item view in groupItem.GetChildren())
                        {
                            if (view.Name.Equals(viewName))
                            {
                                data.View               = view.FQID;
                                data.X                  = 200;
                                data.Y                  = 200;
                                data.Height             = 400;
                                data.Width              = 200;
                                _myMessageInProgress    = true;
                                data.MultiWindowCommand = MultiWindowCommand.OpenFloatingWindow;
                                Collection <object> result = EnvironmentManager.Instance.SendMessage(new VideoOS.Platform.Messaging.Message(MessageId.SmartClient.MultiWindowCommand, data), null, null);
                                if (result != null && result.Count > 0)
                                {
                                    _myWindowFQID2 = result[0] as FQID;                                                 // Save the Window FQID for next updates
                                }
                                _myMessageInProgress = false;
                                return(null);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Handles messages from the Alarm List.
        /// Creates a new view and displays it in a floating window each time a message is sent from the Alarm List.
        /// </summary>
        /// <param name="message">The message contains a list of alarms.</param>
        /// <param name="destination">Ignored since we want all messages from the Alarm List.</param>
        /// <param name="source">Ignored since we want messages from any Alarm List.</param>
        /// <returns>null - since the Alarm List is indifferent of who listens to its messages.</returns>
        private Object CameraListReceiver(VideoOS.Platform.Messaging.Message message, FQID destination, FQID source)
        {
            List <Alarm> alarms = message.Data as List <Alarm>;

            if (alarms != null)
            {
                int viewNumber = _viewCounter + 1;
                // Make a new Temporary view group
                ConfigItem tempGroupItem = (ConfigItem)ClientControl.Instance.CreateTemporaryGroupItem("Temporary" + viewNumber);
                // Make a group
                ConfigItem groupItem = tempGroupItem.AddChild("DynamicViewGroup" + viewNumber, Kind.View, FolderType.UserDefined);
                // Build a layout with wide ViewItems at the top and buttom, and 5 small ones in the middle
                Rectangle[] rect = new Rectangle[7];
                rect[0] = new Rectangle(000, 000, 999, 399);
                rect[1] = new Rectangle(000, 399, 199, 199);
                rect[2] = new Rectangle(199, 399, 199, 199);
                rect[3] = new Rectangle(399, 399, 199, 199);
                rect[4] = new Rectangle(599, 399, 199, 199);
                rect[5] = new Rectangle(799, 399, 199, 199);
                rect[6] = new Rectangle(000, 599, 999, 399);
                int               capacity          = rect.Length;
                string            viewName          = "DynamicView" + viewNumber;
                ViewAndLayoutItem viewAndLayoutItem = groupItem.AddChild(viewName, Kind.View, FolderType.No) as ViewAndLayoutItem;
                viewAndLayoutItem.Layout = rect;

                // Insert cameras
                int index = 0;
                foreach (Alarm alarm in alarms)
                {
                    // Add camera from the triggering event
                    // Note: EventHeader.Source cannot be null because an alarm must have a source
                    if (index < capacity && alarm.EventHeader?.Source.FQID.Kind == Kind.Camera)
                    {
                        viewAndLayoutItem.InsertBuiltinViewItem(index++,
                                                                ViewAndLayoutItem.CameraBuiltinId,
                                                                new Dictionary <string, string>()
                        {
                            { "CameraId", alarm.EventHeader.Source.FQID.ObjectId.ToString() }
                        });
                    }

                    if (alarm.ReferenceList == null)
                    {
                        continue;
                    }

                    // Add related cameras from the alarm
                    foreach (Reference rel in alarm.ReferenceList)
                    {
                        if (index < capacity && rel.FQID.Kind == Kind.Camera)
                        {
                            viewAndLayoutItem.InsertBuiltinViewItem(index++,
                                                                    ViewAndLayoutItem.CameraBuiltinId,
                                                                    new Dictionary <string, string>()
                            {
                                { "CameraId", rel.FQID.ObjectId.ToString() }
                            });
                        }
                    }
                }

                if (index == 0)
                {
                    // Exit here, since no cameras were found in the alarm list
                    return(null);
                }

                viewAndLayoutItem.Save();
                tempGroupItem.PropertiesModified();

                Item screen = Configuration.Instance.GetItemsByKind(Kind.Screen).FirstOrDefault();
                Item window = Configuration.Instance.GetItemsByKind(Kind.Window).FirstOrDefault();
                Item view   = groupItem.GetChildren().FirstOrDefault(v => v.Name.Equals(viewName));
                if (screen == null || window == null || view == null)
                {
                    return(null);
                }

                // Create floating window
                MultiWindowCommandData data = new MultiWindowCommandData();
                data.Screen             = screen.FQID;
                data.Window             = window.FQID;
                data.View               = view.FQID;
                data.X                  = 200;
                data.Y                  = 200;
                data.Height             = 500;
                data.Width              = 500;
                data.MultiWindowCommand = "OpenFloatingWindow";
                data.PlaybackSupportedInFloatingWindow = true;
                EnvironmentManager.Instance.SendMessage(new VideoOS.Platform.Messaging.Message(MessageId.SmartClient.MultiWindowCommand, data), null, null);
                _viewCounter++;
            }
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// This method does all what is required to create a group and viewlayout.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnCreateClick(object sender, EventArgs e)
        {
            List <Item> groups = ClientControl.Instance.GetViewGroupItems();

            if (groups.Count < 1)
            {
                throw new MIPException("You do not have access to any groups?");
            }

            // Use the first one (Private group)
            ConfigItem topGroupItem = (ConfigItem)groups[0];

            ConfigItem groupItem = (ConfigItem)FindName("ScInsertGroup", topGroupItem.GetChildren());

            if (groupItem == null)
            {
                // Make a group
                groupItem = topGroupItem.AddChild("ScInsertGroup", Kind.View, FolderType.UserDefined);
            }

            // Figure out a name that does not exist
            List <Item> currentViews = groupItem.GetChildren();
            int         ix           = 0;

            while (FindName("ScInsertLayout-" + ix, currentViews) != null)
            {
                ix++;
            }

            // Build a layout with one wide ViewItem at top and buttom, and 6 small once in the middle
            Rectangle[] rect = new Rectangle[7];
            rect[0] = new Rectangle(000, 000, 999, 399);
            rect[1] = new Rectangle(000, 399, 199, 199);
            rect[2] = new Rectangle(199, 399, 199, 199);
            rect[3] = new Rectangle(399, 399, 199, 199);
            rect[4] = new Rectangle(599, 399, 199, 199);
            rect[5] = new Rectangle(799, 399, 199, 199);
            rect[6] = new Rectangle(000, 599, 999, 399);
            ViewAndLayoutItem viewAndLayoutItem =
                (ViewAndLayoutItem)groupItem.AddChild("ScInsertLayout-" + ix, Kind.View, FolderType.No);

            viewAndLayoutItem.Layout = rect;
            viewAndLayoutItem.Properties["Created"] = DateTime.Now.ToLongDateString();

            // Insert a HTML ViewItem at top
            Dictionary <String, String> properties = new Dictionary <string, string>();

            properties.Add("URL", "www.google.com");                            // Next 4 for a HTML item
            properties.Add("HideNavigationbar", "true");
            properties.Add("Scaling", "3");                                     // fit in 800x600
            //properties.Add("Addscript", "");				// In case you need to add script
            viewAndLayoutItem.InsertBuiltinViewItem(0, ViewAndLayoutItem.HTMLBuiltinId, properties);

            // Find any camera and insert in index 1
            properties = new Dictionary <string, string>();
            properties.Add("CameraId", JustGetAnyCamera(Configuration.Instance.GetItems(ItemHierarchy.SystemDefined)));
            viewAndLayoutItem.InsertBuiltinViewItem(1, ViewAndLayoutItem.CameraBuiltinId, properties);

            // Insert a hotspot ViewItem at bottom -- index 6
            properties = new Dictionary <string, string>();
            viewAndLayoutItem.InsertBuiltinViewItem(6, ViewAndLayoutItem.HotspotBuiltinId, properties);

            viewAndLayoutItem.Save();
            topGroupItem.PropertiesModified();
            List <Item> windows        = Configuration.Instance.GetItemsByKind(Kind.Window);
            FQID        mainWindowFQID = new FQID(new ServerId("SC", "", 0, Guid.Empty));

            if (windows.Count > 0)
            {
                mainWindowFQID = windows[0].FQID;
            }
            EnvironmentManager.Instance.SendMessage(new Message(MessageId.SmartClient.MultiWindowCommand,
                                                                new MultiWindowCommandData()
            {
                MultiWindowCommand = MultiWindowCommand.SetViewInWindow,
                View   = viewAndLayoutItem.FQID,
                Window = mainWindowFQID
            }));
        }