Пример #1
0
        public static IEnumerable <ThreadInfo> GetNames(ThreadManager TM, string procedure, Dictionary <string, string> query)
        {
            var currentThread = TM.CurrentThread;

            if (query.ContainsKey("version"))
            {
                double version;
                if (Double.TryParse(query["version"], out version))
                {
                    if (version >= Program.LocationsVersion)
                    {
                        yield return(TM.Return(currentThread, new JsonResponse(HttpStatusCode.NoContent)));
                    }
                }
            }

            yield return(TM.MakeDbCall(currentThread, Program.ConnectionString, procedure));

            var table    = TM.GetResult <DataTable>(currentThread);
            var response = new LocationNamesResponse(Program.LocationsVersion);

            foreach (DataRow row in table.Rows)
            {
                var location = new LocationName(row);
                if (location.Id >= 0)
                {
                    response.Names.Add(location);
                }
            }

            response.Names = LocationsHandler.ApplySearchFilter(query, locName => locName.Name, (locName, name) => locName.Name = name, response.Names);

            yield return(TM.Return(currentThread, new JsonResponse(response)));
        }
Пример #2
0
        public static IEnumerable <ThreadInfo> GetLocations(ThreadManager TM, string procedure, bool hideDescs, Dictionary <string, string> query, params SqlParameter[] parameters)
        {
            var currentThread = TM.CurrentThread;

            if (query.ContainsKey("version"))
            {
                double version;
                if (Double.TryParse(query["version"], out version))
                {
                    if (version >= Program.LocationsVersion)
                    {
                        yield return(TM.Return(currentThread, new JsonResponse(HttpStatusCode.NoContent)));
                    }
                }
            }

            yield return(TM.MakeDbCall(currentThread, Program.ConnectionString, procedure, parameters));

            DataTable table    = TM.GetResult <DataTable>(currentThread);
            var       response = new LocationsResponse(Program.LocationsVersion);

            foreach (DataRow row in table.Rows)
            {
                var location = new Location(row, hideDescs);
                if (location.Id >= 0)
                {
                    if (location.IsMapArea())
                    {
                        yield return(TM.MakeDbCall(currentThread, Program.ConnectionString, "spGetMapAreaCorners",
                                                   new SqlParameter("@maparea", location.Id)));

                        DataTable cornerTable = TM.GetResult <DataTable>(currentThread);
                        foreach (DataRow cornerRow in cornerTable.Rows)
                        {
                            location.MapArea.Corners.Add(new LatLong(cornerRow));
                        }
                    }
                    if (location.HasAltNames)
                    {
                        yield return(TM.MakeDbCall(currentThread, Program.ConnectionString, "spGetLocationAltNames",
                                                   new SqlParameter("@location", location.Id)));

                        location.AddAltNames(TM.GetResult <DataTable>(currentThread));
                    }
                    if (location.HasLinks && !hideDescs)
                    {
                        yield return(TM.MakeDbCall(currentThread, Program.ConnectionString, "spGetLocationLinks",
                                                   new SqlParameter("@location", location.Id)));

                        location.AddLinks(TM.GetResult <DataTable>(currentThread));
                    }
                    response.Locations.Add(location);
                }
            }

            response.Locations = LocationsHandler.ApplySearchFilter(query, location => location.Name, (location, name) => location.Name = name, response.Locations);

            yield return(TM.Return(currentThread, new JsonResponse(response)));
        }