예제 #1
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));
                }
            }
        }
예제 #2
0
        /// <summary>
        /// true, if all data *except the ID* is equal (case insensitive)
        /// </summary>
        /// <param name="eqSystem"></param>
        /// <returns></returns>
        public bool EqualsED(EDSystem eqSystem)
        {
            bool retValue = false;

            if (eqSystem != null)
            {
                if (ObjectCompare.EqualsNullable(this.Name, eqSystem.Name) &&
                    ObjectCompare.EqualsNullable(this.X, eqSystem.X) &&
                    ObjectCompare.EqualsNullable(this.Y, eqSystem.Y) &&
                    ObjectCompare.EqualsNullable(this.Z, eqSystem.Z) &&
                    ObjectCompare.EqualsNullable(this.Faction, eqSystem.Faction) &&
                    ObjectCompare.EqualsNullable(this.Population, eqSystem.Population) &&
                    ObjectCompare.EqualsNullable(this.Government, eqSystem.Government) &&
                    ObjectCompare.EqualsNullable(this.Allegiance, eqSystem.Allegiance) &&
                    ObjectCompare.EqualsNullable(this.State, eqSystem.State) &&
                    ObjectCompare.EqualsNullable(this.Security, eqSystem.Security) &&
                    ObjectCompare.EqualsNullable(this.PrimaryEconomy, eqSystem.PrimaryEconomy) &&
                    ObjectCompare.EqualsNullable(this.NeedsPermit, eqSystem.NeedsPermit) &&
                    ObjectCompare.EqualsNullable(this.UpdatedAt, eqSystem.UpdatedAt))
                {
                    retValue = true;
                }
            }

            return(retValue);
        }
예제 #3
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);
        }
예제 #4
0
        /// <summary>
        /// go and get station clones from the own data for a new station
        /// and adds them to the merged data
        /// </summary>
        /// <param name="newSystem">new created system in merged data </param>
        private void copyStationsForNewSystem(EDSystem newSystem)
        {
            // get the list from own data with the name of the new station
            // (it's ok because it must be the same name)
            List <EDStation> ownSystemStations = getStations(newSystem.Name, enDataType.Data_Own);

            // get the gighest index
            int newStationIndex = m_Stations[(int)enDataType.Data_Merged].Max(X => X.Id);

            for (int j = 0; j < ownSystemStations.Count(); j++)
            {
                newStationIndex++;
                m_Stations[(int)enDataType.Data_Merged].Add(new EDStation(newStationIndex, newSystem.Id, ownSystemStations[j]));
            }
        }
예제 #5
0
            /// <summary>
        /// returns a station in a system by name
        /// </summary>
        /// <param name="systemName"></param>
        /// <param name="stationName"></param>
        /// <returns></returns>
        /// <param name="System"></param>
        public EDStation getStation(string systemName, string stationName, out EDSystem System)
        {
            EDStation retValue;

            EDSystem SystemData = m_Systems[(int)enDataType.Data_Merged].Find(x => x.Name==systemName);

            if (SystemData != null)
                retValue = m_Stations[(int)enDataType.Data_Merged].Find(x => x.SystemId==SystemData.Id && x.Name.Equals(stationName, StringComparison.InvariantCultureIgnoreCase));
            else
                retValue = null;

            System = SystemData;

            return retValue;
        }
예제 #6
0
        /// <summary>
        /// get all stations for a system from a particular list
        /// </summary>
        /// <param name="Systemname"></param>
        /// <returns></returns>
        public List <EDStation> getStations(string Systemname, enDataType wantedType)
        {
            List <EDStation> retValue;

            EDSystem SystemData = m_Systems[(int)wantedType].Find(x => x.Name == Systemname);

            if (SystemData != null)
            {
                retValue = m_Stations[(int)wantedType].FindAll(x => x.SystemId == SystemData.Id);
            }
            else
            {
                retValue = new List <EDStation>();
            }

            return(retValue);
        }
예제 #7
0
        /// <summary>
        /// returns a station in a system by name
        /// </summary>
        /// <param name="systemName"></param>
        /// <param name="stationName"></param>
        /// <returns></returns>
        /// <param name="System"></param>
        public EDStation getStation(string systemName, string stationName, out EDSystem System)
        {
            EDStation retValue;

            EDSystem SystemData = m_Systems[(int)enDataType.Data_Merged].Find(x => x.Name == systemName);

            if (SystemData != null)
            {
                retValue = m_Stations[(int)enDataType.Data_Merged].Find(x => x.SystemId == SystemData.Id && x.Name.Equals(stationName, StringComparison.InvariantCultureIgnoreCase));
            }
            else
            {
                retValue = null;
            }

            System = SystemData;

            return(retValue);
        }
예제 #8
0
        /// <summary>
        /// get coordinates of a system
        /// </summary>
        /// <param name="Systemname"></param>
        /// <returns></returns>
        public Point3D getSystemCoordinates(string Systemname)
        {
            Point3D retValue = null;

            if (!String.IsNullOrEmpty(Systemname))
            {
                if (!m_cachedLocations.TryGetValue(Systemname, out retValue))
                {
                    EDSystem mySystem = m_Systems[(int)enDataType.Data_Merged].Find(x => x.Name.Equals(Systemname, StringComparison.InvariantCultureIgnoreCase));

                    if (mySystem != null)
                    {
                        retValue = mySystem.SystemCoordinates();
                        m_cachedLocations.Add(Systemname, retValue);
                    }
                }
            }

            return(retValue);
        }
예제 #9
0
        /// <summary>
        /// copy the values from another system exept for the ID
        /// </summary>
        /// <param name="ValueStation"></param>
        public void getValues(EDSystem ownSystem, bool getAll = false)
        {
            if (getAll)
            {
                Id = ownSystem.Id;
            }

            Name           = ownSystem.Name;
            X              = ownSystem.X;
            Y              = ownSystem.Y;
            Z              = ownSystem.Z;
            Faction        = ownSystem.Faction;
            Population     = ownSystem.Population;
            Government     = ownSystem.Government;
            Allegiance     = ownSystem.Allegiance;
            State          = ownSystem.State;
            Security       = ownSystem.Security;
            PrimaryEconomy = ownSystem.PrimaryEconomy;
            NeedsPermit    = ownSystem.NeedsPermit;
            UpdatedAt      = ownSystem.UpdatedAt;
        }
예제 #10
0
        /// <summary>
        /// true, if all data *except the ID* is equal (case insensitive)
        /// </summary>
        /// <param name="eqSystem"></param>
        /// <returns></returns>
        public bool EqualsED(EDSystem eqSystem)
        {
            bool retValue = false;

            if (eqSystem != null)
            {
                if (ObjectCompare.EqualsNullable(this.Name, eqSystem.Name) &&
                    ObjectCompare.EqualsNullable(this.X, eqSystem.X) &&
                    ObjectCompare.EqualsNullable(this.Y, eqSystem.Y) &&
                    ObjectCompare.EqualsNullable(this.Z, eqSystem.Z) &&
                    ObjectCompare.EqualsNullable(this.Faction, eqSystem.Faction) &&
                    ObjectCompare.EqualsNullable(this.Population, eqSystem.Population) &&
                    ObjectCompare.EqualsNullable(this.Government, eqSystem.Government) &&
                    ObjectCompare.EqualsNullable(this.Allegiance, eqSystem.Allegiance) &&
                    ObjectCompare.EqualsNullable(this.State, eqSystem.State) &&
                    ObjectCompare.EqualsNullable(this.Security, eqSystem.Security) &&
                    ObjectCompare.EqualsNullable(this.PrimaryEconomy, eqSystem.PrimaryEconomy) &&
                    ObjectCompare.EqualsNullable(this.NeedsPermit, eqSystem.NeedsPermit) &&
                    ObjectCompare.EqualsNullable(this.UpdatedAt, eqSystem.UpdatedAt))
                    retValue = true;
            }

            return retValue;             
        }
예제 #11
0
        /// <summary>
        /// go and get station clones from the own data for a new station
        /// and adds them to the merged data
        /// </summary>
        /// <param name="newSystem">new created system in merged data </param>
        private void copyStationsForNewSystem(EDSystem newSystem)
        {
            // get the list from own data with the name of the new station 
            // (it's ok because it must be the same name)
            List<EDStation> ownSystemStations = getStations(newSystem.Name, enDataType.Data_Own);
                
            // get the gighest index
            int newStationIndex = m_Stations[(int)enDataType.Data_Merged].Max(X => X.Id);

            for (int j = 0; j < ownSystemStations.Count(); j++)
            {
                newStationIndex++;
                m_Stations[(int)enDataType.Data_Merged].Add(new EDStation(newStationIndex, newSystem.Id, ownSystemStations[j]));
            }
        }
예제 #12
0
 /// <summary>
  /// creates a new system as a copy of another system
  /// only the id must declared extra
 /// </summary>
 /// <param name="newSystemIndex"></param>
 /// <param name="ownSystem"></param>
 public EDSystem(int newId, EDSystem sourceSystem)
 {
     clear();
     Id              = newId;
     getValues(sourceSystem);   
 }
예제 #13
0
        /// <summary>
        /// merging EDDB and own data to one big list
        /// </summary>
        public bool mergeData()
        {
            int StartingCount;
            bool SystemCanBeDeleted = false;

            //if (false)
            //{ 
            //    // create some data for testing 
            //    if (File.Exists(@".\Data\systems_own.json"))
            //        File.Delete(@".\Data\systems_own.json");
            //    if (File.Exists(@".\Data\stations_own.json"))
            //        File.Delete(@".\Data\stations_own.json");
            //    m_Systems[(int)enMessageInfo.Data_Merged] = new List<EDSystem>(m_Systems[(int)enMessageInfo.Data_EDDB].Where(x => x.Id <= 10));
            //    m_Stations[(int)enMessageInfo.Data_Merged] = new List<EDStation>(m_Stations[(int)enMessageInfo.Data_EDDB].Where(x => x.SystemId <= 10));
            //    saveSystemData(@".\Data\systems_own.json", enMessageInfo.Data_Merged, false);
            //    saveStationData(@".\Data\stations_own.json", enMessageInfo.Data_Merged, false);
            //}
            
            
            // get the base list from EDDB assuming it's the bigger one
            m_Systems[(int)enDataType.Data_Merged] = cloneSystems(enDataType.Data_EDDB);
            m_Stations[(int)enDataType.Data_Merged] = cloneStations(enDataType.Data_EDDB);

            StartingCount =  m_Systems[(int)enDataType.Data_Own].Count;

            for (int i = 0; i < StartingCount; i++)
            {
                SystemCanBeDeleted = true;


                EDSystem ownSystem = m_Systems[(int)enDataType.Data_Own][StartingCount-i-1];
                EDSystem existingEDDNSystem = getSystem(ownSystem.Name);

                //if (existingEDDNSystem != null)
                //    Debug.Print("Id=" + existingEDDNSystem.Id);
                //else
                //    Debug.Print("Id=null");

                if (existingEDDNSystem != null)
                {

                    if (existingEDDNSystem.EqualsED(ownSystem))
                    {
                        // systems are equal, check the stations
                        checkStations(ownSystem, existingEDDNSystem, ref SystemCanBeDeleted, ref m_changedStations);
                    }
                    else
                    {
                        // system is existing, but there are differences -> own version has a higher priority
                        SystemCanBeDeleted = false;
                        existingEDDNSystem.getValues(ownSystem);

                        // now check the stations
                        checkStations(ownSystem, existingEDDNSystem, ref SystemCanBeDeleted, ref m_changedStations);

                    }
                }
                else
                {
                    // system is unknown in the EDDB, copy our own system into the merged list
                    SystemCanBeDeleted = false;
                    int newSystemIndex = m_Systems[(int)enDataType.Data_Merged].Max(X => X.Id) + 1;

                    // create system cloneSystems
                    EDSystem newSystem = new EDSystem(newSystemIndex, ownSystem);

                    // add it to merged data
                    m_Systems[(int)enDataType.Data_Merged].Add(newSystem);

                    // now go and get the stations
                    copyStationsForNewSystem(newSystem);
                }

                if (SystemCanBeDeleted)
                {
                    //
                     
                    // delete the system;
                    m_Systems[(int)enDataType.Data_Own].Remove(ownSystem);
                    m_changedSystems = true;

                }
            }

            return changedStations || changedSystems;
        }
예제 #14
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));
                }
            }
        }
예제 #15
0
        /// <summary>
        /// changes or adds a system 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 ChangeAddSystem(EDSystem m_currentSystemdata, string oldSystemName = null)
        {
            EDSystem        System;
            List <EDSystem> ownSystems = getSystems(enDataType.Data_Own);
            int             newSystemIndex;

            if (String.IsNullOrEmpty(oldSystemName.Trim()))
            {
                oldSystemName = m_currentSystemdata.Name;
            }

            if (!oldSystemName.Equals(m_currentSystemdata.Name))
            {
                // changing system name
                var existing = getSystems(EDMilkyway.enDataType.Data_EDDB).Find(x => x.Name.Equals(oldSystemName, StringComparison.InvariantCultureIgnoreCase));
                if (existing != null)
                {
                    throw new Exception("It's not allowed to rename a EDDB system");
                }
            }

            // 1st put the new values into our local list
            System = ownSystems.Find(x => x.Name.Equals(oldSystemName, StringComparison.CurrentCultureIgnoreCase));
            if (System != null)
            {
                // copy new values into existing system
                System.getValues(m_currentSystemdata);
            }
            else
            {
                // add as a new system to own data
                newSystemIndex = 0;

                if (ownSystems.Count > 0)
                {
                    newSystemIndex = ownSystems.Max(X => X.Id) + 1;
                }

                ownSystems.Add(new EDSystem(newSystemIndex, m_currentSystemdata));
            }

            // 2nd put the new values into our merged list
            List <EDSystem> mergedSystems = getSystems(enDataType.Data_Merged);

            System = mergedSystems.Find(x => x.Name.Equals(oldSystemName, StringComparison.CurrentCultureIgnoreCase));
            if (System != null)
            {
                // copy new values into existing system
                System.getValues(m_currentSystemdata);
            }
            else
            {
                // add as a new system to own data
                newSystemIndex = 0;

                if (mergedSystems.Count > 0)
                {
                    newSystemIndex = mergedSystems.Max(X => X.Id) + 1;
                }
                mergedSystems.Add(new EDSystem(newSystemIndex, m_currentSystemdata));
            }

            if (m_cachedLocations.ContainsKey(oldSystemName))
            {
                m_cachedLocations.Remove(oldSystemName);
            }

            saveStationData(@"./Data/stations_own.json", EDMilkyway.enDataType.Data_Own, true);
            saveSystemData(@"./Data/systems_own.json", EDMilkyway.enDataType.Data_Own, true);
        }
예제 #16
0
 /// <summary>
 /// creates a new system as a copy of another system
 /// only the id must declared extra
 /// </summary>
 /// <param name="newSystemIndex"></param>
 /// <param name="ownSystem"></param>
 public EDSystem(int newId, EDSystem sourceSystem)
 {
     clear();
     Id = newId;
     getValues(sourceSystem);
 }
예제 #17
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);
        }
예제 #18
0
        private void loadSystemData(string Systemname, bool isNew=false)
        {

            m_SystemLoadingValues = true;

            if (isNew)
            {
                cmbSystemsAllSystems.SelectedIndex = 0;
                m_loadedSystemdata = new EDSystem();
                m_loadedSystemdata.Name = Systemname;
                m_SystemIsNew = true;
            }
            else
            {
                cmbSystemsAllSystems.SelectedValue = Systemname;
                m_loadedSystemdata = _Milkyway.getSystem(Systemname);
                m_SystemIsNew = false;
            }

            cmbStationStations.Items.Clear();
            cmbStationStations.Items.Add("");


            if (m_loadedSystemdata != null)
            {
                m_currentSystemdata.getValues(m_loadedSystemdata, true);

                txtSystemId.Text = m_loadedSystemdata.Id.ToString(CultureInfo.CurrentCulture);
                txtSystemName.Text = m_loadedSystemdata.Name;
                txtSystemX.Text = m_loadedSystemdata.X.ToString("0.00000", CultureInfo.CurrentCulture);
                txtSystemY.Text = m_loadedSystemdata.Y.ToString("0.00000", CultureInfo.CurrentCulture);
                txtSystemZ.Text = m_loadedSystemdata.Z.ToString("0.00000", CultureInfo.CurrentCulture);
                txtSystemFaction.Text = m_loadedSystemdata.Faction.NToString();
                txtSystemPopulation.Text = m_loadedSystemdata.Population.ToNString("#,##0.", CultureInfo.CurrentCulture);
                txtSystemUpdatedAt.Text = UnixTimeStamp.UnixTimeStampToDateTime(m_loadedSystemdata.UpdatedAt).ToString(CultureInfo.CurrentUICulture);
                cbSystemNeedsPermit.CheckState = m_loadedSystemdata.NeedsPermit.toCheckState();
                cmbSystemPrimaryEconomy.Text = m_loadedSystemdata.PrimaryEconomy.NToString();
                cmbSystemSecurity.Text = m_loadedSystemdata.Security.NToString();
                cmbSystemState.Text = m_loadedSystemdata.State.NToString();
                cmbSystemAllegiance.Text = m_loadedSystemdata.Allegiance.NToString();
                cmbSystemGovernment.Text = m_loadedSystemdata.Government.NToString();

                setSystemEditable(isNew);

                if(!isNew)
                { 
                    cmdSystemNew.Enabled            = true;
                    cmdSystemEdit.Enabled           = true;
                    cmdSystemSave.Enabled           = false;
                    cmdSystemCancel.Enabled         = cmdSystemSave.Enabled;

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

				    cmbSystemsAllSystems.ReadOnly   = false;
                    cmbStationStations.ReadOnly     = false;
                }

                List<EDStation> StationsInSystem = _Milkyway.getStations(Systemname);
                foreach (var Station in StationsInSystem)
                {
                    cmbStationStations.Items.Add(Station.Name);
                }

                lblStationCount.Text = StationsInSystem.Count().ToString();

                cmbStationStations.SelectedIndex = 0;

            }
            else
            {
                m_currentSystemdata.clear();

                txtSystemId.Text = Program.NULLSTRING;
                txtSystemName.Text = Program.NULLSTRING;
                txtSystemX.Text = Program.NULLSTRING;
                txtSystemY.Text = Program.NULLSTRING;
                txtSystemZ.Text = Program.NULLSTRING;
                txtSystemFaction.Text = Program.NULLSTRING;
                txtSystemPopulation.Text = Program.NULLSTRING;
                txtSystemUpdatedAt.Text = Program.NULLSTRING;
                cbSystemNeedsPermit.CheckState = CheckState.Unchecked;
                cmbSystemPrimaryEconomy.Text = Program.NULLSTRING;
                cmbSystemSecurity.Text = Program.NULLSTRING;
                cmbSystemState.Text = Program.NULLSTRING;
                cmbSystemAllegiance.Text = Program.NULLSTRING;
                cmbSystemGovernment.Text = Program.NULLSTRING;

                setSystemEditable(false);

                cmdSystemNew.Enabled        = true;
                cmdSystemEdit.Enabled       = false;
                cmdSystemSave.Enabled       = false;
                cmdSystemCancel.Enabled     = cmdSystemSave.Enabled;

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

                cmbSystemsAllSystems.ReadOnly = false;

                txtSystemName.ReadOnly = true;
                lblSystemRenameHint.Visible = false;

                lblStationCount.Text = "-";
            }

            m_SystemLoadingValues = false;

        }
예제 #19
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;
                }
        }
예제 #20
0
        /// <summary>
        /// copy the values from another system exept for the ID
        /// </summary>
        /// <param name="ValueStation"></param>
        public void getValues(EDSystem ownSystem, bool getAll=false)
        {
            if(getAll)
                Id = ownSystem.Id;

            Name            = ownSystem.Name;
            X               = ownSystem.X;
            Y               = ownSystem.Y;
            Z               = ownSystem.Z;
            Faction         = ownSystem.Faction;
            Population      = ownSystem.Population;
            Government      = ownSystem.Government;
            Allegiance      = ownSystem.Allegiance;
            State           = ownSystem.State;
            Security        = ownSystem.Security;
            PrimaryEconomy  = ownSystem.PrimaryEconomy;
            NeedsPermit     = ownSystem.NeedsPermit;
            UpdatedAt       = ownSystem.UpdatedAt;
        }
예제 #21
0
        /// <summary>
        /// changes or adds a system 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 ChangeAddSystem(EDSystem m_currentSystemdata, string oldSystemName=null)
        {
            EDSystem System;
            List<EDSystem> ownSystems = getSystems(enDataType.Data_Own);
            int newSystemIndex;

            if(String.IsNullOrEmpty(oldSystemName.Trim()))
                oldSystemName = m_currentSystemdata.Name;

            if(!oldSystemName.Equals(m_currentSystemdata.Name))
            {
                // changing system name
                var existing = getSystems(EDMilkyway.enDataType.Data_EDDB).Find(x => x.Name.Equals(oldSystemName, StringComparison.InvariantCultureIgnoreCase));
                if (existing != null)
                    throw new Exception("It's not allowed to rename a EDDB system");
            }

            // 1st put the new values into our local list
            System = ownSystems.Find(x => x.Name.Equals(oldSystemName, StringComparison.CurrentCultureIgnoreCase));
            if(System != null)
            { 
                // copy new values into existing system
                System.getValues(m_currentSystemdata);
            }
            else
            { 
                // add as a new system to own data
                newSystemIndex = 0;

                if(ownSystems.Count > 0)
                    newSystemIndex = ownSystems.Max(X => X.Id) + 1;
                    
                ownSystems.Add(new EDSystem(newSystemIndex, m_currentSystemdata));
                
            }

            // 2nd put the new values into our merged list
            List<EDSystem> mergedSystems = getSystems(enDataType.Data_Merged);

            System = mergedSystems.Find(x => x.Name.Equals(oldSystemName, StringComparison.CurrentCultureIgnoreCase));
            if(System != null)
            { 
                // copy new values into existing system
                System.getValues(m_currentSystemdata);
            }
            else
            { 
                // add as a new system to own data
                newSystemIndex = 0;

                if(mergedSystems.Count > 0)
                    newSystemIndex = mergedSystems.Max(X => X.Id) + 1;
                mergedSystems.Add(new EDSystem(newSystemIndex, m_currentSystemdata));
            }

            if(m_cachedLocations.ContainsKey(oldSystemName))
                m_cachedLocations.Remove(oldSystemName);

            saveStationData(@"./Data/stations_own.json", EDMilkyway.enDataType.Data_Own, true);
            saveSystemData(@"./Data/systems_own.json", EDMilkyway.enDataType.Data_Own, true);
        }
예제 #22
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);        
        }
예제 #23
0
        /// <summary>
        /// merging EDDB and own data to one big list
        /// </summary>
        public bool mergeData()
        {
            int  StartingCount;
            bool SystemCanBeDeleted = false;

            //if (false)
            //{
            //    // create some data for testing
            //    if (File.Exists(@".\Data\systems_own.json"))
            //        File.Delete(@".\Data\systems_own.json");
            //    if (File.Exists(@".\Data\stations_own.json"))
            //        File.Delete(@".\Data\stations_own.json");
            //    m_Systems[(int)enMessageInfo.Data_Merged] = new List<EDSystem>(m_Systems[(int)enMessageInfo.Data_EDDB].Where(x => x.Id <= 10));
            //    m_Stations[(int)enMessageInfo.Data_Merged] = new List<EDStation>(m_Stations[(int)enMessageInfo.Data_EDDB].Where(x => x.SystemId <= 10));
            //    saveSystemData(@".\Data\systems_own.json", enMessageInfo.Data_Merged, false);
            //    saveStationData(@".\Data\stations_own.json", enMessageInfo.Data_Merged, false);
            //}


            // get the base list from EDDB assuming it's the bigger one
            m_Systems[(int)enDataType.Data_Merged]  = cloneSystems(enDataType.Data_EDDB);
            m_Stations[(int)enDataType.Data_Merged] = cloneStations(enDataType.Data_EDDB);

            StartingCount = m_Systems[(int)enDataType.Data_Own].Count;

            for (int i = 0; i < StartingCount; i++)
            {
                SystemCanBeDeleted = true;


                EDSystem ownSystem          = m_Systems[(int)enDataType.Data_Own][StartingCount - i - 1];
                EDSystem existingEDDNSystem = getSystem(ownSystem.Name);

                //if (existingEDDNSystem != null)
                //    Debug.Print("Id=" + existingEDDNSystem.Id);
                //else
                //    Debug.Print("Id=null");

                if (existingEDDNSystem != null)
                {
                    if (existingEDDNSystem.EqualsED(ownSystem))
                    {
                        // systems are equal, check the stations
                        checkStations(ownSystem, existingEDDNSystem, ref SystemCanBeDeleted, ref m_changedStations);
                    }
                    else
                    {
                        // system is existing, but there are differences -> own version has a higher priority
                        SystemCanBeDeleted = false;
                        existingEDDNSystem.getValues(ownSystem);

                        // now check the stations
                        checkStations(ownSystem, existingEDDNSystem, ref SystemCanBeDeleted, ref m_changedStations);
                    }
                }
                else
                {
                    // system is unknown in the EDDB, copy our own system into the merged list
                    SystemCanBeDeleted = false;
                    int newSystemIndex = m_Systems[(int)enDataType.Data_Merged].Max(X => X.Id) + 1;

                    // create system cloneSystems
                    EDSystem newSystem = new EDSystem(newSystemIndex, ownSystem);

                    // add it to merged data
                    m_Systems[(int)enDataType.Data_Merged].Add(newSystem);

                    // now go and get the stations
                    copyStationsForNewSystem(newSystem);
                }

                if (SystemCanBeDeleted)
                {
                    //

                    // delete the system;
                    m_Systems[(int)enDataType.Data_Own].Remove(ownSystem);
                    m_changedSystems = true;
                }
            }

            return(changedStations || changedSystems);
        }