<commit_before>﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace SharpSMS
{
    /// <summary>
    /// Class represents SMS message to send
    /// </summary>
    public class SMSSubmit
    {
        #region Constants
        /// <summary>
        /// First Octet Bits 1,0 - SMS-SUBMIT
        /// </summary>
        public const byte FIRST_OCTET_SMS_SUBMIT = 0x01;
        /// <summary>
        /// First Octet Bits 4,3 - Validity period is in relative format
        /// </summary>
        public const byte FIRST_OCTET_VALIDITY_PERIOD_RELATIVEFORMAT = 0x10;
        /// <summary>
        /// First Octet Bit 5 - Status delivery requested
        /// </summary>
        public const byte FIRST_OCTET_REQUEST_DELIVERY_CONFIRMATION = 0x20;
        /// <summary>
        /// First Octet Bit 6 - User data header is present
        /// </summary>
        public const byte FIRST_OCTET_USER_DATA_HEADER = 0x40;
        /// <summary>
        /// User data header - concated message
        /// </summary>        
        public const byte PDU_UDH_CONCATED_MESSAGE_16BIT = 0x08;
        /// <summary>
        /// User data header - Length of concated message length
        /// </summary>
        public const byte PDU_UDH_CONCATED_MESSAGE_16BIT_HEADERLENGTH = 0x04;
        /// <summary>
        /// User data header - Length of concated header
        /// </summary>
        public const byte CONCATED_UDH_FULL_LENGTH = 0x07;

        #endregion

        #region Properties

        /// <summary>
        /// Request for message delivery confirmation (optional)
        /// </summary>
        public bool RequestDeliveryConfirmation { get; set; }

        /// <summary>
        /// Validation period of the message (optional)
        /// </summary>
        public TimeSpan ValidityPeriod { get; set; }

        /// <summary>
        /// Message reference (optional)
        /// </summary>
        public byte MessageReference { get; set; }

        /// <summary>
        /// Message protocol identifier (optional)
        /// </summary>
        public byte ProtocolIdentifier { get; set; }

        /// <summary>
        /// Phone number of the message recipient
        /// </summary>
        public string PhoneNumber { get; set; }

        /// <summary>
        /// Specifies how message will be displayed and stored on the phone
        /// </summary>
        public MessageIndication Indication { get; set; }

        /// <summary>
        /// Message data
        /// </summary>
        public ISmsMessageContent MessageToSend { get; set; }
        
        #endregion

        #region Constructor

        /// <summary>
        /// Creates instance of the SubmitSMS message
        /// </summary>
        public SMSSubmit() 
            : this(null)
        {
        }

        /// <summary>
        /// Creates instance of the SubmitSMS message
        /// </summary>
        /// <param name="messageToSent">Message to be sent</param>
        public SMSSubmit(ISmsMessageContent messageToSent)
        {
            // Set the default values
            this.RequestDeliveryConfirmation = false;
            this.ValidityPeriod = TimeSpan.MinValue;
            this.MessageReference = 0x00;
            this.ProtocolIdentifier = 0x00;
            this.MessageToSend = messageToSent;

            this.Indication = new MessageIndication(MessageClass.MESpecific);           
            this.Indication.Type = IndicationType.Voicemail;
            this.Indication.Operation = MessageIndicationOperation.NotSet;
            this.Indication.IsActive = false;
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Method returns list of PDU formated messages.
        /// If data fits into one message than the list has only one item. 
        /// Otherwise the data is concated into more messages.
        /// </summary>
        /// <returns></returns>
        public List<byte[]> GetPDUList()
        {            
            int maxOctetsCount;

            switch (MessageToSend.DataEncoding)
            {
                case DataEncoding.Default7bit:
                    maxOctetsCount = 160;                   
                    break;
                case DataEncoding.Data8bit:
                    maxOctetsCount = 140;     // Might be lower, some roaming partners don't like it when set to 140              
                    break;
                case DataEncoding.UCS2_16bit:
                    maxOctetsCount = 140;                    
                    break;
                default:
                    maxOctetsCount = 140;                   
                    break;
            }

            byte[] body = MessageToSend.GetSMSBytes();            
            byte[] messageUdh = MessageToSend.GetUDHBytes();
            
            // If UDH exists then reserve one more byte for UDH length
            int maxLen = maxOctetsCount - messageUdh.Length;
            maxLen -= (messageUdh.Length > 0) ? 1 : 0;
            
            // Count parts
            int parts = (int)Math.Ceiling((double)body.Length / (double)maxLen);
            parts = (int)Math.Ceiling((double)(body.Length + parts*messageUdh.Length) / (double)maxLen);

            if (parts > 1)
                parts = (int)Math.Ceiling((double)(body.Length + parts * messageUdh.Length + parts * CONCATED_UDH_FULL_LENGTH) / (double)maxLen);
<commit_msg>Fix calculation<commit_after>﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace SharpSMS
{
    /// <summary>
    /// Class represents SMS message to send
    /// </summary>
    public class SMSSubmit
    {
        #region Constants
        /// <summary>
        /// First Octet Bits 1,0 - SMS-SUBMIT
        /// </summary>
        public const byte FIRST_OCTET_SMS_SUBMIT = 0x01;
        /// <summary>
        /// First Octet Bits 4,3 - Validity period is in relative format
        /// </summary>
        public const byte FIRST_OCTET_VALIDITY_PERIOD_RELATIVEFORMAT = 0x10;
        /// <summary>
        /// First Octet Bit 5 - Status delivery requested
        /// </summary>
        public const byte FIRST_OCTET_REQUEST_DELIVERY_CONFIRMATION = 0x20;
        /// <summary>
        /// First Octet Bit 6 - User data header is present
        /// </summary>
        public const byte FIRST_OCTET_USER_DATA_HEADER = 0x40;
        /// <summary>
        /// User data header - concated message
        /// </summary>        
        public const byte PDU_UDH_CONCATED_MESSAGE_16BIT = 0x08;
        /// <summary>
        /// User data header - Length of concated message length
        /// </summary>
        public const byte PDU_UDH_CONCATED_MESSAGE_16BIT_HEADERLENGTH = 0x04;
        /// <summary>
        /// User data header - Length of concated header
        /// </summary>
        public const byte CONCATED_UDH_FULL_LENGTH = 0x07;

        #endregion

        #region Properties

        /// <summary>
        /// Request for message delivery confirmation (optional)
        /// </summary>
        public bool RequestDeliveryConfirmation { get; set; }

        /// <summary>
        /// Validation period of the message (optional)
        /// </summary>
        public TimeSpan ValidityPeriod { get; set; }

        /// <summary>
        /// Message reference (optional)
        /// </summary>
        public byte MessageReference { get; set; }

        /// <summary>
        /// Message protocol identifier (optional)
        /// </summary>
        public byte ProtocolIdentifier { get; set; }

        /// <summary>
        /// Phone number of the message recipient
        /// </summary>
        public string PhoneNumber { get; set; }

        /// <summary>
        /// Specifies how message will be displayed and stored on the phone
        /// </summary>
        public MessageIndication Indication { get; set; }

        /// <summary>
        /// Message data
        /// </summary>
        public ISmsMessageContent MessageToSend { get; set; }
        
        #endregion

        #region Constructor

        /// <summary>
        /// Creates instance of the SubmitSMS message
        /// </summary>
        public SMSSubmit() 
            : this(null)
        {
        }

        /// <summary>
        /// Creates instance of the SubmitSMS message
        /// </summary>
        /// <param name="messageToSent">Message to be sent</param>
        public SMSSubmit(ISmsMessageContent messageToSent)
        {
            // Set the default values
            this.RequestDeliveryConfirmation = false;
            this.ValidityPeriod = TimeSpan.MinValue;
            this.MessageReference = 0x00;
            this.ProtocolIdentifier = 0x00;
            this.MessageToSend = messageToSent;

            this.Indication = new MessageIndication(MessageClass.MESpecific);           
            this.Indication.Type = IndicationType.Voicemail;
            this.Indication.Operation = MessageIndicationOperation.NotSet;
            this.Indication.IsActive = false;
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Method returns list of PDU formated messages.
        /// If data fits into one message than the list has only one item. 
        /// Otherwise the data is concated into more messages.
        /// </summary>
        /// <returns></returns>
        public List<byte[]> GetPDUList()
        {            
            int maxOctetsCount;

            switch (MessageToSend.DataEncoding)
            {
                case DataEncoding.Default7bit:
                    maxOctetsCount = 160;                   
                    break;
                case DataEncoding.Data8bit:
                    maxOctetsCount = 140;     // Might be lower, some roaming partners don't like it when set to 140              
                    break;
                case DataEncoding.UCS2_16bit:
                    maxOctetsCount = 140;                    
                    break;
                default:
                    maxOctetsCount = 140;                   
                    break;
            }

            byte[] body = MessageToSend.GetSMSBytes();            
            byte[] messageUdh = MessageToSend.GetUDHBytes();
            
            // If UDH exists then reserve one more byte for UDH length
            int maxLen = maxOctetsCount - messageUdh.Length;
            maxLen -= (messageUdh.Length > 0) ? 1 : 0;
            
            // Count parts
            int parts = (int)Math.Ceiling((double)body.Length / (double)maxLen);
            parts = (int)Math.Ceiling((double)(body.Length + parts*messageUdh.Length) / (double)maxLen);

            if (parts > 1)
                parts = (int)Math.Ceiling((double)(body.Length + parts * messageUdh.Length + parts * (CONCATED_UDH_FULL_LENGTH + 1)) / (double)maxLen);

{'fraction_non_alphanumeric': 0.09783207789821789, 'fraction_numerical': 0.011298916038949109, 'mean_word_length': 1.5096818810511756, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2931930', 'n_tokens_mistral': 2942, 'n_tokens_neox': 2730, 'n_words': 774}