Ejemplo n.º 1
0
        public static void Run()
        {
            if (_customConfigSet)
            {
                return;
            }
            _customConfigSet = true;

            _customUserIni = Load.ReadFileFromWorldStorage(ConfigConstants.ConfigFileName, typeof(UserSettings));
            if (string.IsNullOrEmpty(_customUserIni))
            {
                StaticLog.WriteToLog("GetCustomUserIni", "No custom settings found. Exporting vanilla settings.", LogType.General);
                ExportDefaultUserSettings.Run();
                return;
            }
            if (!MyIni.TryParse(_customUserIni))
            {
                StaticLog.WriteToLog("GetCustomUserIni", "Parse failed for custom user settings. Exporting vanilla settings.", LogType.General);
                ExportDefaultUserSettings.Run();
                return;
            }
            if (!MyIni.ContainsSection(ConfigConstants.SectionName))
            {
                StaticLog.WriteToLog("GetCustomUserIni", "User config did not contain the proper section. Exporting vanilla settings.", LogType.General);
                ExportDefaultUserSettings.Run();
                return;
            }
            ParseConfig();
        }
Ejemplo n.º 2
0
        public ISubscription Subscribe(string topic, Action <string> messageReceivedAction, MessageBusType messageBusType = MessageBusType.Queue)
        {
            var provider           = GetProvider(messageBusType);
            var messageBusTypeText = messageBusType == MessageBusType.Queue ? "Queue" : "Pub/Sub";

            StaticLog.Information($"MessageBus - Subscriber provider created: {messageBusTypeText} - {provider.GetType().Name}");
            return(provider.Subscribe(topic, messageReceivedAction));
        }
Ejemplo n.º 3
0
        public IPublisher GetPublisher(string topic, MessageBusType messageBusType = MessageBusType.Queue)
        {
            var provider           = GetProvider(messageBusType);
            var messageBusTypeText = messageBusType == MessageBusType.Queue ? "Queue" : "Pub/Sub";

            StaticLog.Information($"MessageBus - Publisher provider created: {messageBusTypeText} - {provider.GetType().Name}");
            return(provider.GetPublisher(topic));
        }
Ejemplo n.º 4
0
        public static void Log(object key, string message, LogMode mode, StaticLog type)
        {
            int logMode = 5;

            if (mode <= (LogMode)logMode)
            {
                string message2 = string.Format("{0} - {1}", key, message);
                string message3 = EngineLogger.AppendTraces(message2);
                ILog   log      = EngineLogger.loggers[type];
                log.Info(message3);
            }
        }
		public static void Log(object key, string message, LogMode mode, StaticLog type)
		{
			int logMode = 5;
			if (mode <= (LogMode)logMode)
			{
				string message2 = string.Format("{0} - {1}", key, message);
				string message3 = EngineLogger.AppendTraces(message2);
				ILog log = EngineLogger.loggers[type];				
				log.Info(message3);
				
			}
		}
 private void DebugLog(string caller, string message)
 {
     StaticLog.WriteToLog($"{EntityName} ({EntityId}): {caller}", message, LogType.Debug);
 }
Ejemplo n.º 7
0
        public IObservable <T> GetObservableTopic <T>(string topic, QueueHandler handler = null) where T : class
        {
            return(Observable.Create <T>(observer => {
                var tokenSource = handler != null ? handler.TokenSource : new CancellationTokenSource();
                var stoppingToken = tokenSource.Token;

                ThreadPool.QueueUserWorkItem(s => {
                    var token = (CancellationToken)s;

                    var consumer = CreateConsumer(topic);

                    while (!token.IsCancellationRequested)
                    {
                        while (handler != null && handler.Wait)
                        {
                            handler.LastActivityTime = DateTimeOffset.Now;
                            Wait();
                        }

                        var pollingInterval = 500;
                        SafeExecute.Sync(() => pollingInterval = _options.Value.QueuePollingInterval);
                        if (pollingInterval < 500)
                        {
                            pollingInterval = 500;
                        }

                        var messageText = string.Empty;

                        try
                        {
                            messageText = PollMessage(consumer, pollingInterval).RunSync();

                            if (handler != null)
                            {
                                handler.LastActivityTime = DateTimeOffset.Now;
                            }

                            if (string.IsNullOrEmpty(messageText))
                            {
                                Wait();
                                continue;
                            }
                        }
                        catch (OperationCanceledException)
                        {
                            // do nothing
                        }
                        catch (Exception e)
                        {
                            StaticLog.Error(e, "Queue consume error: {0}");
                        }

                        try
                        {
                            var messageWrapper = _serializer.DeserializeObject <QueueMessage>(messageText);
                            var item = _serializer.DeserializeObject(messageWrapper.Data, messageWrapper.Type) as T;
                            observer.OnNext(item);
                        }
                        catch (Exception e)
                        {
                            StaticLog.Error($"Deserialise message error: {messageText} - {e.Message}");
                        }
                    }
                }, stoppingToken);

                return () => {
                    tokenSource.Cancel();
                };
            }));
        }
Ejemplo n.º 8
0
        private static void ClassifySpawnGroups()
        {
            foreach (MySpawnGroupDefinition spawnGroupDefinition in MyDefinitionManager.Static.GetSpawnGroupDefinitions())
            {
                try
                {
                    if (spawnGroupDefinition == null)
                    {
                        continue;
                    }
                    if (!spawnGroupDefinition.Public)
                    {
                        continue;
                    }
                    if (spawnGroupDefinition.Prefabs == null || spawnGroupDefinition.Prefabs.Count == 0)
                    {
                        continue;
                    }
                    PrefabType type = spawnGroupDefinition.IsEncounter ? PrefabType.Encounter :
                                      spawnGroupDefinition.IsCargoShip ? PrefabType.CargoShip :
                                      (!spawnGroupDefinition.IsEncounter && !spawnGroupDefinition.IsPirate) ? PrefabType.CargoShip :
                                      PrefabType.None;
                    if (type == PrefabType.None)
                    {
                        continue;
                    }
                    string spawnGroupName = spawnGroupDefinition.Id.SubtypeName;
                    if (string.IsNullOrEmpty(spawnGroupName))
                    {
                        spawnGroupName = "wasNullOrEmpty";
                    }
                    string mod = string.IsNullOrEmpty(spawnGroupDefinition.Context.ModName) ? "Vanilla" : spawnGroupDefinition.Context.ModName;

                    foreach (MySpawnGroupDefinition.SpawnGroupPrefab prefab in spawnGroupDefinition.Prefabs.AsReadOnly())
                    {
                        MyPrefabDefinition prefabDef = MyDefinitionManager.Static.GetPrefabDefinition(prefab.SubtypeId);
                        if (prefabDef == null)
                        {
                            continue;
                        }
                        if (prefabDef.CubeGrids.Length == 0)
                        {
                            continue;
                        }
                        if (!prefabDef.Public)
                        {
                            continue;
                        }
                        string           name = prefabDef.CubeGrids[0].DisplayName;
                        SpawnGroupPrefab sgp  = new SpawnGroupPrefab(spawnGroupName, name, type, false, false, mod);
                        switch (type)
                        {
                        case PrefabType.Encounter:
                            if (EncounterPrefabs.ContainsKey(name))
                            {
                                continue;
                            }
                            EncounterPrefabs.Add(name, sgp);
                            continue;

                        case PrefabType.CargoShip:
                            if (CargoShipPrefabs.ContainsKey(name))
                            {
                                continue;
                            }
                            CargoShipPrefabs.Add(name, sgp);
                            continue;

                        case PrefabType.None:
                            continue;

                        case PrefabType.SubGrid:
                            continue;

                        default:
                            continue;
                        }
                    }
                }
                catch (Exception e)
                {
                    StaticLog.WriteToLog("ClassifySpawnGroups", e.ToString(), LogType.Exception);
                }
            }

            foreach (KeyValuePair <string, SpawnGroupPrefab> prefab in EncounterPrefabs)
            {
                StaticLog.WriteToLog("ClassifySpawnGroups-Encounter", $"{prefab.Value}", LogType.General);
            }

            foreach (KeyValuePair <string, SpawnGroupPrefab> prefab in CargoShipPrefabs)
            {
                StaticLog.WriteToLog("ClassifySpawnGroups-CargoShip", $"{prefab.Value}", LogType.General);
            }

            Ready = true;
        }
Ejemplo n.º 9
0
 static GhprEventListener()
 {
     Reporter = new Reporter(TestingFramework.NUnit);
     StaticLog.Initialize(Reporter.Settings.OutputPath);
 }
Ejemplo n.º 10
0
        public static void Log(Exception ex, LogMode mode, StaticLog type)
        {
            string message = string.Format("{0}\r\n{1}", ex.Message, ex.StackTrace);

            EngineLogger.Log(ex.TargetSite.Name, message, mode, type);
        }
		public static void Log(Exception ex, LogMode mode, StaticLog type)
		{
			string message = string.Format("{0}\r\n{1}", ex.Message, ex.StackTrace);
			EngineLogger.Log(ex.TargetSite.Name, message, mode, type);
		}
        public static void ScanStocks()
        {
            //Log.Error(typeof(CollectDataManager), "Test 1");
            //Log.Error(typeof(CollectDataManager),"Test tets");
            //Log.Error(typeof(CollectDataManager), "Test tets 123", new Exception("Failed to test"));
            var engine = new YahooStockEngine();

            var quoteList = new ObservableCollection <Quote>();
            var boList    = new List <CompanyList>();

            using (var db = new TheFishEntities())
            {
                boList = db.CompanyLists.Where(x => x.Sector.Equals("Health care", StringComparison.OrdinalIgnoreCase) && x.Symbol.Length < 5).ToList();
            }

            int i = 1;
            var quoteSingleCollectionChunk = new List <Quote>();

            foreach (var item in boList)
            {
                //if (i > 2)
                //    break;
                try
                {
                    var quote = new Quote(item.Symbol.Trim());
                    quoteSingleCollectionChunk.Add(quote);
                    if (i == StockFetchTrunk)
                    {
                        YahooStockEngine.Fetch(quoteSingleCollectionChunk);
                        //YahooStockDownoader.GetQuote(quoteSingleCollectionChunk);
                        foreach (var stockInfo in quoteSingleCollectionChunk)
                        {
                            quoteList.Add(stockInfo);
                        }
                        quoteSingleCollectionChunk = new List <Quote>();
                        i = 1;
                    }
                    i++;
                }catch (Exception ex)
                {
                    var message = ex.Message;
                }
                //i++;
            }

            try
            {
                if (quoteSingleCollectionChunk.Count > 0)
                {
                    YahooStockEngine.Fetch(quoteSingleCollectionChunk);
                    //YahooStockDownoader.GetQuote(quoteSingleCollectionChunk);
                    foreach (var stockInfo in quoteSingleCollectionChunk)
                    {
                        quoteList.Add(stockInfo);
                    }
                }
            }catch (Exception ex)
            {
                var message = ex.Message;
            }

            DateTime today    = DateTime.Today;                 // earliest time today
            DateTime tomorrow = DateTime.Today.AddDays(1);      // earliest time tomorrow

            using (var db = new TheFishEntities())
            {
                foreach (var item in quoteList.ToList())
                {
                    try
                    {
                        var result             = StockAnalyzer.AnalyzeStock(item);
                        var isPriceChangeFish  = result.IsPriceChangedDramatically;
                        var isVolumeChangeFish = result.IsVolumeAbnormal;
                        var isPrice52WeeksLow  = result.IsPrice52WeeksLow;
                        if (!(isPriceChangeFish || isVolumeChangeFish || isPrice52WeeksLow))
                        {
                            continue;
                        }
                        if (
                            db.CaughtFish.Where(
                                x => x.Symbol.Equals(item.Symbol) && x.WhenCreated > today && x.WhenCreated < tomorrow)
                            .Any())
                        {
                            continue;
                        }
                        var caughtFish = new CaughtFish();
                        caughtFish.Symbol                = item.Symbol;
                        caughtFish.WhenCreated           = DateTime.Now;
                        caughtFish.Price                 = item.LastTradePrice;
                        caughtFish.PriceChangePercentage = item.ChangeInPercent;
                        caughtFish.Volume                = item.Volume;
                        if (item.AverageDailyVolume > 0 && item.Volume > 0)
                        {
                            caughtFish.VolumeChangePercentage =
                                (int)(0.5M + 100M * (item.Volume - item.AverageDailyVolume) / item.AverageDailyVolume);
                        }
                        var message = "";
                        var subject = "";
                        if (isPriceChangeFish)
                        {
                            caughtFish.FishType = 0;
                            message             = string.Format(MessageText, "Price Change Alert -- ", caughtFish.Symbol,
                                                                caughtFish.Price.ToString(),
                                                                caughtFish.PriceChangePercentage.ToString(),
                                                                caughtFish.Volume.ToString(), caughtFish.VolumeChangePercentage);
                            subject = " Price Drop Alert -- " + caughtFish.Symbol;
                        }
                        else if (isVolumeChangeFish)
                        {
                            caughtFish.FishType = 1;
                            message             = string.Format(MessageText, "Volume Change Alert -- ", caughtFish.Symbol,
                                                                caughtFish.Price.ToString(),
                                                                caughtFish.PriceChangePercentage.ToString(),
                                                                caughtFish.Volume.ToString(),
                                                                caughtFish.VolumeChangePercentage.ToString());
                            subject = " Volumne Change Alert -- " + caughtFish.Symbol;
                        }
                        else if (isPrice52WeeksLow)
                        {
                            caughtFish.FishType = 1;
                            message             = string.Format(MessageText, "52 Weeks low price Alert -- ", caughtFish.Symbol,
                                                                caughtFish.Price.ToString(),
                                                                caughtFish.PriceChangePercentage.ToString(),
                                                                caughtFish.Volume.ToString(),
                                                                caughtFish.VolumeChangePercentage.ToString());
                            subject = " 52 Weeks Low Alert -- " + caughtFish.Symbol;
                        }
                        db.CaughtFish.Add(caughtFish);
                        db.SaveChanges();
                        Messaging.SendEmailGmail(subject, MessageDetail.GetMessageDetail(item));
                    }
                    catch (Exception ex)
                    {
                        StaticLog.Error(ex);
                    }
                }
            }
        }