Exemplo n.º 1
0
        private void menuTakePicture_Click(object sender, EventArgs e)
        {
            CameraCaptureDialog cameraCapture = new CameraCaptureDialog();

            cameraCapture.Owner = this;

            object cameraEnabled = Microsoft.WindowsMobile.Status.SystemState.GetValue(Microsoft.WindowsMobile.Status.SystemProperty.CameraEnabled);

            cameraCapture.DefaultFileName = "haggle-temp.jpg";
            cameraCapture.Title           = "Take PhotoShare Picture";
            cameraCapture.Mode            = CameraCaptureMode.Still;
            cameraCapture.Resolution      = new Size(1024, 768);

            // The filename of the picure taken
            string fileName;

            if (null != cameraEnabled && 0 == (int)cameraEnabled)
            {
                MessageBox.Show("The camera is disabled", this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                return;
            }

            try
            {
                if (cameraCapture.ShowDialog() == DialogResult.OK)
                {
                    fileName = cameraCapture.FileName;

                    Debug.WriteLine("file name of photo is " + fileName);

                    if (cameraCapture.Mode == CameraCaptureMode.Still)
                    {
                        string extension = fileName.Substring(fileName.LastIndexOf("."));
                        string directory = "";
                        long   extra_digit;

                        if (fileName.LastIndexOf("\\") != -1)
                        {
                            directory = fileName.Substring(0, fileName.LastIndexOf("\\") + 1);
                        }

                        fileName    = directory + this.defaultPictureFileName + extension;
                        extra_digit = 0;
                        while (System.IO.File.Exists(fileName))
                        {
                            fileName = directory + this.defaultPictureFileName + "-" + extra_digit + extension;
                            extra_digit++;
                        }

                        System.IO.File.Move(cameraCapture.FileName, fileName);
                    }

                    FileAttributeWindow fileAttrWin = new FileAttributeWindow(fileName);
                    DialogResult        ret         = DialogResult.Cancel;

                    try {
                        ret = fileAttrWin.ShowDialog();
                    } catch (Exception) {
                        Debug.WriteLine("Could not show fileAttrWind dialog");
                    }
                    //fileAttrWin.BringToFront();
                    char[] separators = { ';', ' ' };

                    string[] keywords = fileAttrWin.getResultValueString().Split(separators);

                    Debug.WriteLine("Attributes string is: " + fileAttrWin.getResultValueString());

                    //DialogResult ret = MessageBox.Show("The picture was saved to:\n" + fileName +
                    //        "\nDo you want to publish the picture with Haggle now?",
                    //    this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);

                    if (ret == DialogResult.OK)
                    {
                        try
                        {
                            Haggle.Attribute.AttributeList al = new Haggle.Attribute.AttributeList();

                            Haggle.DataObject dObj = new Haggle.DataObject(fileName);
                            dObj.AddHash();
                            // Add thumbnail:
                            dObj.SetThumbnail(GetThumbnail(fileName, 32, 0));

                            foreach (string kw in keywords)
                            {
                                Haggle.Attribute a = new Haggle.Attribute("Picture", kw);

                                if (!dObj.AddAttribute(a))
                                {
                                    MessageBox.Show("Could not add attribute");
                                    return;
                                }

                                if (fileAttrWin.getAddAsInterest())
                                {
                                    if (ps.addInterestWindow.interestListUpdate(new Haggle.Attribute.AttributeList(a)) > 0)
                                    {
                                        Debug.WriteLine("Adding interest " + a.ToString());
                                        al.Add(a);
                                    }
                                }
                            }
                            // We need to add the interest first if we want the filters to match the
                            // data object we add
                            if (fileAttrWin.getAddAsInterest())
                            {
                                ps.hh.AddInterests(al);
                            }
                            //Haggle.Attribute attr = dObj.GetAttribute("DeviceName");

                            //MessageBox.Show("Data object file name is: " + dObj.GetFileName()
                            //               + " Attribute is: " + attr.GetValue());
                            int sent = ps.hh.PublishDataObject(dObj);

                            if (sent < 0)
                            {
                                MessageBox.Show("Could not publish data object on handle=" +
                                                ps.hh.handle + " Error=" + sent);
                            }
                        }
                        catch (Haggle.DataObject.NoSuchAttributeException)
                        {
                            MessageBox.Show("No such attribute in data object");
                        }
                        catch (Haggle.DataObject.DataObjectException ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        catch (Haggle.Attribute.AttributeNullPtrException)
                        {
                            MessageBox.Show("Attribute null pointer exception");
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Unknown error");
                        }
                    }
                    else if (ret == DialogResult.No)
                    {
                        Debug.WriteLine("camera dialog result \'NO\'");
                    }
                    else
                    {
                        Debug.WriteLine("Unknown camera dialog result");
                        MessageBox.Show("Unknown selection.");
                    }
                    Debug.WriteLine("camera exit");
                }
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
            catch (OutOfMemoryException ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
                                MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
                                MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
        }
Exemplo n.º 2
0
        private void menuTakePicture_Click(object sender, EventArgs e)
        {
            CameraCaptureDialog cameraCapture = new CameraCaptureDialog();
                        cameraCapture.Owner = this;

                        object cameraEnabled = Microsoft.WindowsMobile.Status.SystemState.GetValue(Microsoft.WindowsMobile.Status.SystemProperty.CameraEnabled);

                        cameraCapture.DefaultFileName = "haggle-temp.jpg";
                        cameraCapture.Title = "Take PhotoShare Picture";
                        cameraCapture.Mode = CameraCaptureMode.Still;
                        cameraCapture.Resolution = new Size(1024, 768);

                        // The filename of the picure taken
                        string fileName;

                        if (null != cameraEnabled && 0 == (int)cameraEnabled)
                        {
                                MessageBox.Show("The camera is disabled", this.Text,
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                return;
                        }

                        try
                        {
                                if (cameraCapture.ShowDialog() == DialogResult.OK)
                                {
                                        fileName = cameraCapture.FileName;

                                        Debug.WriteLine("file name of photo is " + fileName);

                                        if (cameraCapture.Mode == CameraCaptureMode.Still)
                                        {
                                                string extension = fileName.Substring(fileName.LastIndexOf("."));
                                                string directory = "";
                                                long extra_digit;

                                                if (fileName.LastIndexOf("\\") != -1)
                                                {
                                                        directory = fileName.Substring(0, fileName.LastIndexOf("\\") + 1);
                                                }

                                                fileName = directory + this.defaultPictureFileName + extension;
                                                extra_digit = 0;
                                                while (System.IO.File.Exists(fileName))
                                                {
                                                    fileName = directory + this.defaultPictureFileName + "-" + extra_digit + extension;
                                                    extra_digit++;
                                                }

                                                System.IO.File.Move(cameraCapture.FileName, fileName);
                                        }

                                        FileAttributeWindow fileAttrWin = new FileAttributeWindow(fileName);
                                        DialogResult ret = DialogResult.Cancel;

                                        try {
                                                ret = fileAttrWin.ShowDialog();
                                        } catch (Exception) {
                                                Debug.WriteLine("Could not show fileAttrWind dialog");
                                        }
                                        //fileAttrWin.BringToFront();
                                        char[] separators = { ';', ' ' };

                                        string[] keywords = fileAttrWin.getResultValueString().Split(separators);

                                        Debug.WriteLine("Attributes string is: " + fileAttrWin.getResultValueString());

                                        //DialogResult ret = MessageBox.Show("The picture was saved to:\n" + fileName +
                                        //        "\nDo you want to publish the picture with Haggle now?",
                                        //    this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);

                                        if (ret == DialogResult.OK)
                                        {
                                                try
                                                {
                                                        Haggle.Attribute.AttributeList al = new Haggle.Attribute.AttributeList();

                                                        Haggle.DataObject dObj = new Haggle.DataObject(fileName);
                                                        dObj.AddHash();
                                                        // Add thumbnail:
                                                        dObj.SetThumbnail(GetThumbnail(fileName, 32, 0));

                                                        foreach (string kw in keywords)
                                                        {
                                                                Haggle.Attribute a = new Haggle.Attribute("Picture", kw);

                                                                if (!dObj.AddAttribute(a))
                                                                {
                                                                        MessageBox.Show("Could not add attribute");
                                                                        return;
                                                                }

                                                                if (fileAttrWin.getAddAsInterest())
                                                                {

                                                                        if (ps.addInterestWindow.interestListUpdate(new Haggle.Attribute.AttributeList(a)) > 0)
                                                                        {
                                                                                Debug.WriteLine("Adding interest " + a.ToString());
                                                                                al.Add(a);
                                                                        }
                                                                }

                                                        }
                                                        // We need to add the interest first if we want the filters to match the
                                                        // data object we add
                                                        if (fileAttrWin.getAddAsInterest())
                                                        {
                                                                ps.hh.AddInterests(al);
                                                        }
                                                        //Haggle.Attribute attr = dObj.GetAttribute("DeviceName");

                                                        //MessageBox.Show("Data object file name is: " + dObj.GetFileName()
                                                        //               + " Attribute is: " + attr.GetValue());
                                                        int sent = ps.hh.PublishDataObject(dObj);

                                                        if (sent < 0)
                                                        {
                                                                MessageBox.Show("Could not publish data object on handle=" +
                                                                        ps.hh.handle + " Error=" + sent);
                                                        }
                                                }
                                                catch (Haggle.DataObject.NoSuchAttributeException)
                                                {
                                                        MessageBox.Show("No such attribute in data object");
                                                }
                                                catch (Haggle.DataObject.DataObjectException ex)
                                                {
                                                        MessageBox.Show(ex.ToString());
                                                }
                                                catch (Haggle.Attribute.AttributeNullPtrException)
                                                {
                                                        MessageBox.Show("Attribute null pointer exception");
                                                }
                                                catch (Exception)
                                                {
                                                        MessageBox.Show("Unknown error");
                                                }
                                        }
                                        else if (ret == DialogResult.No)
                                        {

                                                Debug.WriteLine("camera dialog result \'NO\'");
                                        }
                                        else
                                        {
                                                Debug.WriteLine("Unknown camera dialog result");
                                                MessageBox.Show("Unknown selection.");
                                        }
                                        Debug.WriteLine("camera exit");
                                }
                        }
                        catch (ArgumentException ex)
                        {
                                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        }
                        catch (OutOfMemoryException ex)
                        {
                                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
                                    MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                        }
                        catch (InvalidOperationException ex)
                        {
                                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
                                    MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                        }
        }