Example #1
0
        /// <summary>
        /// Create a new instance of iTunes.
        /// </summary>
        /// <param name="itunes">iTunes application handle.</param>
        /// <param name="devices">List of devices to synchronize.</param>
        /// <param name="configuration">XML configuration</param>
        public DeviceSynchronizer(iTunesApp itunes, Hashtable devices, XmlConfiguration configuration)
        {
            this.itunes        = itunes;
            this.devices       = devices;
            this.configuration = configuration;

            //Check that necessary configuration is available.
            if (configuration.GetValue("SyncModule/FileStructure") == null ||
                configuration.GetValue("SyncModule/Priority") == null)
            {
                throw new ArgumentException("Missing necessary configuration.");
            }
        }
Example #2
0
        public static void ReadConfiguration()
        {
            DatabaseHost     = Instance.GetValue(ConfigName.DB_HOST);
            DatabaseName     = Instance.GetValue(ConfigName.DB_NAME);
            DatabaseUsername = Instance.GetValue(ConfigName.DB_USER);
            DatabasePassword = Instance.GetValue(ConfigName.DB_PASS);

            int iTimeout = Util.ConvertObjectToInteger(Instance.GetValue(ConfigName.SQL_DEFAULT_TIMEOUT));

            if (iTimeout == 0)
            {
                iTimeout = DB_EXECUTE_TIMEOUT;
            }
            SqlDefaultTimeout = iTimeout;
        }
Example #3
0
        /// <summary>
        /// Synchronize the player with iTunes.
        /// </summary>
        public void Synchronize()
        {
            IEnumerator e = devices.Keys.GetEnumerator();

            while (e.MoveNext())
            {
                //Get drive letter
                string driveletter = ((string)e.Current).Substring(0, 1);

                Device device  = (Device)devices[e.Current];
                string usepath = GetWorkingPath(driveletter, device.Folderpattern);

                //check that we have a path to use, report error if not
                if (usepath == null)
                {
                    OnSynchronizeError("Could not locate the correct folder on the device.", device);
                }
                else
                {
                    foreach (IITSource source in itunes.Sources)
                    {
                        foreach (IITPlaylist playlist in source.Playlists)
                        {
                            if (playlist.Name != device.Name)
                            {
                                continue;
                            }

                            foreach (IITTrack track in playlist.Tracks)
                            {
                                //Check that the track is a file. iTA currently only supports synchronization of files.
                                if (track.Kind != ITTrackKind.ITTrackKindFile)
                                {
                                    OnSynchronizeError("The track '" + track.Artist + " - " + track.Name
                                                       + " can not be copied. iTunes Agent currently only supports synchronization "
                                                       + "of music files, not CD-tracks or other types of media.", device);
                                    continue;
                                }

                                IITFileOrCDTrack fileTrack      = (IITFileOrCDTrack)track;
                                string           playerFileName = GetPlayerLocation(fileTrack);

                                string priority = configuration.GetValue("SyncModule/Priority");
                                //Priority == itunes means that only the files in the playlist in iTunes will be available on
                                //the device. All other music files in the media folder for the device will be removed!
                                if (priority == "itunes")
                                {
                                    DirectoryInfo di    = new DirectoryInfo(usepath);
                                    FileInfo[]    files = di.GetFiles("*", SearchOption.AllDirectories);
                                }
                                else
                                {
                                    string fullPathOnDevice = usepath + "\\" + playerFileName;
                                    if (File.Exists(fullPathOnDevice))
                                    {
                                        continue;
                                    }

                                    try
                                    {
                                        ConstructDirectories(usepath, playerFileName);
                                        File.Copy(fileTrack.Location, fullPathOnDevice);
                                    }
                                    catch (Exception ex)
                                    {
                                        OnSynchronizeError("Failed to copy '" + fileTrack.Artist + " - " + fileTrack.Name
                                                           + "' (" + ex.Message + ").", device);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            OnSynchronizeComplete();
        }