Not sure how to store some data - c#

I'm making a website that lets you share your music tastes, it works with a desktop client that monitors your media player (iTunes, whatever), and sends the details of the song that is currently playing to the site, where it is associated with your profile.
This output is displayed on your profile, and the idea is the page mirrors your local music player, right down the the position of a progress bar.
However I can't decide how to store the data. As soon as the song is over, it becomes useless, so something permanent like a MySQL database seems pointless.
Session variables don't work, because the script that does the work is not directing you to the page that displays the output. The idea is that the backend script just gets the info as it arrives and saves it somewhere, and you can get the latest info whenever you load the profile page.
I'm currently using a textfile, as a bad and temporary solution, just writing a new line each time and then reading it.
What is there between session variables and SQL?
And how can I get the output page to update every time there is new data? I need a way of storing it that allows events to be triggered, so checking it mustn't be too intensive.

I think a (My)SQL database would be alright, especially if you want to show the last few songs somebody played.
But if you just need a temporary data store to hold a single song per user, you could use a key-value store like memcached. It stores data directly in memory instead of a file or database. The key would be something unique (like the user's name or id) and the value would be data about the currently playing song.

You should look into memcached with a low cache expiry on keys of this type.

I would definitely store this in a database with a timestamp. For your display query, all you have to do is select the most recent (unless it has been more than a certain amount of time, in case the player is disconnected).
It might be best to hang on to this data. You may want it later to show which songs they play most or something. Otherwise, you can always delete the old records. I suspect keeping them will be worthwhile later. (Also consider the privacy implications of this. Make sure you tell your users the kind of data you keep in your privacy policy.)

Well I think you could use SQL, just have a table that stores the UserId, "current/last" song field, "currentlyPlaying" (bool), and you keep writting on top of that field everytime there is a new song, so that way you only have one row for each user all the time. It is still permanent, but you only keep track of the last song.
As a sidenote, you might want to save in a more permanently way all the songs a user plays.. if it is supposed to be a music tastes sharing site, having a history of played songs would let you make some nice algorithms like recommendations, etc.

Related

Getting updated data from Active Directory?

I have an app with a User table that was populated by an export from the Active Directory user list. Every couple of weeks the users send me another spreadsheet with the latest AD user list, and I have to update our User table with my own magic involving manipulating Excel and matching up usernames to know whether to insert or update.
I think it's time to automate this whole task. The easy way would be to have a scheduled task that polls AD every so often and updates all user information. But that might be a bit of a waste, since 99% of the time nothing will have changed between polls. One answer might be if there's a LastUpdated field anywhere in the AD user list, so I can know whether my information for any given user is up to date. Is there?
If not, is there any way of subscribing to some kind of push notification from AD, so that I don't have to keep checking, but when a user is inserted, updated or deleted, my app will get notified?
There is a way for push notification (LDAP change notification control) but it is restricted to monitoring a single object or the immediate children of a container. Besides, it may greatly affect performance of server.
Instead you may pick the pull mechanism: DirSync or USNChanged.
I am using DirSync in my project and it's working fine.
For details:
http://msdn.microsoft.com/en-us/library/ms677625(v=vs.85).aspx

How can I copy HTML textbox values from one domain to another domain's textboxes?

I'm trying to help save time at work with for a lot of tedious copy/paste tasks we have.
So, we have a propitiatory CRM (with proper HTML ID's, etc for accessing elements) and I'd like to copy those vales from the CRM to textboxes on other web pages (outside of the CRM, so sites like Twitter, Facebook, Google, etc)
I'm aware browsers limit this for security and I'm open to anything, it can be a C#/C++ application, Adobe AIR, etc. We only use Firefox at work so even an extension would work. (We do have GreaseMonkey installed so if that's usable too, sweet).
So, any ideas on how to copy values from one web page to another? Ideally, I'm looking to click a button and have it auto-populate fields. If that button has to launch the web pages that need to be copied over to, that's fine.
Example: Copy customers Username from our CRM, paste it in Facebook's Username field when creating a new account.
UPDATE: To answer a user below, the HTML elements on each domain have specific HTML ID's. The data won't need to be manipulated or cleaned up, just a simple copy from ourCRM.com to facebook.com / twitter.com
Ruby Mechanize is a good bet for scraping the data. Then you can store it and post it however you please.
First, I'd suggest that you more clearly define exactly what it is you're looking to do. I read this as you're trying to take some unstructured data from Point A and copy it to Point B. Do the names of these fields remain constant every time you do the operation? Do you need to simply pull any textbox elements from the page and copy them all over? Do some sort of filtering of this data before writing it over?
Once you've got a clear idea of the requirements, if you go the C# route, I'd use something like SimpleBrowser. Judging by the example on their Github page, you could give it the URL of the page you're looking to copy, then name each of the fields you're looking to obtain the value of, perhaps store these in an IDictionary, then open a new URL and copy those values back into the page (and submit the form).
Alternatively, if you don't know the names of the fields, perhaps there's a provided function in that or a similar project that will allow you to simply enumerate all the text fields on the page and retrieve the values for all of them. Then you'd simply apply some logic of your own to filter those options down to whatever is on the destination form.
SO we thought of an easier way to do this (in case anyone else runs into this issue).
1) From our CRM, we added a "Sign up for Facebook" button
2) The button opens a new window with GET variables in the URL
3) Use a greasemonkey script to read those GET variables and fill in textbox values
4) SUCCESS!
Simple, took about 10 minutes to get working. Thanks for you suggestions.

Where to save dynamic website text

I'd like to give the users of my ASP.NET website the possibility to write/change texts on the start site.
The texts are constantly changing and are therefore not static.
The texts are on the start page of the site, so saving it to the database wouldn't be the best choice, right? Because there would be a database access at every page call.
So my question is: What is the best practice to save this texts? Should I save it in the database? In a text file? xml file? In the web.config?
Edit: An example for the usage:
There is a "contact" area on the start page, the admin should be able to modifiy the content of this contact area. So this data not static, it should be editable.
you can, of course, do many different things, but the normal thing is to just store it in a database and use a caching mechanism if you are concerned about round trips to database.
When a user clicks the submit, button it has to go to the database. Edits and small changing will happen normally. Once the submition, is clicked, it has to go somewhere and a database call needs to happen. You can save it in session, but that will go away if the user goes away.
If it is not a permanent data why not store it in Session?

How do I count how many times someone has logged onto my system?

I am building a basic atm and want to know how to count how many times someone has logged in.
I have a button which when I press I want it to display the amount of logins in the textbox next to it but I am unsure how I would count how many times someone logs in.
Any advice would be great thanks
I am using c#
In whatever data store that you are using to authenticate, you can also store how many times someone logged in. So you look up the user in a user table, and then update the user's row when the log on is successful.
If this is a learning-to-program sort of thing, you might not have a fancy datastore like a sql database, so you can use simple data stores.
The System.Data.DataSet can be saved to a file and behaves like a mini-database. It's what I use when I'm writing throwaway code and I don't want to set up a sql database, but want more features than using System.IO to write to text files. (or raw xml files which have their own overhead, like having to write rather involved reading & parsing logic)

Keyword entries for videos coming back blank, subsequently deleted

UPDATE: apparently this only happens when fetching videos from a playlist feed, which is what I'm doing.
I recently noticed my youtube api requests for videos were returning blank keyword entries. I found the blog post at http://apiblog.youtube.com/2012/08/video-tags-just-for-uploaders.html, and I'm already sending requests as the channel/video owner, yet I still get blank keywords. This has the undesirable side-effect of deleting existing keywords if I make any changes to the video details, such as to descriptions or titles.
For instance, I have video series where every video will have the same description. Perfect place to use the API to run through all the vids in a list and update their details. This used to work fine. But one ill-fated day, this routine became destructive. Any time I do this now, the keywords get blanked out, and I have to go back through all of the affected vids, replacing the lost keywords by hand. I've stopped using my API-based utility since this began happening.
The descriptions and titles will get updated as desired, but the keywords get blanked out, even if I don't touch them. I recall reading somewhere in the API docs something to the effect that when you submit updates for video details, any entries not filled in will be erased. In this instance, because the keyword entries I get back are already blank, any updates I do to the video other than to the keywords cause the keywords to be deleted.
Anybody have any ideas or workarounds? If I can't continue using the API to manage keywords, I would at least like to be able to continue making updates to titles and descriptions, but that won't work right now because the keywords get deleted with any title or description updates :(
The YouTube API should absolutely return media:keywords when you make an authenticated request for a video or a feed of videos in the current account. You can test it yourself at
http://gdata.youtube.com/demo/index.html
Click Authenticate there, then make a request for Uploads -> Query, and enter default as the user name. Run that request and take a look at the responses—all the videos that actually have keywords should have a media:keywords returned for them. (Obviously if you've already deleted the keywords for a given video, they won't be returned, so test with a newly uploaded video that you've set keywords for.)
There is an internal bug that I believe is still open that prevented media:keywords from being returned in playlist entries when you're fetching a playlist feed. Are you perhaps reading your videos from a playlist?
Actually, this is a known issue as YouTube decided to allow Keywords retrieval only for authenticated users.
This is very annoying, but I'm also currently looking for a way safe way to retrieve those keywords, using Zend, without writing donw my password in plain text.
Let's look for a solution together :)
YOUTUBE API : Retrieve video keywords

Categories

Resources