コード例 #1
0
 public Task SendUpdateMessageAsync(UpdateMessage message, CancellationToken cancellationToken = default)
 => UtilityService.ExecuteTask(() =>
 {
     try
     {
         this.GetUpdateMessagePublisher().OnNext(message);
         Global.OnSendRTUMessageSuccess?.Invoke(
             $"Publish an update message successful" + "\r\n" +
             $"- Device: {message.DeviceID}" + "\r\n" +
             $"- Excluded: {(string.IsNullOrWhiteSpace(message.ExcludedDeviceID) ? "None" : message.ExcludedDeviceID)}" + "\r\n" +
             $"- Type: {message.Type}" + "\r\n" +
             $"- Data: {message.Data.ToString(Formatting.None)}"
             );
     }
     catch (Exception exception)
     {
         Global.OnSendRTUMessageFailure?.Invoke($"Error occurred while publishing an update message: {exception.Message}", exception);
     }
 }, cancellationToken);
コード例 #2
0
 public Task SendInterCommunicateMessageAsync(CommunicateMessage message, CancellationToken cancellationToken = default)
 => UtilityService.ExecuteTask(() =>
 {
     if (message != null && !string.IsNullOrWhiteSpace(message.ServiceName))
     {
         try
         {
             this.GetInterCommunicateMessagePublisher(message.ServiceName).OnNext(message);
             Global.OnSendRTUMessageSuccess?.Invoke(
                 $"Publish an inter-communicate message successful" + "\r\n" +
                 $"- Service: {message.ServiceName}" + "\r\n" +
                 $"- Type: {message.Type}" + "\r\n" +
                 $"- Data: {message.Data.ToString(Formatting.None)}"
                 );
         }
         catch (Exception exception)
         {
             Global.OnSendRTUMessageFailure?.Invoke($"Error occurred while publishing an inter-communicate message: {exception.Message}", exception);
         }
     }
 }, cancellationToken);
コード例 #3
0
 Task SendInterCommunicateMessagesAsync(string serviceName, List <CommunicateMessage> messages, CancellationToken cancellationToken = default)
 => UtilityService.ExecuteTask(() =>
 {
     if (messages != null && !string.IsNullOrWhiteSpace(serviceName))
     {
         var subject = this.GetInterCommunicateMessagePublisher(serviceName);
         using (var publisher = messages.ToObservable().Subscribe(
                    message =>
         {
             subject.OnNext(message);
             Global.OnSendRTUMessageSuccess?.Invoke(
                 $"Publish an inter-communicate message successful" + "\r\n" +
                 $"- Service: {message.ServiceName}" + "\r\n" +
                 $"- Type: {message.Type}" + "\r\n" +
                 $"- Data: {message.Data.ToString(Formatting.None)}"
                 );
         },
                    exception => Global.OnSendRTUMessageFailure?.Invoke($"Error occurred while publishing an inter-communicate message: {exception.Message}", exception)
                    )) { }
     }
 }, cancellationToken);
コード例 #4
0
ファイル: VnThuQuan.cs プロジェクト: vieapps/Services.Books
        public async Task <IBookParser> ParseAsync(string url = null, Action <IBookParser, long> onCompleted = null, Action <IBookParser, Exception> onError = null, CancellationToken cancellationToken = default)
        {
            try
            {
                // get HTML of the book
                var stopwatch = Stopwatch.StartNew();
                var html      = await this.SourceUrl.GetVnThuQuanHtmlAsync("GET", this.ReferUrl, null, cancellationToken).ConfigureAwait(false);

                // parse to get details
                await UtilityService.ExecuteTask(() => this.ParseBook(html), cancellationToken).ConfigureAwait(false);

                // permanent identity
                if (string.IsNullOrWhiteSpace(this.PermanentID) || !this.PermanentID.IsValidUUID())
                {
                    this.PermanentID = (this.Title + " - " + this.Author).Trim().ToLower().GetMD5();
                }

                // callback when done
                stopwatch.Stop();
                onCompleted?.Invoke(this, stopwatch.ElapsedMilliseconds);
                return(this);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception ex)
            {
                onError?.Invoke(this, ex);
                if (onError == null)
                {
                    throw;
                }
                return(this);
            }
        }
コード例 #5
0
 public Task SendUpdateMessagesAsync(List <BaseMessage> messages, string deviceID, string excludedDeviceID, CancellationToken cancellationToken = default)
 => UtilityService.ExecuteTask(() =>
 {
     using (var publisher = messages.Select(message => new UpdateMessage
     {
         Type = message.Type,
         Data = message.Data,
         DeviceID = deviceID,
         ExcludedDeviceID = excludedDeviceID
     }).ToObservable().Subscribe(
                message =>
     {
         this.GetUpdateMessagePublisher().OnNext(message);
         Global.OnSendRTUMessageSuccess?.Invoke(
             $"Publish an update message successful" + "\r\n" +
             $"- Device: {message.DeviceID}" + "\r\n" +
             $"- Excluded: {(string.IsNullOrWhiteSpace(message.ExcludedDeviceID) ? "None" : message.ExcludedDeviceID)}" + "\r\n" +
             $"- Type: {message.Type}" + "\r\n" +
             $"- Data: {message.Data.ToString(Formatting.None)}"
             );
     },
                exception => Global.OnSendRTUMessageFailure?.Invoke($"Error occurred while publishing an update message: {exception.Message}", exception)
                )) { }
 }, cancellationToken);
コード例 #6
0
ファイル: Zip.cs プロジェクト: lulzzz/Components.Utility
 /// <summary>
 /// Zips a collection of files
 /// </summary>
 /// <param name="files"></param>
 /// <param name="zipFilePath"></param>
 /// <param name="compressionLevel"></param>
 /// <param name="encoding"></param>
 /// <param name="cancellationToken"></param>
 public static Task ZipAsync(IEnumerable <string> files, string zipFilePath, CompressionLevel compressionLevel = CompressionLevel.Optimal, Encoding encoding = null, CancellationToken cancellationToken = default(CancellationToken))
 => UtilityService.ExecuteTask(() => ZipService.Zip(files, zipFilePath, compressionLevel, encoding), cancellationToken);
コード例 #7
0
ファイル: Zip.cs プロジェクト: lulzzz/Components.Utility
 /// <summary>
 /// Unzips a. ZIP archive file to a folder
 /// </summary>
 /// <param name="zipFilePath"></param>
 /// <param name="destinationPath"></param>
 /// <param name="cancellationToken"></param>
 public static Task UnzipAsync(string zipFilePath, string destinationPath, CancellationToken cancellationToken = default(CancellationToken))
 => UtilityService.ExecuteTask(() => ZipService.Unzip(zipFilePath, destinationPath), cancellationToken);
コード例 #8
0
 /// <summary>
 /// Zips a folder (with all child contents)
 /// </summary>
 /// <param name="sourcePath"></param>
 /// <param name="zipFilePath"></param>
 /// <param name="compressionLevel"></param>
 /// <param name="encoding"></param>
 /// <param name="cancellationToken"></param>
 public static Task ZipAsync(string sourcePath, string zipFilePath, CompressionLevel compressionLevel = CompressionLevel.Optimal, Encoding encoding = null, CancellationToken cancellationToken = default)
 => UtilityService.ExecuteTask(() => ZipService.Zip(sourcePath, zipFilePath, compressionLevel, encoding), cancellationToken);
コード例 #9
0
 /// <summary>
 /// Creates a stream that contains Excel document from this data-set
 /// </summary>
 /// <param name="dataset">DataSet containing the data to be written to the Excel in OpenXML format</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>A stream that contains the Excel document</returns>
 /// <remarks>The stream that contains an Excel document in OpenXML format with MIME type is 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'</remarks>
 public static Task <MemoryStream> SaveAsExcelAsync(this DataSet dataset, CancellationToken cancellationToken = default(CancellationToken))
 => UtilityService.ExecuteTask(() => dataset.SaveAsExcel(), cancellationToken);
コード例 #10
0
ファイル: Messages.cs プロジェクト: lulzzz/Components.Utility
 /// <summary>
 /// Send an e-mail within VIE Portal software using System.Net.Mail namespace.
 /// </summary>
 /// <param name="fromAddress">Sender address.</param>
 /// <param name="replyToAddress">Address will be replied to.</param>
 /// <param name="toAddresses">Collection of recipients</param>
 /// <param name="ccAddresses">Collection of CC recipients</param>
 /// <param name="bccAddresses">Collection of BCC recipients</param>
 /// <param name="subject">The message subject.</param>
 /// <param name="body">The message body.</param>
 /// <param name="attachments">Collection of attachment files (all are full path of attachments).</param>
 /// <param name="additionalFooter">The data will be added into email as footer.</param>
 /// <param name="priority">Priority. See <c>System.Net.Mail.MailPriority</c> class for more information.</param>
 /// <param name="isHtmlFormat">TRUE if the message body is HTML formated.</param>
 /// <param name="encoding">Encoding of body message. See <c>System.Web.Mail.MailEncoding</c> class for more information.</param>
 /// <param name="smtp">Informaiton of SMTP server for sending email.</param>
 /// <param name="cancellationToken">Token for cancelling this task.</param>
 public static Task SendMailAsync(MailAddress fromAddress, MailAddress replyToAddress, List <MailAddress> toAddresses, List <MailAddress> ccAddresses, List <MailAddress> bccAddresses, string subject, string body, List <string> attachments, string additionalFooter, MailPriority priority, bool isHtmlFormat, Encoding encoding, SmtpClient smtp, CancellationToken cancellationToken = default(CancellationToken))
 => UtilityService.ExecuteTask(() => MessageService.SendMail(fromAddress, replyToAddress, toAddresses, ccAddresses, bccAddresses, subject, body, attachments, additionalFooter, priority, isHtmlFormat, encoding, smtp), cancellationToken);
コード例 #11
0
ファイル: Messages.cs プロジェクト: lulzzz/Components.Utility
 /// <summary>
 /// Send an e-mail within VIE Portal software using System.Net.Mail namespace.
 /// </summary>
 /// <param name="from">Sender name and e-mail address.</param>
 /// <param name="replyTo">Address will be replied to.</param>
 /// <param name="to">Recipients. Seperate multiple by comma (,).</param>
 /// <param name="cc">CC recipients. Seperate multiple by comma (,).</param>
 /// <param name="bcc">BCC recipients. Seperate multiple by comma (,).</param>
 /// <param name="subject">Mail subject.</param>
 /// <param name="body">Mail body.</param>
 /// <param name="attachment">Path to attachment file.</param>
 /// <param name="priority">Priority. See <c>System.Net.Mail.MailPriority</c> class for more information.</param>
 /// <param name="isHtmlFormat">TRUE if the message body is HTML formated.</param>
 /// <param name="encoding">Encoding of body message. See <c>System.Web.Mail.MailEncoding</c> class for more information.</param>
 /// <param name="smtpServer">IP address or host name of SMTP server.</param>
 /// <param name="smtpServerPort">Port number for SMTP service on the SMTP server.</param>
 /// <param name="smtpUsername">Username of the SMTP server use for sending mail.</param>
 /// <param name="smtpPassword">Password of user on the SMTP server use for sending mail.</param>
 /// <param name="smtpEnableSsl">TRUE if the SMTP server requires SSL.</param>
 /// <param name="cancellationToken">Token for cancelling this task.</param>
 public static Task SendMailAsync(string from, string replyTo, string to, string cc, string bcc, string subject, string body, string attachment, System.Net.Mail.MailPriority priority, bool isHtmlFormat, Encoding encoding, string smtpServer, string smtpServerPort, string smtpUsername, string smtpPassword, bool smtpEnableSsl = true, CancellationToken cancellationToken = default(CancellationToken))
 => UtilityService.ExecuteTask(() => MessageService.SendMail(from, replyTo, to, cc, bcc, subject, body, attachment, priority, isHtmlFormat, encoding, smtpServer, smtpServerPort, smtpUsername, smtpPassword, smtpEnableSsl, null, null), cancellationToken);