public void BeginPrinting(UInt16 Index, PlotterPenInfo Pen) { DTPMaster.CheckConnAndVal(); StartTime = DateTime.Now; if (ContentMaster == null) { ContentMaster = new PlotterContent(Master); } if (!ContentMaster.ContentTable.VectorAdresses.Contains(Index)) { RaiseErrorEvent(PrintErrorType.CantFoundFileWithSpecifiedIndex); return; } VectorMetaData metaData = ContentMaster.GetVectorMetaData(Index); if (XSize == 0) { XSize = GetXsize(metaData.Width, metaData.Height, YSize); } else { YSize = GetYsize(metaData.Width, metaData.Height, XSize); } GetCoefficients(new SizeF(metaData.Width, metaData.Height)); try { ph.StartPrinting(Pen.ElevationDelta, Pen.ElevationCorrection, (UInt16)XCoef, (UInt16)YCoef, Index); } catch { RaiseErrorEvent(PrintErrorType.CantFoundFileWithSpecifiedIndex); return; } Printing = true; Thread.Sleep(1000); StatusRequestTimer = new Thread(StatusRequestTimerHandler); StatusRequestTimer.Start(); }
public bool UploadVector(Vector vector, string name) { UInt16 index = (UInt16)(CountOfVectors + 1); string previewName = string.Format("{0}.p", index); string vectorName = string.Format("{0}.v", index); string metaDataName = string.Format("{0}.m", index); string previewPcName = string.Format("{1}\\Data\\Cache\\{0}", previewName, Environment.CurrentDirectory); string vectorPcName = string.Format("{1}\\Data\\Cache\\{0}", vectorName, Environment.CurrentDirectory); string metaDataPcName = string.Format("{1}\\Data\\Cache\\{0}", metaDataName, Environment.CurrentDirectory); var preview = new Bitmap(vector.ToBitmap(Color.White, Color.Black), new Size(500, 500)); var bytes = vector.ToBinnaryVector(); var meta = new VectorMetaData(this) { Height = (UInt16)vector.Header.Height, Index = index, Name = name, Type = vector.Header.VectType, Width = (UInt16)vector.Header.Width }; preview.Save(previewPcName); File.WriteAllBytes(vectorPcName, bytes); File.WriteAllBytes(metaDataPcName, meta.ToByteArray()); //Находим хэш файла пк. var localHash = CrCHandler.CRC32(vectorPcName); if (ContentTable.PreviewHashes.Values.Contains(localHash)) { //Если файл с таким хэшем есть на устройстве, то нечего его переотправлять. return(true); } var fileSender = Master.FileSender(FileTransferSecurityFlags.VerifyLengh | FileTransferSecurityFlags.VerifyCheckSum); fileSender.PacketLength = 2000; if (!fileSender.SendFileSync(vectorPcName, vectorName)) { return(false); } if (!fileSender.SendFileSync(previewPcName, previewName)) { return(false); } if (!fileSender.SendFileSync(metaDataPcName, metaDataName)) { return(false); } //Добавляем в нашу таблицу хэш данного вектора. ContentTable.VectorHashes.Add(index, CrCHandler.CRC32(vectorPcName)); //Хэш превью изображения. ContentTable.PreviewHashes.Add(index, CrCHandler.CRC32(previewPcName)); //Сам адресс вектора. ContentTable.VectorAdresses.Add(index); //Загружаем измененный конфиг на девайс. try { ContentTable.Upload(); } catch { //Особо неважно, что именно произошло. return(false); } return(true); }