/* Rules */
        protected virtual MeasuredParameters CheckMeasure(AlertMeasure measure, float value, MeasureDiff diff)
        {
            AlertMeasures measures = null;

            if (!ParentWorkflow.InternalParameters.Contains("AlertMeasures"))
            {
                measures = new AlertMeasures();
                ParentWorkflow.InternalParameters.Add("AlertMeasures", measures);
            }
            else
            {
                measures = (AlertMeasures)ParentWorkflow.InternalParameters["AlertMeasures"];
            }

            MeasuredParameters ret = new MeasuredParameters();

            for (int i = 0; i < _results.Count; i++)
            {
                try
                {
                    MeasuredParameter mp = (MeasuredParameter)_results[i];
                    if (measure.CompositeMeasure)
                    {
                        if (measure.Evaluate(mp, value, diff, measures))
                        {
                            ret.Add(mp.GK, mp);
                        }
                    }
                    else
                    {
                        if (Evaluate(mp.ValueFromMeasure(measure.AlertMeasureName),
                                     value,
                                     diff))
                        {
                            ret.Add(mp.GK, mp);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Write("Exception occured while adding measured parameters", ex);
                    continue;;
                }
            }

            return(ret);
        }
        protected virtual void WriteResult(MeasuredParameter mp, AlertMeasure am)
        {
            DataManager.ConnectionString = AppSettings.GetAbsolute("Easynet.Edge.Core.Workflow.AlertConnectionString");

            //Create the command.
            using (DataManager.Current.OpenConnection())
            {
                AlertMeasures measures = (AlertMeasures)ParentWorkflow.InternalParameters["AlertMeasures"];

                string sql     = "INSERT INTO AlertResults ";
                string columns = "(wf_id,wf_date,wf_parameters,wf_conditionValues,entity_type,Account_id,Channel_id,Account_name,Current_Day,Compare_Day,measure_id,measure_current_value,measure_compare_value,measure_change_ratio";

                columns += GetColumns(mp);
                sql     += columns + " VALUES(";

                int wfID = ParentWorkflow.WorkflowID;
                if (wfID <= 0)
                {
                    if (ParentWorkflow.Parameters.ContainsKey("WorkflowID"))
                    {
                        wfID = Convert.ToInt32(ParentWorkflow.Parameters["WorkflowID"]);
                    }
                }

                string values = String.Empty;
                values  = wfID.ToString() + ",'" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "','" + ParentWorkflow.GetParametersAsString() + "','" + ParentWorkflow.GetConditionValuesAsString() + "'," + Convert.ToInt32(_entityType).ToString() + ",";
                values += mp.AccountID.ToString() + "," + mp.ChannelID.ToString() + ",'" + mp.AccountName + "'," + DayCode.ToDayCode(mp.CurrentDay).ToString() + "," + DayCode.ToDayCode(mp.CompareDate).ToString() + ",";
                values += mp.GetMeasureParameterSQL(am, measures) + ")";

                sql += values;
                SqlCommand alertResults = DataManager.CreateCommand(sql);
                try
                {
                    alertResults.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Log.Write("Failed to write alert result to database.", ex);
                    throw ex;
                }
            }
        }
Beispiel #3
0
        // GET: MeasuredParameters/Delete/5
        public async Task <IActionResult> Delete(int?id,
                                                 string SortOrder,
                                                 string NameKKFilter,
                                                 string NameRUFilter,
                                                 string NameENFilter,
                                                 int?EcomonCodeFilter,
                                                 string OceanusCodeFilter,
                                                 string KazhydrometCodeFilter,
                                                 int?PageSize,
                                                 int?PageNumber)
        {
            ViewBag.SortOrder             = SortOrder;
            ViewBag.PageSize              = PageSize;
            ViewBag.PageNumber            = PageNumber;
            ViewBag.NameKKFilter          = NameKKFilter;
            ViewBag.NameRUFilter          = NameRUFilter;
            ViewBag.NameENFilter          = NameENFilter;
            ViewBag.EcomonCodeFilter      = EcomonCodeFilter;
            ViewBag.OceanusCodeFilter     = OceanusCodeFilter;
            ViewBag.KazhydrometCodeFilter = KazhydrometCodeFilter;
            if (id == null)
            {
                return(NotFound());
            }

            MeasuredParameter   measuredParameter = null;
            HttpResponseMessage response          = await _HttpApiClient.GetAsync($"api/MeasuredParameters/{id.ToString()}");

            if (response.IsSuccessStatusCode)
            {
                measuredParameter = await response.Content.ReadAsAsync <MeasuredParameter>();
            }
            if (measuredParameter == null)
            {
                return(NotFound());
            }

            return(View(measuredParameter));
        }
Beispiel #4
0
        // GET: MeasuredParameters/Edit/5
        public async Task <IActionResult> Edit(int?id,
                                               string SortOrder,
                                               string NameKKFilter,
                                               string NameRUFilter,
                                               string NameENFilter,
                                               int?EcomonCodeFilter,
                                               string OceanusCodeFilter,
                                               string KazhydrometCodeFilter,
                                               int?PageSize,
                                               int?PageNumber)
        {
            ViewBag.SortOrder             = SortOrder;
            ViewBag.PageSize              = PageSize;
            ViewBag.PageNumber            = PageNumber;
            ViewBag.NameKKFilter          = NameKKFilter;
            ViewBag.NameRUFilter          = NameRUFilter;
            ViewBag.NameENFilter          = NameENFilter;
            ViewBag.EcomonCodeFilter      = EcomonCodeFilter;
            ViewBag.OceanusCodeFilter     = OceanusCodeFilter;
            ViewBag.KazhydrometCodeFilter = KazhydrometCodeFilter;
            MeasuredParameter   measuredParameter = null;
            HttpResponseMessage response          = await _HttpApiClient.GetAsync($"api/MeasuredParameters/{id.ToString()}");

            if (response.IsSuccessStatusCode)
            {
                measuredParameter = await response.Content.ReadAsAsync <MeasuredParameter>();
            }
            List <MeasuredParameterUnit> measuredParameterUnits = new List <MeasuredParameterUnit>();
            string urlMeasuredParameterUnits   = "api/MeasuredParameterUnits",
                   routeMeasuredParameterUnits = "";
            HttpResponseMessage responseMeasuredParameterUnits = await _HttpApiClient.GetAsync(urlMeasuredParameterUnits + routeMeasuredParameterUnits);

            if (responseMeasuredParameterUnits.IsSuccessStatusCode)
            {
                measuredParameterUnits = await responseMeasuredParameterUnits.Content.ReadAsAsync <List <MeasuredParameterUnit> >();
            }
            ViewBag.MeasuredParameterUnits = new SelectList(measuredParameterUnits.OrderBy(m => m.Name), "Id", "Name", measuredParameter.MeasuredParameterUnitId);
            return(View(measuredParameter));
        }
        private string GetColumns(MeasuredParameter mp)
        {
            if (mp == null)
            {
                throw new ArgumentNullException("Invalid measure parameter. Cannot be null.");
            }

            string ret = String.Empty;

            if (mp.GetType() == typeof(CampaignAllMeasures))
            {
                ret = ",Campaign_gk,Campaign_name)";
            }
            else if (mp.GetType() == typeof(AdgroupAllMeasures))
            {
                ret = ",Campaign_gk,Campaign_name,Adgroup_gk,Adgroup_name)";
            }
            else if (mp.GetType() == typeof(AdtextAllMeasures))
            {
                ret = ",Campaign_gk,Campaign_name,Adgroup_gk,Adgroup_name,Adtext_gk,Adtext_name,Adtext_Description)";
            }
            else if (mp.GetType() == typeof(KeywordAllMeasures))
            {
                ret = ",Campaign_gk,Campaign_name,Adgroup_gk,Adgroup_name,Keyword_gk,Keyword_name)";
            }
            else if (mp.GetType() == typeof(GatewayAllMeasures))
            {
                ret = ",Campaign_gk,Campaign_name,Adgroup_gk,Adgroup_name,Gateway_gk,Gateway_name,Gateway_id)";
            }
            else
            {
                ret = ")";
            }

            return(ret);
        }
Beispiel #6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,MeasuredParameterUnitId,NameKK,NameRU,NameEN,NameShortKK,NameShortRU,NameShortEN,MPCDailyAverage,MPCMaxSingle,EcomonCode,OceanusCode,KazhydrometCode")] MeasuredParameter measuredParameter,
                                               string SortOrder,
                                               string NameKKFilter,
                                               string NameRUFilter,
                                               string NameENFilter,
                                               int?EcomonCodeFilter,
                                               string OceanusCodeFilter,
                                               string KazhydrometCodeFilter,
                                               int?PageSize,
                                               int?PageNumber)
        {
            ViewBag.SortOrder             = SortOrder;
            ViewBag.PageSize              = PageSize;
            ViewBag.PageNumber            = PageNumber;
            ViewBag.NameKKFilter          = NameKKFilter;
            ViewBag.NameRUFilter          = NameRUFilter;
            ViewBag.NameENFilter          = NameENFilter;
            ViewBag.EcomonCodeFilter      = EcomonCodeFilter;
            ViewBag.OceanusCodeFilter     = OceanusCodeFilter;
            ViewBag.KazhydrometCodeFilter = KazhydrometCodeFilter;
            if (id != measuredParameter.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                HttpResponseMessage response = await _HttpApiClient.PutAsJsonAsync(
                    $"api/MeasuredParameters/{measuredParameter.Id}", measuredParameter);

                string OutputViewText = await response.Content.ReadAsStringAsync();

                OutputViewText = OutputViewText.Replace("<br>", Environment.NewLine);
                try
                {
                    response.EnsureSuccessStatusCode();
                }
                catch
                {
                    dynamic errors = JsonConvert.DeserializeObject <dynamic>(OutputViewText);
                    foreach (Newtonsoft.Json.Linq.JProperty property in errors.Children())
                    {
                        ModelState.AddModelError(property.Name, property.Value[0].ToString());
                    }
                    return(View(measuredParameter));
                }

                measuredParameter = await response.Content.ReadAsAsync <MeasuredParameter>();

                return(RedirectToAction(nameof(Index),
                                        new
                {
                    SortOrder = ViewBag.SortOrder,
                    PageSize = ViewBag.PageSize,
                    PageNumber = ViewBag.PageNumber,
                    NameKKFilter = ViewBag.NameKKFilter,
                    NameRUFilter = ViewBag.NameRUFilter,
                    NameENFilter = ViewBag.NameENFilter,
                    EcomonCodeFilter = ViewBag.EcomonCodeFilter,
                    OceanusCodeFilter = ViewBag.OceanusCodeFilter,
                    KazhydrometCodeFilter = ViewBag.KazhydrometCodeFilter
                }));
            }
            List <MeasuredParameterUnit> measuredParameterUnits = new List <MeasuredParameterUnit>();
            string urlMeasuredParameterUnits   = "api/MeasuredParameterUnits",
                   routeMeasuredParameterUnits = "";
            HttpResponseMessage responseMeasuredParameterUnits = await _HttpApiClient.GetAsync(urlMeasuredParameterUnits + routeMeasuredParameterUnits);

            if (responseMeasuredParameterUnits.IsSuccessStatusCode)
            {
                measuredParameterUnits = await responseMeasuredParameterUnits.Content.ReadAsAsync <List <MeasuredParameterUnit> >();
            }
            ViewBag.MeasuredParameterUnits = new SelectList(measuredParameterUnits.OrderBy(m => m.Name), "Id", "Name", measuredParameter.MeasuredParameterUnitId);
            return(View(measuredParameter));
        }
        protected void AllocateReport(MeasuredParameters mps, string measure, MeasureDiff diff)
        {
            if (ParentWorkflow.InternalParameters.ContainsKey("Reports"))
            {
                Hashtable currentReports = (Hashtable)ParentWorkflow.InternalParameters["Reports"];
                if (currentReports.ContainsKey(_entityType))
                {
                    Reports entReports = (Reports)currentReports[_entityType];
                    if (entReports.ContainsDifference(diff))
                    {
                        //We have a report which contains this type of difference.
                        Report curReport = (Report)entReports[diff];
                        curReport.MeasuredParameters.Append(mps);
                        curReport.Processed      = false;
                        curReport.DifferenceType = diff;

                        if (!curReport.Measures.Contains(MeasuredParameter.FromString(measure)))
                        {
                            curReport.Measures.Add(MeasuredParameter.FromString(measure));
                        }

                        entReports[diff] = curReport;
                    }
                    else
                    {
                        //We do not have a report which contains this type of difference.
                        Report r = new Report();
                        r.MeasuredParameters.Append(mps);
                        r.Processed      = false;
                        r.Name           = this.Name;
                        r.DifferenceType = diff;
                        r.Measures.Add(MeasuredParameter.FromString(measure));
                        entReports.Add(diff, r);
                    }

                    currentReports[_entityType] = entReports;
                }
                else
                {
                    //We do not have a report for this entity type.
                    Report r = new Report();
                    r.MeasuredParameters.Append(mps);
                    r.Processed      = false;
                    r.Name           = this.Name;
                    r.DifferenceType = diff;
                    r.Measures.Add(MeasuredParameter.FromString(measure));

                    if (ParentWorkflow.InternalParameters.ContainsKey("AccountFilters"))
                    {
                        r.Filters = (AccountAlertFilters)ParentWorkflow.InternalParameters["AccountFilters"];
                    }

                    r.Account = Convert.ToInt32(ParentWorkflow.Parameters["AccountID"]);

                    Reports ht = new Reports();
                    ht.Add(diff, r);

                    currentReports.Add(_entityType, ht);
                    ParentWorkflow.InternalParameters["Reports"] = currentReports;
                }
            }
            else
            {
                Report r = new Report();
                r.MeasuredParameters.Append(mps);
                r.Processed      = false;
                r.Name           = this.Name;
                r.DifferenceType = diff;
                r.Measures.Add(MeasuredParameter.FromString(measure));

                if (ParentWorkflow.InternalParameters.ContainsKey("AccountFilters"))
                {
                    r.Filters = (AccountAlertFilters)ParentWorkflow.InternalParameters["AccountFilters"];
                }

                r.Account = Convert.ToInt32(ParentWorkflow.Parameters["AccountID"]);

                Reports ht = new Reports();
                ht.Add(diff, r);

                Hashtable reports = new Hashtable();
                reports.Add(_entityType, ht);
                ParentWorkflow.InternalParameters.Add("Reports", reports);
            }
        }