Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var client = new DEXWebServiceSoapClient();

            if (client.ClientCredentials != null)
            {
                client.ClientCredentials.UserName.UserName = "******";
                client.ClientCredentials.UserName.Password = "******";
            }

            var solarData = client.retreiveData("SOLAR_OPERATIONS_5mAVG", DateTime.Now.AddHours(-5).ToString("yyyy-MM-dd hh:00"));

            //var solarData = client.retreiveData("SOLAR_OPERATIONS_5mAVG", "2014-02-28 22:00");

            var db = new OntarioSolarScadaDataDataContext();
            var maxTime = (from r in db.OntarioSolarScadaDatas
                           select r.BeginDateTime).Max() ?? DateTime.Parse("1960-01-31");

            var solarDataList =
                (
                    from DataRow aPiDataRow in solarData.Rows
                    where ValidatePiDataRow(aPiDataRow)
                          && DateTime.Parse(aPiDataRow["begin_datetime"].ToString()) > maxTime
                    select new OntarioSolarScadaData
                    {
                        OntarioSolarScadaDataId = Guid.NewGuid(),
                        Name = aPiDataRow["name"].ToString(),
                        BeginDateTime = DateTime.Parse(aPiDataRow["begin_datetime"].ToString()),
                        DataQualityValue = aPiDataRow["percent_good"].ToString(),
                        //ScadaValue = Decimal.Parse(aPiDataRow["value"].ToString()),
                        ScadaValue =
                            Decimal.Parse(aPiDataRow["value"].ToString(), System.Globalization.NumberStyles.Float),
                        EngineeringUnits = aPiDataRow["engineering_units"].ToString(),
                        CreatedBy = "TCPL\\jon_gaudette",
                        Interval = aPiDataRow["interval"].ToString(),
                        AggregationValue = aPiDataRow["aggregation"].ToString(),
                        CreatedDateTime = DateTime.Now
                    }).ToList();

            if (solarDataList.Any())
            {
                Console.WriteLine("Inserting " + solarDataList.Count + " rows");

                db.OntarioSolarScadaDatas.InsertAllOnSubmit(solarDataList);
                db.SubmitChanges();
            }

            Console.WriteLine("Done ... press any key to exit");
            //Console.ReadLine();
        }
        public static void Process()
        {
            var client = new DEXWebServiceSoapClient();

            if (client.ClientCredentials != null)
            {
                client.ClientCredentials.UserName.UserName = "******";
                client.ClientCredentials.UserName.Password = "******";
            }

            var plantData = client.retreiveData("HHSPP_DASHBOARD_snap", null);

            var plantDataList = (from DataRow aPiDataRow in plantData.Rows
                where ValidatePiDataRow(aPiDataRow)
                select new PlantStatus
                {
                    PlantStatusId = Guid.NewGuid(),
                    GeneratorId = Guid.Parse("1C6CBB34-B972-4F66-926B-A8D25B1DFD49"),
                    Name = aPiDataRow["name"].ToString(),
                    BeginDateTime = DateTime.Parse(aPiDataRow["begin_datetime"].ToString()),
                    DataQualityValue = aPiDataRow["data_quality"].ToString(),
                    EngineeringUnits = aPiDataRow["engineering_units"].ToString(),
                    CreatedBy = "TCPL\\jon_gaudette",
                    Interval = aPiDataRow["interval"].ToString(),
                    AggregationValue = aPiDataRow["aggregation"].ToString(),
                    CreatedDateTime = DateTime.Now,
                    ScadaValue = aPiDataRow["value"].ToString()
                }).ToList();

            if (plantDataList.Any())
            {
                Console.WriteLine("Inserting {0} rows", plantDataList.Count);

                var db = new TBSPEntities1();
                db.PlantStatuses.AddRange(plantDataList);
                db.SaveChanges();

            }
        }