FromFile() public static method

Obtain credentials from a file. If the file name is not supplied the the default path of Constants.Data_DIR\edsm.json is used
public static FromFile ( string filename = null ) : StarMapConfiguration
filename string
return StarMapConfiguration
コード例 #1
0
 public void Sync(DateTime?since = null)
 {
     Logging.Info("Syncing with EDSM");
     try
     {
         Dictionary <string, StarMapLogInfo> systems  = getStarMapLog(since);
         Dictionary <string, string>         comments = getStarMapComments();
         int total = systems.Count;
         foreach (string system in systems.Keys)
         {
             StarSystem CurrentStarSystem = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(system, false);
             CurrentStarSystem.visits    = systems[system].visits;
             CurrentStarSystem.lastvisit = systems[system].lastVisit;
             if (comments.ContainsKey(system))
             {
                 CurrentStarSystem.comment = comments[system];
             }
             StarSystemSqLiteRepository.Instance.SaveStarSystem(CurrentStarSystem);
         }
         StarMapConfiguration starMapConfiguration = StarMapConfiguration.FromFile();
         starMapConfiguration.lastSync = DateTime.UtcNow;
         starMapConfiguration.ToFile();
         Logging.Info("EDSM sync completed");
     }
     catch (EDSMException edsme)
     {
         Logging.Debug("EDSM error received: " + edsme.Message);
     }
 }
コード例 #2
0
ファイル: StarMapService.cs プロジェクト: jpacelli62/EDDI
        private void SendQueuedEvents(CancellationToken cancellationToken)
        {
            var queue = new List <IDictionary <string, object> >();

            try
            {
                // The `GetConsumingEnumerable` method blocks the thread while the underlying collection is empty
                // If we haven't extracted events to send to EDSM, this will wait / pause background sync until `queuedEvents` is no longer empty.
                foreach (var pendingEvent in queuedEvents.GetConsumingEnumerable(cancellationToken))
                {
                    queue.Add(pendingEvent);
                    if (queue.Count > 0 && queuedEvents.Count == 0)
                    {
                        break;
                    }
                }
                StarMapConfiguration starMapConfiguration = StarMapConfiguration.FromFile();
                SendEventBatch(queue, starMapConfiguration);
            }
            catch (OperationCanceledException)
            {
                // Operation was cancelled. Return any events we've extracted back to the primary queue.
                foreach (var pendingEvent in queue)
                {
                    queuedEvents.Add(pendingEvent);
                }
            }
        }
コード例 #3
0
ファイル: StarMapService.cs プロジェクト: TalShaf/EDDI
        public static void saveStarSystems(List <StarSystem> syncSystems)
        {
            StarSystemSqLiteRepository.Instance.SaveStarSystems(syncSystems);
            StarMapConfiguration starMapConfiguration = StarMapConfiguration.FromFile();

            starMapConfiguration.lastSync = DateTime.UtcNow;
            starMapConfiguration.ToFile();
        }
コード例 #4
0
ファイル: StarMapService.cs プロジェクト: rekrapt/EDDI
        private void SendQueuedEvents()
        {
            StarMapConfiguration starMapConfiguration = StarMapConfiguration.FromFile();
            var queue = new List <IDictionary <string, object> >();

            // The `GetConsumingEnumerable` method blocks the thread while the underlying collection is empty
            // If we haven't extracted events to send to Inara, this will wait / pause background sync until `queuedAPIEvents` is no longer empty.
            foreach (var pendingEvent in queuedEvents.GetConsumingEnumerable())
            {
                queue.Add(pendingEvent);
                if (queue.Count > 0 && queuedEvents.Count == 0)
                {
                    break;
                }
            }
            SendEventBatch(queue, starMapConfiguration);
        }
コード例 #5
0
ファイル: StarMapService.cs プロジェクト: vadark1976/EDDI
        public void SetEdsmCredentials()
        {
            StarMapConfiguration starMapCredentials = StarMapConfiguration.FromFile();

            if (!string.IsNullOrEmpty(starMapCredentials?.apiKey))
            {
                // Commander name might come from EDSM credentials or from the game and companion app
                string cmdrName = starMapCredentials.commanderName ?? commanderFrontierApiName;
                if (!string.IsNullOrEmpty(cmdrName))
                {
                    apiKey        = starMapCredentials.apiKey?.Trim();
                    commanderName = cmdrName?.Trim();
                }
                else
                {
                    Logging.Warn("EDSM Responder not configured: Commander name not set.");
                }
            }
            else
            {
                Logging.Warn("EDSM Responder not configured: API key not set.");
            }
        }
コード例 #6
0
ファイル: StarMapService.cs プロジェクト: lagoth/EDDI
        public StarMapService()
        {
            // Set up the star map service
            StarMapConfiguration starMapCredentials = StarMapConfiguration.FromFile();

            if (starMapCredentials != null && starMapCredentials.apiKey != null)
            {
                // Commander name might come from star map credentials or the companion app's profile
                string commanderName = null;
                if (starMapCredentials.commanderName != null)
                {
                    commanderName = starMapCredentials.commanderName;
                }
                if (commanderName != null)
                {
                    instance = new StarMapService(starMapCredentials.apiKey, commanderName);
                    Logging.Info("EDDI access to EDSM is enabled");
                }
            }
            if (instance == null)
            {
                Logging.Info("EDDI access to EDSM is disabled");
            }
        }
コード例 #7
0
ファイル: StarMapService.cs プロジェクト: rodan123/EDDI
        private void SendEvents(List <IDictionary <string, object> > queue)
        {
            StarMapConfiguration starMapConfiguration = StarMapConfiguration.FromFile();

            SendEventBatch(queue, starMapConfiguration);
        }