Exemplo n.º 1
0
        /// <summary>
        /// Handles the entity selection event represented by the specified <see
        /// cref="Instruction"/>.</summary>
        /// <param name="instruction">
        /// The <see cref="SelectEntityInstruction"/> that represents the entity selection event to
        /// handle.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="instruction"/> is a null reference.</exception>
        /// <remarks><para>
        /// <b>SelectEntityEvent</b> selects the <see cref="Entity"/> indicated by the specified
        /// <paramref name="instruction"/> in the default <see cref="Session.MapView"/> and in the
        /// data view.
        /// </para><para>
        /// <b>SelectEntityEvent</b> does nothing if the specified <paramref name="instruction"/>
        /// indicates no <see cref="Entity"/>, or one that is unplaced.</para></remarks>

        public static void SelectEntityEvent(SelectEntityInstruction instruction)
        {
            if (instruction == null)
            {
                ThrowHelper.ThrowArgumentNullException("instruction");
            }

            // get entity identifier, if any
            string id = instruction.Id;

            if (String.IsNullOrEmpty(id))
            {
                return;
            }

            // get placed entity, if any
            Entity entity = Session.Instance.WorldState.Entities[id];

            if (entity == null || entity.Site == null)
            {
                return;
            }

            // select site and entity
            AsyncAction.Invoke(delegate {
                Session.MapView.SelectedSite       = entity.Site.Location;
                MainWindow.Instance.SelectedEntity = entity.Id;
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the command event represented by the specified <see cref="Instruction"/>.
        /// </summary>
        /// <param name="instruction">
        /// The <see cref="Instruction"/> that represents the command event to handle.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="instruction"/> is a null reference.</exception>
        /// <exception cref="PropertyValueException">
        /// The current session <see cref="Session.State"/> is <see cref="SessionState.Invalid"/>.
        /// </exception>
        /// <remarks><para>
        /// <b>ShowCommandEvent</b> takes the following actions, depending on the exact type of the
        /// specified <paramref name="instruction"/>:
        /// </para><list type="table"><listheader>
        /// <term>Type</term><description>Action</description>
        /// </listheader><item>
        /// <term><see cref="SelectEntityInstruction"/></term>
        /// <description>Call <see cref="SelectEntityEvent"/>.</description>
        /// </item><item>
        /// <term><see cref="ImageInstruction"/></term>
        /// <description>Call <see cref="ShowImageEvent"/>.</description>
        /// </item><item>
        /// <term><see cref="MessageInstruction"/></term>
        /// <description>Call <see cref="ShowMessageEvent"/>.</description>
        /// </item><item>
        /// <term>Other</term><description>Do nothing.</description>
        /// </item></list></remarks>

        public static void ShowCommandEvent(Instruction instruction)
        {
            if (instruction == null)
            {
                ThrowHelper.ThrowArgumentNullException("instruction");
            }

            if (Session.State == SessionState.Invalid)
            {
                ThrowHelper.ThrowPropertyValueExceptionWithFormat("Session.State",
                                                                  Session.State, Tektosyne.Strings.PropertyIsValue, SessionState.Invalid);
            }

            MessageInstruction message = instruction as MessageInstruction;

            if (message != null)
            {
                AsyncAction.Invoke(() =>
                                   ShowMessageEvent(message, MainWindow.Instance.EventMessage, true));
                return;
            }

            SelectEntityInstruction selectEntity = instruction as SelectEntityInstruction;

            if (selectEntity != null)
            {
                SelectEntityEvent(selectEntity);
                return;
            }

            ImageInstruction image = instruction as ImageInstruction;

            if (image != null)
            {
                ShowImageEvent(image);
                return;
            }
        }