/// <summary> /// Does the actual work of pulling the filestreams in /// and passing the blocks into the crytoprovider /// </summary> /// <param name="filenames">An array of String objects, each containing a filename</param> /// <param name="cryptoInterface">An <see cref="ICryptoTransform"/> interface pointing to a cryptoprovider</param> /// <param name="blockSize">Size in bytes of the transform block / read buffer</param> protected void ComputeHashes(String[] filenames, ICryptoTransform cryptoInterface, int blockSize) { for (int loop = 0; loop <= filenames.GetUpperBound(0); loop++) { using (FileStream inputFile = new FileStream(filenames[loop], FileMode.Open, FileAccess.Read)) { byte[] readBuffer = new byte[(int)blockSize]; byte[] copyBuffer; long fileLength = inputFile.Length; int bytesRead = 0; long totalBytesRead = 0; while (totalBytesRead < fileLength) { bytesRead = inputFile.Read(readBuffer, 0, (int)blockSize); if (bytesRead == blockSize) { copyBuffer = readBuffer; } else { copyBuffer = new byte[bytesRead]; Array.Copy(readBuffer, copyBuffer, bytesRead); } totalBytesRead += bytesRead; if (totalBytesRead == fileLength && loop == filenames.GetUpperBound(0)) { // Last block of the last file cryptoInterface.TransformFinalBlock(copyBuffer, 0, copyBuffer.Length); } else { cryptoInterface.TransformBlock(copyBuffer, 0, copyBuffer.Length, copyBuffer, 0); } // Report progress and // check for cancellation request OnHashBlockProcessed(new HasherEventArgs(HasherEventReportType.ProgressReport, filenames.Length, loop + 1, totalBytesRead, fileLength)); if (this.cancelRequested == true) { throw new OperationCanceledException(); } } } } // Report hash computed OnHashComputed(new HasherEventArgs(HasherEventReportType.Completed, null, null, null, null)); }
//Splits a string array into download files array. private DownloadFileInfo[] StringToDownloadFilesArray(String[] downloadList) { DownloadFileInfo[] filesList = null; Int32 currentFileIndex = -1; for (Int32 i = 0; i <= downloadList.GetUpperBound(0); i++) { String[] lineSplit = downloadList[i].Split(new String[] { "=" }, StringSplitOptions.None); switch (lineSplit[0]) { case "FileInfoStart": if (filesList == null) { filesList = new DownloadFileInfo[1]; } else { Array.Resize(ref filesList, filesList.GetUpperBound(0) + 2); } currentFileIndex = filesList.GetUpperBound(0); break; case "PATH": filesList[currentFileIndex].Path = lineSplit[1]; break; case "URL": filesList[currentFileIndex].Url = lineSplit[1]; break; case "HASH": filesList[currentFileIndex].Hash = lineSplit[1]; break; case "ACTION": filesList[currentFileIndex].Action = lineSplit[1]; break; case "NAME": filesList[currentFileIndex].Name = lineSplit[1]; break; case "SIZE": filesList[currentFileIndex].Size = Int64.Parse(lineSplit[1]); break; } } return filesList; }
private void show() { Board bord = controller.Game.Board; Square[,] field = bord.TwoDBord; String[,] text = new String[field.GetUpperBound(0) * 2 + 1, field.GetUpperBound(1) * 2 + 1]; for (int y = 0; y <= text.GetUpperBound(0); y++) { for (int x = 0; x <= text.GetUpperBound(1); x++) { text[y, x] = " "; } } int Yofset = 0; int Ymax = text.GetUpperBound(0), Xmax = text.GetUpperBound(1); string hor = "---"; string ver = " | "; for (int y = 0; y <= field.GetUpperBound(0); y++) { int Xofset = 0; for (int x = 0; x <= field.GetUpperBound(1); x++) { if (field[y, x] != null) { text[y + Yofset, x + Xofset] = field[y, x].View.getText(); for (int i = 0; i < field[y, x].links.Length; i++) { bool NotNull = field[y, x].links[i] != null; switch (i) { case 0: if (NotNull && y + Yofset - 1 >= 0) { text[y + Yofset - 1, x + Xofset] = ver; } break; case 1: if (NotNull && x + Xofset + 1 < Xmax) { text[y + Yofset, x + Xofset + 1] = hor; } break; case 2: if (NotNull && y + Yofset + 1 < Ymax) { text[y + Yofset + 1, x + Xofset] = ver; } break; case 3: if (NotNull && x + Xofset - 1 >= 0) { text[y + Yofset, x + Xofset - 1] = hor; } break; } } } else { text[y + Yofset, x + Xofset] = " "; } Xofset++; } Yofset++; } //actual printing //"\ X: 01 02 03" //"Y __________________" //"01 | < >---< >---< >" Console.Clear(); Console.WriteLine("Current turn: " + controller.Game.CurrentPlayer.Color.ToString()); Console.Write("Dice throw: " + controller.Game.CurrentDiceRoll); if (controller.Game.CurrentDiceRoll == 0) { Console.Write(" use the commando throwdice to start your turn"); } Console.WriteLine(); if (controller.Game.CurrentPlayer.Baricade != null) { Console.WriteLine("There is a Baricade in possesion. you must place it to end your turn"); } Console.Write("\\ X:"); String underLine = " "; for (int i = 0; i <= text.GetUpperBound(1)/2; i++) { string s = ""; if (i + 1 < 10) { s = " "; } s += (i + 1).ToString(); Console.Write(" " + s + " "); underLine += "______"; } Console.WriteLine(); Console.WriteLine("Y" + underLine); for (int y = 0; y <= text.GetUpperBound(0); y++) { if (y % 2 == 0) { if (((y/2) + 1) < 10) { Console.Write(" " + ((y/2)+1)); } else { Console.Write((y/2)+1); } } else { Console.Write(" "); } Console.Write(" | "); for (int x = 0; x <= text.GetUpperBound(1); x++) { Console.Write(text[y, x]); } Console.WriteLine(" |"); } Console.WriteLine(" " + underLine); for (int i = 0; i < controller.Game.Players.List.Count; i++) { Player p = controller.Game.Players.List[i]; Console.WriteLine(p.PlayerPawns[0].View.getChar()+": "+p.PlayerSquare.Pieces.Count); } if (controller.Game.Board.ForestSquare != null) { Console.Write("Forrest: "); if (controller.Game.Board.ForestSquare.Pieces.Count == 0) { Console.WriteLine("0"); } else { for (int i = 0; i < controller.Game.Board.ForestSquare.Pieces.Count; i++) { Console.Write(controller.Game.Board.ForestSquare.Pieces[i].View.getChar() + " "); } Console.WriteLine(); } } Console.WriteLine(); if (commandline == "") { commandline = "<empty>"; } Console.WriteLine("Command: " + commandline); Console.WriteLine(); Console.WriteLine(); }
/// <summary> /// creates a list of "EDStations" with price listings from csv-array in EDDB format /// </summary> /// <param name="CSV_Strings">String to be converted</param> /// <param name="foundSystems"></param> /// <param name="csvRowList">for optional processing outside: a list of the data converted to CsvRow-objects</param> /// <returns></returns> public List<EDStation> fromCSV_EDDB(String[] CSV_Strings) { List<EDStation> foundValues = new List<EDStation>(); Dictionary<Int32, Int32> foundIndex = new Dictionary<Int32, Int32>(); Dictionary<String, Int32> foundSystemIndex = new Dictionary<String, Int32>(); Int32 LastID = 0; EDSystem LastSystem = null; Int32 currentID = 0; EDStation currentStation = null; Int32 Index = 0; Dictionary<String, Int32> commodityIDCache = new Dictionary<string,Int32>(); // quick cache for finding commodity names Int32 currentItem = 0; ProgressEventArgs eva; try { eva = new ProgressEventArgs() { Info="converting data...", CurrentValue=currentItem, TotalValue=CSV_Strings.GetUpperBound(0), NewLine= true}; sendProgressEvent(eva); foreach (String CSV_String in CSV_Strings) { if(!String.IsNullOrEmpty(CSV_String.Trim())) { Listing currentRow = new Listing(CSV_String); currentID = currentRow.StationId; if(LastID != currentID) { if(currentStation != null) currentStation.ListingExtendMode = false; if(foundIndex.TryGetValue(currentID, out Index)) currentStation = foundValues[Index]; else { currentStation = new EDStation(currentRow); foundValues.Add(currentStation); foundIndex.Add(currentID, foundValues.Count-1); } LastID = currentRow.StationId; currentStation.ListingExtendMode = true; } currentStation.addListing(currentRow); } eva = new ProgressEventArgs() { Info="converting data...", CurrentValue=currentItem, TotalValue=CSV_Strings.GetUpperBound(0)}; sendProgressEvent(eva); if(eva.Cancelled) break; currentItem++; } if(currentStation != null) currentStation.ListingExtendMode = false; eva = new ProgressEventArgs() { Info="converting data...", CurrentValue=currentItem, TotalValue=CSV_Strings.GetUpperBound(0), ForceRefresh=true}; sendProgressEvent(eva); return foundValues; } catch (Exception ex) { throw new Exception("Error while getting station values from CSV-String", ex); } }
/// <summary> /// creates a list of "EDStations" with price listings from csv-array /// </summary> /// <param name="CSV_Strings">String to be converted</param> /// <param name="foundSystems"></param> /// <param name="csvRowList">for optional processing outside: a list of the data converted to CsvRow-objects</param> /// <returns></returns> public List<EDStation> fromCSV(String[] CSV_Strings, ref List<EDSystem> foundSystems, ref List<CsvRow> csvRowList) { List<EDStation> foundValues = new List<EDStation>(); Dictionary<String, Int32> foundIndex = new Dictionary<String, Int32>(); Dictionary<String, Int32> foundSystemIndex = new Dictionary<String, Int32>(); String LastID = ""; EDSystem LastSystem = null; String currentID = ""; EDStation currentStation = null; Int32 Index = 0; Dictionary<String, Int32> commodityIDCache = new Dictionary<string,Int32>(); // quick cache for finding commodity names Int32 currentItem = 0; ProgressEventArgs eva; try { eva = new ProgressEventArgs() { Info="converting data...", CurrentValue=currentItem, TotalValue=CSV_Strings.GetUpperBound(0)+1, AddSeparator = true }; sendProgressEvent(eva); if(foundSystems != null) foundSystems.Clear(); else foundSystems = new List<EDSystem>(); foreach (String CSV_String in CSV_Strings) { if(!String.IsNullOrEmpty(CSV_String.Trim())) { CsvRow currentRow = new CsvRow(CSV_String); if(csvRowList != null) csvRowList.Add(currentRow); currentID = currentRow.StationID; if(!LastID.Equals(currentID, StringComparison.InvariantCultureIgnoreCase)) { if(currentStation != null) currentStation.ListingExtendMode = false; if(foundIndex.TryGetValue(currentID, out Index)) currentStation = foundValues[Index]; else { currentStation = new EDStation(currentRow); foundValues.Add(currentStation); foundIndex.Add(currentID, foundValues.Count-1); } LastID = currentRow.StationID; currentStation.ListingExtendMode = true; if((LastSystem == null) || (!LastSystem.Name.Equals(currentRow.SystemName, StringComparison.InvariantCultureIgnoreCase))) { if(foundSystemIndex.TryGetValue(currentRow.SystemName, out Index)) LastSystem = foundSystems[Index]; else { LastSystem = new EDSystem(); LastSystem.Name = currentRow.SystemName; if(LastSystem.Id == 0) LastSystem.Id = currentStation.SystemId; foundSystems.Add(LastSystem); foundSystemIndex.Add(currentRow.SystemName, foundSystems.Count-1); } } } currentStation.addListing(currentRow, ref commodityIDCache); } eva = new ProgressEventArgs() { Info="converting data...", CurrentValue=currentItem, TotalValue=CSV_Strings.GetUpperBound(0)+1}; sendProgressEvent(eva); if(eva.Cancelled) break; currentItem++; } if(currentStation != null) currentStation.ListingExtendMode = false; eva = new ProgressEventArgs() { Info="converting data...", CurrentValue=currentItem, TotalValue=CSV_Strings.GetUpperBound(0)+1, ForceRefresh=true}; sendProgressEvent(eva); return foundValues; } catch (Exception ex) { throw new Exception("Error while getting station values from CSV-String", ex); } }
/// <summary> /// Imports the prices from a list of csv-strings /// </summary> /// <param name="CSV_Strings">data to import</param> /// <param name="importBehaviour">filter, which prices to import</param> /// <param name="dataSource">if data has no information about the datasource, this setting will count</param> /// <returns>a list of converted station data (including correct station ids) </returns> public List<EDStation> ImportPricesFromCSVStrings(String[] CSV_Strings, enImportBehaviour importBehaviour, enDataSource dataSource) { Boolean MissingSystem = false; Boolean MissingStation = false; String currentLanguage; DataTable newData; List<EDStation> StationData; List<EDSystem> SystemData = null; List<CsvRow> csvRowList = new List<CsvRow>(); ProgressEventArgs eva; Int32 counter = 0; Dictionary<String, String> foundNames = new Dictionary<string,string>(); // quick cache for finding commodity names try { // ***************************************************************** // START :section for automatically add unknown commodities currentLanguage = Program.DBCon.getIniValue(IBESettingsView.DB_GROUPNAME, "Language", Program.BASE_LANGUAGE, false); newData = new DataTable(); newData.TableName = "Names"; newData.Columns.Add(Program.BASE_LANGUAGE, typeof(String)); if(currentLanguage != Program.BASE_LANGUAGE) newData.Columns.Add(currentLanguage, typeof(String)); eva = new ProgressEventArgs() { Info="analysing data...", AddSeparator = true}; sendProgressEvent(eva); for (int i = 0; i < CSV_Strings.Length; i++) { String currentName; List<dsEliteDB.tbcommoditylocalizationRow> currentCommodity; if (CSV_Strings[i].Trim().Length > 0) { currentName = new CsvRow(CSV_Strings[i]).CommodityName; if (!String.IsNullOrEmpty(currentName)) { // check if we need to remap this name Datasets.dsEliteDB.tbdnmap_commodityRow mappedName = (Datasets.dsEliteDB.tbdnmap_commodityRow)BaseData.tbdnmap_commodity.Rows.Find(new object[] {currentName, ""}); if (mappedName != null) { CSV_Strings[i] = CSV_Strings[i].Replace(mappedName.CompanionName, mappedName.GameName); currentName = mappedName.GameName; } if (!foundNames.ContainsKey(currentName)) { currentCommodity = Program.Data.BaseData.tbcommoditylocalization.Where(x => x.locname.Equals(currentName, StringComparison.InvariantCultureIgnoreCase)).ToList(); if (currentCommodity.Count == 0) { if (currentLanguage == Program.BASE_LANGUAGE) newData.Rows.Add(currentName); else newData.Rows.Add(currentName, currentName); } foundNames.Add(currentName, ""); } } } counter++; eva = new ProgressEventArgs() { Info="analysing data...", CurrentValue=counter, TotalValue=CSV_Strings.GetUpperBound(0) + 1 }; sendProgressEvent(eva); if(eva.Cancelled) break; } eva = new ProgressEventArgs() { Info="analysing data...", CurrentValue=counter, TotalValue=counter, ForceRefresh=true }; sendProgressEvent(eva); if (!eva.Cancelled) if(newData.Rows.Count > 0) { // add found unknown commodities var ds = new DataSet(); ds.Tables.Add(newData); ImportCommodityLocalizations(ds); // refresh translation columns Program.Data.updateTranslation(); // refresh working tables Program.Data.PrepareBaseTables(Program.Data.BaseData.tbcommoditylocalization.TableName); Program.Data.PrepareBaseTables(Program.Data.BaseData.tbcommodity.TableName); } // END : section for automatically add unknown commodities // ***************************************************************** // convert csv-strings to EDStation-objects StationData = fromCSV(CSV_Strings, ref SystemData, ref csvRowList); // check if we've unknown systems or stations if(!eva.Cancelled) foreach (EDStation Station in StationData) { if (Station.SystemId == 0) MissingSystem = true; else if(Station.Id == 0) MissingStation = true; } if ((!eva.Cancelled) && MissingSystem) { // add unknown systems ImportSystems_Own(ref SystemData, true); } if (!eva.Cancelled && (MissingSystem || MissingStation)) { // add unknown stations foreach (EDStation Station in StationData) { // first get all missing system ids if (Station.SystemId == 0) { EDSystem thisSystem = SystemData.FirstOrDefault(x => x.Name == Station.SystemName); if(thisSystem != null) { // got it - set the id Station.SystemId = thisSystem.Id; } } } ImportStations_Own(StationData, new Dictionary<Int32, Int32>(), true); } // now import the prices ImportPrices(StationData, importBehaviour, dataSource); if (MissingSystem) { // reloading of base tables Program.Data.PrepareBaseTables(Program.Data.BaseData.tbsystems.TableName); } if (MissingSystem || MissingStation) { // reloading of base tables Program.Data.PrepareBaseTables(Program.Data.BaseData.tbstations.TableName); Program.Data.PrepareBaseTables(Program.Data.BaseData.visystemsandstations.TableName); } return StationData; } catch (Exception ex) { throw new Exception("Error while importing self collected price data", ex); } }
// The main entry point for the application. static void Main(String[] args) { // Check command line and print usage if incomplete. if (args.Length < 1) { Console.WriteLine("Usage: HeaderChecker filename [search paths...]"); Console.WriteLine(""); Console.WriteLine("Wildcards are accepted."); return; } // Collect command line arguments. String mask = args[0]; // Build search paths command line. String searchPaths = String.Empty; for (int i = args.GetLowerBound(0) + 1; i <= args.GetUpperBound(0); ++i) { searchPaths += " /I" + args[i]; if (!searchPaths.EndsWith("/")) searchPaths += "\\"; searchPaths += ""; } // Establish the list of files matching the mask. String[] filenames = Directory.GetFiles(".", mask); // Print a message and exit if the filename list is empty. if (filenames.Length == 0) { Console.WriteLine("No files found."); return; } // Call CheckFile() on each file matching the mask. ArrayList failures = new ArrayList(); foreach (String sourcePath in filenames) { // Check this source file. if (CheckFile(sourcePath, searchPaths) == false) failures.Add(sourcePath); // Remove object file if one was created. String objectFile = Path.ChangeExtension(sourcePath, ".obj"); if (File.Exists(objectFile)) File.Delete(objectFile); } // Print results. Console.WriteLine(); Console.Write("Finished, "); if (failures.Count == 0) { Console.WriteLine("all files compile."); } else { Console.WriteLine("{0} file(s) failed to compile:", failures.Count); foreach (String failedFile in failures) Console.WriteLine(" {0}", failedFile); } }
public List<Motor> Get(String[,] MotorProperties) { string MotorName; double MotorForceConstant; double MotorMotorConstant; double MotorBackEMFConstant; double MotorResistance; double MotorPeakForce; double MotorPeakCurrent; double MotorContinuousForce_0psi; double MotorContinuousForce_10psi; double MotorContinuousForce_20psi; double MotorContinuousForce_40psi; double MotorContinuousCurrent_0psi; double MotorContinuousCurrent_10psi; double MotorContinuousCurrent_20psi; double MotorContinuousCurrent_40psi; double MotorCoilMass; double MotorCoilLength; double MotorThermalResistance_100CTEMP_0psi; double MotorThermalResistance_100CTEMP_10psi; double MotorThermalResistance_100CTEMP_20psi; double MotorThermalResistance_100CTEMP_40psi; double MotorThermalResistance_Catalog_0psi; double MotorThermalResistance_Catalog_20psi; double MotorThermalResistance_PercentDifference_0psi; double MotorThermalResistance_PercentDifference_20psi; Motor temp; _motors = new List<Motor>(); String WhereSQL = ""; for (int i = 0; i <= MotorProperties.GetUpperBound(0); i++) { if (i == 0) { WhereSQL += " WHERE " + MotorProperties[i, 0] + " " + MotorProperties[i, 1] + " " + MotorProperties[i, 2]; } else { WhereSQL += " AND " + MotorProperties[i, 0] + " " + MotorProperties[i, 1] + " " + MotorProperties[i, 2]; } } string sql = "select * from _motors" + WhereSQL + ";"; Console.WriteLine(sql); var conn = new SQLiteConnection("Data Source=" + _dbfilename + ";Version=3;"); conn.Open(); DataSet ds = new DataSet(); var da = new SQLiteDataAdapter(sql, conn); da.Fill(ds); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { MotorName = ds.Tables[0].Rows[i]["Motor"].ToString(); MotorForceConstant = Convert.ToDouble(ds.Tables[0].Rows[i]["ForceConstant"].ToString()); MotorMotorConstant = Convert.ToDouble(ds.Tables[0].Rows[i]["MotorConstant"].ToString()); MotorBackEMFConstant = Convert.ToDouble(ds.Tables[0].Rows[i]["BackEMFConstant"].ToString()); MotorResistance = Convert.ToDouble(ds.Tables[0].Rows[i]["Resistance"].ToString()); MotorPeakForce = Convert.ToDouble(ds.Tables[0].Rows[i]["PeakForce"].ToString()); MotorPeakCurrent = Convert.ToDouble(ds.Tables[0].Rows[i]["PeakCurrent"].ToString()); MotorContinuousForce_0psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ContinuousForce_0psi"].ToString()); MotorContinuousForce_10psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ContinuousForce_10psi"].ToString()); MotorContinuousForce_20psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ContinuousForce_20psi"].ToString()); MotorContinuousForce_40psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ContinuousForce_40psi"].ToString()); MotorContinuousCurrent_0psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ContinuousCurrent_0psi"].ToString()); MotorContinuousCurrent_10psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ContinuousCurrent_10psi"].ToString()); MotorContinuousCurrent_20psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ContinuousCurrent_20psi"].ToString()); MotorContinuousCurrent_40psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ContinuousCurrent_40psi"].ToString()); MotorCoilMass = Convert.ToDouble(ds.Tables[0].Rows[i]["CoilMass"].ToString()); MotorCoilLength = Convert.ToDouble(ds.Tables[0].Rows[i]["CoilLength"].ToString()); MotorThermalResistance_100CTEMP_0psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ThermalResistance_100CTEMP_0psi"].ToString()); MotorThermalResistance_100CTEMP_10psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ThermalResistance_100CTEMP_10psi"].ToString()); MotorThermalResistance_100CTEMP_20psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ThermalResistance_100CTEMP_20psi"].ToString()); MotorThermalResistance_100CTEMP_40psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ThermalResistance_100CTEMP_40psi"].ToString()); MotorThermalResistance_Catalog_0psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ThermalResistance_Catalog_0psi"].ToString()); MotorThermalResistance_Catalog_20psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ThermalResistance_Catalog_20psi"].ToString()); MotorThermalResistance_PercentDifference_0psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ThermalResistance_PercentDifference_0psi"].ToString()); MotorThermalResistance_PercentDifference_20psi = Convert.ToDouble(ds.Tables[0].Rows[i]["ThermalResistance_PercentDifference_20psi"].ToString()); temp = new Motor(MotorName, MotorForceConstant, MotorMotorConstant, MotorBackEMFConstant, MotorResistance, MotorPeakForce, MotorPeakCurrent, MotorContinuousForce_0psi, MotorContinuousForce_10psi, MotorContinuousForce_20psi, MotorContinuousForce_40psi, MotorContinuousCurrent_0psi, MotorContinuousCurrent_10psi, MotorContinuousCurrent_20psi, MotorContinuousCurrent_40psi, MotorCoilMass, MotorCoilLength, MotorThermalResistance_100CTEMP_0psi, MotorThermalResistance_100CTEMP_10psi, MotorThermalResistance_100CTEMP_20psi, MotorThermalResistance_100CTEMP_40psi, MotorThermalResistance_Catalog_0psi, MotorThermalResistance_Catalog_20psi, MotorThermalResistance_PercentDifference_0psi, MotorThermalResistance_PercentDifference_20psi); _motors.Add(temp); } return _motors; }
private void Exportuj_rozm_Click(object sender, EventArgs e) { StreamWriter rozm; Int32 csv_sel = 0; String file_nam, tekst, file_ext; String[] text_rozm = new String[1]; StringBuilder sb = new StringBuilder(); Encoding ascii = Encoding.GetEncoding(1250); Encoding unicode = Encoding.Unicode; Byte[] asciibyte; Byte[] unibyte; Int32 curNum = 0; String curSel = "0"; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "txt files (*.txt)|*.txt|csv files (*.csv)|*.csv"; sfd.CheckFileExists = false; sfd.CheckPathExists = true; if (sfd.ShowDialog() == DialogResult.OK) { file_nam = sfd.FileName; file_ext = file_nam[file_nam.Length - 3].ToString(); file_ext = file_ext + file_nam[file_nam.Length - 2].ToString(); file_ext = file_ext + file_nam[file_nam.Length - 1].ToString(); if (file_ext == "csv") { if (MessageBox.Show("Czy dane mają być rozdzielone przecinkiem ?. Jeśli nie, zostaną rozdzielone tabulatorem.", "Tlen Reader Net", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { csv_sel = 1; // comma } else { csv_sel = 2; // tab } } else if (file_ext == "txt") { csv_sel = 0; // txt } ListView.SelectedListViewItemCollection LV_SEL = listView_ListaRozm.SelectedItems; foreach (ListViewItem ITM in LV_SEL) { curSel = ITM.Text; } curNum = Convert.ToInt32(curSel); if (plk_dat_strm != null) { BinaryReader binr = new BinaryReader(plk_dat_strm, ascii); plk_dat_strm.Seek(0, SeekOrigin.Begin); long offset = 0; while (offset < plk_dat_strm.Length) { plk_dat_strm.Seek(offset, SeekOrigin.Begin); cht.time = binr.ReadDouble(); cht.flags = binr.ReadInt32(); cht.size = binr.ReadInt32(); cht.ID = binr.ReadInt32(); cht.unknown = binr.ReadInt32(); asciibyte = binr.ReadBytes(cht.size); unibyte = Encoding.Convert(ascii, unicode, asciibyte); cht.msg = unicode.GetString(unibyte); Char[] kto = new Char[26]; if (cht.ID == curNum) { int x = 0; for (x = 0; x < indeks.Length; x++) { if (cht.ID == indeks[x].id_rozm) { if (csv_sel == 0) { if (Test_JA(cht.flags) == false) { sb.Append(indeks[x].name); } else { sb.Append("JA"); } sb.Append(" - "); sb.Append(Oblicz_date(cht.time)); sb.Append(" - "); sb.Append(cht.msg); tekst = sb.ToString(); sb.Remove(0, sb.Length); Array.Resize(ref text_rozm, text_rozm.Length + 1); text_rozm[text_rozm.GetUpperBound(0)] = tekst; } else if (csv_sel == 1) { sb.Append("\""); if (Test_JA(cht.flags) == false) { sb.Append(indeks[x].name); } else { sb.Append("JA"); } sb.Append("\""); sb.Append(","); sb.Append("\""); sb.Append(Oblicz_date(cht.time)); sb.Append("\""); sb.Append(","); sb.Append("\""); sb.Append(cht.msg); sb.Append("\""); tekst = sb.ToString(); sb.Remove(0, sb.Length); Array.Resize(ref text_rozm, text_rozm.Length + 1); text_rozm[text_rozm.GetUpperBound(0)] = tekst; } else if (csv_sel == 2) { sb.Append("\""); if (Test_JA(cht.flags) == false) { sb.Append(indeks[x].name); } else { sb.Append("JA"); } sb.Append("\""); sb.Append("\t"); sb.Append("\""); sb.Append(Oblicz_date(cht.time)); sb.Append("\""); sb.Append("\t"); sb.Append("\""); sb.Append(cht.msg); sb.Append("\""); tekst = sb.ToString(); sb.Remove(0, sb.Length); Array.Resize(ref text_rozm, text_rozm.Length + 1); text_rozm[text_rozm.GetUpperBound(0)] = tekst; } else { return; } } } } offset = offset + 24 + cht.size; } for (Int32 i = 0; i < indeks.Length; i++) { if (indeks[i].id_rozm == curNum) { rozm = File.CreateText(file_nam); for (Int32 z = 0; z < text_rozm.Length; z++) { rozm.WriteLine(text_rozm[z]); } rozm.Close(); } } } } }
private void eksportujCałeArchSMSToolStripMenuItem_Click(object sender, EventArgs e) { Encoding ascii = Encoding.GetEncoding(1250); Encoding unicode = Encoding.Unicode; Byte[] asciibyte; Byte[] unibyte; StreamWriter rozm; Int32 csv_sel = 0; String file_nam, tekst, msg,file_ext; String[] text_rozm = new String[1]; StringBuilder sb = new StringBuilder(); SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "txt files (*.txt)|*.txt|csv files (*.csv)|*.csv"; sfd.CheckFileExists = false; sfd.CheckPathExists = true; //sfd.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString(); if (sfd.ShowDialog() == DialogResult.OK) { file_nam = sfd.FileName; file_ext = file_nam[file_nam.Length - 3].ToString(); file_ext = file_ext + file_nam[file_nam.Length - 2].ToString(); file_ext = file_ext + file_nam[file_nam.Length - 1].ToString(); if (file_ext == "csv") { if (MessageBox.Show("Czy dane mają być rozdzielone przecinkiem ?. Jeśli nie, zostaną rozdzielone tabulatorem.", "Tlen Reader Net", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { csv_sel = 1; // comma } else { csv_sel = 2; // tab } } else if (file_ext == "txt") { csv_sel = 0; // txt } BinaryReader binr = new BinaryReader(sms_dat_strm, ascii); for (int x = 1; x < indeks.Length; x++) { sms_dat_strm.Seek(indeks[x].offset, SeekOrigin.Begin); asciibyte = binr.ReadBytes(indeks[x].size_sms); unibyte = Encoding.Convert(ascii, unicode, asciibyte); msg = unicode.GetString(unibyte); if (csv_sel == 0) { sb.Append(indeks[x].name); sb.Append(" - "); sb.Append(Oblicz_date(indeks[x].czas)); sb.Append(" - "); sb.Append(msg); tekst = sb.ToString(); sb.Remove(0, sb.Length); Array.Resize(ref text_rozm, text_rozm.Length + 1); text_rozm[text_rozm.GetUpperBound(0)] = tekst; } else if (csv_sel == 1) { sb.Append("\""); sb.Append(indeks[x].name); sb.Append("\""); sb.Append(","); sb.Append("\""); sb.Append(Oblicz_date(indeks[x].czas)); sb.Append("\""); sb.Append(","); sb.Append("\""); sb.Append(msg); sb.Append("\""); tekst = sb.ToString(); sb.Remove(0, sb.Length); Array.Resize(ref text_rozm, text_rozm.Length + 1); text_rozm[text_rozm.GetUpperBound(0)] = tekst; } else if (csv_sel == 2) { sb.Append("\""); sb.Append(indeks[x].name); sb.Append("\""); sb.Append("\t"); sb.Append("\""); sb.Append(Oblicz_date(indeks[x].czas)); sb.Append("\""); sb.Append("\t"); sb.Append("\""); sb.Append(msg); sb.Append("\""); tekst = sb.ToString(); sb.Remove(0, sb.Length); Array.Resize(ref text_rozm, text_rozm.Length + 1); text_rozm[text_rozm.GetUpperBound(0)] = tekst; } else { return; } } rozm = File.CreateText(file_nam); for (Int32 z = 0; z < text_rozm.Length; z++) { rozm.WriteLine(text_rozm[z]); } rozm.Close(); } }
/// <summary> /// processing of the recieved data /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RecievedEDDNData(object sender, EDDN.EDDNRecievedArgs e) { String[] DataRows = new String[0]; String nameAndVersion = String.Empty; String name = String.Empty; String uploaderID = String.Empty; Boolean SimpleEDDNCheck = false; List<String> importData = new List<String>(); enSchema ownSchema; enSchema dataSchema; bool isTrusty = false; try { if (m_lDBCon.getIniValue<Boolean>("EDDN", "SpoolEDDNToFile", false.ToString(), false)) { if (m_EDDNSpooler == null) { if (!File.Exists(Program.GetDataPath(@"Logs\EddnOutput.txt"))) m_EDDNSpooler = File.CreateText(Program.GetDataPath(@"Logs\EddnOutput.txt")); else m_EDDNSpooler = File.AppendText(Program.GetDataPath(@"Logs\EddnOutput.txt")); } m_EDDNSpooler.WriteLine(e.RawData); } ownSchema = m_lDBCon.getIniValue<enSchema>(IBE.EDDN.EDDNView.DB_GROUPNAME, "Schema", "Real", false); switch (e.InfoType) { case EDDN.EDDNRecievedArgs.enMessageInfo.Commodity_v1_Recieved: UpdateStatisticDataMsg(enMessageTypes.Commodity_V1); //Debug.Print("recieved commodity message ignored"); UpdateRawData(String.Format("{0}\r\n(from {2})\r\n{1}", e.Message, e.RawData, e.Adress)); break; case EDDN.EDDNRecievedArgs.enMessageInfo.Commodity_v2_Recieved: UpdateStatisticDataMsg(enMessageTypes.Commodity_V2); //Debug.Print("recieved commodity message ignored"); UpdateRawData(String.Format("{0}\r\n(from {2})\r\n{1}", e.Message, e.RawData, e.Adress)); break; case EDDN.EDDNRecievedArgs.enMessageInfo.Commodity_v3_Recieved: JObject dataJObject = (JObject)e.Data; if(m_DuplicateRelayFilter.DataAccepted(dataJObject.SelectToken("header.uploaderID").ToString(), dataJObject.SelectToken("message.systemName") + "|" + dataJObject.SelectToken("message.stationName"), dataJObject.SelectToken("message.commodities").Count().ToString(), (DateTime)dataJObject.SelectToken("message.timestamp"))) { UpdateStatisticDataMsg(enMessageTypes.Commodity_V3); UpdateRawData(String.Format("{0}\r\n(from {2})\r\n{1}", e.Message, e.RawData, e.Adress)); // process only if it's the correct schema dataSchema = dataJObject.SelectToken("$schemaRef").Contains("/test") ? enSchema.Test : enSchema.Real; if (ownSchema == dataSchema) { //Debug.Print("handle v3 message"); // Don't import our own uploads... if (dataJObject.SelectToken("header.uploaderID").ToString() != UserIdentification()) { DataRows = ConvertCommodityV3_To_CSVRows(dataJObject); nameAndVersion = String.Format("{0} / {1}", dataJObject.SelectToken("header.softwareName"), dataJObject.SelectToken("header.softwareVersion")); name = String.Format("{0}", dataJObject.SelectToken("header.softwareName")); uploaderID = dataJObject.SelectToken("header.uploaderID").ToString(); if(name == "ED-IBE (API)") Debug.Print("handle v3 ^recieved : " + name); } //else //Debug.Print("handle v3 rejected (it's our own message)"); } //else //Debug.Print("handle v3 rejected (wrong schema)"); } //else //Debug.Print("handle v3 rejected (double recieved)"); break; case EDDN.EDDNRecievedArgs.enMessageInfo.Outfitting_v1_Recieved: UpdateStatisticDataMsg(enMessageTypes.Outfitting_V1); //UpdateRawData("recieved outfitting message ignored (coming feature)"); //Debug.Print("recieved outfitting message ignored"); UpdateRawData(String.Format("{0}\r\n(from {2})\r\n{1}", e.Message, e.RawData, e.Adress)); break; case EDDN.EDDNRecievedArgs.enMessageInfo.Outfitting_v2_Recieved: UpdateStatisticDataMsg(enMessageTypes.Outfitting_V2); //UpdateRawData("recieved outfitting message ignored (coming feature)"); //Debug.Print("recieved outfitting message ignored"); UpdateRawData(String.Format("{0}\r\n(from {2})\r\n{1}", e.Message, e.RawData, e.Adress)); break; case EDDN.EDDNRecievedArgs.enMessageInfo.Shipyard_v1_Recieved: UpdateStatisticDataMsg(enMessageTypes.Shipyard_V1); //UpdateRawData("recieved shipyard message ignored (coming feature)"); //Debug.Print("recieved shipyard message ignored"); break; case EDDN.EDDNRecievedArgs.enMessageInfo.Shipyard_v2_Recieved: UpdateStatisticDataMsg(enMessageTypes.Shipyard_V2); //UpdateRawData("recieved shipyard message ignored (coming feature)"); //Debug.Print("recieved shipyard message ignored"); break; case EDDN.EDDNRecievedArgs.enMessageInfo.UnknownData: UpdateStatisticDataMsg(enMessageTypes.unknown); UpdateRawData(String.Format("{0}\r\n(from {2})\r\n{1}", e.Message, e.RawData, e.Adress)); UpdateRawData("Recieved a unknown EDDN message:" + Environment.NewLine + e.Message + Environment.NewLine + e.RawData); //Debug.Print("handle unkown message"); break; case EDDN.EDDNRecievedArgs.enMessageInfo.ParseError: UpdateRawData(String.Format("{0}\r\n(from {2})\r\n{1}", e.Message, e.RawData, e.Adress)); Debug.Print("handle error message"); UpdateRawData("Error while processing recieved EDDN data:" + Environment.NewLine + e.Message + Environment.NewLine + e.RawData); break; } if (DataRows != null && DataRows.GetUpperBound(0) >= 0) { isTrusty = (Program.Data.BaseData.tbtrustedsenders.Rows.Find(name) != null); UpdateStatisticData(DataRows.GetUpperBound(0) + 1, nameAndVersion, e.Adress, uploaderID); foreach (String DataRow in DataRows) { if(m_DuplicateFilter.DataAccepted(DataRow)) { // data is plausible ? if (isTrusty || (!Program.PlausibiltyCheck.CheckPricePlausibility(new string[] { DataRow }, SimpleEDDNCheck))) { // import is wanted ? if (m_lDBCon.getIniValue<Boolean>("EDDN", "ImportEDDN", false.ToString(), false)) { // collect importable data Debug.Print("import :" + DataRow); importData.Add(DataRow); } } else { Debug.Print("implausible :" + DataRow); // data is implausible string InfoString = string.Format("IMPLAUSIBLE DATA : \"{2}\" from {0}/ID=[{1}]", nameAndVersion, uploaderID, DataRow); UpdateRejectedData(InfoString); if (m_lDBCon.getIniValue<Boolean>("EDDN", "SpoolImplausibleToFile", false.ToString(), false)) { FileStream LogFileStream = null; string FileName = Program.GetDataPath(@"Logs\EddnImplausibleOutput.txt"); if (File.Exists(FileName)) LogFileStream = File.Open(FileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite); else LogFileStream = File.Create(FileName); LogFileStream.Write(System.Text.Encoding.Default.GetBytes(InfoString + "\n"), 0, System.Text.Encoding.Default.GetByteCount(InfoString + "\n")); LogFileStream.Close(); } } } } // have we collected importable data -> then import now if (importData.Count() > 0) { Program.Data.ImportPricesFromCSVStrings(importData.ToArray(), SQL.EliteDBIO.enImportBehaviour.OnlyNewer, (isTrusty ? SQL.EliteDBIO.enDataSource.fromEDDN_T : SQL.EliteDBIO.enDataSource.fromEDDN)); DataChangedEvent.Raise(this, new DataChangedEventArgs(enDataTypes.DataImported)); } } } catch (Exception ex) { UpdateRawData("Error while processing recieved EDDN data:" + Environment.NewLine + ex.GetBaseException().Message + Environment.NewLine + ex.StackTrace); } }
/// <summary> /// Concatenates two or more PDF files into one file. /// </summary> /// <param name="inputFiles">A string array containing the names of the pdf files to concatenate</param> /// <param name="outputFile">Name of the concatenated file.</param> public void ConcatenatePDFFiles(String[] inputFiles, String outputFile) { if (inputFiles != null && inputFiles.Length > 0) { if (!String.IsNullOrEmpty(outputFile) && !String.IsNullOrWhiteSpace(outputFile)) { var concatDocument = new iTextSharpText.Document(); var outputCopy = new iTextSharpPDF.PdfCopy(concatDocument, new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite)); concatDocument.Open(); try { for (int loop = 0; loop <= inputFiles.GetUpperBound(0); loop++) { var inputDocument = new iTextSharpPDF.PdfReader(inputFiles[loop]); for (int pageLoop = 1; pageLoop <= inputDocument.NumberOfPages; pageLoop++) { concatDocument.SetPageSize(inputDocument.GetPageSizeWithRotation(pageLoop)); outputCopy.AddPage(outputCopy.GetImportedPage(inputDocument, pageLoop)); } inputDocument.Close(); outputCopy.FreeReader(inputDocument); inputDocument = null; } concatDocument.Close(); outputCopy.Close(); } catch { if (concatDocument != null && concatDocument.IsOpen()) concatDocument.Close(); if (outputCopy != null) outputCopy.Close(); if (File.Exists(outputFile)) { try { File.Delete(outputFile); } catch { } } throw; } } else { throw new ArgumentNullException("outputFile", exceptionArgumentNullOrEmptyString); } } else { throw new ArgumentNullException("inputFiles", exceptionArgumentNullOrEmptyString); } }