Esempio n. 1
0
 public void SetAction(BufferedAction action, int buffer)
 {
     if (character.BfAction <= action)
     {
         character.BfAction    = action;
         character.BufferTimer = buffer;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Disposes this instance.
        /// </summary>
        public void Dispose()
        {
            // ReSharper disable ExceptionNotDocumented
            FileSystemWatcher watcher = Interlocked.Exchange(ref _watcher, null);

            watcher?.Dispose();
            BufferedAction action = Interlocked.Exchange(ref _eventAction, null);

            action?.Dispose();
            // ReSharper restore ExceptionNotDocumented
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationSection{T}" /> class.
        /// </summary>
        /// <exception cref="ConfigurationErrorsException">The selected value conflicts with a value that is already defined.</exception>
        // ReSharper disable once NotNullMemberIsNotInitialized
        protected ConfigurationSection()
        {
            // Set up change buffer
            _changeAction =
                new BufferedAction <string>(
                    // ReSharper disable once EventExceptionNotDocumented, AssignNullToNotNullAttribute
                    changes => Changed?.Invoke((T)this, new ConfigurationChangedEventArgs((T)this, changes)), ConfigurationExtensions.EventBufferMs);

            // This will get set during initialization
            ((IInternalConfigurationElement)this).ConfigurationElementName = $"<{SectionName}>";

            // As our system supports change notification, we can default the restart on external changes to false.
            SectionInformation.RestartOnExternalChanges = false;
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationFileWatcher"/> class.
        /// </summary>
        /// <param name="path">The path.</param>
        private ConfigurationFileWatcher([NotNull] string path)
        {
            _eventAction = new BufferedAction(WatcherOnChanged, 100);
            Path         = path;
            if (!File.Exists(path))
            {
                return;
            }

            // ReSharper disable once AssignNullToNotNullAttribute
            _watcher                     = new FileSystemWatcher(System.IO.Path.GetDirectoryName(path), System.IO.Path.GetFileName(path));
            _watcher.Changed            += (s, e) => _eventAction.Run();
            _watcher.NotifyFilter        = NotifyFilters.LastWrite | NotifyFilters.Size;
            _watcher.EnableRaisingEvents = true;
        }
        /// <summary>
        /// Disposes the specified instance.
        /// </summary>
        /// <param name="disposing">Whether this is disposing or finalizing.</param>
        /// <remarks>
        /// <para><paramref name="disposing"/> indicates whether the method was invoked from the
        /// <see cref="IDisposable.Dispose"/> implementation or from the finalizer. The implementation should check the
        /// parameter before  accessing other reference objects. Such objects should  only be accessed when the method
        /// is called from the <see cref="IDisposable.Dispose"/> implementation (when the <paramref name="disposing"/>
        /// parameter is equal to <see langword="true"/>). If the method is invoked from the finalizer
        /// (disposing is false), other objects should not be accessed. The reason is that objects are finalized in an
        /// unpredictable order and so they, or any of their dependencies, might already have been finalized.</para>
        /// </remarks>
        // ReSharper disable once VirtualMemberNeverOverriden.Global
        protected virtual void Dispose(bool disposing)
        {
            IsDisposed = true;
            // ReSharper disable once ExceptionNotDocumented
            // If we're disposing the active configuration section, we want to reload the active configuration.
            Interlocked.CompareExchange(ref _active, null, (T)this);
            if (!disposing)
            {
                return;
            }
            ConfigurationFileWatcher.UnWatch(this);
            // ReSharper disable once ExceptionNotDocumented
            BufferedAction <string> action = Interlocked.Exchange(ref _changeAction, null);

            action?.Dispose();
        }
Esempio n. 6
0
        /// <summary>
        /// Adds the specified logs to storage in batches.
        /// </summary>
        /// <param name="logs">The logs to add to storage.</param>
        /// <param name="token">The token.</param>
        /// <returns>Task.</returns>
        /// <exception cref="ObjectDisposedException">The logger has been disposed.</exception>
        public override Task Add(IEnumerable <Log> logs, CancellationToken token = new CancellationToken())
        {
            BufferedAction <Log> bufferedAction = _bufferedSend;

            if (bufferedAction == null)
            {
                throw new ObjectDisposedException(nameof(EmailLogger));
            }

            foreach (Log log in logs)
            {
                bufferedAction.Run(log);
            }

            return(TaskResult.Completed);
        }
	// Update is called once per frame

		public void ClearBuffer() {
				BfAction = BufferedAction.NONE;
				BufferTimer = 0;
		}
Esempio n. 8
0
 public void Buffer(string action, float timeToBuffer)
 {
     actions[action] = new BufferedAction(timeToBuffer);
 }
Esempio n. 9
0
		public void SetAction(BufferedAction action, int buffer)
		{
				if (character.BfAction <= action) 
				{
						character.BfAction = action;
						character.BufferTimer = buffer;
				}
		}
 void EnqueueUpdate(BufferedAction action)
 {
     m_QueryUpdates.Enqueue(action);
 }
        /// <summary>
        /// Initializes static members of the <see cref="ConfigurationSection{T}" /> class.
        /// </summary>
        static ConfigurationSection()
        {
            _activeChangeAction =
                new BufferedAction <string>(
                    // ReSharper disable EventExceptionNotDocumented, AssignNullToNotNullAttribute
                    changes =>
            {
                try
                {
                    T active = Active;
                    ActiveChanged?.Invoke(active, new ConfigurationChangedEventArgs(active, changes));
                }
                // ReSharper disable once CatchAllClause
                catch
                {
                    // ignored
                }
            },
                    // ReSharper restore EventExceptionNotDocumented, AssignNullToNotNullAttribute
                    ConfigurationExtensions.EventBufferMs);

            // Try to find attribute
            ConfigurationSectionAttribute attribute =
                (ConfigurationSectionAttribute)
                typeof(T).GetCustomAttributes(typeof(ConfigurationSectionAttribute), false).
                FirstOrDefault();

            string sectionName = attribute?.Name;

            if (string.IsNullOrEmpty(sectionName))
            {
                sectionName = typeof(T).Name;

                int len = sectionName.Length;

                // If it ends with 'configuration' strip it.
                if (len > 20 &&
                    sectionName.EndsWith(
                        "configurationsection",
                        StringComparison.CurrentCultureIgnoreCase))
                {
                    sectionName = sectionName.Substring(0, len -= 20);
                }
                else if (len > 13 &&
                         sectionName.EndsWith(
                             "configuration",
                             StringComparison.CurrentCultureIgnoreCase))
                {
                    sectionName = sectionName.Substring(0, len -= 13);
                }
                else if (len > 7 &&
                         sectionName.EndsWith(
                             "section",
                             StringComparison.CurrentCultureIgnoreCase))
                {
                    sectionName = sectionName.Substring(0, len -= 7);
                }
                else if (len > 6 &&
                         sectionName.EndsWith(
                             "config",
                             StringComparison.CurrentCultureIgnoreCase))
                {
                    sectionName = sectionName.Substring(0, len -= 6);
                }

                // Convert to lower camel case
                sectionName = sectionName.Substring(0, 1).ToLower() + (len > 1
                    ? sectionName.
                                                                       Substring(1)
                    : string.Empty);
            }

            SectionName = sectionName;
        }
Esempio n. 12
0
    // Update is called once per frame

    public void ClearBuffer()
    {
        BfAction    = BufferedAction.NONE;
        BufferTimer = 0;
    }
Esempio n. 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LoggerBase" /> class.
        /// </summary>
        /// <param name="name">The name of the logger.</param>
        /// <param name="fromAddress">The from address.</param>
        /// <param name="senderAddress">The sender address.</param>
        /// <param name="toAddresses">The to addresses.</param>
        /// <param name="ccAddresses">The CC addresses.</param>
        /// <param name="bccAddresses">The BCC addresses.</param>
        /// <param name="subject">The email subject format.</param>
        /// <param name="bodyHtml">The HTML body format.</param>
        /// <param name="bodyPlainText">The plain text body format.</param>
        /// <param name="bufferCount">The maximum number of logs to send in a single email.</param>
        /// <param name="bufferDuration">The duration of time to buffer logs to send in a single email.</param>
        /// <param name="host">The SMTP host.</param>
        /// <param name="port">The SMTP port.</param>
        /// <param name="timeout">The SMTP timeout.</param>
        /// <param name="ssl">if set to <see langword="true" /> SSL will be used.</param>
        /// <param name="deliveryMethod">The delivery method.</param>
        /// <param name="deliveryFormat">The delivery format.</param>
        /// <param name="username">The network username.</param>
        /// <param name="password">The network password.</param>
        /// <param name="networkDomain">The network domain.</param>
        /// <param name="validLevels">The valid levels.</param>
        /// <remarks>The SMTP connection settings will be pulled from the <c>&lt;system.net&gt;/&lt;mailSettings&gt;/&lt;smtp&gt;</c>
        /// configuration section if the parameters are left as their default values.
        /// (See https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/network/smtp-element-network-settings for details)</remarks>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.ArgumentOutOfRangeException">At least one to/CC/BCC address must be given.
        /// or
        /// The bufferCount must be greater than zero.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="name" /> is <see langword="null" /></exception>
        /// <exception cref="ArgumentOutOfRangeException"><para>The <paramref name="bufferCount" /> was less than or equal to zero.</para>
        /// <para>-or-</para>
        /// <para>At least one to/CC/BCC address was not given.</para></exception>
        public EmailLogger(
            [NotNull] string name,
            [CanBeNull] MailAddress fromAddress            = null,
            [CanBeNull] MailAddress senderAddress          = null,
            [CanBeNull] MailAddressCollection toAddresses  = null,
            [CanBeNull] MailAddressCollection ccAddresses  = null,
            [CanBeNull] MailAddressCollection bccAddresses = null,
            [CanBeNull] FormatBuilder subject       = null,
            [CanBeNull] FormatBuilder bodyHtml      = null,
            [CanBeNull] FormatBuilder bodyPlainText = null,
            ushort bufferCount           = 10,
            Duration?bufferDuration      = null,
            [CanBeNull] string host      = null,
            ushort port                  = 0,
            [CanBeNull] Duration?timeout = null,
            [CanBeNull] bool?ssl         = null,
            [CanBeNull] SmtpDeliveryMethod?deliveryMethod = null,
            [CanBeNull] SmtpDeliveryFormat?deliveryFormat = null,
            [CanBeNull] string username       = null,
            [CanBeNull] SecureString password = null,
            [CanBeNull] string networkDomain  = null,
            LoggingLevels validLevels         = LoggingLevels.All)
            : base(name, true, validLevels)
        {
            if ((toAddresses == null || toAddresses.Count < 1) &&
                (ccAddresses == null || ccAddresses.Count < 1) &&
                (bccAddresses == null || bccAddresses.Count < 1))
            {
                throw new ArgumentOutOfRangeException(
                          nameof(toAddresses),
                          Resources.EmailLogger_ToAddressMissing);
            }
            if (bufferCount < 1 && bufferDuration == TimeHelpers.InfiniteDuration)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(bufferCount),
                          bufferCount,
                          Resources.EmailLogger_InvalidBufferCount);
            }

            FromAddress   = fromAddress;
            SenderAddress = senderAddress;
            ToAddresses   = toAddresses;
            CCAddresses   = ccAddresses;
            BccAddresses  = bccAddresses;
            Subject       = subject ?? DefaultSubject;
            BodyHtml      = bodyHtml ?? (bodyPlainText == null ? DefaultBodyHtml : null);
            BodyPlainText = bodyPlainText;

            _smtpClient         = new SmtpClient(host, port);
            _smtpClient.Timeout = (int?)timeout?.TotalMilliseconds() ?? DefaultTimeout;
            if (ssl.HasValue)
            {
                _smtpClient.EnableSsl = ssl.Value;
            }
            if (deliveryMethod.HasValue)
            {
                _smtpClient.DeliveryMethod = deliveryMethod.Value;
            }
            if (deliveryFormat.HasValue)
            {
                _smtpClient.DeliveryFormat = deliveryFormat.Value;
            }
            if (username != null && password != null)
            {
                _smtpClient.Credentials = new NetworkCredential(username, password, networkDomain ?? string.Empty);
            }

            _bufferedSend = new BufferedAction <Log>(
                SendLogs,
                bufferDuration ?? DefaultBufferDuration,
                bufferCount);
        }