public static T GetContent <T>(PathType contentType, string contentFileName) where T : class { string path = Path.Combine(GetPath(contentType), contentFileName); object retT = null; Type tType = typeof(T); if (tType == typeof(Image)) { retT = Bitmap.FromFile(path); } else if (tType == typeof(System.Media.SoundPlayer)) { retT = new System.Media.SoundPlayer(path); } else if (tType == typeof(MapResponse)) { retT = FileControler.Open(path); } else { retT = System.IO.File.OpenRead(path); } return(retT as T); }
/// <summary> /// 建立更新控制端 /// </summary> /// <param name="code"></param> private void builtUpdateControler(BaseCommunication sender, Code code) { BaseControler controler = sender as BaseControler; if (controler != null) { PortCode readyCode = code as PortCode; if (readyCode != null) { if (serverupdateControler == null) { serverupdateControler = new FileControler(controler.ServerAddress, readyCode.Port); } if (serverupdateControler != null) { serverupdateControler.CloseConnections(); Thread.Sleep(500); serverupdateControler = new FileControler(controler.ServerAddress, readyCode.Port); serverupdateControler.SourceFile = updatedFile; serverupdateControler.DestinationFile = ICanSeeYou.Common.IO.GetName(updatedFile); serverupdateControler.IsDownload = false;//上传更新文件 serverupdateControler.Open(); } } } }
/// <summary> /// 下载或上传文件 /// </summary> /// <param name="sourceFile">原文件</param> /// <param name="destinationFile">目标文件</param> /// <param name="destinationFile">是否下载命令(true表示下载,false表示上传)</param> public void DownOrUpload(string sourceFile, string destinationFile, bool IsDownloaded) { if (fileControler != null) { fileControler.CloseConnections(); fileControler.SourceFile = sourceFile; fileControler.DestinationFile = destinationFile; fileControler.IsDownload = IsDownloaded; fileControler.Open(); } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = FileControler.FILTER; if (ofd.ShowDialog() == DialogResult.OK && System.IO.File.Exists(ofd.FileName)) { this.IsNew = false; this.MapPath = ofd.FileName; this.BrickPath = FileControler.GetPath(ofd.FileName) + "Bricks\\"; MapResponse response = FileControler.Open(ofd.FileName); this.pcmMapPaint.TileHeigth = response.TileHeight; this.pcmMapPaint.TileWidth = response.TileWidth; this.pcmMapPaint.QtdColumns = response.Matrix.Columns; this.pcmMapPaint.QtdRows = response.Matrix.Rows; this.pcmMapPaint.Cells = response.Matrix; this.ltvBricks.Items.Clear(); for (int i = 0; i < response.Bricks.Count; i++) { Brick brk = response.Bricks[i]; brk.IsNew = false; brk.Image = Bitmap.FromFile(this.BrickPath + brk.ImagePath); BrickListItem item = new BrickListItem(); item.Brick = brk; item.Text = brk.ImagePath; this.ltvBricks.Items.Add(item); } this.pcmMapPaint.Invalidate(); dudWidth.Text = this.pcmMapPaint.TileHeigth.ToString(); dudHeigth.Text = this.pcmMapPaint.TileWidth.ToString(); nudColumns.Value = this.pcmMapPaint.QtdColumns; nudRows.Value = this.pcmMapPaint.QtdRows; this.lblSize.Text = pcmMapPaint.Width.ToString() + "x" + pcmMapPaint.Height.ToString(); } }