|
You are not setting NotePad as the ForegroundWindow correctly. Try:
SetForegroundWindow(notePad.MainWindowHandle);
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
modified 7-Oct-13 16:04pm.
|
|
|
|
|
Your Thread.Sleep lines can be removed. You don't need them. Also, the numbers you have in there are just arbitrary and make certain assumptions about the performance if the system.
A better way to wait for Notepad to launch is:
notePad.WaitForInputIdle();
|
|
|
|
|
I have the byte array of my mp4 video, how can I play it without saving to my laptop/hard disk?
Thanks.
|
|
|
|
|
You can embed Windows media player in your code and open the audio URL via the player.
Note that the file will still be temporarily cached to your hard drive.
|
|
|
|
|
A few months ago, I wrote an article about dynamically loading classes at runtime:
The "Rule-O-Nator" - An example of dynamically loading classes at runtime[^]
For me, it was eye opening when Darek Danielewski gently asked, "Hey did you know about this thing called MEF?" DOE!!! Time to teach this old dog new tricks....
Since then, I've spent considerable time banging my head on my desk and getting over the hurdles. Almost all of the examples are extremely simplistic, copies of MS Calculator example, and not much time is spent talking about using MEF in the real world. I ultimately wrote a wrapper to make it easier to plug MEF into existing applications and to simplify a few things like composition, managing the catalog and container, diagnostics and debugging, avoiding pitfalls when using MEF in threads, etc.
Do you think there's any intrest for a .Net MEF wrapper, and an article about it on codeproject?
Would it be better to post the wrapper as a separate article and then smaller posts on using the wrapper vs a single article?
I'm also looking for some sanity checks. Would someone like to review the wrapper?
Look forward to to your thoughts and suggestions.
Best,
-james
-james
"If you've got to make code changes in something you didn't write, tread lightly. Your predecessor was regarded as either a genius or a moron. The truth most likely lies somewhere in the middle..."
|
|
|
|
|
As you know, I really liked the Rule-O-Nator article, and I'd definitely like to see an article on MEF by you.
thanks, Bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
Hey Bill! Thanks for the vote of confidence.
-james
"If you've got to make code changes in something you didn't write, tread lightly. Your predecessor was regarded as either a genius or a moron. The truth most likely lies somewhere in the middle..."
|
|
|
|
|
Article Please!!
Keep Clam And Proofread
--
√(-1) 23 ∑ π...
And it was delicious.
|
|
|
|
|
Hey Brisingr,
Thanks for the input!
-james
"If you've got to make code changes in something you didn't write, tread lightly. Your predecessor was regarded as either a genius or a moron. The truth most likely lies somewhere in the middle..."
|
|
|
|
|
Definitely do the article please, then push out as many real world examples as you are willing to publish.
I find real world examples so much more useful, it may not be relevant to our problem but it allows us to see how a problem was solved.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
It really depends what you are trying to do with the wrapper. When I started MEF, the biggest issues for me were things like clear examples of resolving multiple versions of the same interface - as well as interface versioning, plus custom catalogs. Also, you might want to cover what you get from MEF 2 as well as MEF 1.
|
|
|
|
|
Hi All,
I need your assitance with the following:
i have created a small application that is taking information from a DB, puting it in a datagridview and then will create a KML file.
i have add support on the datagridview from a previous post and now i am stuck with the following:
basically the sql query will give you the following:
State Name Long Lat
Day AZ1 11.11111 22.2222
Day AZ1 11.22222 22.3333
Day AZ1 11.33333 22.4444
Day AZ1 11.44444 22.5555
Day AZ2 11.11111 22.2222
Day AZ2 22.22222 33.3333
Day AZ2 22.33333 33.4444
Day AZ2 22.44444 33.5555
Night AZ1 11.11111 22.2222
Night AZ1 11.22222 22.3333
Night AZ1 11.33333 22.4444
Night AZ1 11.44444 22.5555
Night AZ5 55.11111 66.2222
Night AZ5 55.22222 66.3333
Night AZ5 55.33333 66.4444
Night AZ5 55.44444 66.5555
The output of the creatkml should be a kml file ( i know how to create it, just have issues with putting the above correctly)
<Folder>
<name>Day</name>
<Placemark>
<name>AZ1</name>
<styleUrl>#m_ylw-pushpin</styleUrl>
<Polygon>
<tessellate>1</tessellate>
<outerBoundaryIs>
<LinearRing>
<coordinates>
11.11111,22.2222,0 11.22222,22.3333,01 1.33333,22.4444,0 11.44444,22.5555,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark>
<name>AZ2</name>
< styleUrl>#m_ylw-pushpin</styleUrl>
< Polygon>
< tessellate>1</tessellate>
< outerBoundaryIs>
< LinearRing>
< coordinates>
11.11111,22.2222,0 22.22222,33.3333,0 22.33333,33.4444,0 22.44444,33.5555
< /coordinates>
< /LinearRing>
</outerBoundaryIs>
< /Polygon>
</Placemark>
</Folder>
<Folder>
<name>Night</name>
...
.
.
..... basically the same as the above placemarks just with the night names
when clicking on the createKML button the application stops with the following error in the phase of :
LatLongCollectionByName.Add(matchHandle, lst);
ERROR MESSAGE "An item with the same key has already been added."
the attached code is suppose to collect all the names and the points (without the state value. this is something new i added).
i have uploaded the code and a small sample of the DB
hope i am clear
thanks alot
Jonathan
<pre lang="c#">
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Threading;
using System.IO;
using System.Diagnostics;
using Microsoft.SqlServer.Management.Smo;
using System.Linq;
namespace WisToKML
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DisconnectBtn.Enabled = false;
KMLDestinationTB.Enabled = false;
DBConBtn.Enabled = false;
userTB.Text = "sa";
PassTB.Text = "Password!";
//FromDate.CustomFormat = "2013-06-01";
//FromDate.Format = DateTimePickerFormat.Custom;
//TODate.CustomFormat = "2013-06-01";
//TODate.Format = DateTimePickerFormat.Custom;
}
private void Form1_Load(object sender, EventArgs e)
{
BrowseBtn.Enabled = false;
DataTable dt = SmoApplication.EnumAvailableSqlServers(true);
DBSrvTB.ValueMember = "Name";
DBSrvTB.DataSource = dt;
}
private void DBSrvTB_SelectedIndexChanged(object sender, EventArgs e)
{
DBNameTB.Items.Clear();
if (DBSrvTB.SelectedIndex != -1)
{
string serverName = DBSrvTB.SelectedValue.ToString();
Server server = new Server(serverName);
try
{
foreach (Database database in server.Databases)
{
DBNameTB.Items.Add(database.Name);
}
}
catch (Exception ex)
{
string exception = ex.Message;
}
}
}
private void DBConBtn_Click(object sender, EventArgs e)
{
if ((DBNameTB.Text == null) || (DBNameTB.Text == ""))
{
MessageBox.Show("Database Name is missing", "Error");
return;
}
else
{
try
{
string username = userTB.Text;
string password = PassTB.Text;
string server = DBSrvTB.Text;
string database = DBNameTB.Text;
string ConnectionString = "User ID=" + username + ";" + "Password=" + password + ";" + "Database=" + database + ";" + "server=" + server;
SqlConnection connection = new SqlConnection(ConnectionString);
connection.Open();
// MessageBox.Show("DB Connected","(Connected)");
DBConBtn.Enabled = false;
DBConBtn.Text = "DB Connected";
DBConBtn.BackColor = Color.Green;
BrowseBtn.Enabled = true;
DisconnectBtn.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show("DB Authentication Failed", "Error");
return;
}
}
}
private void DisconnectBtn_Click(object sender, EventArgs e)
{
string username = userTB.Text;
string password = PassTB.Text;
string server = DBSrvTB.Text;
string database = DBNameTB.Text;
string ConnectionString = "User ID=" + username + ";" + "Password=" + password + ";" + "Database=" + database + ";" + "server=" + server;
SqlConnection connection = new SqlConnection(ConnectionString);
connection.Close();
DBConBtn.Enabled = true;
DBConBtn.BackColor = default(Color);
DisconnectBtn.Enabled = false;
BrowseBtn.Enabled = false;
}
#region Class LatLongPair
class LatLongPair
{
public double Lat { get;set; }
public double Lon { get;set; }
}
#endregion
private void button3_Click(object sender, EventArgs e)
{
#region testing new code from web
// this is a new code from the web
Dictionary<string, List<LatLongPair>> LatLongCollectionByName = new Dictionary<string, List<LatLongPair>>();
List<LatLongPair> lst = null;
LatLongPair lPair = null;
string matchHandle = string.Empty;
for (int i = 0; i < LayersGrid.Rows.Count; i++)
{
if (LayersGrid.Rows[i].Cells[1].Value.ToString() == matchHandle)
{
lPair.Lat = Convert.ToDouble(LayersGrid.Rows[i].Cells[3].Value);
lPair.Lon = Convert.ToDouble(LayersGrid.Rows[i].Cells[2].Value);
lst.Add(lPair);
}
else
{
matchHandle = LayersGrid.Rows[i].Cells[1].Value.ToString();
lPair = new LatLongPair();
lPair.Lat = Convert.ToDouble(LayersGrid.Rows[i].Cells[3].Value);
lPair.Lon = Convert.ToDouble(LayersGrid.Rows[i].Cells[2].Value);
lst = new List<LatLongPair>();
lst.Add(lPair);
LatLongCollectionByName.Add(matchHandle, lst);
}
foreach (KeyValuePair<string, List<LatLongPair>> item in LatLongCollectionByName)
{
Console.WriteLine("\n For name : " + item.Key + ", lat/long vaues are:\n");
foreach (LatLongPair lp in item.Value)
{
Console.Write("\t" + lp.Lat + ",\t" + lp.Lon + " | ");
}
}
//end of new code from web
#endregion
#region KML Header & Footer
string kmlheader = "=" + "=" + "" + "\r\n";
string kmlheader1 = "<kml xmlns=" + "\"" + "http://www.opengis.net/kml/2.2" + "\"" + " xmlns:gx=" + "\"" + "http://www.google.com/kml/ext/2.2" + "\"" + " xmlns:kml=" + "\"" + "http://www.opengis.net/kml/2.2" + "\"" + " xmlns:atom=" + "\"" + "http://www.w3.org/2005/Atom" + "\"" + ">" + "\r\n" + "<Document>" + "\r\n";
string kmlfooter = "</Document>" + "\r\n" + "</kml>";
#endregion
#region KML Document Name
string kmldocname = "\t" + "<name>" + sitenameTB.Text + "</name>" + "\r\n";
#endregion
#region KML Style
string stylemap = "\t" + "<StyleMap id=" + "\"" + "msn_polygon" + "\"" + ">" + "\r\n" + "\t" + "\t" + "<pair>" + "\r\n" + "\t" + "\t" + "\t" + "<key>normal</key>" + "\r\n" + "\t" + "\t" + "\t" + "<styleUrl>#sn_polygon</styleUrl>" + "\r\n" + "\t" + "\t" + "</pair>" + "\r\n" + "\t" + "\t" + "<pair>" + "\r\n" + "\t" + "\t" + "\t" + "<key>highlight</key>" + "\r\n" + "\t" + "\t" + "\t" + "<styleUrl>#sh_polygon</styleUrl>" + "\r\n" + "\t" + "\t" + "</pair>" + "\r\n" + "\t" + "</StyleMap>" + "\r\n";
string styleid_highlight = "\t" + "<Style id=" + "\"" + "sh_polygon" + "\"" + ">" + "\r\n" + "\t" + "\t" + "<IconStyle>" + "\r\n" + "\t" + "\t" + "\t" + "<color>ff00ff55</color>" + "\r\n" + "\t" + "\t" + "\t" + "<scale>0.709091</scale>" + "\r\n" + "\t" + "\t" + "\t" + "<Icon>" + "\r\n" + "\t" + "\t" + "\t" + "\t" + "<href>http://maps.google.com/mapfiles/kml/shapes/polygon.png</href>" + "\r\n" + "\t" + "\t" + "\t" + "</Icon>" + "\r\n" + "\t" + "\t" + "</IconStyle>" + "\r\n" + "\t" + "\t" + "<LabelStyle>" + "\r\n" + "\t" + "\t" + "\t" + "<scale>0.6</scale>" + "\r\n" + "\t" + "\t" + "</LabelStyle>" + "\r\n" + "\t" + "\t" + "<ListStyle></ListStyle>" + "\r\n" + "\t" + "</Style>" + "\r\n";
string styleid_normal = "\t" + "<Style id=" + "\"" + "sn_polygon" + "\"" + ">" + "\r\n" + "\t" + "\t" + "<IconStyle>" + "\r\n" + "\t" + "\t" + "\t" + "<color>ff00ff55</color>" + "\r\n" + "\t" + "\t" + "\t" + "<scale>0.709091</scale>" + "\r\n" + "\t" + "\t" + "\t" + "<Icon>" + "\r\n" + "\t" + "\t" + "\t" + "\t" + "<href>http://maps.google.com/mapfiles/kml/shapes/polygon.png</href>" + "\r\n" + "\t" + "\t" + "\t" + "</Icon>" + "\r\n" + "\t" + "\t" + "</IconStyle>" + "\r\n" + "\t" + "\t" + "<LabelStyle>" + "\r\n" + "\t" + "\t" + "\t" + "<scale>0.6</scale>" + "\r\n" + "\t" + "\t" + "</LabelStyle>" + "\r\n" + "\t" + "\t" + "<ListStyle></ListStyle>" + "\r\n" + "\t" + "</Style>" + "\r\n";
#endregion
#region kml file writer definition
StreamWriter KMLwriter = new System.IO.StreamWriter(KMLDestinationTB.Text + "\\" + sitenameTB.Text + ".kml", false);
#endregion
#region kml writer
KMLwriter.WriteLine(kmlheader + kmlheader1 + kmldocname + stylemap + styleid_highlight + styleid_normal);
//KMLwriter.Close();
KMLwriter.WriteLine("\t" + "<Placemark>" + "\r\n");
// KMLwriter.WriteLine("\t" + "\t" + "<name>" + LayersGrid.Rows.Cells["Target ID"].Value + "</name>" + "\r\n");
KMLwriter.WriteLine("\t" + "\t" + "<styleUrl>#msn_polygon</styleUrl>" + "\r\n");
KMLwriter.WriteLine("\t" + "\t" + "<Polygon>" + "\r\n");
KMLwriter.WriteLine("\t" + "\t" + "<tessellate>1</tessellate>" + "\r\n");
KMLwriter.WriteLine("\t" + "\t" + "\t" + "<outerBoundaryIs>" + "\r\n");
KMLwriter.WriteLine("\t" + "\t" + "\t" + "<LinearRing>" + "\r\n");
KMLwriter.WriteLine("\t" + "\t" + "\t" + "<coordinates>" + "\r\n");
#endregion
#region this is old code
//this is the old code
/*
for (int i = 1; i < LayersGrid.Rows.Count; i++)
{
if (LayersGrid.Rows[i].Cells["Name"] != null)
{
if (LayersGrid.Rows[i].Cells["Name"].Value.ToString() == LayersGrid.Rows[i - 1].Cells["Name"].Value.ToString())
{
// DO XXXXXXXXXXX
}
else
{
// DO YYYYYYYYYY
// MessageBox.Show(LayersGrid.Rows[i].Cells.ToString(), "different names");
try
{
KMLwriter.WriteLine("\t" + "\t" + "\t" + LayersGrid.Rows[i].Cells["Longitude"].Value + "," + LayersGrid.Rows[i].Cells["Latitude"].Value + ",0" + "\r\n");
}
catch (NullReferenceException ex)
{
}
}
}
}
*/
// end this is the old code
#endregion
#region KML Writer
KMLwriter.WriteLine("\t" + "\t" + "\t" + "</coordinates>" + "\r\n");
KMLwriter.WriteLine("\t" + "\t" + "\t" + "</outerBoundaryIs>" + "\r\n");
KMLwriter.WriteLine("\t" + "\t" + "</Polygon>" + "\r\n");
KMLwriter.WriteLine("\t" + "</Placemark>" + "\r\n");
KMLwriter.WriteLine(kmlfooter);
KMLwriter.Close();
#endregion
#region oldcode
//foreach (DataGridViewRow row in LayersGrid.Rows)
//{
// #region writing KML for each row
// //if (row.Cells["Name"].Value != null)
// //{
// // KMLwriter.WriteLine("\t" + "<Placemark>" + "\r\n");
// // KMLwriter.WriteLine("\t" + "\t" + "<name>" + row.Cells["Name"].Value + "</name>" + "\r\n");
// // KMLwriter.WriteLine("\t" + "\t" + "<LookAt>" + "\r\n" + "\t" + "\t" + "<longitude>" + row.Cells["Longitude"].Value + "</longitude>" + "\r\n" + "\t" + "\t" + "<latitude>" + row.Cells["Latitude"].Value + "</latitude>" + "\r\n" + "\t" + "\t" + "<altitude>0</altitude>" + "\r\n" + "\t" + "\t" + "<heading>1</heading>" + "\r\n" + "\t" + "\t" + "<tilt>0</tilt>" + "\r\n" + "\t" + "\t" + "<range>5000</range>" + "\r\n" + "\t" + "\t" + "<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>" + "\r\n" + "\t" + "</LookAt>" + "\r\n");
// // KMLwriter.WriteLine("\t" + "\t" + "<styleUrl>#msn_polygon</styleUrl>");
// // KMLwriter.WriteLine("\t" + "\t" + "<Point>" + "\r\n" + "\t" + "\t" + "\t" + "<coordinates>" + row.Cells["Longitude"].Value + "," + row.Cells["Latitude"].Value + ",0" + "</coordinates>" + "\r\n" + "\t" + "\t" + "</Point>" + "\r\n");
// // KMLwriter.WriteLine("\t" + "</Placemark>" + "\r\n");
// //}
// #endregion
// //***************** testing comparinson ***********************
// #region bool function
// bool functionname;
//{
// if (LayersGrid.RowCount == 0)
// {
// // return false; // or true? Your call
// MessageBox.Show("empty table");
// }
// // Get cell value in first row
// object oldValue = LayersGrid.Rows[0].Cells[0].Value;
// for (int i = 1; i < LayersGrid.RowCount; ++i)
// {
// if (LayersGrid.Rows[i].Cells[0].Value != oldValue)
// {
// // return false; // they are some differences
// MessageBox.Show("there are different layers");
// }
// }
// // All cells are the same as the one in first row
// // return true;
// MessageBox.Show("only one layer");
//} //closing bool function
//#endregion
//} //close for loop
#endregion
}
}
private void DBNameTB_SelectedIndexChanged(object sender, EventArgs e)
{
if (DBNameTB.Text != null)
{
DBConBtn.Enabled = true;
}
}
private void LyrLoadData_Click(object sender, EventArgs e)
{
string username = userTB.Text;
string password = PassTB.Text;
string server = DBSrvTB.Text;
string database = DBNameTB.Text;
string ConnectionString = "User ID=" + username + ";" + "Password=" + password + ";" + "Database=" + database + ";" + "server=" + server;
string ignore = "select * from Layers";
MessageBox.Show(ignore);
//testing new connection
// String reportQuery = @" complicated query returning many rows ";
SqlConnection ReportConnect = new SqlConnection(ConnectionString);
ReportConnect.Open();
SqlCommand command = new SqlCommand(ignore, ReportConnect);
command.CommandTimeout = 300; //5 mins
DataSet tempDataset = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds, "Layers");
// connection.Open();
LayersGrid.DataSource = ds;
LayersGrid.DataMember = "Layers";
//
}
<pre lang="c#">
}
}
thanks
Jonathan
|
|
|
|
|
Unfortunately you have not shown the code that causes the error, so it is not obvious why or how you are generating a duplicate key.
Veni, vidi, abiit domum
|
|
|
|
|
sorry
didnt notice it cut the code in the middle.
<pre>private void button3_Click(object sender, EventArgs e)
{
#region testing new code from web
Dictionary<string, List<LatLongPair>> LatLongCollectionByName = new Dictionary<string, List<LatLongPair>>();
List<LatLongPair> lst = null;
LatLongPair lPair = null;
string matchHandle = string.Empty;
for (int i = 0; i < LayersGrid.Rows.Count; i++)
{
if (LayersGrid.Rows[i].Cells[1].Value.ToString() == matchHandle)
{
lPair.Lat = Convert.ToDouble(LayersGrid.Rows[i].Cells[3].Value);
lPair.Lon = Convert.ToDouble(LayersGrid.Rows[i].Cells[2].Value);
lst.Add(lPair);
}
else
{
matchHandle = LayersGrid.Rows[i].Cells[1].Value.ToString();
lPair = new LatLongPair();
lPair.Lat = Convert.ToDouble(LayersGrid.Rows[i].Cells[3].Value);
lPair.Lon = Convert.ToDouble(LayersGrid.Rows[i].Cells[2].Value);
lst = new List<LatLongPair>();
lst.Add(lPair);
LatLongCollectionByName.Add(matchHandle, lst);
}
foreach (KeyValuePair<string, List<LatLongPair>> item in LatLongCollectionByName)
{
Console.WriteLine("\n For name : " + item.Key + ", lat/long vaues are:\n");
foreach (LatLongPair lp in item.Value)
{
Console.Write("\t" + lp.Lat + ",\t" + lp.Lon + " | ");
}
}
|
|
|
|
|
LatLongCollectionByName.Add(matchHandle, lst);
According to the data you have shown, your matchHandle has either the value AZ1 or AZ2 , so you can only add 1 entry of each name, since the Dictionary class does not allow duplicate keys.
Veni, vidi, abiit domum
|
|
|
|
|
so should i remove the dictionary and work only with the list?
|
|
|
|
|
It all depends on what you are trying to do. You could use a list or one of the other members of the collection classes. It is best to look at the documentation[^] and then decide which class is most useful to you.
Veni, vidi, abiit domum
|
|
|
|
|
hi
i am trying to collect all the lat and longs for each AZ.
then once all of them are collected to write them to a kml/text file.
since i am not much familiar with all the classes can you please advise.
thanks
|
|
|
|
|
yoni.kess wrote: since i am not much familiar with all the classes can you please advise. As I said in my previous comment, it is really dependent on how you want to handle the data. You will have to go and read the documentation for yourself to decide which class offers what you want, whether it is a simple list or one of the more specialized classes. You may also like to consider whether you need a collection at all, or can just write the data direct to your file.
Veni, vidi, abiit domum
|
|
|
|
|
Your question would be much more understandable if you put the code for button3_Click that you disclosed to Richard MacCutchan in your original post, and edited the code so only the possible problem area is shown.
If you have a field in your db that is guaranteed unique per row that you can use as a key, then using a Dictionary makes sense ... but, in this case, it appears you don't.
I'd start by modeling data structures from "inside to outside," from "atoms," to "molecules."
So, I'd define an "atomic class" that would hold only the necessary data for a single ship position measurement:
public class Position
{
public bool IsDay { get; private set; }
public double Latitude { get; private set; }
public double Longitude { get; private set; }
public Position(bool isDay, double latitude, double longitude)
{
IsDay = isDay;
Latitude = latitude;
Longitude = longitude;
}
public override string ToString()
{
return
"Time: "
+ (IsDay ? "Day " : "Night ")
+ " Latitude: " + Latitude.ToString()
+ " Longitude: " + Longitude.ToString();
}
} I'd then move on to the question of what my final goal is here: clearly each ship is going to have a collection of instances of Position:
internal class ShipPositionList : List<Position>
{
public override string ToString()
{
string s = "";
foreach (Position pos in this)
{
s += pos.ToString() + Environment.NewLine;
}
return s;
}
} And, finally, I'd consider what the data structure for the outermost object is:
public class Ship
{
public string ShipName { get; private set; }
internal ShipPositionList PositionList { get; private set; }
public Ship(string shipName)
{
ShipName = shipName;
PositionList = new ShipPositionList();
}
public void AddPosition(bool isDay, double lati, double longi)
{
PositionList.Add(new Position(isDay, lati, longi));
}
public override string ToString()
{
return
ShipName
+ Environment.NewLine
+ PositionList.ToString();
}
} At this point, I might well start wondering why I am writing out such an elaborate multi-class model, and start coding lean-and-mean
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
Hi BillWoodruff
thanks for the detailed answer, but now i am even more confused
i would have uploaded the project and the db if i only had were too.
small question: can i use one of the coordindated (for example: longitude) as a unique key and then use the dictionary?
thanks
|
|
|
|
|
Hi Yoni.Kess,
I don't think you need to post any more code in order to solve your challenge
If you get the object-structure right, you can make it serializable into XML; if you've got the XML, you can, if necessary, transform it into KML with an XSLT. I'm not familiar with KML, but I would guess that there's probably good tools available to create it. My impression from looking at your data is that it's simple, and there's nothing there that's recursive, and that you can easily create your own structured output in whatever form with your own simple serializer.
A .NET Dictionary (a collection of KeyValuePairs) must have a unique key for each KeyValuePair: if you are absolutely sure that you'll never have two longitude values that are the same, yes, you can use them as keys. But, what is it that makes you think a dictionary is the right thing in this case ?
fyi: the standard .NET XML serializer cannot handle writing a Dictionary to XML: [^]. I have read that the .NET DataContractSerializer can serialize a Dictionary, but I have not tried this: [^], [^].
Being more confused is not necessarily a bad thing in learning to program, although it may not feel comfortable to be confused. Of course, that's no excuse, if my response confused you !
The goal I had in responding to you was to "point you to" thinking about the "big picture" in your current challenge: what you are really modeling. Thinking in terms of "atoms to molecules to compounds" ... or the reverse ... is just one metaphor for OOP modeling.
There's a lot I can't tell from eye-balling your data: it may be the case that what you really need is to break out the data by Day/Night ... since it appears written that way in the KML fragment you show. Knowing more details is not necessary, however.
I believe if you are clear about what your final goal is, then the design of the data structures you really need will "fall-out" organically: that's a very idealistic statement. In the real-world, it often doesn't work that way: we get "immersed" in the data, and observe patterns of organization in the data, reach conclusions about what variation is in the data, and how that may constrain our solution, and from that we get ideas about how to structure and optimize the data structures we'll create to contain the data.
good luck, Bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
I try to add an object to a database, but I get an exception
Code:
DataModelContainer cont = new DataModelContainer();
(...)
cont.AddToStudentSet(cont.StudentSet.CreateObject());
cont.SaveChanges();
After running the code twice, I get:
Exception:
AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges.
The Id of Student has an AutoIncrement set to TRUE in the database. On the first run a single Student record is created with Id 0. Later, no data is saved to the table at all.
The reason of why is it happening seems to be obvious, but it should work anyway.
Any help appreciated
Greetings - Jacek
modified 6-Oct-13 9:04am.
|
|
|
|
|
Well, since you already have a student record with an Id of 0, you can't add another one. ID's should not start with 0.
|
|
|
|
|
The scenario was:
1. I had designed tables with an inheritance relationship.
2. Decided that it was not a good idea
3. Removed an inheritance relationship
4. Added required IDs to the tables and set IsIdentity to true.
5. Forgot to set an identity property to "Identity".
Well...
Greetings - Jacek
|
|
|
|
|