public ActionResult Create(ViewDevice viewdevice) { try { if (viewdevice != null) { Guid userId = GetUserId(); if (ModelState.IsValid) { DeviceRepository.AddDevice(viewdevice, userId); return(RedirectToAction("GroupDevices", "Device", new { id = viewdevice.GroupID })); } FillAuxData(userId, viewdevice.GroupID, viewdevice.OwnerID != null ? (Int64)viewdevice.OwnerID : 0, viewdevice.TypeID, viewdevice.GroupID); } return(View(viewdevice)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public ViewResult Index(long id /*идентификатор физического устройства*/) { try { Guid userId = GetUserId(); ViewDevice viewdevice = _deviceRepository.GetDevice(id, userId); ViewBag.DeviceTypeID = viewdevice.TypeID; ViewBag.DeviceName = viewdevice.Name; ViewBag.DeviceGroupID = viewdevice.GroupID; ViewBag.DeviceID = id; ViewDeviceType viewdevicetype = _deviceTypeRepository.GetDeviceType(viewdevice.TypeID, userId); ViewBag.DeviceTypeName = viewdevicetype.Description.TrimEnd(); List <ViewCOSEMLogicalDevice> viewcosemlogicaldevice = _cosemLogicalDeviceRepository.GetCosemLogicalDeviceList(viewdevice.TypeID, userId); return(View(viewcosemlogicaldevice)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public long?AddDeviceWithAddress(ViewDevice d, ViewAddress a, Guid userId) { if (!_firstIpPortAssigned) { FirstIpPort = d.Port; _firstIpPortAssigned = true; } if (!_firstIpAddressAssigned) { FirstIpAddress = d.IP1 + "." + d.IP2 + "." + d.IP3 + "." + d.IP4; _firstIpAddressAssigned = true; } if (!_firstSecIpAddressAssigned && d.SecondaryIP1 != null) { FirstSecIpAddress = d.SecondaryIP1 + "." + d.SecondaryIP2 + "." + d.SecondaryIP3 + "." + d.SecondaryIP4; _firstSecIpAddressAssigned = true; } if (!_firstSecIpPortAssigned) { FirstSecIpPort = d.SecondaryPort; _firstSecIpPortAssigned = true; } LastIpPort = d.Port; LastIpAddress = d.IP1 + "." + d.IP2 + "." + d.IP3 + "." + d.IP4; if (d.SecondaryIP1 != null) { LastSecIpAddress = d.SecondaryIP1 + "." + d.SecondaryIP2 + "." + d.SecondaryIP3 + "." + d.SecondaryIP4; } LastSecIpPort = d.SecondaryPort; DeviceRowAffected++; return(DeviceRowAffected); }
public long?AddDevice(ViewDevice viewdevice, Guid userId) { DeviceRowAffected++; if (!_firstIpPortAssigned) { FirstIpPort = viewdevice.Port; _firstIpPortAssigned = true; } if (!_firstIpAddressAssigned) { FirstIpAddress = viewdevice.IP1 + "." + viewdevice.IP2 + "." + viewdevice.IP3 + "." + viewdevice.IP4; _firstIpAddressAssigned = true; } if (!_firstSecIpAddressAssigned && viewdevice.SecondaryIP1 != null) { FirstSecIpAddress = viewdevice.SecondaryIP1 + "." + viewdevice.SecondaryIP2 + "." + viewdevice.SecondaryIP3 + "." + viewdevice.SecondaryIP4; _firstSecIpAddressAssigned = true; } if (!_firstSecIpPortAssigned) { FirstSecIpPort = viewdevice.SecondaryPort; _firstSecIpPortAssigned = true; } LastIpPort = viewdevice.Port; LastIpAddress = viewdevice.IP1 + "." + viewdevice.IP2 + "." + viewdevice.IP3 + "." + viewdevice.IP4; if (viewdevice.SecondaryIP1 != null) { LastSecIpAddress = viewdevice.SecondaryIP1 + "." + viewdevice.SecondaryIP2 + "." + viewdevice.SecondaryIP3 + "." + viewdevice.SecondaryIP4; } LastSecIpPort = viewdevice.SecondaryPort; return(DeviceRowAffected); }
public ViewResult Index(long id /*logical object identifier*/, long deviceid /*physical device identifier*/, long logicaldeviceid) { try { ViewBag.DeviceID = deviceid; ViewBag.ObjectID = id; ViewBag.LogicalDeviceID = logicaldeviceid; Guid userId = GetUserId(); ViewDevice viewdevice = _deviceRepository.GetDevice(deviceid, userId); ViewBag.DeviceName = viewdevice.Name; ViewDeviceType viewdevicetype = _deviceTypeRepository.GetDeviceType(viewdevice.TypeID, userId); ViewBag.DeviceTypeName = viewdevicetype.Description.TrimEnd(); ViewCOSEMObject viewcosemobject = _cosemObjectRepository.GetCosemObject(id, userId); ViewBag.ObjectName = viewcosemobject.COSEMLogicalName; List <ViewCOSEMAttributeValue> viewcosemattribute = _cosemAttributeRepository.GetCosemAttributeValueList(deviceid, viewcosemobject.ID, viewcosemobject.COSEMClassID, userId); return(View(viewcosemattribute)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
private void loaddevicegrid(HttpContext context) { string Keywords = context.Request.Params["Keywords"]; string page = context.Request.Form["page"]; string rows = context.Request.Form["rows"]; long startRowIndex = (long.Parse(page) - 1) * long.Parse(rows); int pageSize = int.Parse(rows); int DeviceGroupID = WebUtil.GetIntValue(context, "DeviceGroupID"); string ProjectIDs = context.Request["ProjectIDList"]; List <int> ProjectIDList = new List <int>(); if (!string.IsNullOrEmpty(ProjectIDs)) { ProjectIDList = JsonConvert.DeserializeObject <List <int> >(ProjectIDs); } bool canexport = WebUtil.GetBoolValue(context, "canexport"); DataGrid dg = ViewDevice.GetViewDeviceGridByKeywords(Keywords, DeviceGroupID, ProjectIDList, "order by AddTime asc", startRowIndex, pageSize, canexport: canexport); if (canexport) { string downloadurl = string.Empty; string error = string.Empty; bool status = APPCode.ExportHelper.DownLoadDeviceData(dg, out downloadurl, out error); WebUtil.WriteJson(context, new { status = status, downloadurl = downloadurl, error = error }); return; } string result = JsonConvert.SerializeObject(dg); context.Response.Write(result); }
public ViewDevice GetDevice(Int64 id, Guid userId) { Trace.Assert(_db != null); ObjectSet <ViewDevice> os = _db.ViewDevice; ViewDevice result = os.Single(t => (t.ID == id) && (t.DataOwnerID == userId)); return(result); }
protected void FillEditViewBag(ViewDevice viewdevice) { var userId = GetUserId(); // should have the same name as viewdevice field for automatic data filling ViewBag.TypeID = DeviceTypeRepository.GetDeviceTypes(userId, viewdevice.TypeID, null); ViewBag.GroupID = GroupRepository.GetGroups(userId, viewdevice.GroupID); ViewBag.CurrentGroupID = viewdevice.GroupID; }
public void UpdateDevice(ViewDevice viewdevice, Guid userId) { Trace.Assert(_db != null); _db.UpdateDevice(viewdevice.ID, viewdevice.Name, viewdevice.InternalAddress, viewdevice.AddressType, viewdevice.Port, viewdevice.GroupID, viewdevice.TypeID, viewdevice.OwnerID, viewdevice.IP1, viewdevice.IP2, viewdevice.IP3, viewdevice.IP4, viewdevice.SecondaryPort, viewdevice.SecondaryIP1, viewdevice.SecondaryIP2, viewdevice.SecondaryIP3, viewdevice.SecondaryIP4, userId); }
private List <ViewCOSEMAttributeValue> FillCurrentStateData(long id) { ViewBag.DeviceID = id; Guid userId = GetUserId(); ViewDevice viewdevice = _deviceRepository.GetDevice(id, userId); ViewBag.DeviceName = viewdevice.Name; ViewBag.DeviceGroupID = viewdevice.GroupID; ViewDeviceType viewdevicetype = _deviceTypeRepository.GetDeviceType(viewdevice.TypeID, userId); ViewBag.DeviceTypeName = viewdevicetype.Description.TrimEnd(); return(_cosemAttributeRepository.GetCosemAttributeValueList(id, userId)); }
public ActionResult Edit(ViewDevice viewdevice) { try { if (ModelState.IsValid) { DeviceRepository.UpdateDevice(viewdevice, GetUserId()); return(RedirectToAction("GroupDevices/" + viewdevice.GroupID.ToString(CultureInfo.InvariantCulture))); } FillEditViewBag(viewdevice); return(View(viewdevice)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public long?AddDevice(ViewDevice v, Guid userId) { Trace.Assert(_db != null); ObjectResult <long?> result = _db.AddDevice(v.Name, v.InternalAddress, v.AddressType, v.Port, v.GroupID, v.TypeID, v.OwnerID, v.IP1, v.IP2, v.IP3, v.IP4, v.SecondaryPort, v.SecondaryIP1, v.SecondaryIP2, v.SecondaryIP3, v.SecondaryIP4, userId, null, false); Trace.Assert(result != null); IEnumerator <long?> resultList = result.GetEnumerator(); Trace.Assert(resultList != null); resultList.MoveNext(); long?deviceId = resultList.Current; resultList.Dispose(); // for transaction to be able to complete return(deviceId); }
public ActionResult Create(long id /*device group identifier*/) { try { var userId = GetUserId(); FillAuxData(userId, id, 0, 0, 0); // to fill hidden page fields conviniently var viewdevice = new ViewDevice { AddressType = "IP", GroupID = id }; return(View("CreateWithoutIP" /*temporarily IP input disabled !!!*/, viewdevice)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public long?AddDeviceWithAddress(ViewDevice d, ViewAddress a, Guid userId) { Trace.Assert(_db != null); ObjectResult <long?> result = _db.AddDeviceWithAddress(d.Name, d.InternalAddress, d.AddressType, d.Port, d.GroupID, d.TypeID, d.OwnerID, d.IP1, d.IP2, d.IP3, d.IP4, d.SecondaryPort, d.SecondaryIP1, d.SecondaryIP2, d.SecondaryIP3, d.SecondaryIP4, a.Apartament, a.Building, a.Street, a.City, a.State, a.Country, a.ZipCode, userId); Trace.Assert(result != null); IEnumerator <long?> resultList = result.GetEnumerator(); Trace.Assert(resultList != null); resultList.MoveNext(); long?deviceId = resultList.Current; resultList.Dispose(); // for transaction to be able to complete return(deviceId); }
public ActionResult SetOwner(long id /*device id.*/, long?ownerId /*null terminates the owner setup sequence*/) { try { if (null != ownerId) { if (ModelState.IsValid) { // this code finalizes the owner setup sequence var v = new ViewDevice { ID = id, OwnerID = ownerId }; DeviceRepository.UpdateDeviceOwnerId(v, GetUserId()); } } return(RedirectToAction("Details/" + id.ToString(CultureInfo.InvariantCulture))); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public ViewResult Index(long id /*logical device identifier*/, long deviceid /*physical device identifier*/) { try { ViewBag.DeviceID = deviceid; ViewBag.LogicalDeviceID = id; Guid userId = GetUserId(); ViewDevice viewdevice = _deviceRepository.GetDevice(deviceid, userId); ViewBag.DeviceName = viewdevice.Name; ViewDeviceType viewdevicetype = _deviceTypeRepository.GetDeviceType(viewdevice.TypeID, userId); ViewBag.DeviceTypeName = viewdevicetype.Description.TrimEnd(); List <ViewCOSEMObject> viewcosemobject = _cosemObjectRepository.GetCosemObjectList(id, userId); return(View(viewcosemobject)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public ActionResult AddMetersForBuildings(ViewGroup viewgroup) { try { try { // parameters checking if (viewgroup.DeviceNamePrefix == null) { AddForBuildingsResult = AddForBuildingsResults.DeviceNamePrefixError; return(AddMetersForBuildings()); } if (string.IsNullOrEmpty(viewgroup.Name)) { AddForBuildingsResult = AddForBuildingsResults.NameError; return(AddMetersForBuildings()); } UInt32 startingIp1 = 0, startingIp2 = 0, startingIp3 = 0, startingIp4 = 0; Boolean startingIpUndefined = false; if (String.IsNullOrWhiteSpace(viewgroup.StartingIP1) && String.IsNullOrWhiteSpace(viewgroup.StartingIP2) && String.IsNullOrWhiteSpace(viewgroup.StartingIP3) && String.IsNullOrWhiteSpace(viewgroup.StartingIP4)) { startingIpUndefined = true; } else { if (String.IsNullOrWhiteSpace(viewgroup.StartingIP1) || (!UInt32.TryParse(viewgroup.StartingIP1, out startingIp1)) || String.IsNullOrWhiteSpace(viewgroup.StartingIP2) || (!UInt32.TryParse(viewgroup.StartingIP2, out startingIp2)) || String.IsNullOrWhiteSpace(viewgroup.StartingIP3) || (!UInt32.TryParse(viewgroup.StartingIP3, out startingIp3)) || String.IsNullOrWhiteSpace(viewgroup.StartingIP4) || (!UInt32.TryParse(viewgroup.StartingIP4, out startingIp4))) { AddForBuildingsResult = AddForBuildingsResults.StartingIpError; return(AddMetersForBuildings()); } if (!IsValidIpClass(startingIp1, startingIp2, startingIp3, startingIp4)) { AddForBuildingsResult = AddForBuildingsResults.StartingIpError; return(AddMetersForBuildings()); } UInt32 startingIpPort; if (String.IsNullOrWhiteSpace(viewgroup.StartingIPPort) || (!UInt32.TryParse(viewgroup.StartingIPPort, out startingIpPort)) || !(startingIpPort <= 65535)) { AddForBuildingsResult = AddForBuildingsResults.StartingIpPortError; return(AddMetersForBuildings()); } } UInt32 secondaryStartingIp1 = 0, secondaryStartingIp2 = 0, secondaryStartingIp3 = 0, secondaryStartingIp4 = 0; Boolean secondaryStartingIpUndefined = false; if (String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP1) && String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP2) && String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP3) && String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP4)) { secondaryStartingIpUndefined = true; } else { if (String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP1) || (!UInt32.TryParse(viewgroup.SecondaryStartingIP1, out secondaryStartingIp1)) || String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP2) || (!UInt32.TryParse(viewgroup.SecondaryStartingIP2, out secondaryStartingIp2)) || String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP3) || (!UInt32.TryParse(viewgroup.SecondaryStartingIP3, out secondaryStartingIp3)) || String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP4) || (!UInt32.TryParse(viewgroup.SecondaryStartingIP4, out secondaryStartingIp4))) { AddForBuildingsResult = AddForBuildingsResults.SecondaryStartingIpError; return(AddMetersForBuildings()); } if (!IsValidIpClass(secondaryStartingIp1, secondaryStartingIp2, secondaryStartingIp3, secondaryStartingIp4)) { AddForBuildingsResult = AddForBuildingsResults.SecondaryStartingIpError; return(AddMetersForBuildings()); } UInt32 secondaryStartingIpPort; if (String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIPPort) || (!UInt32.TryParse(viewgroup.SecondaryStartingIPPort, out secondaryStartingIpPort)) || !(secondaryStartingIpPort <= 65535)) { AddForBuildingsResult = AddForBuildingsResults.SecondaryStartingPortError; return(AddMetersForBuildings()); } } uint zipCode, startingBuilding, endingBuilding, startingApartament, endingApartament; if (!UInt32.TryParse(viewgroup.ZipCode, out zipCode)) { AddForBuildingsResult = AddForBuildingsResults.ZipCodeError; return(AddMetersForBuildings()); } if (!UInt32.TryParse(viewgroup.StartingBuilding, out startingBuilding)) { AddForBuildingsResult = AddForBuildingsResults.StartingBuildingError; return(AddMetersForBuildings()); } if (!UInt32.TryParse(viewgroup.EndingBuilding, out endingBuilding)) { AddForBuildingsResult = AddForBuildingsResults.EndingBuildingError; return(AddMetersForBuildings()); } if (!UInt32.TryParse(viewgroup.StartingApartment, out startingApartament)) { AddForBuildingsResult = AddForBuildingsResults.StartingApartamentError; return(AddMetersForBuildings()); } if (!UInt32.TryParse(viewgroup.EndingApartment, out endingApartament)) { AddForBuildingsResult = AddForBuildingsResults.EndingApartamentError; return(AddMetersForBuildings()); } if (viewgroup.Street == "") { AddForBuildingsResult = AddForBuildingsResults.StreetError; return(AddMetersForBuildings()); } if (viewgroup.City == "") { AddForBuildingsResult = AddForBuildingsResults.CityError; return(AddMetersForBuildings()); } if (viewgroup.State == "") { AddForBuildingsResult = AddForBuildingsResults.StateError; return(AddMetersForBuildings()); } if (viewgroup.Country == "") { AddForBuildingsResult = AddForBuildingsResults.CountryError; return(AddMetersForBuildings()); } ////////////////////////////////////////// // devices creating if (ModelState.IsValid) { UInt32 netShift = 0, netSecShift = 0; if (!startingIpUndefined && GetIPClass(startingIp1) == IpClass.A) { netShift = 24; // class-A } else if (!startingIpUndefined && GetIPClass(startingIp1) == IpClass.B) { netShift = 16; // class-B } else if (!startingIpUndefined && GetIPClass(startingIp1) == IpClass.C) { netShift = 8; // class-C } if (!secondaryStartingIpUndefined && GetIPClass(secondaryStartingIp1) == IpClass.A) { netSecShift = 24; // class-A } else if (!secondaryStartingIpUndefined && GetIPClass(secondaryStartingIp1) == IpClass.B) { netSecShift = 16; // class-B } else if (!secondaryStartingIpUndefined && GetIPClass(secondaryStartingIp1) == IpClass.C) { netSecShift = 8; // class-C } UInt32 startingIpAddr = startingIp1 << 24 | startingIp2 << 16 | startingIp3 << 8 | startingIp4; UInt32 secondaryStartingIpAddr = secondaryStartingIp1 << 24 | secondaryStartingIp2 << 16 | secondaryStartingIp3 << 8 | secondaryStartingIp4; var ipMask = (UInt32)((1 << (Int32)netShift) - 1); var ipSecMask = (UInt32)((1 << (Int32)netSecShift) - 1); Guid userId = GetUserId(); using (var transaction = new TransactionScope()) { // сначала нужно добавить группу, чтобы получить идентификатор long? groupId = _groupRepository.AddGroup(viewgroup, userId); Int32 serNum = 1; uint sIp = startingIpAddr; uint sSecIp = secondaryStartingIpAddr; UInt32 sBuilding, eBuilding, sApartament, eApartament; if (startingBuilding <= endingBuilding) { sBuilding = startingBuilding; eBuilding = endingBuilding; } else { sBuilding = endingBuilding; eBuilding = startingBuilding; } if (startingApartament <= endingApartament) { sApartament = startingApartament; eApartament = endingApartament; } else { sApartament = endingApartament; eApartament = startingApartament; } UInt32 netPart = (sIp >> (Int32)netShift); UInt32 ipPart = sIp & ipMask; UInt32 netSecPart = (sSecIp >> (Int32)netSecShift); UInt32 ipSecPart = sSecIp & ipSecMask; if (startingIpUndefined) { var td = new ViewDevice { InternalAddress = "1", AddressType = "IP", GroupID = groupId.Value, TypeID = viewgroup.DeviceTypeID }; UInt32 building = sBuilding; UInt32 apartament = sApartament; if (0 != viewgroup.DeviceNamePrefix.Trim().Length) { td.Name = viewgroup.DeviceNamePrefix.Trim() + (serNum).ToString(CultureInfo.InvariantCulture); } var a = new ViewAddress { Apartament = apartament.ToString(CultureInfo.InvariantCulture), Building = building.ToString(CultureInfo.InvariantCulture), Street = viewgroup.Street, City = viewgroup.City, State = viewgroup.State, Country = viewgroup.Country, ZipCode = viewgroup.ZipCode }; _deviceRepository.AddDeviceWithAddress(td, a, userId); } else { for (UInt32 building = sBuilding, ipAddr = sIp, ipSecAddr = sSecIp; building <= eBuilding; building++) { for (UInt32 apartament = sApartament; apartament <= eApartament; apartament++) { var td = new ViewDevice { InternalAddress = "1", AddressType = "IP", GroupID = groupId.Value, TypeID = viewgroup.DeviceTypeID }; if (0 != viewgroup.DeviceNamePrefix.Trim().Length) { td.Name = viewgroup.DeviceNamePrefix.Trim() + (serNum++).ToString(CultureInfo.InvariantCulture); } td.IP1 = (ipAddr >> 24).ToString(CultureInfo.InvariantCulture); td.IP2 = ((ipAddr >> 16) & 0xff).ToString(CultureInfo.InvariantCulture); td.IP3 = ((ipAddr >> 8) & 0xff).ToString(CultureInfo.InvariantCulture); td.IP4 = (ipAddr & 0xff).ToString(CultureInfo.InvariantCulture); td.Port = viewgroup.StartingIPPort; if (!secondaryStartingIpUndefined) { td.SecondaryIP1 = (ipSecAddr >> 24).ToString(CultureInfo.InvariantCulture); td.SecondaryIP2 = ((ipSecAddr >> 16) & 0xff).ToString(CultureInfo.InvariantCulture); td.SecondaryIP3 = ((ipSecAddr >> 8) & 0xff).ToString(CultureInfo.InvariantCulture); td.SecondaryIP4 = (ipSecAddr & 0xff).ToString(CultureInfo.InvariantCulture); td.SecondaryPort = viewgroup.SecondaryStartingIPPort; } var a = new ViewAddress { Apartament = apartament.ToString(CultureInfo.InvariantCulture), Building = building.ToString(CultureInfo.InvariantCulture), Street = viewgroup.Street, City = viewgroup.City, State = viewgroup.State, Country = viewgroup.Country, ZipCode = viewgroup.ZipCode }; _deviceRepository.AddDeviceWithAddress(td, a, userId); ipPart++; if (ipPart == ipMask) { ipPart = 1; netPart++; } ipAddr = (netPart << (Int32)netShift) | ipPart; ipSecPart++; if (ipSecPart == ipSecMask) { ipSecPart = 1; netSecPart++; } ipSecAddr = (netSecPart << (Int32)netSecShift) | ipSecPart; } } } transaction.Complete(); } AddForBuildingsResult = AddForBuildingsResults.MetersAddedSuccessfully; return(RedirectToAction("Index")); } AddForBuildingsResult = AddForBuildingsResults.ModelStateIsNotValid; return(AddMetersForBuildings()); } catch (Exception e) { ExceptionMessageToViewBag(e); AddForBuildingsResult = AddForBuildingsResults.ExceptionRaised; return(View("Error")); } } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public ActionResult AddMetersForIPs(ViewGroup viewgroup) { try { if (viewgroup.DeviceNamePrefix == null) { AddForIPsResult = AddForIPsResults.DeviceNamePrefixError; return(AddMetersForIPs()); } if (string.IsNullOrEmpty(viewgroup.Name)) { AddForIPsResult = AddForIPsResults.NameError; return(AddMetersForIPs()); } UInt32 startingIp1 = 0, startingIp2 = 0, startingIp3 = 0, startingIp4 = 0, startingIpPort = 0; Boolean startingIpUndefined = false; if (String.IsNullOrWhiteSpace(viewgroup.StartingIP1) && String.IsNullOrWhiteSpace(viewgroup.StartingIP2) && String.IsNullOrWhiteSpace(viewgroup.StartingIP3) && String.IsNullOrWhiteSpace(viewgroup.StartingIP4)) { startingIpUndefined = true; } else { if (String.IsNullOrWhiteSpace(viewgroup.StartingIP1) || (!UInt32.TryParse(viewgroup.StartingIP1, out startingIp1)) || String.IsNullOrWhiteSpace(viewgroup.StartingIP2) || (!UInt32.TryParse(viewgroup.StartingIP2, out startingIp2)) || String.IsNullOrWhiteSpace(viewgroup.StartingIP3) || (!UInt32.TryParse(viewgroup.StartingIP3, out startingIp3)) || String.IsNullOrWhiteSpace(viewgroup.StartingIP4) || (!UInt32.TryParse(viewgroup.StartingIP4, out startingIp4))) { AddForIPsResult = AddForIPsResults.StartingIpError; return(AddMetersForIPs()); } if (!IsValidIpClass(startingIp1, startingIp2, startingIp3, startingIp4)) { AddForIPsResult = AddForIPsResults.StartingIpError; return(AddMetersForIPs()); } if (String.IsNullOrWhiteSpace(viewgroup.StartingIPPort) || (!UInt32.TryParse(viewgroup.StartingIPPort, out startingIpPort)) || !(startingIpPort <= 65535)) { AddForIPsResult = AddForIPsResults.StartingIpPortError; return(AddMetersForIPs()); } } UInt32 endingIp1 = 0, endingIp2 = 0, endingIp3 = 0, endingIp4 = 0, endingIpPort = 0; if (String.IsNullOrWhiteSpace(viewgroup.EndingIP1) && String.IsNullOrWhiteSpace(viewgroup.EndingIP2) && String.IsNullOrWhiteSpace(viewgroup.EndingIP3) && String.IsNullOrWhiteSpace(viewgroup.EndingIP4)) { } else { if (String.IsNullOrWhiteSpace(viewgroup.EndingIP1) || (!UInt32.TryParse(viewgroup.EndingIP1, out endingIp1)) || String.IsNullOrWhiteSpace(viewgroup.EndingIP2) || (!UInt32.TryParse(viewgroup.EndingIP2, out endingIp2)) || String.IsNullOrWhiteSpace(viewgroup.EndingIP3) || (!UInt32.TryParse(viewgroup.EndingIP3, out endingIp3)) || String.IsNullOrWhiteSpace(viewgroup.EndingIP4) || (!UInt32.TryParse(viewgroup.EndingIP4, out endingIp4))) { AddForIPsResult = AddForIPsResults.EndingIpError; return(AddMetersForIPs()); } if (!IsValidIpClass(endingIp1, endingIp2, endingIp3, endingIp4)) { AddForIPsResult = AddForIPsResults.EndingIpError; return(AddMetersForIPs()); } if (String.IsNullOrWhiteSpace(viewgroup.EndingIPPort) || (!UInt32.TryParse(viewgroup.EndingIPPort, out endingIpPort)) || !(endingIpPort <= 65535)) { AddForIPsResult = AddForIPsResults.EndingIpPortError; return(AddMetersForIPs()); } } UInt32 secondaryStartingIp1 = 0, secondaryStartingIp2 = 0, secondaryStartingIp3 = 0, secondaryStartingIp4 = 0, secondaryStartingIpPort = 0; Boolean secondaryStartingIpUndefined = false; if (String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP1) && String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP2) && String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP3) && String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP4)) { secondaryStartingIpUndefined = true; } else { if (String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP1) || (!UInt32.TryParse(viewgroup.SecondaryStartingIP1, out secondaryStartingIp1)) || String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP2) || (!UInt32.TryParse(viewgroup.SecondaryStartingIP2, out secondaryStartingIp2)) || String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP3) || (!UInt32.TryParse(viewgroup.SecondaryStartingIP3, out secondaryStartingIp3)) || String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIP4) || (!UInt32.TryParse(viewgroup.SecondaryStartingIP4, out secondaryStartingIp4))) { AddForIPsResult = AddForIPsResults.SecondaryStartingIpError; return(AddMetersForIPs()); } if (!IsValidIpClass(secondaryStartingIp1, secondaryStartingIp2, secondaryStartingIp3, secondaryStartingIp4)) { AddForIPsResult = AddForIPsResults.SecondaryStartingIpError; return(AddMetersForIPs()); } if (String.IsNullOrWhiteSpace(viewgroup.SecondaryStartingIPPort) || (!UInt32.TryParse(viewgroup.SecondaryStartingIPPort, out secondaryStartingIpPort)) || !(secondaryStartingIpPort <= 65535)) { AddForIPsResult = AddForIPsResults.SecondaryStartingPortError; return(AddMetersForIPs()); } } if (ModelState.IsValid) { UInt32 netShift = 0, netSecShift = 0; if (!startingIpUndefined && GetIPClass(startingIp1) == IpClass.A) { if (GetIPClass(endingIp1) != IpClass.A) { AddForIPsResult = AddForIPsResults.EndingIpError; return(AddMetersForIPs()); } netShift = 24; // class-A } else if (!startingIpUndefined && GetIPClass(startingIp1) == IpClass.B) { if (GetIPClass(endingIp1) != IpClass.B) { AddForIPsResult = AddForIPsResults.EndingIpError; return(AddMetersForIPs()); } netShift = 16; // class-B } else if (!startingIpUndefined && GetIPClass(startingIp1) == IpClass.C) { if (GetIPClass(endingIp1) != IpClass.C) { AddForIPsResult = AddForIPsResults.EndingIpError; return(AddMetersForIPs()); } netShift = 8; // class-C } if (!secondaryStartingIpUndefined && GetIPClass(secondaryStartingIp1) == IpClass.A) { netSecShift = 24; // class-A } else if (!secondaryStartingIpUndefined && GetIPClass(secondaryStartingIp1) == IpClass.B) { netSecShift = 16; // class-B } else if (!secondaryStartingIpUndefined && GetIPClass(secondaryStartingIp1) == IpClass.C) { netSecShift = 8; // class-C } UInt32 startingIpAddr = startingIp1 << 24 | startingIp2 << 16 | startingIp3 << 8 | startingIp4; UInt32 endingIpAddr = endingIp1 << 24 | endingIp2 << 16 | endingIp3 << 8 | endingIp4; UInt32 secondaryStartingIpAddr = secondaryStartingIp1 << 24 | secondaryStartingIp2 << 16 | secondaryStartingIp3 << 8 | secondaryStartingIp4; var ipMask = (UInt32)((1 << (Int32)netShift) - 1); var ipSecMask = (UInt32)((1 << (Int32)netSecShift) - 1); Guid userId = GetUserId(); using (var transaction = new TransactionScope()) { // сначала нужно добавить группу, чтобы получить идентификатор long? groupId = _groupRepository.AddGroup(viewgroup, userId); Int32 serNum = 1; UInt32 sIp, eIp, sPort, ePort; if (startingIpAddr <= endingIpAddr) { sIp = startingIpAddr; eIp = endingIpAddr; } else { sIp = endingIpAddr; eIp = startingIpAddr; } if (startingIpPort <= endingIpPort) { sPort = startingIpPort; ePort = endingIpPort; } else { ePort = startingIpPort; sPort = endingIpPort; } UInt32 netPart = (sIp >> (Int32)netShift); UInt32 ipPart = sIp & ipMask; uint sSecIp = secondaryStartingIpAddr; uint sSecPort = secondaryStartingIpPort; UInt32 netSecPart = (sSecIp >> (Int32)netSecShift); UInt32 ipSecPart = sSecIp & ipSecMask; if (startingIpUndefined) { var td = new ViewDevice { InternalAddress = "1", AddressType = "IP", GroupID = groupId.Value, TypeID = viewgroup.DeviceTypeID }; if (0 != viewgroup.DeviceNamePrefix.Trim().Length) { td.Name = viewgroup.DeviceNamePrefix.Trim() + (serNum).ToString(CultureInfo.InvariantCulture); } long?deviceId = _deviceRepository.AddDevice(td, userId); _deviceLogicalDeviceRepository.AddAllDeviceAttrToCollectList((long)deviceId, userId); } else { for (UInt32 ipAddr = sIp, ipSecAddr = sSecIp; ipAddr <= eIp;) { for (UInt32 ipPort = sPort, ipSecPort = sSecPort; ipPort <= ePort;) { var td = new ViewDevice { InternalAddress = "1", AddressType = "IP", GroupID = groupId.Value, TypeID = viewgroup.DeviceTypeID }; if (0 != viewgroup.DeviceNamePrefix.Trim().Length) { td.Name = viewgroup.DeviceNamePrefix.Trim() + (serNum++).ToString(CultureInfo.InvariantCulture); } td.IP1 = (ipAddr >> 24).ToString(CultureInfo.InvariantCulture); td.IP2 = ((ipAddr >> 16) & 0xff).ToString(CultureInfo.InvariantCulture); td.IP3 = ((ipAddr >> 8) & 0xff).ToString(CultureInfo.InvariantCulture); td.IP4 = (ipAddr & 0xff).ToString(CultureInfo.InvariantCulture); td.Port = ipPort.ToString(CultureInfo.InvariantCulture); if (!secondaryStartingIpUndefined) { td.SecondaryIP1 = (ipSecAddr >> 24).ToString(CultureInfo.InvariantCulture); td.SecondaryIP2 = ((ipSecAddr >> 16) & 0xff).ToString(CultureInfo.InvariantCulture); td.SecondaryIP3 = ((ipSecAddr >> 8) & 0xff).ToString(CultureInfo.InvariantCulture); td.SecondaryIP4 = (ipSecAddr & 0xff).ToString(CultureInfo.InvariantCulture); td.SecondaryPort = ipSecPort.ToString(CultureInfo.InvariantCulture); } _deviceRepository.AddDevice(td, userId); ipPort++; ipSecPort++; if (ipPort > ePort) { ipPart++; if (ipPart == ipMask) { ipPart = 1; netPart++; } ipAddr = (netPart << (Int32)netShift) | ipPart; ipSecPart++; if (ipSecPart == ipSecMask) { ipSecPart = 1; netSecPart++; } ipSecAddr = (netSecPart << (Int32)netSecShift) | ipSecPart; break; } } } } transaction.Complete(); } AddForIPsResult = AddForIPsResults.MetersAddedSuccessfully; return(RedirectToAction("Index")); } AddForIPsResult = AddForIPsResults.ModelStateIsNotValid; return(AddMetersForIPs()); } catch (Exception e) { ExceptionMessageToViewBag(e); AddForIPsResult = AddForIPsResults.ExceptionRaised; return(View("Error")); } }
public void UpdateDeviceOwnerId(ViewDevice v, Guid userId) { Trace.Assert(_db != null); _db.UpdateDeviceOwnerID(v.ID, v.OwnerID, userId); }
public void UpdateDevice(ViewDevice viewdevicetype, Guid userId) { }
public void UpdateDeviceAddress(ViewDevice v, Guid userId) { }
public void UpdateDeviceAddress(ViewDevice v, Guid userId) { Trace.Assert(_db != null); _db.UpdateDeviceAddress(v.ID, v.LocationAddressID, userId); }
public void UpdateDeviceOwnerId(ViewDevice v, Guid userId) { }