Example #1
0
        /// <summary>
        /// Adds a new <see cref="GroupDefinition"/> to the graph and returns the ID for that group.
        /// </summary>
        /// <param name="id">The ID of the group that is being added.</param>
        /// <param name="group">The group that should be added to the graph.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="id"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="group"/> is <see langword="null" />.
        /// </exception>
        public void Add(GroupCompositionId id, GroupDefinition group)
        {
            {
                Lokad.Enforce.Argument(() => id);
                Lokad.Enforce.Argument(() => group);
            }

            if (!m_Definitions.ContainsKey(group.Id))
            {
                m_Definitions.Add(group.Id, group);
            }

            m_Groups.Add(id, group.Id);
            m_GroupConnections.AddVertex(id);

            foreach (var part in group.Parts)
            {
                var partId = new PartCompositionId(id, part.Id);
                m_Parts.Add(partId, new PartCompositionInfo(part));
                m_PartConnections.AddVertex(partId);
            }

            var parts = PartsForGroup(id);

            ConnectParts(group.InternalConnections, parts, parts);
        }
Example #2
0
        /// <summary>
        /// Replaces the action current stored against the given ID with a new one.
        /// </summary>
        /// <param name="actionToReplace">The ID of the action that should be replaced.</param>
        /// <param name="newAction">The new action.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="actionToReplace"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="newAction"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="UnknownScheduleActionException">
        ///     Thrown if <paramref name="actionToReplace"/> is not linked to a known action.
        /// </exception>
        public void Update(
            ScheduleElementId actionToReplace,
            IScheduleAction newAction)
        {
            {
                Lokad.Enforce.Argument(() => actionToReplace);
                Lokad.Enforce.Argument(() => newAction);
                Lokad.Enforce.With <UnknownScheduleActionException>(
                    m_Actions.ContainsKey(actionToReplace),
                    Resources.Exceptions_Messages_UnknownScheduleAction);
            }

            var oldInfo = m_Actions[actionToReplace].Information;
            var info    = new ScheduleActionInformation(
                actionToReplace,
                oldInfo.Name,
                oldInfo.Description);

            m_Actions[actionToReplace] = new ActionMap(info, newAction);
        }
Example #3
0
        /// <summary>
        /// Replaces the schedule current stored against the given ID with a new one.
        /// </summary>
        /// <param name="scheduleToReplace">The ID of the schedule that should be replaced.</param>
        /// <param name="newSchedule">The new schedule.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="scheduleToReplace"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="newSchedule"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="UnknownScheduleException">
        ///     Thrown if <paramref name="scheduleToReplace"/> is not linked to a known schedule.
        /// </exception>
        public void Update(
            ScheduleId scheduleToReplace,
            ISchedule newSchedule)
        {
            {
                Lokad.Enforce.Argument(() => scheduleToReplace);
                Lokad.Enforce.Argument(() => newSchedule);
                Lokad.Enforce.With <UnknownScheduleException>(
                    m_Schedules.ContainsKey(scheduleToReplace),
                    Resources.Exceptions_Messages_UnknownSchedule);
            }

            var oldInfo = m_Schedules[scheduleToReplace].Information;
            var info    = new ScheduleInformation(
                scheduleToReplace,
                oldInfo.Name,
                oldInfo.Description);

            m_Schedules[scheduleToReplace] = new ScheduleMap(info, newSchedule);
        }
Example #4
0
        /// <summary>
        /// Removes the group that is related to the specified ID.
        /// </summary>
        /// <param name="group">The ID of the group that should be removed.</param>
        public void Remove(GroupCompositionId group)
        {
            if (group == null)
            {
                return;
            }

            if (!m_Groups.ContainsKey(group))
            {
                return;
            }

            var definitionId = m_Groups[group];
            var definition   = m_Definitions[definitionId];

            foreach (var part in definition.Parts)
            {
                var partId = new PartCompositionId(group, part.Id);
                Debug.Assert(m_Parts.ContainsKey(partId), "The part collection should have the given part ID.");
                Debug.Assert(m_PartConnections.ContainsVertex(partId), "The part connections graph should have the given part ID.");

                var info = m_Parts[partId];
                if (info.Instance != null)
                {
                    ReleaseInstance(partId);
                }

                m_PartConnections.RemoveVertex(partId);
                m_Parts.Remove(partId);
            }

            Debug.Assert(m_GroupConnections.ContainsVertex(group), "The connections graph should have the given group ID.");
            m_GroupConnections.RemoveVertex(group);

            m_Groups.Remove(group);
            if (!m_Groups.Any(p => p.Value.Equals(definitionId)))
            {
                m_Definitions.Remove(definitionId);
            }
        }