Пример #1
0
        /// <summary>
        /// copy the values from another station exept for the ID
        /// </summary>
        /// <param name="ValueStation"></param>
        public void getValues(EDStation ValueStation, bool getAll = false)
        {
            if (getAll)
            {
                Id       = ValueStation.Id;
                SystemId = ValueStation.SystemId;
            }

            Name = ValueStation.Name;
            MaxLandingPadSize = ValueStation.MaxLandingPadSize;
            DistanceToStar    = ValueStation.DistanceToStar;
            Faction           = ValueStation.Faction;
            Government        = ValueStation.Government;
            Allegiance        = ValueStation.Allegiance;
            State             = ValueStation.State;
            Type           = ValueStation.Type;
            HasBlackmarket = ValueStation.HasBlackmarket;
            HasCommodities = ValueStation.HasCommodities;
            HasRefuel      = ValueStation.HasRefuel;
            HasRepair      = ValueStation.HasRepair;
            HasRearm       = ValueStation.HasRearm;
            HasOutfitting  = ValueStation.HasOutfitting;
            HasShipyard    = ValueStation.HasShipyard;

            ImportCommodities     = ValueStation.ImportCommodities.CloneN();
            ExportCommodities     = ValueStation.ExportCommodities.CloneN();
            ProhibitedCommodities = ValueStation.ProhibitedCommodities.CloneN();
            Economies             = ValueStation.Economies.CloneN();
        }
Пример #2
0
        /// <summary>
        /// check if the stations of two stations are equal if the system
        /// exists in the EDDB data and in the own data
        /// </summary>
        /// <param name="ownSystem">system from own data</param>
        /// <param name="existingEDDNSystem">system from EDDB data</param>
        /// <param name="SystemCanBeDeleted">normally true, except there are differences between at least one stations.
        /// if so the system must be hold as reference. If a own data station is 100% equal (e.g. Commoditynames and other strings
        /// are not casesensitive compared) to the eddb station it will automatically deleted</param>
        private void checkStations(EDSystem ownSystem, EDSystem existingEDDNSystem, ref bool SystemCanBeDeleted, ref bool StationsChanged)
        {
            // own system can be deleted if the stations are equal, too
            List <EDStation> ownSystemStations = getStations(ownSystem.Name, enDataType.Data_Own);

            for (int j = 0; j < ownSystemStations.Count(); j++)
            {
                EDStation ownStation          = ownSystemStations[j];
                EDStation existingEDDNStation = getSystemStation(ownSystem.Name, ownSystemStations[j].Name);

                if (existingEDDNStation != null)
                {
                    if (existingEDDNStation.EqualsED(ownStation))
                    {
                        // no favour to hold it anymore
                        m_Stations[(int)enDataType.Data_Own].Remove(ownStation);
                        StationsChanged = true;
                    }
                    else
                    {
                        // copy the values and hold it
                        existingEDDNStation.getValues(ownStation);
                        SystemCanBeDeleted = false;
                    }
                }
                else
                {
                    // station is in EDDB not existing, so we'll hold the station
                    SystemCanBeDeleted = false;
                    int newStationIndex = m_Stations[(int)enDataType.Data_Merged].Max(X => X.Id) + 1;

                    m_Stations[(int)enDataType.Data_Merged].Add(new EDStation(newStationIndex, existingEDDNSystem.Id, ownStation));
                }
            }
        }
Пример #3
0
        /// <summary>
        /// true, if all data *except the two IDs* is equal (case insensitive)
        /// </summary>
        /// <param name="eqSystem"></param>
        /// <returns></returns>
        public bool EqualsED(EDStation eqStation)
        {
            bool retValue = false;

            if (eqStation != null)
            {
                if (ObjectCompare.EqualsNullable(this.Name, eqStation.Name) &&
                    ObjectCompare.EqualsNullable(this.MaxLandingPadSize, eqStation.MaxLandingPadSize) &&
                    ObjectCompare.EqualsNullable(this.DistanceToStar, eqStation.DistanceToStar) &&
                    ObjectCompare.EqualsNullable(this.Faction, eqStation.Faction) &&
                    ObjectCompare.EqualsNullable(this.Government, eqStation.Government) &&
                    ObjectCompare.EqualsNullable(this.Allegiance, eqStation.Allegiance) &&
                    ObjectCompare.EqualsNullable(this.State, eqStation.State) &&
                    ObjectCompare.EqualsNullable(this.Type, eqStation.Type) &&
                    ObjectCompare.EqualsNullable(this.HasBlackmarket, eqStation.HasBlackmarket) &&
                    ObjectCompare.EqualsNullable(this.HasCommodities, eqStation.HasCommodities) &&
                    ObjectCompare.EqualsNullable(this.HasRefuel, eqStation.HasRefuel) &&
                    ObjectCompare.EqualsNullable(this.HasRepair, eqStation.HasRepair) &&
                    ObjectCompare.EqualsNullable(this.HasRearm, eqStation.HasRearm) &&
                    ObjectCompare.EqualsNullable(this.HasOutfitting, eqStation.HasOutfitting) &&
                    ObjectCompare.EqualsNullable(this.HasShipyard, eqStation.HasShipyard) &&
                    ObjectCompare.EqualsNullable(this.ImportCommodities, eqStation.ImportCommodities) &&
                    ObjectCompare.EqualsNullable(this.ExportCommodities, eqStation.ExportCommodities) &&
                    ObjectCompare.EqualsNullable(this.ProhibitedCommodities, eqStation.ProhibitedCommodities) &&
                    ObjectCompare.EqualsNullable(this.Economies, eqStation.Economies))
                {
                    retValue = true;
                }
            }

            return(retValue);
        }
Пример #4
0
        /// <summary>
        /// creates a new station as a copy of another station
        /// only Id and SystemID must declared extra
        /// </summary>
        /// <param name="newId"></param>
        /// <param name="sourceSystemID"></param>
        /// <param name="sourceStation"></param>
        public EDStation(int newId, int sourceSystemID, EDStation sourceStation)
        {
            clear();

            Id       = newId;
            SystemId = sourceSystemID;
            getValues(sourceStation);
        }
Пример #5
0
        internal EDStationView(EDStation Station)
        {
            InitializeComponent();

            m_Station = Station;

            showData();

            this.Show();
        }
Пример #6
0
        internal EDStationView(EDStation Station)
        {

            InitializeComponent();

            m_Station = Station;

            showData();

            this.Show();
        }
Пример #7
0
        private EDStation getSystemStation(string Systemname, string StationName)
        {
            EDStation wantedStation = null;
            EDSystem  wantedSystem  = getSystem(Systemname);

            if (wantedSystem != null)
            {
                wantedStation = m_Stations[(int)enDataType.Data_Merged].Find(x => (x.SystemId == wantedSystem.Id) && (x.Name.Equals(StationName)));
            }

            return(wantedStation);
        }
Пример #8
0
        /// <summary>
        /// returns distance of a station to the star
        /// </summary>
        /// <param name="systemName"></param>
        /// <param name="stationName"></param>
        /// <returns></returns>
        public Int32 getStationDistance(string systemName, string stationName)
        {
            Int32 Distance = 0;

            if (!m_cachedStationDistances.TryGetValue(systemName + "|" + stationName, out Distance))
            {
                EDStation retValue = getStation(systemName, stationName);

                if ((retValue != null) && (retValue.DistanceToStar != null))
                {
                    Distance = (int)(retValue.DistanceToStar);
                }
                else
                {
                    Distance = -1;
                }

                m_cachedStationDistances.Add(systemName + "|" + stationName, Distance);
            }

            return(Distance);
        }
Пример #9
0
        /// <summary>
        /// changes or adds a station to the "own" list and to the merged list
        /// EDDB basedata will not be changed
        /// </summary>
        /// <param name="m_currentSystemdata">systemdata to be added</param>
        internal void ChangeAddStation(string Systemname, EDStation m_currentStationdata, string oldStationName=null)
        {
            EDSystem System;
            EDStation Station;
            int newStationIndex;

            if(String.IsNullOrEmpty(oldStationName.Trim()))
                oldStationName = m_currentStationdata.Name;

            List<EDSystem> ownSystems       = getSystems(enDataType.Data_Own);
            List<EDStation> ownStations     = getStations(enDataType.Data_Own);

            List<EDSystem> mergedSystems    = getSystems(enDataType.Data_Merged);
            List<EDStation> mergedStations  = getStations(enDataType.Data_Merged);

            // 1st put the new values into our local list
            System = ownSystems.Find(x => x.Name.Equals(Systemname, StringComparison.CurrentCultureIgnoreCase));
            if(System == null)
            {
                // own system is not existing, look for a EDDNCommunicator system
                System = mergedSystems.Find(x => x.Name.Equals(Systemname, StringComparison.CurrentCultureIgnoreCase));

                if(System == null)
                    throw new Exception("System in merged list required but not existing");
                
                // get a new local system id 
                int newSystemIndex = 0;
                if (m_Systems[(int)enDataType.Data_Own].Count > 0)
                   newSystemIndex = m_Systems[(int)enDataType.Data_Own].Max(X => X.Id) + 1;

                // and add the EDDNCommunicator system as a new system to the local list
                System = new EDSystem(newSystemIndex, System);
                ownSystems.Add(System);

                // get a new station index
                newStationIndex = 0;
                if(ownStations.Count > 0)
                    newStationIndex = ownStations.Max(X => X.Id) + 1;
                
                // add the new station in the local station dictionary
                ownStations.Add(new EDStation(newStationIndex, newSystemIndex, m_currentStationdata));
            }
            else
            { 
                // the system is existing in the own dictionary 
                Station = ownStations.Find(x => (x.Name.Equals(oldStationName, StringComparison.CurrentCultureIgnoreCase)) && 
                                                (x.SystemId == System.Id));
                if(Station != null)
                { 
                    // station is already existing, copy new values into existing Station
                    Station.getValues(m_currentStationdata);
                }
                else
                { 
                    // station is not existing, get a new station index
                    newStationIndex = 0;
                    if(ownStations.Count > 0)
                        newStationIndex = ownStations.Max(X => X.Id) + 1;
                    
                    // add the new station in the local station dictionary
                    ownStations.Add(new EDStation(newStationIndex, System.Id, m_currentStationdata));
                }
            }

            // 1st put the new values into the merged list
            System = mergedSystems.Find(x => x.Name.Equals(Systemname, StringComparison.CurrentCultureIgnoreCase));
            if(System == null)
            {
                // system is not exiting in merged list
                System = ownSystems.Find(x => x.Name.Equals(Systemname, StringComparison.CurrentCultureIgnoreCase));

                if(System == null)
                    throw new Exception("System in own list required but not existing");
                
                // get a new merged system id 
                int newSystemIndex = m_Systems[(int)enDataType.Data_Merged].Max(X => X.Id) + 1;

                // and add system to the merged list
                System = new EDSystem(newSystemIndex, System);
                mergedSystems.Add(System);

                // get a new station index
                newStationIndex = 0;
                if(mergedStations.Count > 0)
                    newStationIndex = mergedStations.Max(X => X.Id) + 1;
                
                // add the new station in the local station dictionary
                mergedStations.Add(new EDStation(newStationIndex, newSystemIndex, m_currentStationdata));
            }
            else
            { 
                // the system is existing in the merged dictionary 
                Station = mergedStations.Find(x => (x.Name.Equals(oldStationName, StringComparison.CurrentCultureIgnoreCase)) && 
                                                (x.SystemId == System.Id));
                if(Station != null)
                { 
                    // station is already existing, copy new values into existing Station
                    Station.getValues(m_currentStationdata);
                }
                else
                { 
                    // station is not existing, get a new station index
                    newStationIndex = 0;
                    if(mergedStations.Count > 0)
                        newStationIndex = mergedStations.Max(X => X.Id) + 1;
                    
                    // add the new station in the merged station dictionary
                    mergedStations.Add(new EDStation(newStationIndex, System.Id, m_currentStationdata));
                }
            }
           
            if(m_cachedStationDistances.ContainsKey(oldStationName))
                m_cachedStationDistances.Remove(oldStationName);

            saveStationData(@"./Data/stations_own.json", EDMilkyway.enDataType.Data_Own, true);
            saveSystemData(@"./Data/Systems_own.json", EDMilkyway.enDataType.Data_Own, true);        
        }
Пример #10
0
        /// <summary>
        /// copy the values from another station exept for the ID
        /// </summary>
        /// <param name="ValueStation"></param>
        public void getValues(EDStation ValueStation, bool getAll = false)
        {
            if (getAll)
            {
                Id          = ValueStation.Id;
                SystemId    = ValueStation.SystemId;
            }

            Name                  = ValueStation.Name;
            MaxLandingPadSize     = ValueStation.MaxLandingPadSize;
            DistanceToStar        = ValueStation.DistanceToStar;
            Faction               = ValueStation.Faction;
            Government            = ValueStation.Government;
            Allegiance            = ValueStation.Allegiance;
            State                 = ValueStation.State;
            Type                  = ValueStation.Type;
            HasBlackmarket        = ValueStation.HasBlackmarket;
            HasCommodities        = ValueStation.HasCommodities;
            HasRefuel             = ValueStation.HasRefuel;
            HasRepair             = ValueStation.HasRepair;
            HasRearm              = ValueStation.HasRearm;
            HasOutfitting         = ValueStation.HasOutfitting;
            HasShipyard           = ValueStation.HasShipyard;

            ImportCommodities     = ValueStation.ImportCommodities.CloneN();
            ExportCommodities     = ValueStation.ExportCommodities.CloneN();
            ProhibitedCommodities = ValueStation.ProhibitedCommodities.CloneN();
            Economies             = ValueStation.Economies.CloneN();

        }
Пример #11
0
        /// <summary>
        /// true, if all data *except the two IDs* is equal (case insensitive)
        /// </summary>
        /// <param name="eqSystem"></param>
        /// <returns></returns>
        public bool EqualsED(EDStation eqStation)
        {
            bool retValue = false;

            if(eqStation != null)
            {


                if (ObjectCompare.EqualsNullable(this.Name, eqStation.Name) &&
                    ObjectCompare.EqualsNullable(this.MaxLandingPadSize, eqStation.MaxLandingPadSize) && 
                    ObjectCompare.EqualsNullable(this.DistanceToStar, eqStation.DistanceToStar) && 
                    ObjectCompare.EqualsNullable(this.Faction, eqStation.Faction) && 
                    ObjectCompare.EqualsNullable(this.Government, eqStation.Government) && 
                    ObjectCompare.EqualsNullable(this.Allegiance, eqStation.Allegiance) && 
                    ObjectCompare.EqualsNullable(this.State, eqStation.State) && 
                    ObjectCompare.EqualsNullable(this.Type, eqStation.Type) && 
                    ObjectCompare.EqualsNullable(this.HasBlackmarket, eqStation.HasBlackmarket) && 
                    ObjectCompare.EqualsNullable(this.HasCommodities, eqStation.HasCommodities) && 
                    ObjectCompare.EqualsNullable(this.HasRefuel, eqStation.HasRefuel) &&
                    ObjectCompare.EqualsNullable(this.HasRepair, eqStation.HasRepair) && 
                    ObjectCompare.EqualsNullable(this.HasRearm, eqStation.HasRearm) &&
                    ObjectCompare.EqualsNullable(this.HasOutfitting, eqStation.HasOutfitting) &&
                    ObjectCompare.EqualsNullable(this.HasShipyard, eqStation.HasShipyard) &&
                    ObjectCompare.EqualsNullable(this.ImportCommodities, eqStation.ImportCommodities) &&
                    ObjectCompare.EqualsNullable(this.ExportCommodities, eqStation.ExportCommodities) &&
                    ObjectCompare.EqualsNullable(this.ProhibitedCommodities, eqStation.ProhibitedCommodities) &&
                    ObjectCompare.EqualsNullable(this.Economies, eqStation.Economies))
                        retValue = true;

            }

            return retValue;             
        }
Пример #12
0
        /// <summary>
         /// creates a new station as a copy of another station
         /// only Id and SystemID must declared extra
         /// </summary>
         /// <param name="newId"></param>
         /// <param name="sourceSystemID"></param>
         /// <param name="sourceStation"></param>
        public EDStation(int newId, int sourceSystemID, EDStation sourceStation)
        {
            clear();

            Id              = newId;
            SystemId        = sourceSystemID;
            getValues(sourceStation);   
        }
Пример #13
0
        private void loadStationData(string Systemname, string Stationname, bool isNew=false)
        {

            m_StationLoadingValues = true;

            if (isNew)
            {
                cmbStationStations.SelectedIndex    = -1;
                m_loadedStationdata                 = new EDStation();
                m_loadedStationdata.Name            = Stationname;
                m_StationIsNew                      = true;
            }
            else
            {
                cmbStationStations.SelectedItem    = Stationname;
                m_loadedStationdata                 = _Milkyway.getStation(Systemname, Stationname);
                m_StationIsNew                      = false;
            }

            if (m_loadedStationdata != null)
            {
                m_currentStationdata.getValues(m_loadedStationdata, true);

                txtStationId.Text = m_loadedStationdata.Id.ToString(CultureInfo.CurrentCulture);
                txtStationName.Text = m_loadedStationdata.Name.ToString();
                cmbStationMaxLandingPadSize.Text = m_loadedStationdata.MaxLandingPadSize.NToString();
                txtStationDistanceToStar.Text = m_loadedStationdata.DistanceToStar.ToNString();
                txtStationFaction.Text = m_loadedStationdata.Faction.NToString();
                cmbStationGovernment.Text = m_loadedStationdata.Government.NToString();
                cmbStationAllegiance.Text = m_loadedStationdata.Allegiance.NToString();
                cmbStationState.Text = m_loadedStationdata.State.NToString();
                cmbStationType.Text = m_loadedStationdata.Type.NToString();

                txtStationUpdatedAt.Text = UnixTimeStamp.UnixTimeStampToDateTime(m_loadedStationdata.UpdatedAt).ToString(CultureInfo.CurrentUICulture);

                lbStationEconomies.Items.Clear();

                foreach (string Economy in m_loadedStationdata.Economies)
                    lbStationEconomies.Items.Add(Economy);

                cbStationHasCommodities.CheckState = m_loadedStationdata.HasCommodities.toCheckState();
                cbStationHasBlackmarket.CheckState = m_loadedStationdata.HasBlackmarket.toCheckState();
                cbStationHasOutfitting.CheckState = m_loadedStationdata.HasOutfitting.toCheckState();
                cbStationHasShipyard.CheckState = m_loadedStationdata.HasShipyard.toCheckState();
                cbStationHasRearm.CheckState = m_loadedStationdata.HasRearm.toCheckState();
                cbStationHasRefuel.CheckState = m_loadedStationdata.HasRefuel.toCheckState();
                cbStationHasRepair.CheckState = m_loadedStationdata.HasRepair.toCheckState();

                setStationEditable(isNew);

                if(!isNew)
                {
                    cmdStationNew.Enabled       = true;
                    cmdStationEdit.Enabled      = true;
                    cmdStationSave.Enabled      = false;
                    cmdStationCancel.Enabled    = cmdStationSave.Enabled;

                    cmbStationStations.ReadOnly = false;

                }

                if (_Milkyway.getStations(EDMilkyway.enDataType.Data_EDDB).Exists(x => (x.Name.Equals(m_loadedStationdata.Name, StringComparison.InvariantCultureIgnoreCase)) &&
                                                                                      (x.SystemId == m_loadedStationdata.SystemId)))
                {
                    txtStationName.ReadOnly = true;
                    lblStationRenameHint.Visible = true;
                }
                else
                {
                    txtStationName.ReadOnly = false;
                    lblStationRenameHint.Visible = false;
                }

            }
            else
            {
                m_currentStationdata.clear();

                txtStationId.Text = Program.NULLSTRING;
                txtStationName.Text = Program.NULLSTRING;
                cmbStationMaxLandingPadSize.Text = Program.NULLSTRING;
                txtStationDistanceToStar.Text = Program.NULLSTRING;
                txtStationFaction.Text = Program.NULLSTRING;
                cmbStationGovernment.Text = Program.NULLSTRING;
                cmbStationAllegiance.Text = Program.NULLSTRING;
                cmbStationState.Text = Program.NULLSTRING;
                txtStationUpdatedAt.Text = Program.NULLSTRING;
                cmbStationType.Text = Program.NULLSTRING;

                lbStationEconomies.Items.Clear();

                cbStationHasCommodities.CheckState = CheckState.Unchecked;
                cbStationHasBlackmarket.CheckState = CheckState.Unchecked;
                cbStationHasOutfitting.CheckState = CheckState.Unchecked;
                cbStationHasShipyard.CheckState = CheckState.Unchecked;
                cbStationHasRearm.CheckState = CheckState.Unchecked;
                cbStationHasRefuel.CheckState = CheckState.Unchecked;
                cbStationHasRepair.CheckState = CheckState.Unchecked;

                setStationEditable(false);

                cmdStationNew.Enabled    = cmdStationNew.Enabled;
                cmdStationEdit.Enabled   = false;
                cmdStationSave.Enabled   = false;

                lblStationRenameHint.Visible = false;

                cmbStationStations.Text = "";

            }

            m_StationLoadingValues = false;

        }
Пример #14
0
        private void ParseEddnJson(object text, Dictionary<string, string> headerDictionary, IDictionary<string, string> messageDictionary, bool import)
        {
            string txt = text.ToString();
            // .. we're here because we've received some data from EDDNCommunicator

            if (txt != "")
                try
                {
                    // ReSharper disable StringIndexOfIsCultureSpecific.1
                    var headerRawStart = txt.IndexOf(@"""header""") + 12;
                    var headerRawLength = txt.Substring(headerRawStart).IndexOf("}");
                    var headerRawData = txt.Substring(headerRawStart, headerRawLength);

                    var schemaRawStart = txt.IndexOf(@"""$schemaRef""") + 14;
                    var schemaRawLength = txt.Substring(schemaRawStart).IndexOf(@"""message"":");
                    var schemaRawData = txt.Substring(schemaRawStart, schemaRawLength);

                    var messageRawStart = txt.IndexOf(@"""message"":") + 12;
                    var messageRawLength = txt.Substring(messageRawStart).IndexOf("}");
                    var messageRawData = txt.Substring(messageRawStart, messageRawLength);
                    // ReSharper restore StringIndexOfIsCultureSpecific.1

                    schemaRawData = schemaRawData.Replace(@"""", "").Replace(",","");
                    var headerRawPairs = headerRawData.Replace(@"""", "").Split(',');
                    var messageRawPairs = messageRawData.Replace(@"""", "").Split(',');


                    if((RegulatedNoiseSettings.UseEddnTestSchema  && (schemaRawData.IndexOf("Test", StringComparison.InvariantCultureIgnoreCase) >= 0)) ||
                       (!RegulatedNoiseSettings.UseEddnTestSchema && (schemaRawData.IndexOf("Test", StringComparison.InvariantCultureIgnoreCase)  < 0)))
                    {
                        foreach (var rawHeaderPair in headerRawPairs)
                        {
                            var splitPair = new string[2];
                            splitPair[0] = rawHeaderPair.Substring(0, rawHeaderPair.IndexOf(':'));
                            splitPair[1] = rawHeaderPair.Substring(splitPair[0].Length + 1);
                            if (splitPair[0].StartsWith(" ")) splitPair[0] = splitPair[0].Substring(1);
                            if (splitPair[1].StartsWith(" ")) splitPair[1] = splitPair[1].Substring(1);
                            headerDictionary.Add(splitPair[0], splitPair[1]);
                        }

                        foreach (var rawMessagePair in messageRawPairs)
                        {
                            var splitPair = new string[2];
                            splitPair[0] = rawMessagePair.Substring(0, rawMessagePair.IndexOf(':'));
                            splitPair[1] = rawMessagePair.Substring(splitPair[0].Length + 1);
                            if (splitPair[0].StartsWith(" ")) splitPair[0] = splitPair[0].Substring(1);
                            if (splitPair[1].StartsWith(" ")) splitPair[1] = splitPair[1].Substring(1);
                            messageDictionary.Add(splitPair[0], splitPair[1]);
                        }

                        var nameAndVersion = (headerDictionary["softwareName"] + " / " + headerDictionary["softwareVersion"]);
                        if (!_eddnPublisherStats.ContainsKey(nameAndVersion))
                            _eddnPublisherStats.Add(nameAndVersion, new EddnPublisherVersionStats());

                        _eddnPublisherStats[nameAndVersion].MessagesReceived++;

                        var output = "";
                        foreach (var appVersion in _eddnPublisherStats)
                        {
                            output = output + appVersion.Key + " : " + appVersion.Value.MessagesReceived + " messages\r\n";
                        }
                        tbEddnStats.Text = output;

                        string commodity = getLocalizedCommodity(RegulatedNoiseSettings.Language, messageDictionary["itemName"]);

                        if((cachedSystem == null) || (!messageDictionary["systemName"].Equals(cachedSystem.Name, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            cachedSystem = _Milkyway.getSystem(messageDictionary["systemName"]);
                        }
                        if(cachedSystem == null)
                        {
                            cachedSystem = new EDSystem();
                            cachedSystem.Name = messageDictionary["systemName"];
                        }

                        if((cachedSystem != null) && ((cachedStation == null) || (!messageDictionary["stationName"].Equals(cachedStation.Name, StringComparison.InvariantCultureIgnoreCase))))
                        {
                            cachedStation = _Milkyway.getStation(messageDictionary["systemName"], messageDictionary["stationName"]);
                        }
                        if(cachedStation == null)
                        {
                            cachedStation = new EDStation();
                            cachedStation.Name = messageDictionary["stationName"];
                        }

                        if(!String.IsNullOrEmpty(commodity))
                        {

                            //System;Station;Commodity_Class;Sell;Buy;Demand;;Supply;;Date;
                            if (headerDictionary["uploaderID"] != tbUsername.Text) // Don't import our own uploads...
                            {
                                string csvFormatted = cachedSystem.Name + ";" +
                                                      cachedStation.Name + ";" +
                                                      commodity + ";" +
                                                      (messageDictionary["sellPrice"] == "0" ? "" : messageDictionary["sellPrice"]) + ";" +
                                                      (messageDictionary["buyPrice"] == "0" ? "" : messageDictionary["buyPrice"]) + ";" +
                                                      messageDictionary["demand"] + ";" +
                                                      ";" +
                                                      messageDictionary["stationStock"] + ";" +
                                                      ";" +
                                                      messageDictionary["timestamp"] + ";"
                                                      +
                                                      "<From EDDN>" + ";";

                                if(!checkPricePlausibility(new string[] {csvFormatted}, true))
                                {
                                    if(import)
                                        ImportCsvString(csvFormatted);

                                }else{

                                    string InfoString = string.Format("IMPLAUSIBLE DATA : \"{3}\" from {0}/{1}/ID=[{2}]", headerDictionary["softwareName"], headerDictionary["softwareVersion"], headerDictionary["uploaderID"], csvFormatted );

                                    lbEddnImplausible.Items.Add(InfoString);
                                    lbEddnImplausible.SelectedIndex = lbEddnImplausible.Items.Count-1;
                                    lbEddnImplausible.SelectedIndex = -1;

                                    if(cbSpoolImplausibleToFile.Checked)
                                    {
                                        FileStream LogFileStream = null;
                                        string FileName = @".\EddnImplausibleOutput.txt";

                                        if(File.Exists(FileName))
                                        { 
                                            LogFileStream = File.Open(FileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                                        }
                                        else
                                        {
                                            LogFileStream = File.Create(FileName);
                                        }

                                       LogFileStream.Write(System.Text.Encoding.Default.GetBytes(InfoString + "\n"), 0, System.Text.Encoding.Default.GetByteCount(InfoString + "\n"));
                                       LogFileStream.Close();
                                    }

                                    Debug.Print("Implausible EDDN Data: " + csvFormatted);
                                }
                            }
                        

                            if ((DateTime.Now - _lastGuiUpdate) > TimeSpan.FromSeconds(10))
                            {
                                SetupGui();
                                _lastGuiUpdate = DateTime.Now;
                            }
                        }
                        else 
                        { 
                            string csvFormatted = messageDictionary["systemName"] + ";" +
                                                    messageDictionary["stationName"] + ";" +
                                                    messageDictionary["itemName"] + ";" +
                                                    (messageDictionary["sellPrice"] == "0" ? "" : messageDictionary["sellPrice"]) + ";" +
                                                    (messageDictionary["buyPrice"] == "0" ? "" : messageDictionary["buyPrice"]) + ";" +
                                                    messageDictionary["demand"] + ";" +
                                                    ";" +
                                                    messageDictionary["stationStock"] + ";" +
                                                    ";" +
                                                    messageDictionary["timestamp"] + ";"
                                                    +
                                                    "<From EDDN>" + ";";
                            string InfoString = string.Format("UNKNOWN COMMODITY : \"{3}\" from {0}/{1}/ID=[{2}]", headerDictionary["softwareName"], headerDictionary["softwareVersion"], headerDictionary["uploaderID"], csvFormatted );

                            lbEddnImplausible.Items.Add(InfoString);
                            lbEddnImplausible.SelectedIndex = lbEddnImplausible.Items.Count-1;
                            lbEddnImplausible.SelectedIndex = -1;

                            if(cbSpoolImplausibleToFile.Checked)
                            {

                                FileStream LogFileStream = null;
                                string FileName = @".\EddnImplausibleOutput.txt";

                                if(File.Exists(FileName))
                                { 
                                    LogFileStream = File.Open(FileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                                }
                                else
                                {
                                    LogFileStream = File.Create(FileName);
                                }

                                LogFileStream.Write(System.Text.Encoding.Default.GetBytes(InfoString + "\n" ), 0, System.Text.Encoding.Default.GetByteCount(InfoString + "\n"));
                                LogFileStream.Close();
                            }

                        }
                    }
                }
                catch
                {
                    tbEDDNOutput.Text = "Couldn't parse JSON!\r\n\r\n" + tbEDDNOutput.Text;
                }
        }
Пример #15
0
        /// <summary>
        /// changes or adds a station to the "own" list and to the merged list
        /// EDDB basedata will not be changed
        /// </summary>
        /// <param name="m_currentSystemdata">systemdata to be added</param>
        internal void ChangeAddStation(string Systemname, EDStation m_currentStationdata, string oldStationName = null)
        {
            EDSystem  System;
            EDStation Station;
            int       newStationIndex;

            if (String.IsNullOrEmpty(oldStationName.Trim()))
            {
                oldStationName = m_currentStationdata.Name;
            }

            List <EDSystem>  ownSystems  = getSystems(enDataType.Data_Own);
            List <EDStation> ownStations = getStations(enDataType.Data_Own);

            List <EDSystem>  mergedSystems  = getSystems(enDataType.Data_Merged);
            List <EDStation> mergedStations = getStations(enDataType.Data_Merged);

            // 1st put the new values into our local list
            System = ownSystems.Find(x => x.Name.Equals(Systemname, StringComparison.CurrentCultureIgnoreCase));
            if (System == null)
            {
                // own system is not existing, look for a EDDNCommunicator system
                System = mergedSystems.Find(x => x.Name.Equals(Systemname, StringComparison.CurrentCultureIgnoreCase));

                if (System == null)
                {
                    throw new Exception("System in merged list required but not existing");
                }

                // get a new local system id
                int newSystemIndex = 0;
                if (m_Systems[(int)enDataType.Data_Own].Count > 0)
                {
                    newSystemIndex = m_Systems[(int)enDataType.Data_Own].Max(X => X.Id) + 1;
                }

                // and add the EDDNCommunicator system as a new system to the local list
                System = new EDSystem(newSystemIndex, System);
                ownSystems.Add(System);

                // get a new station index
                newStationIndex = 0;
                if (ownStations.Count > 0)
                {
                    newStationIndex = ownStations.Max(X => X.Id) + 1;
                }

                // add the new station in the local station dictionary
                ownStations.Add(new EDStation(newStationIndex, newSystemIndex, m_currentStationdata));
            }
            else
            {
                // the system is existing in the own dictionary
                Station = ownStations.Find(x => (x.Name.Equals(oldStationName, StringComparison.CurrentCultureIgnoreCase)) &&
                                           (x.SystemId == System.Id));
                if (Station != null)
                {
                    // station is already existing, copy new values into existing Station
                    Station.getValues(m_currentStationdata);
                }
                else
                {
                    // station is not existing, get a new station index
                    newStationIndex = 0;
                    if (ownStations.Count > 0)
                    {
                        newStationIndex = ownStations.Max(X => X.Id) + 1;
                    }

                    // add the new station in the local station dictionary
                    ownStations.Add(new EDStation(newStationIndex, System.Id, m_currentStationdata));
                }
            }

            // 1st put the new values into the merged list
            System = mergedSystems.Find(x => x.Name.Equals(Systemname, StringComparison.CurrentCultureIgnoreCase));
            if (System == null)
            {
                // system is not exiting in merged list
                System = ownSystems.Find(x => x.Name.Equals(Systemname, StringComparison.CurrentCultureIgnoreCase));

                if (System == null)
                {
                    throw new Exception("System in own list required but not existing");
                }

                // get a new merged system id
                int newSystemIndex = m_Systems[(int)enDataType.Data_Merged].Max(X => X.Id) + 1;

                // and add system to the merged list
                System = new EDSystem(newSystemIndex, System);
                mergedSystems.Add(System);

                // get a new station index
                newStationIndex = 0;
                if (mergedStations.Count > 0)
                {
                    newStationIndex = mergedStations.Max(X => X.Id) + 1;
                }

                // add the new station in the local station dictionary
                mergedStations.Add(new EDStation(newStationIndex, newSystemIndex, m_currentStationdata));
            }
            else
            {
                // the system is existing in the merged dictionary
                Station = mergedStations.Find(x => (x.Name.Equals(oldStationName, StringComparison.CurrentCultureIgnoreCase)) &&
                                              (x.SystemId == System.Id));
                if (Station != null)
                {
                    // station is already existing, copy new values into existing Station
                    Station.getValues(m_currentStationdata);
                }
                else
                {
                    // station is not existing, get a new station index
                    newStationIndex = 0;
                    if (mergedStations.Count > 0)
                    {
                        newStationIndex = mergedStations.Max(X => X.Id) + 1;
                    }

                    // add the new station in the merged station dictionary
                    mergedStations.Add(new EDStation(newStationIndex, System.Id, m_currentStationdata));
                }
            }

            if (m_cachedStationDistances.ContainsKey(oldStationName))
            {
                m_cachedStationDistances.Remove(oldStationName);
            }

            saveStationData(@"./Data/stations_own.json", EDMilkyway.enDataType.Data_Own, true);
            saveSystemData(@"./Data/Systems_own.json", EDMilkyway.enDataType.Data_Own, true);
        }