public static void ClearCache() { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Clear Cache"); } tileMutex.WaitOne(); queueMutex.WaitOne(); WaitingTileQueueMutex.WaitOne(); try { WaitingTileQueue = new Queue <Tile>(); foreach (Tile t in tiles.Values) { try { t.CleanUp(true); } catch { } } tiles.Clear(); } finally { tileMutex.ReleaseMutex(); queueMutex.ReleaseMutex(); WaitingTileQueueMutex.ReleaseMutex(); } return; }
public ImageSetHelper(ImageSetType dataSetType, BandPass bandPass) { generic = true; this.name = "Generic"; this.sparse = false; this.dataSetType = dataSetType; this.bandPass = bandPass; this.quadTreeTileMap = ""; this.url = ""; this.levels = 0; this.baseTileDegrees = 0; this.imageSetID = 0; this.extension = ""; this.projection = ProjectionType.Equirectangular; this.bottomsUp = false; this.baseLevel = 0; this.mercator = (projection == ProjectionType.Mercator); this.centerX = 0; this.centerY = 0; this.rotation = 0; //todo add scale this.thumbnailUrl = ""; matrix = Matrix3d.Identity; matrix.Multiply(Matrix3d.RotationX((((Rotation)) / 180f * Math.PI))); matrix.Multiply(Matrix3d.RotationZ(((CenterY) / 180f * Math.PI))); matrix.Multiply(Matrix3d.RotationY((((360 - CenterX) + 180) / 180f * Math.PI))); Earth3d.AddImageSetToTable(this.GetHash(), this); }
public static Tile GetCachedTile(int level, int x, int y, IImageSet dataset, Tile parent) { if (level < dataset.BaseLevel) { return(null); } Tile retTile = null; long tileKey = ImageSetHelper.GetTileKey(dataset, level, x, y); try { if (!tiles.ContainsKey(tileKey)) { return(null); } else { retTile = tiles[tileKey]; } } catch { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile Initialize: Exception"); } } return(retTile); }
public void PreRender(Earth3d window) { if (OverlayLayer != null) { OverlayLayer.ShowEditUi = true; OverlayLayer.UiLines = lines; } }
public void PreRender(Earth3d window) { if (tour == null || tour.CurrentTourStop == null) { return; } UpdateSlideStates(); }
private void ProxyPort_Validated(object sender, EventArgs e) { if (ignoreChanges) { return; } Properties.Settings.Default.ProxyPort = ProxyPort.Text; Earth3d.UpdateProxySettings(); }
public static void PurgeQueue() { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Purging Queue"); } queueMutex.WaitOne(); queue.Clear(); RequestCount = 0; queueMutex.ReleaseMutex(); }
public void Render(Earth3d window) { if (popup == null) { popup = new ImageAlignPopup(); popup.Owner = Earth3d.MainWindow; popup.Show(); } // todo Draw Achor and tanget points.. return; }
public void Shutdown() { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Shutting Down Web Server"); } _bQuit = true; foreach (WebListener wl in listeners) { wl.Stop(); } listeners.Clear(); }
public static Tile GetTileNow(int level, int x, int y, IImageSet dataset, Tile parent) { if (level < dataset.BaseLevel) { return(null); } Tile retTile = null; long tileKey = ImageSetHelper.GetTileKey(dataset, level, x, y); try { if (!tiles.ContainsKey(tileKey)) { retTile = ImageSetHelper.GetNewTile(dataset, level, x, y, parent); tileMutex.WaitOne(); tiles.Add(tileKey, retTile); tileMutex.ReleaseMutex(); } else { retTile = tiles[tileKey]; } } catch { if (Earth3d.Logging) { Earth3d.WriteLogMessage("GetTile: Exception"); } } finally { //todoperf get rid of this write for GC retTile.AccessCount = AccessID++; } // Create if not ready to render if (!retTile.ReadyToRender) { TileCache.GetTileFromWeb(retTile, false); retTile.CreateGeometry(Earth3d.MainWindow.RenderContext11, false); } return(retTile); }
// Age things in queue. If they are not visible they will go away in time public static void DecimateQueue() { queueMutex.WaitOne(); removeList.Clear(); try { foreach (Tile t in queue.Values) { if (!t.RequestPending) { t.RequestHits = t.RequestHits / 2; try { if (t.RequestHits < 2)// && !t.DirectLoad) { removeList.Add(t.Key); } else if (!t.InViewFrustum) { removeList.Add(t.Key); } } catch { } } } foreach (long key in removeList) { queue.Remove(key); } } catch { if (Earth3d.Logging) { Earth3d.WriteLogMessage("DecimateQueue: Exception"); } } finally { queueMutex.ReleaseMutex(); } }
private Bitmap GetChartImageBitmap(Earth3d window) { Bitmap bmp = null; if (chartType == ChartTypes.Histogram) { if (!Stats.Computed) { Stats = layer.GetSingleColumnHistogram(TargetColumn); } bmp = GetBarChartBitmap(Stats); texture = Texture11.FromBitmap(bmp, 0); } else if (chartType == ChartTypes.BarChart) { if (!Stats.Computed) { Stats = layer.GetDomainValueBarChart(domainColumn, targetColumn, denominatorColumn, statType); } bmp = GetBarChartBitmap(Stats); texture = Texture11.FromBitmap(bmp, 0); } else if (chartType == ChartTypes.TimeChart) { if (!Stats.Computed) { Stats = layer.GetDateHistogram(TargetColumn, DateFilter); } bmp = GetBarChartBitmap(Stats); texture = Texture11.FromBitmap(bmp, 0); } Width = bmp.Width; Height = bmp.Height; Top = (int)window.RenderContext11.ViewPort.Height - (Height + 120); Left = (int)window.RenderContext11.ViewPort.Width / 2 - (Width / 2); return(bmp); }
protected override bool ProcessDialogKey(Keys keyData) { if (keyData == (Keys.F4 | Keys.Alt)) { dontClose = true; } if (keyData == (Keys.F1)) { if (this is TourEditTab) { WebWindow.OpenUrl("http://www.worldwidetelescope.org/Learn/?Authoring#slidebasedtours", true); } else { Earth3d.LaunchHelp(); } } return(base.ProcessDialogKey(keyData)); }
public static void AddFolderToSearch(Folder parent, bool sky) { foreach (Object child in parent.Children) { if (child is IImageSet) { IImageSet childImageset = (IImageSet)child; if (Earth3d.ProjectorServer) { Earth3d.AddImageSetToTable(childImageset.GetHash(), childImageset); } } if (child is IPlace) { IPlace place = (IPlace)child; if (place.StudyImageset != null) { if (Earth3d.ProjectorServer) { Earth3d.AddImageSetToTable(place.StudyImageset.GetHash(), place.StudyImageset); } } if (place.BackgroundImageSet != null) { if (Earth3d.ProjectorServer) { Earth3d.AddImageSetToTable(place.BackgroundImageSet.GetHash(), place.BackgroundImageSet); } } if (place.StudyImageset != null && (place.StudyImageset.Projection == ProjectionType.Toast || place.StudyImageset.Projection == ProjectionType.Equirectangular)) { continue; } AddPlaceToContextSearch(place); } if (child is Folder) { AddFolderToSearch((Folder)child, sky); } } }
public ImageSetHelper(string name, string url, ImageSetType dataSetType, BandPass bandPass, ProjectionType projection, int imageSetID, int baseLevel, int levels, int tileSize, double baseTileDegrees, string extension, bool bottomsUp, string quadTreeMap, double centerX, double centerY, double rotation, bool sparse, string thumbnailUrl, bool defaultSet, bool elevationModel, int wf, double offsetX, double offsetY, string credits, string creditsUrl, string demUrlIn, string alturl, double meanRadius, string referenceFrame) { this.ReferenceFrame = referenceFrame; this.MeanRadius = meanRadius; this.altUrl = alturl; this.demUrl = demUrlIn; this.creditsText = credits; this.creditsUrl = creditsUrl; this.offsetY = offsetY; this.offsetX = offsetX; this.widthFactor = wf; this.elevationModel = elevationModel; this.defaultSet = defaultSet; this.name = name; this.sparse = sparse; this.dataSetType = dataSetType; this.bandPass = bandPass; this.quadTreeTileMap = quadTreeMap; this.url = url; this.levels = levels; this.baseTileDegrees = baseTileDegrees; this.imageSetID = imageSetID; this.extension = extension; this.projection = projection; this.bottomsUp = bottomsUp; this.baseLevel = baseLevel; this.mercator = (projection == ProjectionType.Mercator); this.centerX = centerX; this.centerY = centerY; this.rotation = rotation; this.thumbnailUrl = thumbnailUrl; ComputeMatrix(); //if (Earth3d.multiMonClient) { Earth3d.AddImageSetToTable(this.GetHash(), this); } }
public static Tile GetTile(int level, int x, int y, IImageSet dataset, Tile parent) { if (level < dataset.BaseLevel) { return(null); } Tile retTile = null; long tileKey = ImageSetHelper.GetTileKey(dataset, level, x, y); try { if (!tiles.ContainsKey(tileKey)) { retTile = ImageSetHelper.GetNewTile(dataset, level, x, y, parent); tileMutex.WaitOne(); tiles.Add(tileKey, retTile); tileMutex.ReleaseMutex(); } else { retTile = tiles[tileKey]; } } catch { if (Earth3d.Logging) { Earth3d.WriteLogMessage("GetTile: Exception"); } } finally { //todoperf get rid of this write for GC retTile.AccessCount = AccessID++; } return(retTile); }
public void Render(Earth3d window) { //todo11 reanble this if (texture == null) { Bitmap bmp = null; bmp = GetChartImageBitmap(window); bmp.Dispose(); } Sprite2d.Draw2D(window.RenderContext11, texture, new SizeF(texture.Width, texture.Height), new PointF(0, 0), 0, new PointF(Left + texture.Width / 2, Top + texture.Height / 2), Color.White); if (!String.IsNullOrEmpty(HoverText)) { Rectangle recttext = new Rectangle((int)(hoverPoint.X + 15), (int)(hoverPoint.Y - 8), 0, 0); } return; }
public void ListenerThreadFunc(object data) { WebListener webListener = data as WebListener; if (webListener == null) { return; } _RunCount++; while (!_bQuit) { try { //Accept a new connection Socket mySocket = webListener.Listener.AcceptSocket(); if (mySocket.Connected) { if (AsyncRequests) { ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), mySocket); } else { HandleRequest(mySocket); } } } catch { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Web Server Listener Exception"); } } } _RunCount--; }
public void Render(Earth3d window) { window.SetupMatricesOverlays(); window.RenderContext11.DepthStencilMode = DepthStencilMode.Off; if (tour == null || tour.CurrentTourStop == null) { return; } if (ProjectorServer) { overlayBlend.State = true; } if (!onTarget && !ProjectorServer) { slideStartTime = SpaceTimeController.MetaNow; if (Earth3d.MainWindow.OnTarget(Tour.CurrentTourStop.Target)) { onTarget = true; overlayBlend.State = !Tour.CurrentTourStop.FadeInOverlays; overlayBlend.TargetState = true; if (!PreRoll) { if (tour.CurrentTourStop.MusicTrack != null) { tour.CurrentTourStop.MusicTrack.Play(); } if (tour.CurrentTourStop.VoiceTrack != null) { tour.CurrentTourStop.VoiceTrack.Play(); } foreach (Overlay overlay in tour.CurrentTourStop.Overlays) { overlay.Play(); } } LayerManager.SetVisibleLayerList(tour.CurrentTourStop.Layers); if (tour.CurrentTourStop.KeyFramed) { tour.CurrentTourStop.KeyFrameMover.CurrentDateTime = tour.CurrentTourStop.StartTime; tour.CurrentTourStop.KeyFrameMover.CurrentPosition = tour.CurrentTourStop.Target.CamParams; tour.CurrentTourStop.KeyFrameMover.MoveTime = (double)(tour.CurrentTourStop.Duration.TotalMilliseconds / 1000.0); Earth3d.MainWindow.Mover = tour.CurrentTourStop.KeyFrameMover; } else if (tour.CurrentTourStop.EndTarget != null && tour.CurrentTourStop.EndTarget.ZoomLevel != -1) { if (tour.CurrentTourStop.Target.Type == ImageSetType.SolarSystem) { tour.CurrentTourStop.Target.UpdatePlanetLocation(SpaceTimeController.UtcToJulian(tour.CurrentTourStop.StartTime)); tour.CurrentTourStop.EndTarget.UpdatePlanetLocation(SpaceTimeController.UtcToJulian(tour.CurrentTourStop.EndTime)); } Earth3d.MainWindow.Mover = new ViewMoverKenBurnsStyle(tour.CurrentTourStop.Target.CamParams, tour.CurrentTourStop.EndTarget.CamParams, tour.CurrentTourStop.Duration.TotalMilliseconds / 1000.0, tour.CurrentTourStop.StartTime, tour.CurrentTourStop.EndTime, tour.CurrentTourStop.InterpolationType); } Settings.TourSettings = tour.CurrentTourStop; SpaceTimeController.Now = tour.CurrentTourStop.StartTime; SpaceTimeController.SyncToClock = false; } } if (currentMasterSlide != null) { foreach (Overlay overlay in currentMasterSlide.Overlays) { overlay.TweenFactor = 1f; overlay.Draw3D(window.RenderContext11, 1.0f, false); } } if (onTarget || ProjectorServer) { foreach (Overlay overlay in tour.CurrentTourStop.Overlays) { if (!Tour.CurrentTourStop.KeyFramed || (overlay.Animate && overlay.AnimationTarget == null)) { overlay.TweenFactor = (float)CameraParameters.EaseCurve(tour.CurrentTourStop.TweenPosition, overlay.InterpolationType == InterpolationType.Default ? tour.CurrentTourStop.InterpolationType : overlay.InterpolationType); } overlay.Draw3D(window.RenderContext11, overlayBlend.Opacity, false); } } }
void IUiController.Render(Earth3d window) { return; }
private void ExportCache_Click(object sender, EventArgs e) { Earth3d.ExtractCache(); }
public void PreRender(Earth3d window) { }
void IUiController.Render(Earth3d window) { lines.DrawLines(window.RenderContext11, 1); return; }
public static void GetDemTileFromWeb(Tile retTile) { string directory = retTile.DemDirectory; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string filename = retTile.DemFilename; FileInfo fi = new FileInfo(filename); bool exists = fi.Exists; if (exists) { if (fi.Length != 2178 && fi.Length != 1026 && fi.Length != 2052 && (retTile.Dataset.Projection != ProjectionType.Mercator)) { try { File.Delete(filename); } catch { } exists = false; } } if (!exists) { try { WebClient Client = new WebClient(); Client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"); string dlFile = string.Format("{0}.tmp{1}", filename, NodeID); Client.DownloadFile(CacheProxy.GetCacheUrl(retTile.DemURL), dlFile); try { if (File.Exists(dlFile)) { if (File.Exists(filename)) { File.Delete(filename); } File.Move(dlFile, filename); } } catch { } fi = new FileInfo(filename); exists = fi.Exists; } catch { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Dem Download: Exception"); } exists = false; } } retTile.DemReady = true; retTile.demFileExists = exists; return; }
public bool Startup() { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Starting Web Server"); } SetAccessLists(); if (!initializedOnce) { RequestHandler.RegisterHandler(new HTTPImagesetWtml()); RequestHandler.RegisterHandler(new HTTPLayerApi()); RequestHandler.RegisterHandler(new HttpXmlRpc()); RequestHandler.RegisterHandler(new HttpImageFiles()); RequestHandler.RegisterHandler(new HttpCrossDomain()); RequestHandler.RegisterHandler(new HttpClientStatus()); XmlRpcMethod.RegisterDispatchMap(new SampClientReceiveNotification()); initializedOnce = true; } try { // Find IPV4 Address _bQuit = false; IpAddress = ""; listeners.Clear(); WebListener listener = null; foreach (IPAddress ipAdd in Dns.GetHostEntry(Dns.GetHostName()).AddressList) { if (ipAdd.AddressFamily == AddressFamily.InterNetwork) { if (string.IsNullOrEmpty(IpAddress)) { IpAddress = ipAdd.ToString(); } if (ipAdd.ToString() != "127.0.0.1") { if (Earth3d.Logging) { Earth3d.WriteLogMessage(" Web Server - Adding:" + ipAdd.ToString()); } listener = new WebListener(new ParameterizedThreadStart(ListenerThreadFunc), ipAdd); listeners.Add(listener); listener.Start(); } } } if (Earth3d.Logging) { Earth3d.WriteLogMessage(" Web Server - Adding Loopback"); } // Add Loopback localhost listener = new WebListener(new ParameterizedThreadStart(ListenerThreadFunc), IPAddress.Loopback); listeners.Add(listener); listener.Start(); } catch (Exception e) { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Failed Starting Web Server"); Earth3d.WriteLogMessage(e.Message); Earth3d.WriteLogMessage(e.Source); Earth3d.WriteLogMessage(e.StackTrace); } _bQuit = true; return(false); } return(true); }
public static void HandleRequest(object param) { Socket mySocket = (Socket)param; int iStartPos = 0; String sRequest; String sErrorMessage; try { //Console.WriteLine("\nClient Connected!!\n==================\nCLient IP {0}\nLocal IP {1}", mySocket.RemoteEndPoint, mySocket.LocalEndPoint) ; //make a byte array and receive data from the client Byte[] bReceive = new Byte[4096]; int i = mySocket.Receive(bReceive, bReceive.Length, 0); //Convert Byte to String string sBuffer = Encoding.UTF8.GetString(bReceive, 0, i); string body = ""; int bodySize = 0; if (string.IsNullOrEmpty(sBuffer) || (sBuffer.Substring(0, 3) != "GET" && sBuffer.Substring(0, 4) != "POST")) { mySocket.Close(); return; } if (sBuffer.Substring(0, 4) == "POST") { string contentLength = "Content-Length:"; int start = sBuffer.IndexOf(contentLength); int bodyLeft = bodySize; if (start > -1) { start += contentLength.Length; string length = sBuffer.Substring(start); length = length.Substring(0, length.IndexOf("\r")); bodySize = Convert.ToInt32(length); bodyLeft = bodySize; int bodyStart = sBuffer.IndexOf("\r\n\r\n") + 4; if (sBuffer.Length > bodyStart) { body = sBuffer.Substring(bodyStart); bodyLeft = bodySize - body.Length; } } bool sentContinue = false; int count = 0; bool firstTime = true; if (bodyLeft > 0) { StringBuilder sb = new StringBuilder(body, bodySize); while (bodyLeft > 0) { if (!firstTime && (bodyLeft == bodySize) && !sentContinue && (sBuffer.Contains("Expect: 100-continue"))) { RequestHandler.SendContinue(ref mySocket); sentContinue = true; } firstTime = false; string moreData = RequestHandler.GetBody(bodyLeft, ref mySocket); bodyLeft -= moreData.Length; sb.Append(moreData); count++; } body = sb.ToString(); } } // Look for HTTP request iStartPos = sBuffer.IndexOf("HTTP", 1); // Get the HTTP _Text and version e.g. it will return "HTTP/1.1" RequestHandler.HttpVersion = sBuffer.Substring(iStartPos, 8); // Extract the Requested Type and Requested file/directory sRequest = sBuffer.Substring(0, iStartPos - 1); //Replace backslash with Forward Slash, if Any sRequest.Replace("\\", "/"); //Console.WriteLine("Request: " + sRequest); // Check authentication from whitelist IPEndPoint ipep = mySocket.RemoteEndPoint as IPEndPoint; bool authenticated = true; if (ipep != null) { authenticated = IsAuthorized(ipep.Address); } try { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Web Request:" + sRequest); } RequestHandler rh = RequestHandler.GetHandler(sRequest); if (rh != null) { rh.ProcessRequest(sRequest, ref mySocket, authenticated, body); mySocket.Close(); return; } //Console.WriteLine("Sending 404 error"); sErrorMessage = "<H2>Error!! No Default File Name Specified</H2>"; RequestHandler.SendHeader(RequestHandler.HttpVersion, "", sErrorMessage.Length, " 404 Not Found", ref mySocket); RequestHandler.SendToBrowser(sErrorMessage, ref mySocket); mySocket.Close(); } catch (Exception ex) { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Web Server Request Exception" + ex.Message); } sErrorMessage = "<H2>Error: " + ex.ToString() + "</H2>"; RequestHandler.SendHeader(RequestHandler.HttpVersion, "", sErrorMessage.Length, " 200 OK", ref mySocket); RequestHandler.SendHeader(RequestHandler.HttpVersion, "", sErrorMessage.Length, " 404 Not Found", ref mySocket); RequestHandler.SendToBrowser(sErrorMessage, ref mySocket); mySocket.Close(); return; } } catch { } }
private void ImportCache_Click(object sender, EventArgs e) { Earth3d.RestoreCache(); }
private void ComputeWcs() { if (header.ContainsKey("CROTA2")) { rotation = Convert.ToDouble(header["CROTA2"].Trim()); hasRotation = true; } if (header.ContainsKey("CDELT1")) { scaleX = Convert.ToDouble(header["CDELT1"].Trim()); if (header.ContainsKey("CDELT2")) { scaleY = Convert.ToDouble(header["CDELT2"].Trim()); hasScale = true; } } if (header.ContainsKey("CRPIX1")) { referenceX = Convert.ToDouble(header["CRPIX1"].Trim()) - 1; if (header.ContainsKey("CRPIX2")) { referenceY = Convert.ToDouble(header["CRPIX2"].Trim()) - 1; hasPixel = true; } } bool galactic = false; bool tan = false; if (header.ContainsKey("CTYPE1")) { if (header["CTYPE1"].Contains("GLON-")) { galactic = true; tan = true; } if (header["CTYPE2"].Contains("GLAT-")) { galactic = true; tan = true; } if (header["CTYPE1"].Contains("-TAN")) { tan = true; } if (header["CTYPE1"].Contains("-SIN")) { tan = true; } } if (!tan) { throw new System.Exception("Only TAN projected images are supported: "); } hasSize = true; if (header.ContainsKey("CRVAL1")) { centerX = Convert.ToDouble(header["CRVAL1"].Trim()); if (header.ContainsKey("CRVAL2")) { centerY = Convert.ToDouble(header["CRVAL2"].Trim()); hasLocation = true; } } if (galactic) { double[] result = Earth3d.GalactictoJ2000(centerX, centerY); centerX = result[0]; centerY = result[1]; } if (header.ContainsKey("CD1_1") && header.ContainsKey("CD1_2") && header.ContainsKey("CD2_1") && header.ContainsKey("CD2_2")) { cd1_1 = Convert.ToDouble(header["CD1_1"].Trim()); cd1_2 = Convert.ToDouble(header["CD1_2"].Trim()); cd2_1 = Convert.ToDouble(header["CD2_1"].Trim()); cd2_2 = Convert.ToDouble(header["CD2_2"].Trim()); if (!hasRotation) { CalculateRotationFromCD(); } if (!hasScale) { CalculateScaleFromCD(); } hasScale = true; hasRotation = true; } ValidWcs = hasScale && hasRotation && hasPixel && hasLocation; }
public override void ProcessRequest(string request, ref Socket socket, bool authenticated, string body) { bool cache = true; QueryString query = new QueryString(request); String sMimeType = "image/JPEG"; if (request.ToLower().IndexOf(".png") > -1) { sMimeType = "image/PNG"; } int iTotBytes = 0; string fileName = request.Substring(request.LastIndexOf("/") + 1); byte[] data = new byte[0]; if (request.Contains("/tour/")) { if (Earth3d.MainWindow.TourEdit != null) { TourDocument tour = Earth3d.MainWindow.TourEdit.Tour; if (fileName.ToLower() == "slidelist.xml") { sMimeType = "text/xml"; data = tour.GetSlideListXML(); } else if (tour != null) { data = ReadBinaryWebFileFromDisk(tour.WorkingDirectory + fileName); } } else { if (fileName.ToLower() == "slidelist.xml") { sMimeType = "text/xml"; data = TourDocument.GetEmptySlideListXML(); } } } else if (fileName == "refresh.png") { Earth3d.RefreshCommunity(); } else if (fileName == "screenshot.png") { if (ScreenBroadcast.Capturing) { data = ScreenBroadcast.ScreenImage; } } else if (request.Contains("/imageset/")) { string[] parts = request.Split(new char[] { '/' }); IImageSet imageset = (IImageSet)Earth3d.ImagesetHashTable[Convert.ToInt32(parts[2])]; if (imageset != null) { data = ReadBinaryWebFileFromDisk(imageset.Url); } } else if (fileName == "layermap") { SendBinaryFileFromDisk(Properties.Settings.Default.CahceDirectory + "\\layerSync.layers", ref socket, sMimeType); return; } else if (fileName == "tour.wtt") { SendBinaryFileFromDisk(Properties.Settings.Default.CahceDirectory + "\\tourSync.wtt", ref socket, sMimeType); return; } else if (fileName == "colorsettings") { data = NetControl.GetColorSettingsData(); } else if (fileName == "executable") { SendBinaryFileFromDisk("wwtexplorer.exe", ref socket, sMimeType); return; } else if (fileName.StartsWith("distort") || fileName.StartsWith("blend")) { string path = String.Format("{0}\\ProjetorWarpMaps\\", Properties.Settings.Default.CahceDirectory); data = ReadBinaryWebFileFromDisk(path + fileName); } else { data = ReadBinaryWebFile(fileName); } iTotBytes = data.Length; SendHeader(HttpVersion, sMimeType, iTotBytes, " 200 OK", ref socket, cache); SendToBrowser(data, iTotBytes, ref socket); }
public static Tile GetTileFromWeb(Tile retTile, bool Initialize) { WebClient Client = null; if (retTile.Dataset.Projection == ProjectionType.SkyImage && retTile.Dataset.Url.EndsWith("/screenshot.png")) { SkyImageTile tile = retTile as SkyImageTile; Client = new WebClient(); string url = tile.URL; tile.ImageData = Client.DownloadData(url); retTile.DemReady = true; retTile.FileExists = true; retTile.ReadyToRender = true; retTile.TextureReady = true; //retTile.CreateGeometry(Tile.prepDevice); Client.Dispose(); return(retTile); } Tile parent = retTile.Parent; if (retTile.DemEnabled && (parent == null || (parent != null && parent.DemGeneration == 0))) { GetDemTileFromWeb(retTile); } else { retTile.DemReady = true; } if (retTile.Dataset.WcsImage != null && retTile.Dataset.WcsImage is FitsImage) { retTile.TextureReady = true; InitializeTile(retTile); return(retTile); } string directory = retTile.Directory; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string filename = retTile.FileName; Client = new WebClient(); FileInfo fi = new FileInfo(filename); bool exists = fi.Exists; if (exists) { if (fi.Length != 8 && fi.Length < 100 || retTile.Volitile) { try { File.Delete(filename); } catch { } exists = false; } } if (!exists) { try { if (retTile.Dataset.IsMandelbrot) { retTile.ComputeMandel(); fi = new FileInfo(filename); exists = fi.Exists; } else { Client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"); string url = retTile.URL; if (string.IsNullOrEmpty(url)) { retTile.errored = true; } else { string dlFile = string.Format("{0}.tmp{1}", filename, NodeID); Client.DownloadFile(CacheProxy.GetCacheUrl(url), dlFile); try { if (File.Exists(dlFile)) { if (File.Exists(filename)) { File.Delete(filename); } File.Move(dlFile, filename); } } catch { // UiTools.ShowMessageBox("File Download collision catch"); } fi = new FileInfo(filename); exists = fi.Exists; } // Code for drawing tile it onto tile for debuggin //if (retTile.Dataset.Projection == ProjectionType.Toast) //{ // //Bitmap bmpText = new Bitmap(filename); // Bitmap bmpText = UiTools.LoadBitmap(filename); // Graphics g = Graphics.FromImage(bmpText); // g.DrawString(retTile.Key, UiTools.StandardRegular, UiTools.StadardTextBrush, new RectangleF(0, 0, 255, 255), UiTools.StringFormatCenterCenter); // g.Flush(); // g.Dispose(); // bmpText.Save(filename); // bmpText.Dispose(); //} } } catch { //todo retry login on non - HTTP failuers. if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile Download: Exception"); } retTile.errored = true; } } try { if (exists) { if (fi.Length < 100 || (fi.Length == 1033)) { retTile.errored = true; return(retTile); } } // todo 3d Cities remove support for 3d Cities for now if (retTile.Dataset.Projection == ProjectionType.Mercator && Properties.Settings.Default.Show3dCities) { string tileID = retTile.GetTileID(); //check coverage cache before downloading int gen = CoverageMap.GetCoverage(tileID); if (gen > 0) { //try downloading mesh try { string meshFilename = retTile.FileName + ".mesh"; if (!File.Exists(meshFilename)) { Client.Headers.Add("User-Agent", "Win8Microsoft.BingMaps.3DControl/2.214.2315.0 (;;;;x64 Windows RT)"); string dlFile = string.Format("{0}.tmp{1}", meshFilename, NodeID); Client.DownloadFile(string.Format("http://ak.t{1}.tiles.virtualearth.net/tiles/mtx{0}?g={2}", tileID, Tile.GetServerID(retTile.X, retTile.Y), gen.ToString()), dlFile); try { if (File.Exists(dlFile)) { if (File.Exists(meshFilename)) { File.Delete(meshFilename); } File.Move(dlFile, meshFilename); } } catch { // UiTools.ShowMessageBox("File Download collision catch"); } } } catch { } } } retTile.FileExists = true; retTile.TextureReady = true; if (Initialize) { InitializeTile(retTile); } } catch (System.Exception) { if (Earth3d.Logging) { Earth3d.WriteLogMessage("Tile Initialize: Exception"); } retTile.errored = true; } return(retTile); }