Most efficient internal database for a media player - c#

I'm currently learning C# and .NET (coming from a UNIX background), and have just started writing a media player. I was hoping for some suggestions on the best way to store the internal database of songs. SQL? Some kind of text file? I don't really have any experience in this area so all points will be really appreciated.
Cheers!

You should probably use SQLite, and you can use LINQ on that to take full advantage of C# 3.5.
http://www.codeproject.com/KB/linq/linqToSql_7.aspx

There is also SQL Server Compact. Linq to Sql works with this as well.

There is a whole spectrum of requirements involved here, to name a few:
multi user?
exepected size(s)
do you want to store the multi media binaries as well?
for complex structured data text files won't do very well.
for storing binaries I wouldn't use XML
So it's probably going to be: What Sql database to use? You can search for discussions about SQLite, Sql Express, SqlCE etc.

A more fundamental question should probably be asked before we move along toward recommending one technology over another...
That of architecture. From the brief description above, it seems like what you are building is a Windows Media Player Library-like piece of functionality. If that's the case, the suggestion of a SQL database might seem appropriate, but the complication of synchronization of the filesystem (you weren't planning on turning the media files to be played into a monolithic datastore, were you?)
If you are instead only worried about persisting playlists.... a text-based format seems appropriate.
Playlists might want to be text-based (which, to me, includes XML representations of an object graph), but library information would seem to want to be in a more robust, more queryable datastore.
An object database could also be appropriate, as it lets you work with a much more transparent view of persistence compared to other suggestions. Isolating the number of new topics you're dealing with while you learn can be an important way to manage your learning curve. db4o has a .Net variation that I haven't looked at recently.

Related

Xamarin - Storage data in smartphone memory

I am work with xamarin and I need to storage data in memory of my Android device. In order to have the data once the game has reopened. How can I do? where can I find an example code?
Depends on data type, structure and your specific needs the approach may vary. Since we are talking about a game most probably you need a database. Luckily the official documentation nicely covering this topic.
Beside that if you using .NET Standard take a look on EntityFramework.
P.S.: Generally I would recommend to make a research (as the options above are not the only one) to compare existing solutions and than decide which way to go.
Akavache could be a good solution. It's fairly simple and flexible too.

Can No-SQL be used on the xbox 360 with xna and c# or vb.net?

I was wondering is their a dll library for no-sql written entirely in c# that can create databases for use on the xbox 360?
BerkeleyDB is a KeyValue embedded database, essentially the NoSQL equivalent of SQLite. Here is a C# Tutorial.
However, I strongly suggest finding an alternative solution to this. Unless you have a ton of data you're better off holding all your objects in RAM and persisting on a need basis with a JSON, XML, or whatever you want serializer. LINQ makes it incredibly easy to query in-memory objects the same way you'd query a database.
I found another possible solution thats open source :
http://ostrivdb.codeplex.com/
The reason for this is coding for xml on xbox byitself sucks and gets too complicated in a massive game project.
I will still click on Dharuns answer because he updated with c# tutorial but I wanted to show what I was talking about.

.Net ORM with the fastest learning curve?

A little briefing first; I've been a Delphi person for years, and been away from C# for two years. The last thing I've done in C# was a mid scale DB app with my own custom DAL. Ie, I had coded my own functions to retrieve data as list, functions to append data and so on. Now I am offered a small to mid scale project using C# WinForms and SQL Server, and there's a deadline which is about 2 or 3 weeks. Note that I forgot LINQ syntax and lots of things.
Now, which ORM would be easiest and fastest to learn? I can cope with not using business abstraction layer if need be, to gain time that is. I need something that'll ease manual labour. Thanks in advance.
For quick-to-implement etc, I'd look at LINQ-to-SQL; the jury is still out on who considers it to be full ORM, but tbh I don't care; it lets me map my data quickly, simply, conveniently and safely, with decent IDE/language support. The LINQ you generally need is pretty minimal... from, where, select, etc. And setting it up is just a case of telling the designer about the tables/columns vs clases/properties.
If I were you I would go for Entity framework. It's pretty simple,easy to implement, efficient and successful ORM tool. You can use LINQ as well in the entity framework while retrieving the data.
As a recent ex-Delphi developer I've been amazed with using MyGeneration to generate basic DAL/BLL classes from an existing database, via custom templates. Takes a lot of the drudgery out of the task.
I've also seen some high praise for Business Logic Toolkit for .NET. Its clean and simple architecture and small learning curve makes it very attractive. Not really ORM, but will get you up and running quickly.
If you search for the terms C#/ORM here, you will find lots of lively and interesting debates!
Choosing Database and ORM for a .NET project
Some suggestions on which .NET ORM to look at learning
https://stackoverflow.com/questions/132676/which-orm-for-net-would-you-recommend
https://stackoverflow.com/questions/146087/best-performing-orm-for-net
If you don't mind a commercial product, Lightspeed is almost too good to be true. I've used it for about 6 months now and it has helped me in every way possible, from designing the model using a graphical tool, to migrations when upgrading, updating the database with a single click, good unit testing, easy custom extending, validation, etc. At least try out the free version!
I have a project on .NET and MySQL. I've learned Devart LinqConnect in three weeks to complete it. All of LINQ functionality, wide support of MySQL, high quality support - like this product.

Which RDBMS and development tool should I choose to re-write my character-based app?

I have a pawnshop CRUD app written 20 years ago with INFORMIX-SQL/SE (DOS) which is currently running on DOS 6.22 within Microsoft Virtual PC 2007 on Windows Vista. I would like to modernize this app with a GUI, SQL-based engine and retain its existing functionality. It doesn't require any networking or multi-user capability. I would prefer a product which is royalty-free.
I also would like to quickly re-write it with as little effort possible. Which tool would you recommend?
I'm debating whether to re-write my INFORMIX-SQL app with I4GL (character-based) or another Windows/GUI-based tool.
My app is very robust and has some incredible features which my users are very happy with. Only obstacle which is keeping me from effectively acheiving market penetration is, believe it, my app is char-based and I would like to duplicate the same functionality with a GUI. My feeling is that its quicker for a user to process a transaction with my char-based app vs. having to focus a cursor with a mouse, but cosmetics is hurting me!
I would like to know specific instances of limitations, bugs or drawbacks of using another development tool before I invest considerable amount of time evaling another product. Answers to this question could save me a lot of time and money!
If you visit www.frankcomputer.com you can view a video-demo of my pawnshop app. (CAVEAT: The website's in Spanish, use google translate to get a more-or-less decent translation of the text. Start the video at the two-minute mark, with 720p resolution and full-screen to best comprehend my app.)
If I were doing it, I would probably choose to write a WPF GUI in C# with a SQL Server Express backend database. An embedded database like SQLite might work as well. But the main reason I would choose that is because that's what I'm most familiar with. Someone else would likely choose something else...
I might also choose ASP.NET MVC and make it a web application if that were an option (you say that multi-user is not required, but I say it's not required yet).
Also, if you're not the one who's going to be developing it (i.e. you're going to hire someone to build it for you) then I would say that you should find the developer first and let them choose (or at least have a say in) the technology. If you choose the technology up-front then you're simply limiting the field of developers who'll be able to work with you and there's really not much point in that.
I'd recommend you use Python with a PostgreSQL backend. Now some will think this is overkill, but after watching your video and reading your site (I had to use a translator), I suspect the added flexibility is something you will truly enjoy by going this route.
The reasons I'd argue for this solution are:
Python and PostgreSQL are both great products with amazing communities when you need them.
Both products have a bright outlook in their development paths. Since you obviously spent a lot of time and effort tweaking SPACE, I'm betting you will do the same over the next 40 years. So, the tools you choose now need to be there for you as you continue your development cycle.
They are both free with friendly licenses.
Cross-platform support.
Scalability. You can use PostgreSQL installed locally and connect via socket or scale it all the way up to several servers using load balanced connection pooling.
Security.
Data integrity. This includes how easy it is to make your whole environment easy to backup and thus easy to restore in the event of a catastrophe.
Whatever tools you end up choosing. I wish you the best in this project. I can tell you are working on something you truly love and that is something more of us should strive for!!
Based upon your answers and your emphasis upon time to make the changes and that you don't seem to want to change the Application at all but it is being forced upon you by then you should certainly evaluate Genero from 4js.
This will allow you to utilise your existing code but provide a nicer looking front-end. You can also maintain a single codebase supporting both character and "Gui" clients.
Choose whatever language and technology is easiest for you. If you need DB access and a short lead time it sounds like Java or Visual Basic would be best. Both have plenty of free tools to get you started.
The top languages tags in StackOverflow are C# (by a long margin), then Java, PHP and DotNet, followed by C++ and Python. Some of that will be skewed by the Joel & Jeff origin of the site, but any of those is more than capable of the task. Personally, I'd go with Java or Python but I don't like being tied to the Microsoft stack.
wxWidgets and QT might be options for the GUI components.
Of the databases, mysql, SQL Server Express or Oracle Express Edition are all free and robust. SQLite is good enough for most single user applications though. I'd put this at the bottom of the 'importance' list. For small-scale single user apps, you should be able to chop and change DB platforms without much hassle. The biggest relevance would be in how you actually backup/copy/restore data in the event of disk failure or corruption.

Serializing vs Database

I believe that the best way to save your application state is to a traditional relational database which most of the time its table structure is pretty much represent the data model of our system + meta data.
However other guys in my team think that today it's best to simply serialize the entire object graph to a binary or XML file.
No need to say (but I'll still say it) that World War 3 is going between us and I would like to hear your opinion about this issue.
Personally I hate serialization because:
The data saved is adhered only to your development platform (C# in my case). No other platforms like Java or C++ can use this data.
Entire object graph (including all the inheritance chain) is saved and not only the data we need.
Changing the data model might cause severe backward compatibility issues when trying to load old states.
Sharing parts of the data between applications is problematic.
I would like to hear your opinion about that.
You didn't say what kind of data it is -- much depends on your performance, simultaneity, installation, security, and availability/centralization requirements.
If this data is very large (e.g. many instances of the objects in question), a database can help performance via its indexing capabilities. Otherwise it probably hurts performance, or is indistinguishable.
If your app is being run by multiple users simultaneously, and they may want to write this data, a database helps because you can rely on transactions to ensure data integrity. With file-based persistence you have to handle that yourself. If the data is single-user or single-instance, a database is very likely overkill.
If your app has its own soup-to-nuts installation, using a database places an additional burden on the user, who must set up and maintain (apply patches etc.) the database server. If the database can be guaranteed to be available and is handled by someone else, this is less of an issue.
What are the security requirements for the data? If the data is centralized, with multiple users (either simultaneous or sequential), you may need to manage security and permissions on the data. Without seeing the data it's hard to say whether it would be easier to manage with file-based persistence or a database.
If the data is local-only, many of the above questions about the data have answers pointing toward file-based persistence. If you need centralized access, the answers generally point toward a database.
My guess is that you probably don't need a database, based solely on the fact that you're asking about it mainly from a programming-convenience perspective and not a data-requirements perspective. Serialization, especially in .NET, is highly customizable and can be easily tailored to persist only the essential pieces you need. There are well-known best practices for versioning this data as well, so I'm not sure there's an advantage on the database side from that perspective.
About cross-platform concerns: If you do not know for certain that cross-platform functionality will be required in the future, do not build for it now. It's almost certainly easier overall to solve that problem when the time comes (migration etc.) than to constrain your development now. More often than not, YAGNI.
About sharing data between parts of the application: That should be architected into the application itself, e.g. into the classes that access the data. Don't overload the persistence mechanism to also be a data conduit between parts of the application; if you overload it that way, you're turning the persisted state into a cross-object contract instead of properly treating it as an extension of the private state of the object.
It depends on what you want to serialize of course. In some cases serialization is ridicilously easy.
(I once wrote kind of a timeline program in Java,
where you could draw en drag around and resize objects. If you were ready you could save it in file (like myTimeline.til). On that momenet hundreds of objects where saved, their position on the canvas, their size, their colors, their innertexts, their special effects,...
You could than ofcourse open myTimeLine.til and work further.
All this only asked a few lines of code. (just made all classes and their dependencies
serializable) and my coding time took less than 5 minutes, I was astonished myself! (it was the first time I used serialization ever)
Working on a timeline you could also 'saveAs' for different versions and the 'til' files where very easy to backup and mail.
I think in my particular case it would be a bit idiot to use databases. But that's of course for document-like structures only, like Word to name one.)
My point thus first : there are certainly several scenarios in which databases wouldn't be the best solution. Serialization was not invented by developers just because they were bored.
Not true if you use XMLserialization or SOAP
Not quite relevant anymore
Only if you are not carefull, plenty of 'best practices' for that.
Only if you want it to be problematic, see 1
Of course serialization has besides the speed of implementation other important advantages like not needing a database at all in some cases!
See this Stackoverflow posting for a commentary on the applicability of XML vs. the applicability of a database management system. It discusses an issue that's quite similar to the subject of the debate in your team.
You have some good points. I pretty much agree with you, but I'll play the devil's advocate.
Well, you could always write a converter in C# to extract the data later if needed.
That's a weak point, because disk space is cheap and the amount of extra bytes we'll use costs far less than the time we'll waste trying to get this all to work your way.
That's the way of the world. Burn the bridges and require upgrades. Convert the data, or make a tool to do that, and then no longer support the old version's way of doing it.
Not if the C# program hands off the data to the other applications. Other applications should not be accessing the data that belongs to this application directly, should they?
For transfer and offline storage, serialization is fine; but for active use, some kind of database is far preferable.
Typically (as you say), without a database, you need to deserialize the entire stream to perform any query, which makes it hard to scale. Add the inherent issues with threading etc, and you're asking for pain.
Some of your other pain points about serialization aren't all true - as long as you pick wisely. Obviously, BinaryFormatter is a bad choice for portability and versioning, but "protocol buffers" (Google's serialization format) has versions for Java, C++, C#, and a lot of others, and is designed to be version tolerant.
Just make sure you have a component that handles saving/loading state with a clean interface to the rest of your application. Then whatever choice you make for persistence can easily be revisited later.
Serializing an object graph to a file might be a good quick and dirty initial solution that is very quick to implement.
But if you start to run into issues that make a database a better choice you can plug in a new version with little or no impact on the rest of the application.
Yes propably true. The downside is that you must retrieve the whole object which is like retrieving all rows from a table. And if it's big it will be a downside. But if it ain't so big and with my hobbyprojects they are not, so maybe they should be a perfect match?

Categories