public HttpResponseMessage SaveNode([FromBody] Node node)
 {
     try
     {
         var result = sarfDao.SaveNode(node);
         return(WrapObjectToHttpResponse(result));
     }
     catch (Exception ex)
     {
         throw new Exception("Error : " + ex.Message);
     }
 }
Пример #2
0
        private int SaveNodes(List <List <decimal> > points)
        {
            List <decimal> vertex = new List <decimal>();

            nodes = new List <Node>();
            if (points.Count == 1)
            {
                Node   node         = null;
                Random random       = new Random(1000);
                var    randomNumber = random.Next(9999).ToString();
                vertex = points.First();
                node   = new Node
                {
                    SarfId          = currentSarfId,
                    HubId           = (int)hubIDList[0],
                    Latitude        = vertex[1], // decMaxLat,
                    Longitude       = vertex[0], //decMaxLong,
                    AtollSiteName   = "SITE SF-" + currentSarfId + "-0" + randomNumber,
                    iPlanJobNumber  = "WR-RWOR-" + currentSarfId + "-0" + randomNumber,
                    PaceNumber      = "MRGE000" + currentSarfId + "-0" + randomNumber,
                    DateCreated     = DateTime.Now,
                    NodeType        = ResourceConstants.NodeType_Electric_Pole,
                    VendorName      = ResourceConstants.VendorName_MasTec,
                    ContactPolice   = ResourceConstants.PoliceDepartment,
                    ContactFire     = ResourceConstants.FireDepartment,
                    ContactEnergy   = ResourceConstants.EnergyDepartment,
                    IsATTOwned      = ResourceConstants.IsATTOwned_Yes,
                    StructureHeight = ResourceConstants.StructureHeight,
                    Company         = ResourceConstants.Company_CELLULAR_ONE,
                    BusinessPhone   = ResourceConstants.BusinessPhone
                };
                nodes.Add(node);
            }
            else
            {
                List <List <decimal> > mappedList    = new List <List <decimal> >();
                List <List <decimal> > notMappedList = new List <List <decimal> >();
                int filterLength = points.Count * 3 / 4;
                mappedList.AddRange(points.Take(filterLength).ToList());
                notMappedList.AddRange(points.Skip(mappedList.Count).Take(points.Count - mappedList.Count).ToList());
                int  midIndex   = mappedList.Count / 3;
                int  hubCount   = 0;
                Node node       = null;
                int  checkCount = 0;

                //adding nodes with mapping hub
                for (var count = 0; count < mappedList.Count; count++)
                {
                    checkCount++;
                    Random random       = new Random(1000);
                    var    randomNumber = random.Next(9999).ToString();
                    vertex = mappedList[count];
                    node   = new Node
                    {
                        SarfId          = currentSarfId,
                        HubId           = (int)hubIDList[hubCount],
                        Latitude        = vertex[1], // decMaxLat,
                        Longitude       = vertex[0], //decMaxLong,
                        AtollSiteName   = "SITE SF-" + currentSarfId + (int)hubIDList[hubCount] + "-0" + randomNumber,
                        iPlanJobNumber  = "WR-RWOR-" + currentSarfId + (int)hubIDList[hubCount] + "-0" + randomNumber,
                        PaceNumber      = "MRGE000" + currentSarfId + (int)hubIDList[hubCount] + "-0" + randomNumber,
                        DateCreated     = DateTime.Now,
                        ContactPolice   = ResourceConstants.PoliceDepartment,
                        ContactFire     = ResourceConstants.FireDepartment,
                        ContactEnergy   = ResourceConstants.EnergyDepartment,
                        StructureHeight = ResourceConstants.StructureHeight,
                        BusinessPhone   = ResourceConstants.BusinessPhone
                    };

                    if (count <= (mappedList.Count * 1 / 4))
                    {
                        node.NodeType   = ResourceConstants.NodeType_Electric_Pole;
                        node.VendorName = ResourceConstants.VendorName_MasTec;
                        node.IsATTOwned = ResourceConstants.IsATTOwned_Yes;
                        node.Company    = ResourceConstants.Company_CELLULAR_ONE;
                    }
                    else if (count > (mappedList.Count * 1 / 4) && count <= (mappedList.Count * 1 / 2))
                    {
                        node.NodeType   = ResourceConstants.NodeType_Light_Pole;
                        node.VendorName = ResourceConstants.VendorName_Goodman_Networks;
                        node.IsATTOwned = ResourceConstants.IsATTOwned_No;
                        node.Company    = ResourceConstants.Company_T_MOBILE;
                    }
                    else if (count > (mappedList.Count * 1 / 2) && count < mappedList.Count)
                    {
                        node.NodeType   = ResourceConstants.NodeType_Building;
                        node.VendorName = ResourceConstants.VendorName_Black_Veatch;
                        node.IsATTOwned = ResourceConstants.IsATTOwned_Yes;
                        node.Company    = ResourceConstants.Company_US_CELLULAR;
                    }

                    nodes.Add(node);
                    if (checkCount == midIndex)
                    {
                        hubCount++;
                        checkCount = 0;
                        if (hubCount >= hubIDList.Count)
                        {
                            hubCount = hubIDList.Count - 1;
                        }
                    }
                }

                //adding nodes without mapping hub
                for (var count = 0; count < notMappedList.Count; count++)
                {
                    Random random       = new Random(1000);
                    var    randomNumber = random.Next(9999).ToString();
                    vertex = notMappedList[count];
                    node   = new Node
                    {
                        SarfId          = currentSarfId,
                        HubId           = 0,
                        Latitude        = vertex[1], // decMaxLat,
                        Longitude       = vertex[0], //decMaxLong,
                        AtollSiteName   = "SITE SF-" + currentSarfId + "-0" + randomNumber,
                        iPlanJobNumber  = "WR-RWOR-" + currentSarfId + "-0" + randomNumber,
                        PaceNumber      = "MRGE000" + currentSarfId + "-0" + randomNumber,
                        DateCreated     = DateTime.Now,
                        ContactPolice   = ResourceConstants.PoliceDepartment,
                        ContactFire     = ResourceConstants.FireDepartment,
                        ContactEnergy   = ResourceConstants.EnergyDepartment,
                        StructureHeight = ResourceConstants.StructureHeight,
                        BusinessPhone   = ResourceConstants.BusinessPhone
                    };
                    if (count <= (notMappedList.Count * 1 / 4))
                    {
                        node.NodeType   = ResourceConstants.NodeType_Electric_Pole;
                        node.VendorName = ResourceConstants.VendorName_MasTec;
                        node.IsATTOwned = ResourceConstants.IsATTOwned_Yes;
                        node.Company    = ResourceConstants.Company_CELLULAR_ONE;
                    }
                    else if (count > (notMappedList.Count * 1 / 4) && count <= (notMappedList.Count * 1 / 2))
                    {
                        node.NodeType   = ResourceConstants.NodeType_Light_Pole;
                        node.VendorName = ResourceConstants.VendorName_Goodman_Networks;
                        node.IsATTOwned = ResourceConstants.IsATTOwned_No;
                        node.Company    = ResourceConstants.Company_T_MOBILE;
                    }
                    else if (count > (notMappedList.Count * 1 / 2) && count < notMappedList.Count)
                    {
                        node.NodeType   = ResourceConstants.NodeType_Building;
                        node.VendorName = ResourceConstants.VendorName_Black_Veatch;
                        node.IsATTOwned = ResourceConstants.IsATTOwned_Yes;
                        node.Company    = ResourceConstants.Company_US_CELLULAR;
                    }
                    nodes.Add(node);
                }
            }

            foreach (var nodeItem in nodes)
            {
                sarfDao.SaveNode(nodeItem);
            }
            return(nodes.Count);
        }