示例#1
0
        // Handle mouse clicks
        private void OnCheckBoxClickEvent(object sender, EventArgs args)
        {
            CheckBoxListItem item = _availableComics.Items[_availableComics.SelectedIndex] as CheckBoxListItem;

            if (item == null)
            {
                return;
            }

            ComicInfo ci = (ComicInfo)item.Value;

            SingletonComicsUpdater.Instance.Subscribe(ci.DisplayName, item.CheckBox.Checked);
            return;
        }
示例#2
0
        // Click the checkbox to subscribe or unsubscribe
        private void OnItemActivated(object sender, ItemActivatedArgs args)
        {
            CheckBoxListItem item = _availableComics.Items[args.ActivatedIndex] as CheckBoxListItem;

            if (item == null)
            {
                return;
            }

            item.CheckBox.Checked = !item.CheckBox.Checked;
            ComicInfo ci = (ComicInfo)item.Value;

            SingletonComicsUpdater.Instance.Subscribe(ci.DisplayName, item.CheckBox.Checked);
            return;
        }
        // Update the subscribed comics
        public void UpdateSubscribedComics(ArrayList subscribedComics)
        {
            ArrayList newComics = new ArrayList();

            // Download each comic subscribed to
            foreach (ComicInfo ci in subscribedComics)
            {
                try
                {
                    ComicInfo ciAdded = UpdateSingleComic(ci);
                }
                catch
                {
                }
            }
        }
        public static ArrayList LoadComics(string fileName)
        {
            ArrayList comics;
            // PropertyBagArray
            PropertyBag bags;

            comics = new ArrayList();
            bags   = new PropertyBag();
            bags.Load(fileName);
            for (int x = 0; x < bags.BagCount; x++)
            {
                PropertyBag bag;
                ComicInfo   ci;

                bag = (PropertyBag)bags.GetBagAt(x);
                ci  = new ComicInfo();

                for (int y = 0; y < bag.PropertyCount; y++)
                {
                    string name, val;
                    bag.GetPropertyAt(y, out name, out val);

                    if (name == "Website")
                    {
                        ci.Website = val;
                    }
                    if (name == "FolderName")
                    {
                        ci.FolderName = val;
                    }
                    if (name == "DisplayName")
                    {
                        ci.DisplayName = val;
                    }
                    else if (name == "ImageSuffix")
                    {
                        ci.ImageSuffix = val;
                    }
                    else if (name == "ImageFilename")
                    {
                        ci.ImageFilename = val;
                    }
                    else if (name == "ImagePath")
                    {
                        ci.ImagePath = val;
                    }
                    else if (name == "Subscribed")
                    {
                        try
                        {
                            ci.Subscribed = bool.Parse(val);
                        }
                        catch (Exception e)
                        {
                            Helpers.AppException.PrintException(e);
                        }
                    }
                }

                comics.Add(ci);
            }

            return(comics);
        }
        // Get a single comic
        private ComicInfo UpdateSingleComic(ComicInfo ci)
        {
            for (int i = 0; i < daysToKeep; i++)
            {
                // Create a webclient
                System.Net.WebClient webClient = new System.Net.WebClient();

                // Create the image filename from the format in the XML file
                char[] delims = { '$' };
                // Parse the String format and form the path with the year
                String[] ImagePathTokens = ci.ImagePath.Split(delims, 100);
                String   ImagePath       = "";
                foreach (String s in ImagePathTokens)
                {
                    int dt = DateTime.Now.Year;
                    // Year
                    if (s.Equals("yyyy"))
                    {
                        ImagePath += dt.ToString();
                    }
                    else
                    {
                        ImagePath += s;
                    }
                }

                // Parse the String format and form the filename with the date
                // Dilbert Hack: Create a filename to store that is consistent with the rest
                String[] FilenameTokens     = ci.ImageFilename.Split(delims, 100);
                String   URIImageFilename   = "";
                String   SavedImageFilename = "";
                foreach (String s in FilenameTokens)
                {
                    DateTime dt = DateTime.Now.AddDays(-i);
                    // Year
                    if (s.Equals("YY"))
                    {
                        SavedImageFilename += dt.ToString("yy", DateTimeFormatInfo.InvariantInfo);
                    }
                    // Month
                    else if (s.Equals("MM"))
                    {
                        SavedImageFilename += dt.ToString("MM", DateTimeFormatInfo.InvariantInfo);
                    }
                    // Day
                    else if (s.Equals("DD"))
                    {
                        SavedImageFilename += dt.ToString("dd", DateTimeFormatInfo.InvariantInfo);
                    }
                    else
                    {
                        SavedImageFilename += s;
                    }
                }

                // Comics.com support
                if (ci.Website == "Comics.com")
                {
                    try
                    {
                        DateTime        dt = DateTime.Now.AddDays(-i);
                        HttpWebRequest  webreq;
                        HttpWebResponse webres;
                        string          trimmedPath = ci.ImagePath.Remove(ci.ImagePath.IndexOf("images/"), 7);
                        System.Uri      uri         = new System.Uri(trimmedPath + ci.FolderName + "-" + DateTime.Now.Year.ToString() + dt.ToString("MM", DateTimeFormatInfo.InvariantInfo) + dt.ToString("dd", DateTimeFormatInfo.InvariantInfo) + ".html");
                        webreq = (HttpWebRequest)WebRequest.Create(uri);
                        webres = (HttpWebResponse)webreq.GetResponse();
                        Stream resStream = webres.GetResponseStream();
                        string response  = new StreamReader(resStream).ReadToEnd();
                        response = response.Substring(response.IndexOf("archive/images/" + ci.FolderName));
                        string[] responseArray = response.Split('/');
                        char[]   dms           = new  Char[] { '"', '&' };
                        URIImageFilename = responseArray[2].Split(dms)[0];
                        ci.ImageSuffix   = URIImageFilename.Split('.')[1];
                    }
                    catch (Exception e)
                    {
                        SnapStream.Logging.WriteLog(e.StackTrace);
                    }
                }
                // End Comics.com support

                // Add the extension name to the save file name
                SavedImageFilename += "." + ci.ImageSuffix;

                // ucomics filename needs an extension
                if (ci.Website != "Comics.com")
                {
                    URIImageFilename = SavedImageFilename;
                }

                // Add the website path before the image filename
                String URIImagePath = ImagePath + URIImageFilename;

                // Download the image
                try
                {
                    // Prepare the local storage folder, if it needs to be created
                    string alphaNumericName = ToAlphaNumericString(ci.FolderName);
                    string comicDirectory   = _homeDirectory + "\\" + alphaNumericName;
                    if (System.IO.Directory.Exists(comicDirectory) == false)
                    {
                        System.IO.Directory.CreateDirectory(comicDirectory);
                    }

                    // Now create the local image path to save the file
                    string imagePath = _homeDirectory + "\\" + alphaNumericName + "\\" + SavedImageFilename;

                    // If the file exists, don't download it again
                    if (System.IO.File.Exists(imagePath) == false)
                    {
                        string tempFilename = System.IO.Path.GetTempFileName();
                        webClient.DownloadFile(URIImagePath, tempFilename);
                        System.IO.File.Copy(tempFilename, imagePath, true);
                        System.IO.File.Delete(tempFilename);
                    }
                }
                catch (Exception e)
                {
                    SnapStream.Logging.WriteLog(e.StackTrace);
                }
            }
            // Now add
            ComicInfo ciAdd = new ComicInfo();

            return(ciAdd = ci);
        }
        // Get a single comic
        private ComicInfo UpdateSingleComic( ComicInfo ci )
        {
            for (int i = 0; i < daysToKeep; i++)
            {
                // Create a webclient
                System.Net.WebClient webClient = new System.Net.WebClient();

                // Create the image filename from the format in the XML file
                char[] delims = {'$'};
                // Parse the String format and form the path with the year
                String[] ImagePathTokens = ci.ImagePath.Split(delims,100);
                String ImagePath = "";
                foreach( String s in ImagePathTokens )
                {
                    int dt = DateTime.Now.Year;
                    // Year
                    if ( s.Equals("yyyy") )
                        ImagePath += dt.ToString();
                    else
                        ImagePath += s;
                }

                // Parse the String format and form the filename with the date
                // Dilbert Hack: Create a filename to store that is consistent with the rest
                String[] FilenameTokens = ci.ImageFilename.Split(delims,100);
                String URIImageFilename = "";
                String SavedImageFilename = "";
                foreach( String s in FilenameTokens )
                {
                    DateTime dt = DateTime.Now.AddDays(-i);
                        // Year
                    if ( s.Equals("YY") )
                    {
                        SavedImageFilename += dt.ToString("yy",DateTimeFormatInfo.InvariantInfo);
                    }
                        // Month
                    else if ( s.Equals("MM") )
                    {
                        SavedImageFilename += dt.ToString("MM",DateTimeFormatInfo.InvariantInfo);
                    }
                        // Day
                    else if ( s.Equals("DD") )
                    {
                        SavedImageFilename += dt.ToString("dd",DateTimeFormatInfo.InvariantInfo);
                    }
                    else
                    {
                        SavedImageFilename += s;
                    }
                }

                // Comics.com support
                if ( ci.Website == "Comics.com" )
                {
                    try
                    {
                        DateTime dt = DateTime.Now.AddDays(-i);
                        HttpWebRequest webreq;
                        HttpWebResponse	webres;
                        string trimmedPath =  ci.ImagePath.Remove(ci.ImagePath.IndexOf("images/"),7);
                        System.Uri uri = new System.Uri(trimmedPath+ci.FolderName+"-"+DateTime.Now.Year.ToString() + dt.ToString("MM",DateTimeFormatInfo.InvariantInfo) + dt.ToString("dd",DateTimeFormatInfo.InvariantInfo) + ".html");
                        webreq = (HttpWebRequest)WebRequest.Create(uri);
                        webres = (HttpWebResponse)webreq.GetResponse();
                        Stream resStream = webres.GetResponseStream();
                        string response = new StreamReader( resStream ).ReadToEnd();
                        response = response.Substring(response.IndexOf("archive/images/"+ci.FolderName));
                        string[] responseArray = response.Split('/');
                        char[] dms = new  Char[] {'"','&'};
                        URIImageFilename = responseArray[2].Split(dms)[0];
                        ci.ImageSuffix = URIImageFilename.Split('.')[1];
                    }
                    catch (Exception e)
                    {
                        SnapStream.Logging.WriteLog( e.StackTrace );
                    }
                }
                // End Comics.com support

                // Add the extension name to the save file name
                SavedImageFilename += "." + ci.ImageSuffix;

                // ucomics filename needs an extension
                if (ci.Website != "Comics.com")
                    URIImageFilename = SavedImageFilename;

                // Add the website path before the image filename
                String URIImagePath = ImagePath + URIImageFilename;

                // Download the image
                try
                {
                    // Prepare the local storage folder, if it needs to be created
                    string alphaNumericName = ToAlphaNumericString( ci.FolderName );
                    string comicDirectory = _homeDirectory + "\\" + alphaNumericName;
                    if( System.IO.Directory.Exists(comicDirectory) == false )
                    {
                        System.IO.Directory.CreateDirectory( comicDirectory );
                    }

                    // Now create the local image path to save the file
                    string imagePath = _homeDirectory + "\\" + alphaNumericName + "\\" + SavedImageFilename;

                    // If the file exists, don't download it again
                    if( System.IO.File.Exists(imagePath) == false )
                    {
                        string tempFilename = System.IO.Path.GetTempFileName();
                        webClient.DownloadFile( URIImagePath, tempFilename );
                        System.IO.File.Copy( tempFilename, imagePath, true );
                        System.IO.File.Delete( tempFilename );
                    }
                }
                catch (Exception e)
                {
                    SnapStream.Logging.WriteLog( e.StackTrace );
                }
            }
            // Now add
            ComicInfo ciAdd = new ComicInfo();
            return ciAdd = ci;
        }
        public static ArrayList LoadComics( string fileName )
        {
            ArrayList			comics;
            // PropertyBagArray
            PropertyBag			bags;

            comics = new ArrayList();
            bags = new PropertyBag();
            bags.Load( fileName );
            for( int x=0; x < bags.BagCount; x++ )
            {
                PropertyBag bag;
                ComicInfo	ci;

                bag = (PropertyBag)bags.GetBagAt(x);
                ci = new ComicInfo();

                for( int y=0; y < bag.PropertyCount; y++ )
                {
                    string	name, val;
                    bag.GetPropertyAt( y, out name, out val );

                    if( name == "Website" )
                    {
                        ci.Website = val;
                    }
                    if( name == "FolderName" )
                    {
                        ci.FolderName = val;
                    }
                    if( name == "DisplayName" )
                    {
                        ci.DisplayName = val;
                    }
                    else if( name == "ImageSuffix" )
                    {
                        ci.ImageSuffix = val;
                    }
                    else if( name == "ImageFilename" )
                    {
                        ci.ImageFilename = val;
                    }
                    else if( name == "ImagePath" )
                    {
                        ci.ImagePath = val;
                    }
                    else if( name == "Subscribed" )
                    {
                        try
                        {
                            ci.Subscribed = bool.Parse( val );
                        }
                        catch( Exception e )
                        {
                            Helpers.AppException.PrintException( e );
                        }
                    }
                }

                comics.Add( ci );
            }

            return comics;
        }