コード例 #1
0
        public void addTo(AlertCard card)
        {
            if (childList.Count == 0)
            {
                Header.PullData(Exchange, Coin, Pair);
            }

            exchangeIF.add(card, Coin, Pair, childList);
            CardGrid.Children.Add(card);
            SetPosition();
        }
コード例 #2
0
        public void removeTo(AlertCard card)
        {
            exchangeIF.remove(card, childList);
            CardGrid.Children.Remove(card);

            if (childList.Count == 0)
            {
                Application curApp     = Application.Current;
                MainWindow  mainWindow = (MainWindow)curApp.MainWindow;

                Header.source.Cancel();
                mainWindow.listCellCoin.Children.Remove(this);
            }

            SetPosition();
        }
コード例 #3
0
        public void add(CandleWidth selectedWidth, Indicators selectedIndicator, IndicatorConditions selectedCondition, double value)
        {
            foreach (AlertCard c in CardGrid.Children)                                  //search for card with same indicator exists
            {
                if (c.Indicator == selectedIndicator && c.CandleWidth == selectedWidth) //if card with same indicator and candle width exists
                {
                    c.addCondition(selectedCondition, value);                           //just needed to add condition, else it is a new card
                    return;
                }
            }

            AlertCard card = new AlertCard(this, selectedWidth, Exchange, Coin, Pair, selectedIndicator);

            card.addCondition(selectedCondition, value);
            addTo(card);
            SetPosition();
        }
コード例 #4
0
ファイル: Binance.cs プロジェクト: SavarKeiner/Alerts
        public void remove(AlertCard card, List <AlertCard> childList)
        {
            System.Diagnostics.Debug.WriteLine("DBG_REMOVE");

            candlePulled -= card.CandlePull;

            childList.Remove(card);

            if (childList.Count == 0)
            {
                CancellationTokenSource source;
                stopAsyncToken.TryGetValue(CandleWidth.INIT, out source);
                if (source != null)
                {
                    source.Cancel();
                    source.Dispose();
                }
            }

            if (childList.Find(x => x.CandleWidth == card.CandleWidth) == null)
            {
                CancellationTokenSource source;
                stopAsyncToken.TryGetValue(card.CandleWidth, out source);
                if (source != null)
                {
                    List <CandleBinance> clist;
                    dictCandle.TryGetValue(card.CandleWidth, out clist);
                    clist?.Clear();

                    source?.Cancel();
                    source?.Dispose();
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("DBG-ERROR 2: " + card.CandleWidth);
                }
            }
            childList.Sort((x, y) => x.CandleWidth.CompareTo(y.CandleWidth));
        }
コード例 #5
0
ファイル: AlertCreated.cs プロジェクト: scantegra/scantegra
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("AlertCreated Function Triggered Via Webhook.");

            // Get the remote execution context
            string jsonContext = await req.Content.ReadAsStringAsync();

            log.Info("Read context: " + jsonContext);

            jsonContext = FormatJson(jsonContext);
            log.Info("Formatted JSON Context string: " + jsonContext);

            Microsoft.Xrm.Sdk.RemoteExecutionContext context = DeserializeJsonString <Microsoft.Xrm.Sdk.RemoteExecutionContext>(jsonContext);

            //var context = await req.Content.ReadAsAsync<RemoteExecutionContext>();

            // Ensure this function was called on the create message of the scan_alert entity
            if (context.MessageName != "Create" && context.PrimaryEntityName != "scan_alert")
            {
                var err = "AlertCreated Context Execution Is Invalid";
                log.Error(err);
                return(req.CreateResponse(HttpStatusCode.BadRequest, err));
            }

            var alert = context.PostEntityImages.FirstOrDefault().Value.ToEntity <scan_alert>();

            if (alert == null)
            {
                var err = "Invalid Alert Post Entity Image";
                log.Error(err);
                return(req.CreateResponse(HttpStatusCode.BadRequest, err));
            }

            log.Info("Obtained Valid Context");
            log.Info("Processing Alert " + alert.Id.ToString());

            string orgUrl = ConfigurationManager.AppSettings["ScantegraOrgUrl"];
            Uri    orgUri = new Uri(orgUrl);

            log.Info(orgUri.ToString());
            //var proxyClient = new OrganizationWebProxyClient(orgUri, true);
            CrmServiceClient.AuthOverrideHook = new AuthHook();
            //CrmServiceClient test = new CrmServiceClient()
            CrmServiceClient crmSvc = new CrmServiceClient(orgUri, true);

            if (crmSvc.IsReady)
            {
                log.Info("Connected To Dynamics 365");
            }
            //crmSvc.OrganizationWebProxyClient.EnableProxyTypes();

            var scantegraContext = new ScantegraServiceContext(crmSvc.OrganizationWebProxyClient);


            // Pull the alert to get the full entity
            alert = scantegraContext.scan_alertSet.Where(a => a.Id == alert.Id).FirstOrDefault();


            // Pull the alert notification group from the rule
            var alertNotificationGroup = scantegraContext.scan_alertnotificationgroupSet.Where(ang => ang.Id == alert.scan_AlertNotificationGroup.Id).FirstOrDefault();

            log.Info("ANG ID " + alertNotificationGroup.Id.ToString());

            // Pull the alert notification actions from the intersection table
            var alertNotificationActionAssociations = scantegraContext.scan_alertgroupalertnotificationassociationSet.Where(a => a.scan_AlertNotificationGroup.Id == alertNotificationGroup.Id).ToList();

            // Iterate through the alert notification actions and process accordingly
            foreach (var association in alertNotificationActionAssociations)
            {
                var alertNotificationAction = scantegraContext.scan_alertnotificationactionSet.Where(aa => aa.Id == association.scan_AlertNotificationAction.Id).FirstOrDefault();
                log.Info("Processing action " + alertNotificationAction.Id.ToString());
                switch (alertNotificationAction.scan_NotificationActionType.Value)
                {
                case (int)scan_AlertNotificationActionType.PostToMicrosoftTeams:
                    var client = new TeamsClient(alertNotificationAction.scan_TeamsWebhookUrl);
                    var card   = new AlertCard()
                    {
                        Title = alert.scan_name,
                        Text  = $"{alert.FormattedValues["scan_alertseverity"]} - {alert.scan_name}"
                    };
                    client.PostMessage(card);
                    break;
                }
            }

            return(req.CreateResponse(HttpStatusCode.OK));
        }