/// <summary> /// Creates instance of profile server from snapshot. /// </summary> /// <param name="Snapshot">Profile server snapshot.</param> /// <returns>New profile server instance.</returns> public static ProfileServer CreateFromSnapshot(ProfileServerSnapshot Snapshot) { ProfileServer res = new ProfileServer(Snapshot.Name, new GpsLocation(Snapshot.LocationLatitude, Snapshot.LocationLongitude), Snapshot.BasePort); res.availableIdentitySlots = Snapshot.AvailableIdentitySlots; res.clientAppServiceInterfacePort = Snapshot.ClientAppServiceInterfacePort; res.clientCustomerInterfacePort = Snapshot.ClientCustomerInterfacePort; res.clientNonCustomerInterfacePort = Snapshot.ClientNonCustomerInterfacePort; res.ipAddress = IPAddress.Parse(Snapshot.IpAddress); res.locPort = Snapshot.LocPort; res.networkId = Crypto.FromHex(Snapshot.NetworkId); res.primaryInterfacePort = Snapshot.PrimaryInterfacePort; res.serverNeighborInterfacePort = Snapshot.ServerNeighborInterfacePort; res.instanceDirectory = res.GetInstanceDirectoryName(); res.locServer = new LocServer(res); byte[] ipBytes = res.ipAddress.GetAddressBytes(); Iop.Locnet.NodeContact contact = new Iop.Locnet.NodeContact() { IpAddress = ProtocolHelper.ByteArrayToByteString(ipBytes), ClientPort = (uint)res.locPort, NodePort = (uint)res.locPort }; return(res); }
/// <summary> /// Loads snapshot from snapshot folder. /// </summary> /// <returns>true if the function succeeds, false otherwise.</returns> public bool Load() { log.Trace("()"); bool error = false; try { log.Debug("Loading profile servers information."); string serializedProfileServers = File.ReadAllText(profileServersFile); log.Debug("Deserializing profile servers information."); ProfileServers = JsonConvert.DeserializeObject <List <ProfileServerSnapshot> >(serializedProfileServers); log.Debug("Loading identities information."); string serializedIdentities = File.ReadAllText(identitiesFile); log.Debug("Deserializing identities information."); Identities = JsonConvert.DeserializeObject <List <IdentitySnapshot> >(serializedIdentities); log.Debug("Loading images information."); string serializedImages = File.ReadAllText(imagesFile); log.Debug("Deserializing images information."); Images = JsonConvert.DeserializeObject <Dictionary <string, string> >(serializedImages); log.Debug("Loading profile servers instance folders."); foreach (ProfileServerSnapshot server in ProfileServers) { string serverInstanceDirectory = ProfileServer.GetInstanceDirectoryName(server.Name); string snapshotInstanceDirectory = Path.Combine(new string[] { snapshotDirectory, "bin", server.Name }); log.Debug("Copying '{0}' to '{1}'.", snapshotInstanceDirectory, serverInstanceDirectory); if (!Helpers.DirectoryCopy(snapshotInstanceDirectory, serverInstanceDirectory)) { log.Error("Unable to copy files from directory '{0}' to '{1}'.", snapshotInstanceDirectory, serverInstanceDirectory); error = true; break; } } } catch (Exception e) { log.Error("Exception occurred while trying to load serialized simulation files: {0}", e.ToString()); error = true; } bool res = !error; log.Trace("(-):{0}", res); return(res); }