Ejemplo n.º 1
0
        public void DeleteIncumbent_ValidLPAuxRequest_DeletesLPAuxIncumbentSuccesfully()
        {
            IRequestParameters addIncumbentRequestParams = this.AddIncumbentRequestParamsForLPAuxDeviceType();

            this.whitespacesDataClient.AddIncumbent(addIncumbentRequestParams);

            IRequestParameters getIncumbentRequestParams = this.GetIncumbentRequestParams("LPAux");

            var getIncumbentsResponse = this.whitespacesDataClient.GetIncumbents(getIncumbentRequestParams);

            var lowPowerAuxs = getIncumbentsResponse.IncumbentList.Select(obj => JsonSerialization.DeserializeString <LPAuxRegistration>(obj.ToString())).ToList();

            ////Delete MVPD Incumbents
            ////Get RegistrationId of the added incumbent
            var requiredLpAux = lowPowerAuxs.Where(x => x.PointsArea[0].Latitude.ToString() == addIncumbentRequestParams.Params.PointsArea[0].Latitude && x.PointsArea[0].Longitude.ToString() == addIncumbentRequestParams.Params.PointsArea[0].Longitude).FirstOrDefault();

            IRequestParameters deleteIncumbentRequestParams = this.GetRequestParams(
                req =>
            {
                req.RegionName = "United States";
                req.Params     = new Parameters
                {
                    IncumbentType           = "LPAux",
                    RegistrationDisposition = new RegistrationDisposition
                    {
                        RegId = requiredLpAux.Disposition.RegId
                    }
                };
            });

            var actualResponse = this.whitespacesDataClient.DeleteIncumbent(deleteIncumbentRequestParams);

            Assert.AreEqual("Incumbent deleted successfully.", actualResponse.Message);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the dumped file.
        /// </summary>
        /// <typeparam name="T">type of object</typeparam>
        /// <param name="fileName">Name of the file.</param>
        /// <returns>returns System.Collections.Generic.List&lt;T&gt;.</returns>
        public static List <T> ReadDumpedFile <T>(string fileName)
        {
            List <T> dumpedData = new List <T>();

            try
            {
                string filePath = Utils.GetLocalStorCacheFileName(fileName);

                if (!File.Exists(filePath))
                {
                    throw new Exception("Incorrect Path : " + filePath);
                }

                var fileData = File.ReadAllLines(filePath);
                if (fileData == null)
                {
                    throw new Exception("File Not Exist");
                }

                for (int i = 0; i < fileData.Length; i++)
                {
                    dumpedData.Add(JsonSerialization.DeserializeString <T>(fileData[i]));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }

            return(dumpedData);
        }
Ejemplo n.º 3
0
        public void DeleteIncumbent_ValidMVPDRequest_DeletesMVPDIncumbentSuccesfully()
        {
            IRequestParameters addIncumbentRequestParams = this.AddIncumbentRequestParamsForMVPDDeviceType();

            this.whitespacesDataClient.AddIncumbent(addIncumbentRequestParams);

            IRequestParameters getIncumbentRequestParams = this.GetIncumbentRequestParams("MVPD");

            var getIncumbentsResponse = this.whitespacesDataClient.GetIncumbents(getIncumbentRequestParams);
            var mvpds = getIncumbentsResponse.IncumbentList.Select(obj => JsonSerialization.DeserializeString <MVPDRegistration>(obj.ToString())).ToList();

            ////Get RegistrationId of the added incumbent
            var requiredMvpd = mvpds.Where(x => x.Latitude == addIncumbentRequestParams.Params.MVPDLocation.Latitude && x.Longitude == addIncumbentRequestParams.Params.MVPDLocation.Longitude).FirstOrDefault();

            IRequestParameters deleteIncumbentRequestParams = this.GetRequestParams(
                req =>
            {
                req.RegionName = "United States";
                req.Params     = new Parameters
                {
                    IncumbentType           = "MVPD",
                    RegistrationDisposition = new RegistrationDisposition
                    {
                        RegId = requiredMvpd.Disposition.RegId
                    }
                };
            });

            var actualResponse = this.whitespacesDataClient.DeleteIncumbent(deleteIncumbentRequestParams);

            Assert.AreEqual("Incumbent deleted successfully.", actualResponse.Message);
        }
        /// <summary>
        /// Get contours data from raw contours info
        /// </summary>
        /// <param name="rawContour">raw contours info</param>
        /// <returns>contour data</returns>
        private static string GetContourPoints(string rawContour)
        {
            lock (rawContourLock)
            {
                List <Position> contourPoints  = new List <Position>();
                StringBuilder   contourBuilder = new StringBuilder();

                if (!string.IsNullOrWhiteSpace(rawContour))
                {
                    Contour contour = JsonSerialization.DeserializeString <Contour>(rawContour);

                    if (contour.ContourPoints != null)
                    {
                        foreach (Location location in contour.ContourPoints)
                        {
                            contourBuilder.Append(location.Latitude);
                            contourBuilder.Append(" ");
                            contourBuilder.Append(location.Longitude);
                            contourBuilder.Append(" ");
                        }
                    }
                }

                return(contourBuilder.ToString().Trim());
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Checks the if any of the incumbents contains desired location.
        /// </summary>
        /// <param name="station">The incumbent.</param>
        /// <param name="point">The target incumbent.</param>
        /// <param name="offContourDistance">The desired external contour distance.</param>
        /// <returns>returns Incumbent.</returns>
        public static bool IsInOrAroundContour(this Incumbent station, Location point, Distance offContourDistance)
        {
            if (string.IsNullOrEmpty(station.Contour))
            {
                return(false);
            }

            var             contour       = JsonSerialization.DeserializeString <Contour>(station.Contour);
            List <Location> polygonPoints = contour.ContourPoints;

            if (GeoCalculations.IsPointInPolygon(polygonPoints, point))
            {
                return(true);
            }

            // point is not in contour
            // need to check for safe Distance from contour
            var bearingToTarget = GeoCalculations.CalculateBearing(station.Location, point);

            double distance = 0.0;
            bool   lessThanOffContourDistance = false;
            int    index;

            for (int i = (int)bearingToTarget - 90; i < (int)bearingToTarget + 90; i++)
            {
                index = i;
                if (index >= 360)
                {
                    index = i - 360;
                }
                else if (index < 0)
                {
                    index = 360 + i;
                }

                distance = GeoCalculations.GetDistance(point, polygonPoints[index]).Value / 1000.0;
                if (distance <= offContourDistance.InKm())
                {
                    lessThanOffContourDistance = true;
                    break;
                }
            }

            return(lessThanOffContourDistance);
        }
        /// <summary>
        /// Get list of PortalContours from list of MVPDRegistration
        /// </summary>
        /// <param name="cdbsData">list of MVPDRegistration</param>
        /// <param name="incumbentType">incumbent type</param>
        /// <returns>list of portal contours</returns>
        public static List <PortalContour> GetContoursFromMvpd(List <MVPDRegistration> registrations)
        {
            List <PortalContour> sourceContours = new List <PortalContour>();
            object lockObject = new object();
            int    type       = (int)IncumbentType.MVPD;

            Parallel.ForEach(registrations, mvpdRegistration =>
            {
                try
                {
                    PortalContour portalContour   = new PortalContour();
                    portalContour.Type            = type;
                    portalContour.Latitude        = mvpdRegistration.Latitude;
                    portalContour.Longitude       = mvpdRegistration.Longitude;
                    portalContour.ParentLatitude  = mvpdRegistration.TxLatitude;
                    portalContour.ParentLongitude = mvpdRegistration.TxLongitude;
                    portalContour.RowKey          = type + "-" + mvpdRegistration.RowKey;

                    if (!string.IsNullOrEmpty(mvpdRegistration.MVPDChannel))
                    {
                        TvSpectrum spectrum        = JsonSerialization.DeserializeString <TvSpectrum>(mvpdRegistration.MVPDChannel);
                        portalContour.CallSign     = spectrum.CallSign;
                        portalContour.Channel      = Convert.ToInt16(spectrum.Channel);
                        portalContour.PartitionKey = "RGN1-" + portalContour.Channel.ToString();
                        portalContour.Contour      = GetContourPoints(portalContour);

                        lock (lockObject)
                        {
                            sourceContours.Add(portalContour);
                        }
                    }
                }
                catch (Exception ex)
                {
                    AzureLogger.Log(TraceEventType.Error, LoggingMessageId.RegistrationSyncManagerGenericMessage, "Error while processing MVPD with latitude:" + mvpdRegistration.Latitude + " longitude: " + mvpdRegistration.Longitude + " " + ex.ToString());
                }
            });

            return(sourceContours);
        }
Ejemplo n.º 7
0
        private static List <Position> GetContourPoints(string rawContour)
        {
            List <Position> contourPoints = new List <Position>();

            if (!string.IsNullOrWhiteSpace(rawContour))
            {
                Contour contour = JsonSerialization.DeserializeString <Contour>(rawContour);

                if (contour.ContourPoints != null)
                {
                    foreach (Location location in contour.ContourPoints)
                    {
                        contourPoints.Add(new Position
                        {
                            Latitude  = location.Latitude,
                            Longitude = location.Longitude
                        });
                    }
                }
            }

            return(contourPoints);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Copies the specified object record.
        /// </summary>
        /// <typeparam name="T">type of object</typeparam>
        /// <param name="objRecord">The object record.</param>
        /// <returns>returns ULSRecord.</returns>
        public static T Copy <T>(this T objRecord)
        {
            var rec = JsonSerialization.DeserializeString <T>(JsonSerialization.SerializeObject(objRecord));

            return(rec);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Copies the specified object record.
        /// </summary>
        /// <param name="objRecord">The object record.</param>
        /// <returns>returns ULSRecord.</returns>
        public static CDBSTvEngData Copy(this CDBSTvEngData objRecord)
        {
            CDBSTvEngData rec = JsonSerialization.DeserializeString <CDBSTvEngData>(JsonSerialization.SerializeObject(objRecord));

            return(rec);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Copies the specified object record.
        /// </summary>
        /// <param name="objRecord">The object record.</param>
        /// <returns>returns ULSRecord.</returns>
        public static ULSRecord Copy(this ULSRecord objRecord)
        {
            ULSRecord rec = JsonSerialization.DeserializeString <ULSRecord>(JsonSerialization.SerializeObject(objRecord));

            return(rec);
        }
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            var  request          = actionContext.ActionArguments[RequestArgumentName];
            bool enableValidation = false;

            if (Utils.Configuration.HasSetting(Constants.ValidateWSDLocation))
            {
                enableValidation = Utils.Configuration[Constants.ValidateWSDLocation].ToBool();
            }

            if (request == null || !enableValidation)
            {
                return;
            }

            HttpRequestMessage httpRequest  = (HttpRequestMessage)request;
            Request            requestparam = new Request();

            this.PawsAuditor.UserId        = this.PawsLogger.UserId;
            this.PawsAuditor.TransactionId = this.PawsLogger.TransactionId;
            this.PawsAuditor.RegionCode    = Utils.Configuration.CurrentRegionId;

            try
            {
                requestparam = JsonSerialization.DeserializeString <Request>(httpRequest.Content.ReadAsStringAsync().Result);
                GeoLocation   geolocation  = requestparam.Params.Location;
                GeoLocation[] geolocations = requestparam.Params.Locations;

                List <RegionPolygonsCache> subregions = (List <RegionPolygonsCache>)DatabaseCache.ServiceCacheHelper.GetServiceCacheObjects(ServiceCacheObjectType.RegionPolygons, null);

                bool isValidRequest = false;
                bool isBatchRequest = false;

                if (geolocation != null)
                {
                    isValidRequest = ValidateRequestedLocation(geolocation, subregions);
                }
                else if (geolocations != null && geolocations.Length > 0)
                {
                    isBatchRequest = true;
                    isValidRequest = ValidateBatchRequestLocations(geolocations, subregions);
                }

                stopWatch.Stop();

                if (!isValidRequest)
                {
                    PawsResponse errorResponse = null;

                    if (isBatchRequest)
                    {
                        errorResponse = ErrorHelper.CreateErrorResponse(requestparam.Method, geolocations, Constants.ErrorMessageOutsideCoverage);
                    }
                    else
                    {
                        errorResponse = ErrorHelper.CreateErrorResponse(requestparam.Method, geolocation, Constants.ErrorMessageOutsideCoverage);
                    }

                    this.PawsLogger.Log(TraceEventType.Error, LoggingMessageId.PAWSGenericMessage, errorResponse.Error.Message);

                    string  auditMethod;
                    AuditId auditId = PawsUtil.GetAuditId(requestparam.Method, out auditMethod);

                    this.PawsAuditor.Audit(auditId, AuditStatus.Failure, stopWatch.ElapsedMilliseconds, auditMethod + " failed");

                    actionContext.Response = actionContext.Request.CreateResponse <PawsResponse>(errorResponse);
                }
            }
            catch (Exception ex)
            {
                stopWatch.Stop();

                this.PawsLogger.Log(TraceEventType.Error, LoggingMessageId.PAWSGenericMessage, ex.ToString());

                string  auditMethod;
                AuditId auditId = PawsUtil.GetAuditId(requestparam.Method, out auditMethod);

                this.PawsAuditor.Audit(auditId, AuditStatus.Failure, stopWatch.ElapsedMilliseconds, auditMethod + " failed");

                PawsResponse errorResponse = ErrorHelper.CreateExceptionResponse(requestparam.Method, ex.Message);

                actionContext.Response = actionContext.Request.CreateResponse <PawsResponse>(errorResponse);
            }
        }
Ejemplo n.º 12
0
 private static List <T> GetDeserializedIncumbents <T>(object[] rawIncumbents)
 {
     return(rawIncumbents.Select(obj => JsonSerialization.DeserializeString <T>(obj.ToString())).ToList());
 }
Ejemplo n.º 13
0
        public PawsResponse Post(HttpRequestMessage httpRequest)
        {
            PawsResponse postResponse = new PawsResponse();
            string       methodId     = string.Empty;
            Request      requestparam = new Request();

            try
            {
                // Begin Log transaction
                this.PawsLogger.Log(TraceEventType.Information, LoggingMessageId.PAWSGenericMessage, "Enter " + this.methodName);

                // Begin elapsed time calculation
                this.stopWatch = new Stopwatch();
                this.stopWatch.Start();

                try
                {
                    requestparam = JsonSerialization.DeserializeString <Request>(httpRequest.Content.ReadAsStringAsync().Result);
                }
                catch (Exception)
                {
                    return(new PawsResponse
                    {
                        JsonRpc = "2.0",
                        Error = new Result
                        {
                            Code = "-201",
                            Message = Constants.InvalidRequest
                        }
                    });
                }

                postResponse = this.Router(requestparam);

                if (postResponse.Error != null)
                {
                    postResponse.Error.Version = requestparam.Params.Version;
                }

                // Populate audit id based on method in the request
                string auditMethod;

                this.auditId         = PawsUtil.GetAuditId(requestparam.Method, out auditMethod);
                this.auditMethodName = auditMethod;

                // End Audit transaction
                this.PawsAuditor.UserId        = this.PawsLogger.UserId;
                this.PawsAuditor.TransactionId = this.PawsLogger.TransactionId;
                this.PawsAuditor.RegionCode    = Utils.Configuration.CurrentRegionId;

                // End Elapsed Time Calculation
                this.stopWatch.Stop();
                this.elapsedTime = this.stopWatch.ElapsedMilliseconds;
                if (postResponse.Result == null && postResponse.Error.Code != null)
                {
                    this.PawsAuditor.Audit(this.auditId, AuditStatus.Failure, this.elapsedTime, this.auditMethodName + " failed");
                }
                else if (postResponse.Error == null && postResponse.Result.Type != null)
                {
                    this.PawsAuditor.Audit(this.auditId, AuditStatus.Success, this.elapsedTime, this.auditMethodName + " passed");
                }

                // End Log transaction
                this.PawsLogger.Log(TraceEventType.Information, LoggingMessageId.PAWSGenericMessage, "Exit " + this.methodName);
                return(postResponse);
            }
            catch (Exception exception)
            {
                // Log transaction Failure
                this.PawsLogger.Log(TraceEventType.Error, LoggingMessageId.PAWSGenericMessage, exception.ToString());

                // Audit transaction Failure
                this.PawsAuditor.UserId        = this.PawsLogger.UserId;
                this.PawsAuditor.TransactionId = this.PawsLogger.TransactionId;
                this.PawsAuditor.RegionCode    = Utils.Configuration.CurrentRegionId;

                string auditMethod;

                this.auditId         = PawsUtil.GetAuditId(requestparam.Method, out auditMethod);
                this.auditMethodName = auditMethod;

                // End Elapsed Time Calculation
                this.stopWatch.Stop();
                this.elapsedTime = this.stopWatch.ElapsedMilliseconds;
                this.PawsAuditor.Audit(this.auditId, AuditStatus.Failure, this.elapsedTime, this.auditMethodName + " failed");
                return(new PawsResponse
                {
                    JsonRpc = "2.0",
                    Error = new Result
                    {
                        Code = "-201",
                        Message = exception.Message
                    }
                });
            }
        }