Пример #1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="fName">String containing the field name</param>
 /// <returns>
 /// 0 if there is no data for the field
 /// -1 if there is an error in the field
 /// >1 if data exists for the field</returns>
 /// <exception>
 /// ArgumentNullException if no length is specified
 /// FormatException if length is not an integer
 /// OverflowException if length is greater than System.Int32.MaxValue
 /// </exception>
 public static int fieldLength(string fName)
 {
     if (fName == null)
     {
         QsoException ex = new QsoException("Programming Error: Attempting to " +
             "get the field length contained in a null QSO field.\r\n" +
             "Contact program vendor.");
         throw ex;
     }
     // look for end of field name
     int iEnd = fName.IndexOf('>');
     // not there? return -1 to show error
     if (iEnd == -1)
     {
         return -1;
     }
     // look for separator before size
     int index = fName.IndexOf(":");
     if (index == -1)
     {
         // no size, so return 0
         return 0;
     }
     // look for separator for data type
     int iType = fName.IndexOf(':', index + 1);
     if (iType != -1)
     {
         // separator found, so length is between index and iEnd
         iEnd = iType;
     }
     string strLen = fName.Substring(index + 1, iEnd - index - 1);
     int len = Int32.Parse(strLen);
     return len;
 }
Пример #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="inStr"></param>
 /// <exception>
 /// QsoExcpeption if input string does not contain <eor>
 /// </exception>
 public AdifString(string inStr)
 {
     inString = inStr;
     string upper = inStr.ToUpper();
     int iEOR = upper.IndexOf("<EOR>");
     if (iEOR == -1)
     {
         QsoException ex = new QsoException("ADIF string does not contain <eor>");
         ex.Data.Add("ADIF String", inStr);
         throw ex;
     }
 }
Пример #3
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="b">name of the band - should be as defined in ADIF standard</param>
 /// <param name="lEdge">lowest frequency of the band (in MHz) as defined in ADIF standard</param>
 /// <param name="uEdge">highest frequency of the band (in MHz) as defined in ADIF standard</param>
 /// <exception>
 /// QsoException if lower edge frequency is larger than or equal to upper edge frequency
 /// </exception>
 internal HamBand(string b, float lEdge, float uEdge)
 {
     if (lEdge >= uEdge)
     {
         QsoException ex = new QsoException("Invalid HamBand constructor paramaters");
         ex.Data.Add("Band", b);
         ex.Data.Add("Lower Edge", lEdge);
         ex.Data.Add("Upper Edge", uEdge);
         throw ex;
     }
     band = b;
     lowerEdge = lEdge;
     upperEdge = uEdge;
 }
Пример #4
0
 /// <summary>
 /// gets the next field in the ADIF QSO, if one exists
 /// </summary>
 /// <returns>
 /// null if no field
 /// field if field exists</returns>
 /// <exception>
 /// QsoException if no '>' found
 /// ArgumentException if the data length is not specified
 /// FormatException if length is not an integer
 /// OverflowException if length is greater than Int32.MaxValue
 /// </exception>
 private string getAField()
 {
     // get
     string adif = inString.Substring(index);
     int fStart = adif.IndexOf('<');
     if(fStart == -1)
     {
         return null;
     }
     adif = adif.Substring(fStart);
     int fEnd = adif.IndexOf('>');
     if (fEnd == -1)
     {
         return null;
     }
     string fieldName = adif.Substring(0, fEnd + 1);
     int dataLen = fieldLength(fieldName);
     if (dataLen == -1)
     {
         QsoException ex = new QsoException("Invalid QSO field name");
         ex.Data.Add("QSO Field Name:", fieldName);
         throw ex;
     }
     else if (dataLen == 0)
     {
         index += fieldName.Length + fStart;
         return fieldName;
     }
     else
     {
         index += fieldName.Length + dataLen + fStart;
         return adif.Substring(0, fieldName.Length + dataLen);
     }
 }
Пример #5
0
 /// <summary>
 /// retrieves the next field in the ADIF string
 /// </summary>
 /// <returns>next string in the ADIFString</returns>
 /// <exception>
 /// QsoException if there are no more fields or if field is invalid</exception>
 public string getNextField()
 {
     string field = null;
     try
     {
         field = getAField();
     }
     catch (Exception e)
     {
         QsoException ex = new QsoException(
             "Error occured while attempting to retrieve the next ADIF field"
             , e);
         throw ex;
     }
     if (field == null)
     {
         QsoException ex = new QsoException("Programming Error: Attempted to " +
             "retrieve field from an ADIFString but no fields remain. \r\n" +
             "Contact program vendor.");
         throw ex;
     }
     return field;
 }
Пример #6
0
 /// <summary>
 /// reset to first field and retrieve it
 /// </summary>
 /// <returns>first field in ADIFString</returns>
 /// <exception>
 /// QsoException for any error</exception>
 public string getFirstField()
 {
     index = 0;
     string field = null;
     try
     {
         field = getAField();
     }
     catch (Exception e)
     {
         QsoException ex = new QsoException(
             "Error occured while attempting to retrieve the first ADIF field"
             , e);
         throw ex;
     }
     return field;
 }
Пример #7
0
 /// <summary>
 /// retrieve value from QSO field
 /// </summary>
 /// <param name="field">QSO field</param>
 /// <returns>value specified in QSO field</returns>
 /// <exception>
 /// QsoException if value in input contains fewer than specified number of characters
 /// </exception>
 public static string getValueFromField(string field)
 {
     string fName = getFieldName(field);
     int valueLen = fieldLength(fName);
     int index = field.IndexOf(fName) + fName.Length;
     if (index + valueLen > field.Length)
     {
         QsoException ex = new QsoException("Programming Error: Field does " +
             "not contain specified number of characters in the value.\r\n" +
             "Contact program vendor");
         ex.Data.Add("QSO field:", field);
         throw ex;
     }
     string value = field.Substring(index, valueLen);
     return value;
 }
Пример #8
0
 /// <summary>
 /// retrieves key from the field name
 /// </summary>
 /// <param name="fName">field name</param>
 /// <returns>key from field name</returns>
 /// <exception>
 /// QsoException if input does not contain both '<' and '>'</exception>
 public static string getKeyFromFieldName(string fName)
 {
     string field = getFieldName(fName);
     if (field == null)
     {
         QsoException ex = new QsoException("Programming Error: Trying to get " +
             "key from an invalid QSO field name.\r\n" +
             "Contact program vendor.");
         ex.Data.Add("QSO field name:", fName);
         throw ex;
     }
     int index = field.IndexOf(':');
     if (index == -1)
     {
         index = field.IndexOf('>');
     }
     return field.Substring(1, index - 1);
 }