0

I have a file in the following format consisting of multiple entries in different lines. DirectorName MovieName GrossRevenue . eg

abc movie1 1mill
xyz movie2 2mill
abc movie3 1mill
abc movie2 4mill

the director name repeats itself and so does the moviename (director1 can direct a movie with the same name as director2)? what would be the best way to parse the file while providing the ability to get details like, total revenue for a director. I was planning on having a Dictionary of dictionaries something like

   Dictionary<string, Dictionary<string,long>> 

with the key for the outer dictionary being director name and the key for the inner dictionary being movie name. I could make this look better by wrapping my inner dictionary within a custom class but I was wondering if there is a better approach to this problem. Also how would i design this so that if later my file has additional content like genre, actors etc added , i would still not have to do a complete redesign while providing the ability to group by genre or actor

5
  • 2
    You should use a database and Entity Framework. Commented May 4, 2012 at 20:38
  • I am aware that storing the data in a database would simplify the problem but I am looking for a solution that works with parsing the file and no databases. One more solution i can think of is to create a class with properties for the 3 fields (name, movie name and revenue), create objects and use linq queries on a collection of those objects Commented May 4, 2012 at 20:43
  • 1
    You're trying to turn a relational problem into a hierarchical solution, which is going to be a real pain. The first step is deciding on your entities and their relationships. Commented May 4, 2012 at 20:44
  • How can movie2 have 2 different gross revenues? If it's a different movie with the same name, don't you want to use a unique identifier? Commented May 4, 2012 at 20:47
  • 'movie2' is just the name of the movie , it's two different movies directed by two different people but with the same name Commented May 4, 2012 at 20:50

2 Answers 2

1

Rather than using the Dictionary, You can use a custom class with Generic List.

you can create a class like

public class Director {

 public string StrDirector { get; set; }
 public string StrMovie { get; set; }
 public Long Revenue { get; set; }

}

then use the

List<Director> LstEntity = new List<Director>();
Director objDirector = new Director();
objDirector.StrDirector = "abc";
objDirector.StrMovie = "xyz";
objDirector.Revenue = 1000;
LstEntity.Add(objDirector);

//Add each Director Same way

This way, In future , if you need to make any modification in the director's attributes, you can easily make by updating the class without any problem.

I hope that will resolve your problem.

Sign up to request clarification or add additional context in comments.

Comments

1

I would first add a class

public class Movie
{
    public string MovieName {get;set;}
    public DateTime ProductionDate {get;set}
    public decimal Revenue  {get;set;}

    public List<MoviePerson> Stuff {get;set;}
}

public class MoviePerson
{
   public enum PersonType{Actor,Director, ....}

   public string Name {get;set;}
   public string Surname {get;set;}
   public PersonType Duty {get;set}
   ...
}

Having the collection of Movies you can simply query it for director, example

List<Movie> movies = new List<Movie>();
....

MoviePerson director = 
         new MoviePerson {Name = "James",
                                Surname = "Cameron", 
                                   PersonType = Director}
from movie in movies where movie.Stuff.Contains(director) select movie

To make this work you have to override default reference comparison of MoviePerson.

These are just ideas, you have to fit them to your needs.

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.