本文整理汇总了C#中System.String.GetUpperBound方法的典型用法代码示例。如果您正苦于以下问题:C# String.GetUpperBound方法的具体用法?C# String.GetUpperBound怎么用?C# String.GetUpperBound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.GetUpperBound方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputeHashes
/// <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));
}
示例2: StringToDownloadFilesArray
//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;
}
示例3: show
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)
{
//.........这里部分代码省略.........
示例4: fromCSV_EDDB
/// <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);
}
}
示例5: fromCSV
/// <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);
//.........这里部分代码省略.........
示例6: ImportPricesFromCSVStrings
/// <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);
//.........这里部分代码省略.........
示例7: Main
// 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);
}
}
示例8: Get
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;
}
示例9: Exportuj_rozm_Click
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;
}
//.........这里部分代码省略.........
示例10: StringBuilder
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
//.........这里部分代码省略.........
示例11: RecievedEDDNData
//.........这里部分代码省略.........
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);
}
}
示例12: ConcatenatePDFFiles
/// <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);
}
}