Esempio n. 1
0
 /// <summary>
 /// Fires the variable operation event.
 /// </summary>
 /// <param name="variable">The variable.</param>
 /// <param name="eventHandler">The event handler.</param>
 private void FireVariableOperationEvent(PacketPropertyVariable variable, VariableOperationEventHandler eventHandler)
 {
     if (null != eventHandler)
     {
         eventHandler(variable);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Does the variable operation.
        /// </summary>
        /// <param name="variableName">Name of the variable.</param>
        /// <param name="operationHandler">The operation handler.</param>
        /// <param name="successHandler">The success handler.</param>
        /// <returns><code>true</code> if variable exists and <paramref name="operationHandler"/> returned <code>true</code>.</returns>
        private bool DoVariableOperation(string variableName,
                                         InternalVariableOperation operationHandler,
                                         VariableOperationEventHandler successHandler)
        {
            bool ret;

            try
            {
                // Check if variable exists
                VariableEntry entry;
                ret = variableEntriesByName.TryGetValue(variableName, out entry);

                PacketPropertyVariable variable = (ret ? entry.variable : null);

                if (ret)
                {
                    // Do operation
                    ret = operationHandler(variable);
                }

                if (ret)
                {
                    // Fire event only on successful modification of list
                    successHandler(variable);
                }
            }
            catch (Exception e)
            {
                ret = false;
                // Format message
                string message = string.Format("Error in variable operation with params: variableName={0}, operationHandler={1}, successHandler={2}"
                                               , variableName ?? "null"
                                               , operationHandler ?? (object)"null"
                                               , successHandler ?? (object)"null");

                Log.Error(message, e);
            }

            return(ret);
        }
 /// <summary>
 /// Fires the variable operation event.
 /// </summary>
 /// <param name="variable">The variable.</param>
 /// <param name="eventHandler">The event handler.</param>
 private void FireVariableOperationEvent(PacketPropertyVariable variable, VariableOperationEventHandler eventHandler)
 {
     if (null != eventHandler)
     {
         eventHandler(variable);
     }
 }
        /// <summary>
        /// Does the variable operation.
        /// </summary>
        /// <param name="variableName">Name of the variable.</param>
        /// <param name="operationHandler">The operation handler.</param>
        /// <param name="successHandler">The success handler.</param>
        /// <returns><code>true</code> if variable exists and <paramref name="operationHandler"/> returned <code>true</code>.</returns>
        private bool DoVariableOperation(string variableName,
            InternalVariableOperation operationHandler,
            VariableOperationEventHandler successHandler)
        {
            bool ret;
            try
            {
                // Check if variable exists
                VariableEntry entry;
                ret = variableEntriesByName.TryGetValue(variableName, out entry);

                PacketPropertyVariable variable = (ret ? entry.variable : null);

                if (ret)
                {
                    // Do operation
                    ret = operationHandler(variable);
                }

                if (ret)
                {
                    // Fire event only on successful modification of list
                    successHandler(variable);
                }
            }
            catch (Exception e)
            {
                ret = false;
                // Format message
                string message = string.Format("Error in variable operation with params: variableName={0}, operationHandler={1}, successHandler={2}"
                    , variableName ?? "null"
                    , operationHandler ?? (object)"null"
                    , successHandler ?? (object)"null");

                Log.Error(message, e);
            }

            return ret;
        }