/// <summary>
        /// Call this to check/create an xml file of avaliable photos
        /// </summary>
        /// <param name="datapath">The path were the data should be saved</param>
        /// <param name="numberOfPhotos">the number of photos found</param>
        /// <param name="database">The Xml database</param>
        void ValidateDatabaseFile(ref string datapath, ref PhotoDataSet database)
        {
            // check that the database exists if not create it
            if (!System.IO.File.Exists(datapath))
            {
                System.IO.File.Create(datapath).Close();
            }
            try
            {
                // check the xml document exists
                if (database == null)
                    database = new PhotoDataSet();
                // lock it

                if (database.Log.Rows.Count == 0)
                {
                    // load into it
                    database.ReadXml(datapath, XmlReadMode.Auto);
                }
                this.mNumberOfPictures = database.Photo.Count;


            }
            catch (Exception er)
            {
                database = new PhotoDataSet();
                this.mNumberOfPictures = -1;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Attempts to login to Google Accounts
        /// </summary>
        /// <returns></returns>

        /*  public bool CheckLogin(out token)
         * {
         *    WebProxy myProxy = CreateProxy();
         *    PicasaWebReader reader = new PicasaWebReader(this.mUserName, this.mPassword, "WallpaperReader", myProxy);
         *    string CAPTCHA = string.Empty;
         *    string temptoken = reader.LoginToGoogle(out CAPTCHA);
         *    if(temptoken == string.Empty)
         *        return false;
         *    else
         *        token = temptoken;
         *
         *    reader.Dispose();
         *    reader = null;
         *    myProxy = null;
         *    if (token == string.Empty)
         *        return CAPTCHA;
         *    else
         *        return token;
         * }*/

        /// <summary>
        /// Looks for changes in the web album
        /// </summary>
        /// <param name="database"></param>
        /// <param name="tags"></param>
        /// <returns></returns>
        public int Reindex(ref PhotoDataSet database, bool tags)
        {
            this.mDatabase = database;
            DateTime lastUpdated;

            if (tags)
            {
                lastUpdated = this.GetAllAvailablePhotos();
            }
            else
            {
                lastUpdated = this.GetUpdatedPhotos();
            }
            return(Update(lastUpdated));
        }
Ejemplo n.º 3
0
        /// <summary>Password1
        ///
        /// Gets a picture changer info object
        /// </summary>
        /// <param name="database">The xml document containg the data</param>
        /// <param name="datapath">The path to the database</param>
        /// <param name="wallpaperSize">The %screen size of the wall paper</param>
        /// <returns>A picture change info object that will be used to change the wallpaper</returns>
        protected internal PictureChangerInfo ChangePhoto(PhotoDataSet database, string datapath, Decimal wallpaperSize)
        {
            this.mRandom = new Random();
            int next = 0;

            if (database.Photo.Count > 0)
            {
                // get a random number to determine which photo
                try
                {
                    next = this.mRandom.Next(0, database.Photo.Count - 1);
                    if (next == -1)
                    {
                        next = 0;
                    }
                }
                catch (Exception ex)
                {
                    this.ev_ExceptionThrown(ex, "Changing photo. Getting a random number returned an out of range value");

                    this.mRandom = null;
                    return(PictureChangerInfo.nothing);
                }


                PicasaWebPhotoConverter photo = null;

                try
                {
                    // downloads the photo
                    photo = new PicasaWebPhotoConverter(database.Photo[next].Location, database.Photo[next].Height.ToString(), database.Photo[next].Width.ToString());
                    try
                    {
                        // create the photo as file
                        photo.CreateImage();
                    }
                    catch (Exception ex)
                    {
                        this.ev_ExceptionThrown(ex, "Creating photo. Downloading from web. Photo Id " + database.Photo[next].ID);
                        if (photo != null)
                        {
                            photo.Dispose();
                        }
                        photo = null;

                        this.mRandom = null;

                        return(PictureChangerInfo.nothing);
                    }
                }
                catch (Exception ex)
                {
                    this.ev_ExceptionThrown(ex, "Creating photo. Creating converter. Photo Id " + database.Photo[next].ID);
                    if (photo != null)
                    {
                        photo.Dispose();
                    }
                    photo = null;

                    this.mRandom = null;

                    return(PictureChangerInfo.nothing);
                }

                try
                {
                    // look for and deletes any bitmaps in the  program directory
                    foreach (string file in Directory.GetFiles(datapath, "*.bmp"))
                    {
                        File.Delete(file);
                    }
                }
                catch (Exception ex)
                {
                    this.ev_ExceptionThrown(ex, "Deleting old image. Deleting old bitmaps.");
                    if (photo != null)
                    {
                        photo.Dispose();
                    }
                    photo = null;

                    this.mRandom = null;

                    return(PictureChangerInfo.nothing);
                }
                try
                {
                    // scales the photo to display on the screen.
                    photo.Scale(wallpaperSize).Save(datapath + "\\" + database.Photo[next].PhotoID + ".bmp", ImageFormat.Bmp);
                }
                catch (Exception ex)
                {
                    this.ev_ExceptionThrown(ex, "Creating photo. Saving and scaling. Photo Id " + database.Photo[next].ID);
                    if (photo != null)
                    {
                        photo.Dispose();
                    }
                    photo = null;
                    return(PictureChangerInfo.nothing);
                }

                if (photo != null)
                {
                    photo.Dispose();
                }
                photo = null;
            }
            else
            {
                return(new PictureChangerInfo(string.Empty, string.Empty, string.Empty));
            }


            return(new PictureChangerInfo(datapath + "\\" + database.Photo[next].PhotoID + ".bmp", database.Photo[next].Title, database.Photo[next].ID));
        }
Ejemplo n.º 4
0
        /// <summary>Password1
        /// 
        /// Gets a picture changer info object
        /// </summary>
        /// <param name="database">The xml document containg the data</param>
        /// <param name="datapath">The path to the database</param>
        /// <param name="wallpaperSize">The %screen size of the wall paper</param>
        /// <returns>A picture change info object that will be used to change the wallpaper</returns>
        protected internal PictureChangerInfo ChangePhoto(PhotoDataSet database,string datapath, Decimal wallpaperSize)
        {
                      
            this.mRandom = new Random();
            int next = 0;
            if (database.Photo.Count > 0)
            {
                // get a random number to determine which photo
                try
                {
                    next = this.mRandom.Next(0, database.Photo.Count - 1);
                    if (next == -1)
                        next = 0;
                }
                catch (Exception ex)
                {

                    this.ev_ExceptionThrown(ex, "Changing photo. Getting a random number returned an out of range value");

                    this.mRandom = null;
                    return PictureChangerInfo.nothing;
                }


                PicasaWebPhotoConverter photo = null;

                try
                {
                    // downloads the photo
                    photo = new PicasaWebPhotoConverter(database.Photo[next].Location, database.Photo[next].Height.ToString(), database.Photo[next].Width.ToString());
                    try
                    {
                        // create the photo as file
                        photo.CreateImage();
                    }
                    catch (Exception ex)
                    {
                        this.ev_ExceptionThrown(ex, "Creating photo. Downloading from web. Photo Id " + database.Photo[next].ID);
                        if (photo != null)
                            photo.Dispose();
                        photo = null;

                        this.mRandom = null;

                        return PictureChangerInfo.nothing;
                    }
                }
                catch (Exception ex)
                {
                    this.ev_ExceptionThrown(ex, "Creating photo. Creating converter. Photo Id " + database.Photo[next].ID);
                    if (photo != null)
                        photo.Dispose();
                    photo = null;

                    this.mRandom = null;

                    return PictureChangerInfo.nothing;
                }

                try
                {
                    // look for and deletes any bitmaps in the  program directory               
                    foreach (string file in Directory.GetFiles(datapath, "*.bmp"))
                    {
                        File.Delete(file);
                    }
                }
                catch (Exception ex)
                {
                    this.ev_ExceptionThrown(ex, "Deleting old image. Deleting old bitmaps.");
                    if (photo != null)
                        photo.Dispose();
                    photo = null;

                    this.mRandom = null;

                    return PictureChangerInfo.nothing;

                }
                try
                {
                    // scales the photo to display on the screen.
                    photo.Scale(wallpaperSize).Save(datapath + "\\" + database.Photo[next].PhotoID + ".bmp", ImageFormat.Bmp);
                }
                catch (Exception ex)
                {
                    this.ev_ExceptionThrown(ex, "Creating photo. Saving and scaling. Photo Id " + database.Photo[next].ID);
                    if (photo != null)
                        photo.Dispose();
                    photo = null;
                    return PictureChangerInfo.nothing;
                }

                if (photo != null)
                    photo.Dispose();
                photo = null;
            }
            else
                return new PictureChangerInfo(string.Empty, string.Empty, string.Empty);


            return new PictureChangerInfo(datapath + "\\" + database.Photo[next].PhotoID + ".bmp", database.Photo[next].Title, database.Photo[next].ID);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Attempts to login to Google Accounts
        /// </summary>
        /// <returns></returns>
      /*  public bool CheckLogin(out token)
        {
            WebProxy myProxy = CreateProxy();
            PicasaWebReader reader = new PicasaWebReader(this.mUserName, this.mPassword, "WallpaperReader", myProxy);
            string CAPTCHA = string.Empty;
            string temptoken = reader.LoginToGoogle(out CAPTCHA);
            if(temptoken == string.Empty)
                return false;
            else
                token = temptoken;

            reader.Dispose();
            reader = null;
            myProxy = null;
            if (token == string.Empty)
                return CAPTCHA;
            else
                return token;
        }*/

        /// <summary>
        /// Looks for changes in the web album
        /// </summary>
        /// <param name="database"></param>
        /// <param name="tags"></param>
        /// <returns></returns>
        public int Reindex(ref PhotoDataSet database, bool tags)
        {
            this.mDatabase = database;
            DateTime lastUpdated;
            if (tags)
                lastUpdated= this.GetAllAvailablePhotos();
            else
                lastUpdated = this.GetUpdatedPhotos();
            return Update(lastUpdated);
        }