Example #1
0
        public void i_TransmitQueuedData(object sender, System.Timers.ElapsedEventArgs e)
        {
            EDSMTransmissionData currentData;

            try
            {
                m_SendTimer.Stop();

                if (m_SendQueue.Count > 0)
                {
                    while (m_SendQueue.Count > 0)
                    {
                        currentData = m_SendQueue.Dequeue();

                        if (m_GUIInterface.GetIniValue <Boolean>("SendToEDSM", true.ToString(), false) && (!Program.actualCondition.GameversionIsBeta_Jrnl))
                        {
                            switch (currentData.TType)
                            {
                            case TransmissionType.Visit:
                                i_TransmitVisit(currentData);
                                break;

                            case TransmissionType.CommentExtension:
                                String oldComment = GetSystemComment(currentData.SystemName, currentData.DateVisited);

                                if (!String.IsNullOrWhiteSpace(oldComment))
                                {
                                    currentData.Comment = oldComment + "\r\n" + currentData.Comment;
                                }

                                i_TransmitComment(currentData);
                                break;

                            default:
                                break;
                            }
                        }

                        System.Threading.Thread.Sleep(25);
                    }
                }
                else
                {
                    System.Threading.Thread.Sleep(1000);
                }

                m_SendTimer.Start();
            }
            catch (Exception ex)
            {
                DataTransmittedEvent.Raise(this, new DataTransmittedEventArgs(enTransmittedStates.Error, m_SendQueue.Count));
                m_SendTimer.Start();
                m_LogFile.Log("Exception: /n/d" + ex.Message + "/n/d" + ex.StackTrace);
            }
        }
Example #2
0
        private void i_TransmitComment(EDSMTransmissionData data)
        {
            dynamic    answer   = null;
            ErrorCodes retValue = ErrorCodes.No_Answer;
            String     transmissionString;
            String     cmdrName = m_GUIInterface.DBConnection.getIniValue(DB_GROUPNAME, "CommandersName", "");
            String     apiKey   = m_GUIInterface.DBConnection.getIniValue(DB_GROUPNAME, "API_Key", "");

            try
            {
                if (String.IsNullOrWhiteSpace(cmdrName) || String.IsNullOrWhiteSpace(apiKey))
                {
                    throw new Exception("Invalid credentials for EDSM");
                }

                transmissionString = String.Format("/api-logs-v1/set-comment" +
                                                   "?commanderName={0}" +
                                                   "&apiKey={1}" +
                                                   "&systemName={2}" +
                                                   "&fromSoftware={3}" +
                                                   "&fromSoftwareVersion={4}" +
                                                   "&dateVisited={5:yyyy-MM-dd HH:mm:ss}" +
                                                   "&comment={6}",
                                                   System.Web.HttpUtility.UrlEncode(cmdrName),
                                                   apiKey,
                                                   System.Web.HttpUtility.UrlEncode(data.SystemName),
                                                   "ED-IBE",
                                                   m_CurrentVersion,
                                                   data.DateVisited.ToUniversalTime(),
                                                   System.Web.HttpUtility.UrlEncode(data.Comment));


                if (m_GUIInterface.GetIniValue <Boolean>("SaveToFile", false.ToString(), false))
                {
                    m_LogFile.Log(RemoveApiKey(transmissionString));
                }

                answer = GetDataFromServer(transmissionString);

                if (answer != null)
                {
                    if (m_GUIInterface.GetIniValue <Boolean>("SaveToFile", false.ToString(), false))
                    {
                        m_LogFile.Log(RemoveApiKey(answer.ToString()));
                    }

                    retValue = answer.msgnum;
                }

                if (retValue == ErrorCodes.OK)
                {
                    DataTransmittedEvent.Raise(this, new DataTransmittedEventArgs(enTransmittedStates.Sent, m_SendQueue.Count));
                }
                else
                {
                    DataTransmittedEvent.Raise(this, new DataTransmittedEventArgs(enTransmittedStates.Error, m_SendQueue.Count));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error while transmitting comment", ex);
            }
        }
Example #3
0
        public String GetSystemComment(String systemName, DateTime timestamp)
        {
            dynamic    answer   = null;
            ErrorCodes retValue = ErrorCodes.No_Answer;
            String     transmissionString;
            String     commentString;
            String     cmdrName = m_GUIInterface.DBConnection.getIniValue(DB_GROUPNAME, "CommandersName", "");
            String     apiKey   = m_GUIInterface.DBConnection.getIniValue(DB_GROUPNAME, "API_Key", "");

            try
            {
                if (String.IsNullOrWhiteSpace(cmdrName) || String.IsNullOrWhiteSpace(apiKey))
                {
                    throw new Exception("Invalid credentials for EDSM");
                }

                if (timestamp.Year > 1970)
                {
                    transmissionString = String.Format("/api-logs-v1/get-comment" +
                                                       "?commanderName={0}" +
                                                       "&apiKey={1}" +
                                                       "&systemName={2}" +
                                                       "&dateVisited={3:yyyy-MM-dd HH:mm:ss}",
                                                       System.Web.HttpUtility.UrlEncode(cmdrName),
                                                       apiKey,
                                                       System.Web.HttpUtility.UrlEncode(systemName),
                                                       timestamp.ToUniversalTime());
                }
                else
                {
                    transmissionString = String.Format("/api-logs-v1/get-comment" +
                                                       "?commanderName={0}" +
                                                       "&apiKey={1}" +
                                                       "&systemName={2}",
                                                       System.Web.HttpUtility.UrlEncode(cmdrName),
                                                       apiKey,
                                                       System.Web.HttpUtility.UrlEncode(systemName));
                }

                if (m_GUIInterface.GetIniValue <Boolean>("SaveToFile", false.ToString(), false))
                {
                    m_LogFile.Log(RemoveApiKey(transmissionString));
                }

                answer = GetDataFromServer(transmissionString);

                if (answer != null)
                {
                    if (m_GUIInterface.GetIniValue <Boolean>("SaveToFile", false.ToString(), false))
                    {
                        m_LogFile.Log(RemoveApiKey(answer.ToString()));
                    }

                    retValue = answer.msgnum;
                }

                switch (retValue)
                {
                case ErrorCodes.OK:
                    commentString = answer.comment;
                    DataTransmittedEvent.Raise(this, new DataTransmittedEventArgs(enTransmittedStates.Recieved, m_SendQueue.Count));
                    break;

                case ErrorCodes.OK_NoData:
                    commentString = "";
                    DataTransmittedEvent.Raise(this, new DataTransmittedEventArgs(enTransmittedStates.Recieved, m_SendQueue.Count));
                    break;

                default:
                    commentString = null;
                    DataTransmittedEvent.Raise(this, new DataTransmittedEventArgs(enTransmittedStates.Error, m_SendQueue.Count));
                    break;
                }

                return(commentString);
            }
            catch (Exception ex)
            {
                throw new Exception("Error while recieving comment", ex);
            }
        }