internal MessageFormularRegistry()
        {
            var formular = new MessageFormular(MessageFormular.DYNAMIC, null as Message); // empty message

            Data["_dyn"] = new List <MessageFormular>();
            Data["_dyn"].Add(formular);
        }
 /// <summary>
 /// Unregisters a specific Formular from a specific definer source
 /// </summary>
 /// <param name="definerId"></param>
 /// <returns>true, if undefine had an effect.</returns>
 public bool Undefine(string definerId, MessageFormular formular)
 {
     if (!Data.ContainsKey(definerId))
     {
         return(false);
     }
     return(Data[definerId].Remove(formular));
 }
        /// <summary>Tries to define a Formular. Each named Formular can only be defined by one sender entity</summary>
        /// <param name="definerId">A unique string that helps to keep track, who registered a given Formular.</param>
        /// <param name="formular">A MessageFormular to be registered.</param>
        /// <param name="supressEvent">A bool indicating if the registry should skip informing interested parties about this change.</param>
        /// <exception cref="ArgumentNullException">Thrown when the Formular is null.</exception>
        /// <exception cref="RegistryException">This exception is thrown if a syntax error prevents the config to be parsed.</exception>
        /// <returns>success</returns>
        /// <remarks>Setting the supressEvent parameter to true will prevent this method to inform any TypeChanged subscribers.</remarks>
        public bool Define(string definerId, MessageFormular formular, bool supressEvent = false)
        {
            if (formular == null)
            {
                throw new ArgumentNullException("Formular cannot be null");
            }
            if (formular.IsDynamic)
            {
                return(false);
            }

            if (!Data.ContainsKey(definerId))
            {
                Data[definerId] = new List <MessageFormular>();
            }

            var conflict = (
                from nodeId in Data.Keys
                where definerId != nodeId
                from form in Data[nodeId]
                where formular.Name == form.Name
                select form.Name
                ).FirstOrDefault();


            if (conflict != null)
            {
                throw new RegistryException("Cannot add the formular to the registry. Another formular with the name \"" + conflict + "\" already exists.");
            }

            var ownFormulars = Data[definerId];
            var oldForm      = (
                from form in ownFormulars
                where form.Name == formular.Name
                select form
                ).FirstOrDefault();

            // no need to worry someone, if we conclude nothing's changed.
            // if (formular.Equals(oldForm)) return false;

            if (oldForm != null)
            {
                ownFormulars.Remove(oldForm);
            }
            ownFormulars.Add(formular);

            if (!supressEvent)
            {
                if (FormularChanged != null)
                {
                    FormularChanged(this, formular);
                }
            }
            return(true);
        }
Beispiel #4
0
 public Message(MessageFormular formular)
     : this()
 {
     Formular = formular;
 }
Beispiel #5
0
 public Message(MessageFormular formular)
     : base()
 {
     Formular = formular;
 }