/// <summary> /// Calculates expected search query results from the given profile server and its neighbors. /// </summary> /// <param name="NameFilter">Name filter of the search query, or null if name filtering is not required.</param> /// <param name="TypeFilter">Type filter of the search query, or null if type filtering is not required.</param> /// <param name="LocationFilter">Location filter of the search query, or null if location filtering is not required.</param> /// <param name="Radius">If <paramref name="LocationFilter"/> is not null, this is the radius of the target area.</param> /// <param name="IncludeHostedOnly">If set to true, the search results should only include profiles hosted on the queried profile server.</param> /// <param name="IncludeImages">If set to true, the search results should include images.</param> /// <param name="ExpectedCoveredServers">If the function succeeds, this is filled with list of covered servers that the search query should return.</param> /// <param name="LocalServerResultsCount">If the function succeeds, this is filled with the number of search results obtained from the local server.</param> /// <returns>List of profiles that match the given criteria or null if the function fails.</returns> public List <IdentityNetworkProfileInformation> GetExpectedSearchResults(string NameFilter, string TypeFilter, GpsLocation LocationFilter, int Radius, bool IncludeHostedOnly, bool IncludeImages, out List <byte[]> ExpectedCoveredServers, out int LocalServerResultsCount) { log.Trace("(NameFilter:'{0}',TypeFilter:'{1}',LocationFilter:'{2}',Radius:{3},IncludeHostedOnly:{4},IncludeImages:{5})", NameFilter, TypeFilter, LocationFilter, Radius, IncludeHostedOnly, IncludeImages); List <IdentityNetworkProfileInformation> res = new List <IdentityNetworkProfileInformation>(); ExpectedCoveredServers = new List <byte[]>(); ExpectedCoveredServers.Add(networkId); List <IdentityNetworkProfileInformation> localResults = SearchQuery(NameFilter, TypeFilter, LocationFilter, Radius, IncludeImages); LocalServerResultsCount = localResults.Count; foreach (IdentityNetworkProfileInformation localResult in localResults) { localResult.IsHosted = true; localResult.IsOnline = false; } res.AddRange(localResults); if (!IncludeHostedOnly) { List <ProfileServer> neighbors = LocServer.GetNeighbors(); foreach (ProfileServer neighbor in neighbors) { ByteString neighborId = ProtocolHelper.ByteArrayToByteString(neighbor.GetNetworkId()); ExpectedCoveredServers.Add(neighborId.ToByteArray()); List <IdentityNetworkProfileInformation> neighborResults = neighbor.SearchQuery(NameFilter, TypeFilter, LocationFilter, Radius, IncludeImages); foreach (IdentityNetworkProfileInformation neighborResult in neighborResults) { neighborResult.IsHosted = false; neighborResult.HostingServerNetworkId = neighborId; } res.AddRange(neighborResults); } } log.Trace("(-):*.Count={0}", res.Count); return(res); }
/// <summary> /// Initialize a new instance of a profile server. /// </summary> /// <returns>true if the function succeeds, false otherwise.</returns> public bool Initialize() { log.Trace("()"); bool res = false; try { instanceDirectory = GetInstanceDirectoryName(); Directory.CreateDirectory(instanceDirectory); if (Helpers.DirectoryCopy(CommandProcessor.ProfileServerBinariesDirectory, instanceDirectory)) { string configFinal = Path.Combine(instanceDirectory, ConfigFileName); if (InitializeConfig(configFinal)) { locServer = new LocServer(this); res = locServer.Start(); } else { log.Error("Unable to initialize configuration file '{0}' for server '{1}'.", configFinal, name); } } else { log.Error("Unable to copy files from directory '{0}' to '{1}'.", CommandProcessor.ProfileServerBinariesDirectory, instanceDirectory); } } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } log.Trace("(-):{0}", res); return(res); }