Search Results

Search found 14 results on 1 pages for 'farstucker'.

Page 1/1 | 1 

  • Appending an existing XML file with c#

    - by Farstucker
    I have an existing XML file that I would like to append without changing the format. Existing File looks like this: <Clients> <User username="farstucker"> <UserID>1</UserID> <DOB /> <FirstName>Steve</FirstName> <LastName>Lawrence</LastName> <Location>NYC</Location> </User> </Clients> How can I add another user using this format? My existing code is: string fileLocation = "clients.xml"; XmlTextWriter writer; if (!File.Exists(fileLocation)) { writer = new XmlTextWriter(fileLocation, null); writer.WriteStartDocument(); // Write the Root Element writer.WriteStartElement("Clients"); // End Element and Close writer.WriteEndElement(); writer.Close(); } // Append new data here Ive thought about using XmlDocument Fragment to append the data but Im not certain if I can maintain the existing format ( and empty tags ) without messing up the file. Any advice you could give is much appreciated. EDIT Ive changed the code to read the original XML but the file keeps getting overwritten.

    Read the article

  • Using singleton instead of a global static instance

    - by Farstucker
    I ran into a problem today and a friend recommended I use a global static instance or more elegantly a singleton pattern. I spent a few hours reading about singletons but a few things still escape me. Background: What Im trying to accomplish is creating an instance of an API and use this one instance in all my classes (as opposed to making a new connection, etc). There seems to be about 100 ways of creating a singleton but with some help from yoda I found some thread safe examples. ..so given the following code: public sealed class Singleton { public static Singleton Instance { get; private set; } private Singleton() { APIClass api = new APIClass(); //Can this be done? } static Singleton() { Instance = new Singleton(); } } How/Where would you instantiate the this new class and how should it be called from a separate class? EDIT: I realize the Singleton class can be called with something like Singleton obj1 = Singleton.Instance(); but would I be able to access the methods within the APIs Class (ie. obj1.Start)? (not that I need to, just asking) EDIT #2: I might have been a bit premature in checking the answer but I do have one small thing that is still causing me problems. The API is launching just fine, unfortunately Im able to launch two instances? New Code public sealed class SingletonAPI { public static SingletonAPI Instance { get; private set; } private SingletonAPI() {} static SingletonAPI() { Instance = new SingletonAPI(); } // API method: public void Start() { API myAPI = new API();} } but if I try to do something like this... SingletonAPI api = SingletonAPI.Instance; api.Start(); SingletonAPI api2 = SingletonAPI.Instance; // This was just for testing. api2.Start(); I get an error saying that I cannot start more than one instance.

    Read the article

  • C# Process flow - Datastream, XML and datagrid

    - by Farstucker
    Im looking for some advice/suggestions on how I should setup the work flow of a small application Im building. When the application is launched the datagrid will be populated via the XML file. Once running the application will receive a datastream that I hope to update the file and datagrid. So Im curious what you would suggest on how I setup the workflow (ie, split the data from the data stream and simultaneously populate the file and grid or would you suggest populating the XML file first and setting up a timer to have the grid read the file?) Im really looking for optimal performance.

    Read the article

  • Sending string from class to Form1

    - by Farstucker
    Although there are some similar questions I’m having difficulties finding an answer on how to receive data in my form from a class. I have been trying to read about instantiation and its actually one of the few things that does make sense to me :) but if I were to instantiate my form, would I not have two form objects? To simplify things, lets say I have a some data in Class1 and I would like to pass a string into a label on Form1. Is it legal to instantiate another form1? When trying to do so it looks like I can then access label1.Text but the label isn’t updating. The only thing I can think of is that the form needs to be redrawn or there is some threading issue that I’m unaware of. Any insight you could provide would be greatly appreciated.

    Read the article

  • iterating through an array

    - by Farstucker
    Iterating though an array isn’t a problem but what if I only wanted to incremented only when the method is called? Im not even sure if this would work but is there an easier way of doing this int counter; string[] myArray = {"foo", "bar", "something", "else", "here"}; private string GetNext() { string myValue = string.Empty; if (counter < myArray.Length) { myValue = myArray [counter]; } else { counter = 0; } counter++; return myValue; }

    Read the article

  • C# Using singleton instead of a global static instance

    - by Farstucker
    I ran into a problem today and a friend recommended I use a global static instance or more elegantly a singleton pattern. I spent a few hours reading about singletons but a few things still escape me. Background: What Im trying to accomplish is creating an instance of an API and use this one instance in all my classes (as opposed to making a new connection, etc). There seems to be about 100 ways of creating a singleton but with some help from yoda I found some thread safe examples. ..so given the following code: public sealed class Singleton { public static Singleton Instance { get; private set; } static Singleton() { Instance = new Singleton(); } } How/Where would you instantiate the this new class and how should it be called from a separate class? Thanks for your help.

    Read the article

  • Grading your programming ability?

    - by Farstucker
    I understand this is a subjective question and very likely could be closed, and although there is no right or wrong answer I do believe its a legitimate question. At what point do you no longer consider someone a beginner (ie knowledge of loops, encapsulation, instantiation), an intermediate (design patterns, reflection, delegates, interfaces) or an expert (architecture, multi-threadding). My rational for asking such a question is two-fold, first, when do I stop labeling my questions as beginner and during a job interview how should I categorize myself?

    Read the article

  • dynamically updating a datagrid from a XML file c# 3.5

    - by Farstucker
    I have a datagrid that is populated via XML file when the form loads. Everything is working great but I would like the datagrid to update dynamically when a new order is received (Separate class receives a data stream and updates the file). Im looking for suggestions on how this should be done. (ie using a timer update every second, or monitor the file using FileSystemWatcher.. etc) Since where here, I might as well mention that in order to update the datagrid Im clearing the whole data set and Re-reading the file using: DataSet.Clear(); DataSet.ReadXml("file.xml"); dataGridView1.DataSource = DataSet; if this is not the proper approach, please offer any alternate suggestions.

    Read the article

  • Instantiation vs. Typed reference

    - by Farstucker
    Just when I think Im starting to understand the basics, I find something that brings me right back to reality. In this case, typed reference. I found an example similar to this: class Worker { Boss boss; public void Advise(Boss pBoss) { this.boss = pBoss; } How can you reference methods within the Boss class if its not static and not instantiated? I guess my real question is whats the difference between: Boss boss; and Boss boss = new Boss(); Thank you, FS

    Read the article

  • Should I use an ArrayList or IList

    - by Farstucker
    Im using the .NET framework 1.1 and Im hoping someone could help me implement a dynamic array of objects? A watered-down example of the object I wish use is below. Class CarObj { public string CarName; public string CarYear; } Should I use an ArrayList or do you think it would be better to make a CarList class to implement an IList interface? Is there a performance benefit for one over another?

    Read the article

1