Exemplo n.º 1
0
        public static void AsyncCallbackImpl(IAsyncResult ar)
        {
            string path;

            try
            {
                path = fh.EndInvoke(ar);
                if (path == null)
                {
                    Console.WriteLine("Callback() failed to download...");
                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Callback() failed to download...");
                return;
            }
            Console.WriteLine(path + "\t Done...");
            SimplePhoto item = new SimplePhoto();

            item.path = path;

            mutex.WaitOne();
            if (PicStore.currentPhotos.Count > Setting.iMaxPicNum)
            {
                PicStore.Remove(0);
            }
            PicStore.currentPhotos.Add(item);
            PicStore.Save();
            mutex.ReleaseMutex();
        }
Exemplo n.º 2
0
 /*
  * Load: load date from file to memory
  */
 public static void Load()
 {
     for (int i = 0; i < 5; i++)
         photoAlbum[i] = new List<SimplePhoto>();
     if (!File.Exists(filename)) // check data.dat if exist
         return;
     StreamReader fRead = new StreamReader(filename, false); // file reader
     int count = int.Parse(fRead.ReadLine());    // read number of current photo
     for (int i = 0; i < count; i++)
     {
         // add photos into list
         SimplePhoto item = new SimplePhoto();
         item.path = fRead.ReadLine();
         for (int j = 0; j < Setting.picModeStr.Length; j++)
             if (Setting.picModeStr[j].Equals(item.path.Substring(0, 2)))
                 photoAlbum[j].Add(item);
     }
     currentPhotos = photoAlbum[Setting.picMode];
     fRead.Close();
     fRead.Dispose();
 }
Exemplo n.º 3
0
        static void Download()
        {
            while (true)
            {
                Console.WriteLine("Download() try to download...");
                string result;
                try
                {
                    result = NetConnect.HttpGet(url, data);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Download() fail to get response...");
                    Thread.Sleep(Setting.downloadFailFrequent);
                    continue;
                }
                //Console.WriteLine(result);
                //Console.ReadLine();

                List <Photo> photos = JsonConvert.DeserializeObject <List <Photo> >(result);
                int          i      = 0;
                foreach (Photo photo in photos)
                {
                    Console.WriteLine("Download() " + i++ + "\t" + photo.id + "\t Downloading...");
                    string path = Setting.picModeStr[Setting.picMode] + @"\" + photo.id + ".jpg";
                    string url;
                    if (Setting.picMode == Setting.PICMODE_RAW)
                    {
                        url = photo.urls.raw;
                    }
                    else if (Setting.picMode == Setting.PICMODE_FULL)
                    {
                        url = photo.urls.full;
                    }
                    else if (Setting.picMode == Setting.PICMODE_REGULAR)
                    {
                        url = photo.urls.regular;
                    }
                    else if (Setting.picMode == Setting.PICMODE_SMALL)
                    {
                        url = photo.urls.small;
                    }
                    else
                    {
                        url = photo.urls.thumb;
                    }

                    mutex.WaitOne();
                    SimplePhoto r = PicStore.currentPhotos.Find(
                        delegate(SimplePhoto simplePhoto)
                    {
                        return(simplePhoto.path.Equals(path));
                    });
                    mutex.ReleaseMutex();
                    if (r != null)
                    {
                        continue;
                    }
                    fh.BeginInvoke(url, path, callback, null);
                }
                Console.WriteLine("Download wait for next download...");
                Thread.Sleep(Setting.downloadFrequent);
            }
        }