コード例 #1
0
ファイル: OFFCOMHelper.cs プロジェクト: DougHulme/webapi
        public static bool writeoffcomtable()
        {
            OrionAdminEntities db             = new OrionAdminEntities();
            string             responseString = HTTPHelper.httpGetforunms("devices");
            List <UNMSDevice>  devices        = JsonConvert.DeserializeObject <List <UNMSDevice> >(responseString);

            foreach (UNMSDevice dev in devices)
            {
                OFFCOM offcom = new OFFCOM();
                if ((dev.identification.site != null) && (dev.identification.site.id != null))
                {
                    responseString = HTTPHelper.httpGetforunms("sites/" + dev.identification.site.id);
                    UNMSSite site = JsonConvert.DeserializeObject <UNMSSite>(responseString);
                    offcom.address   = site.description.address;
                    offcom.surname   = dev.identification.name;
                    offcom.firstname = dev.identification.mac;
                    if ((site.description.location != null) && (site.description.location.latitude != 0))
                    {
                        offcom.easting  = site.description.location.latitude.ToString();
                        offcom.northing = site.description.location.longitude.ToString();
                        if ((offcom.easting.Substring(0, 1) + offcom.northing.Substring(1, 1)) == "50")
                        {
                            offcom.C2lettergridsquare = "TV";
                        }
                        if ((offcom.easting.Substring(0, 1) + offcom.northing.Substring(1, 1)) == "51")
                        {
                            offcom.C2lettergridsquare = "TQ";
                        }
                        if ((offcom.easting.Substring(0, 1) + offcom.northing.Substring(1, 1)) == "52")
                        {
                            offcom.C2lettergridsquare = "TL";
                        }
                        if ((offcom.easting.Substring(0, 1) + offcom.northing.Substring(1, 1)) == "53")
                        {
                            offcom.C2lettergridsquare = "TF";
                        }

                        string east  = Math.Round(Convert.ToDouble(offcom.easting) / 100, 4).ToString();
                        string north = Math.Round(Convert.ToDouble(offcom.northing) / 10, 4).ToString();
                        offcom.C3lettereasting  = offcom.easting.Substring(3, 3);
                        offcom.C3letternorthing = offcom.northing.Substring(3, 3);
                    }
                    offcom.terminaltype = dev.identification.role;
                    db.OFFCOMs.Add(offcom);
                    db.SaveChanges();
                }
            }

            return(true);
        }
コード例 #2
0
        public static bool UpdateRadius()
        {
            radiusEntities     redb = new radiusEntities();
            OrionAdminEntities oadb = new OrionAdminEntities();
            var aa = (from z in redb.radaccts
                      where z.acctstarttime.Value.Year == 2020 && z.acctstarttime.Value.Month < 4
                      orderby z.acctstarttime
                      select z);

            foreach (radacct ra in aa)
            {
                if (ra.acctstoptime != null)
                {
                    if (ra.acctstarttime.Value.Day == ra.acctstoptime.Value.Day)
                    {
                        radiusUsage ru = new radiusUsage();
                        ru.date     = ra.acctstarttime;
                        ru.upload   = ra.acctinputoctets / 8;
                        ru.download = ra.acctoutputoctets / 8;
                        ru.username = ra.username;
                        oadb.radiusUsages.Add(ru);
                        oadb.SaveChanges();
                    }
                    else
                    {
                        long totaldays = Convert.ToInt64((ra.acctstoptime - ra.acctstarttime).Value.TotalDays + 1);
                        for (int i = 0; i < totaldays; i++)
                        {
                            radiusUsage ru = new radiusUsage();
                            ru.date     = ra.acctstarttime.Value.AddDays(i);
                            ru.upload   = (ra.acctinputoctets / 8) / totaldays;
                            ru.download = (ra.acctoutputoctets / 8) / totaldays;
                            ru.username = ra.username;
                            oadb.radiusUsages.Add(ru);
                            oadb.SaveChanges();
                        }
                    }
                }
            }


            return(true);
        }
コード例 #3
0
        public static bool editsnmpresults()
        {
            OrionAdminEntities db = new OrionAdminEntities();

            List <snmpResult> rslist = (from x in db.snmpResults where x.Date >= new DateTime(2020, 1, 1) orderby x.Server, x.Date, x.Name select x).ToList();

            long?  raduploadbytes   = 0;
            long?  raddownloadbytes = 0;
            string pppName          = "";


            foreach (snmpResult rs in rslist)
            {
                if ((rs.Name != pppName) && (pppName != ""))
                {
                    db.SaveChanges();
                }
                ;

                if ((raddownloadbytes != 0) && (rs.outbytes > raddownloadbytes))
                {
                    snmpResultsEdited snmpe = new snmpResultsEdited();
                    snmpe.Server   = rs.Server;
                    snmpe.Name     = rs.Name;
                    snmpe.DateFrom = rs.Date;
                    snmpe.download = (rs.outbytes - raddownloadbytes) / 30000000;
                    snmpe.upload   = (rs.inbytes - raduploadbytes) / 30000000;
                    db.snmpResultsEditeds.Add(snmpe);
                    db.SaveChanges();
                }

                raduploadbytes   = rs.inbytes;
                raddownloadbytes = rs.outbytes;
            }
            db.SaveChanges();
            return(true);
        }
コード例 #4
0
ファイル: HTTPHelper.cs プロジェクト: DougHulme/webapi
    public static bool httpPost(string entity, object entityObj)
    {
        var client = gethttpclient();

        var postdataJson    = JsonConvert.SerializeObject(entityObj);
        var postdataString  = new StringContent(postdataJson, new UTF8Encoding(), "application/json");
        var responseMessage = client.PostAsync(entity, postdataString).Result;
        var responseString  = responseMessage.Content.ReadAsStringAsync().Result;

        if (responseMessage.IsSuccessStatusCode)
        {
            return(true);
        }
        else
        {
            OrionAdminEntities db   = new OrionAdminEntities();
            WebHookLog         dbwl = new WebHookLog();
            dbwl.body = "err " + responseString;
            dbwl.Date = DateTime.Now;
            db.WebHookLogs.Add(dbwl);
            db.SaveChanges();
            return(false);
        };
    }