示例#1
0
        /// <summary>
        /// The function to call when sending a picture
        /// </summary>
        /// <param name="cp">fill the packet with the appropriate information and write the image to the stream</param>
        public void SendPicture()
        {
            Microsoft.Win32.OpenFileDialog ofd;
            ofd                  = new Microsoft.Win32.OpenFileDialog();
            ofd.FileName         = "openFileDialog1";
            ofd.Filter           = "(*.JPG, *.GIF, *.PNG)|*.jpg;*.gif;*.png|All Files (*.*)|*.*";
            ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            ofd.RestoreDirectory = true;
            ofd.Title            = "Select a Picture";


            //check return value, but how in wpf?
            bool ok = (bool)ofd.ShowDialog();

            if (ok)
            {
                System.IO.Stream stream;
                if ((stream = ofd.OpenFile()) != null)
                {
                    PicturePacket packet = new PicturePacket();
                    packet.s        = stream;
                    packet.fileName = System.IO.Path.GetFileName(ofd.FileName);
                    MetadataFileInfo md = new MetadataFileInfo();
                    md.ReadMetaData(ofd.FileName);
                    packet.title          = md.Title;
                    packet.senderNodeName = mNodeName;
                    mOperationContract(packet);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Make a call to this in order to send a picture.
        /// </summary>
        /// <param name="fullFileName"></param>
        public void SendPicture(String fullFileName)
        {
            if (fullFileName == null)
            {  //send an empty picture...
                PicturePacket packet = new PicturePacket();
                packet.s = new MemoryStream();
                packet.senderNodeName = mNodeName;
                mOperationContract(packet);
                return;
            }

            System.IO.Stream stream;
            if ((stream = System.IO.File.OpenRead(fullFileName)) != null)
            {
                PicturePacket packet = new PicturePacket();
                packet.s        = stream;
                packet.fileName = System.IO.Path.GetFileName(fullFileName);
                MetadataFileInfo md = new MetadataFileInfo();
                md.ReadMetaData(fullFileName);
                packet.title          = md.Title;
                packet.senderNodeName = mNodeName;
                mOperationContract(packet);
            }
        }
示例#3
0
        /// <summary>
        /// This function actually sends a packet out. Continue to call this function until it returns true.
        /// </summary>
        /// <returns>true when the entire file is sent</returns>
        public bool SendStream()
        {
            StreamedPacket packet = new StreamedPacket();

            Byte[] b   = new Byte[12000];
            int    len = 0; //the number of bytes read so far.
            bool   finished;

            //only send the meta data on the first packet to conserve bandwidth
            //I'm sure there is still some overhead of sending null strings for the rest of the data.
            if (mSendingPacketNo == 0)
            {
                packet.fileName = System.IO.Path.GetFileName(mCurrentFileName);
                MetadataFileInfo metaData = new MetadataFileInfo();
                metaData.ReadMetaData(mCurrentFileName);
                packet.album  = metaData.AlbumName;
                packet.artist = metaData.ArtistName;
                packet.title  = metaData.Title;
            }
            //debug put it in each packet...
            packet.fileName = System.IO.Path.GetFileName(mCurrentFileName);

            //read from the file
            len = mCurrentStream.Read(b, 0, 12000);
            //write it to the packet's stream.
            packet.stream.Write(b, 0, len);
            packet.stream.Position = 0;            //set the stream back to the initial position.
            packet.guid            = mCurrentGuid; //set the guid.

            if (mCurrentStream.Length != mCurrentStream.Position && false == mStopStream)
            {
                finished           = false;
                packet.endOfStream = false;
            }
            else
            {
                //we are at the end of the file, or someone canceled the file via mStopAudioStream
                //set the file to be finished and send out a endOfStream packet.
                finished           = true;
                mStopStream        = false;
                packet.endOfStream = true; //either reached the end or we canceled the stream.
                mCurrentStream.Close();
            }

            //include the node name
            packet.senderNodeName = mNodeName;
            //set the packet number, and increment the sending packet number.
            packet.packetNumber = mSendingPacketNo++;

            try
            {
                if (del != null)
                {
                    del(packet);
                }
            }
            catch (Exception)
            {
                mStopStream = false;
            }
            return(finished);
        }