public static bool GetCsvFileContents(ref string sChosenFile, ref string sCsvFileContents)
        {
            bool   bRet        = false;
            string sFolderPath = GetPathToAdditionalPropertiesFolder();

            sCsvFileContents = string.Empty;

            System.Windows.Forms.OpenFileDialog oFD = new System.Windows.Forms.OpenFileDialog();

            string sFile = string.Empty;

            string sPath = (Path.GetDirectoryName(sChosenFile));

            if (UserIoHelper.PickLoadFromFile(sPath, "*.csv", ref sFile, "CSV files (*.csv)|*.csv"))
            {
                try
                {
                    sChosenFile      = sFile;
                    sCsvFileContents = System.IO.File.ReadAllText(sFile);

                    bRet = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error loading file.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
            }

            return(bRet);
        }
Exemple #2
0
        public bool SaveSettingsToFile()  // TestingForm oTestingForm)
        {
            bool   bRet  = false;
            string sFile = string.Empty;
            string sConnectionSettings = string.Empty;

            //SetDataFromForm(oTestingForm);

            if (UserIoHelper.PickSaveFileToFolder(FormDataFilePath, "Connection Settings " + TimeHelper.NowMashup() + ".xml", ref sFile, "XML files (*.xml)|*.xml"))
            {
                sConnectionSettings = SerialHelper.SerializeObjectToString <TestSettingsData>(SettingsData);
                if (sConnectionSettings != string.Empty)
                {
                    try
                    {
                        System.IO.File.WriteAllText(sFile, sConnectionSettings);
                        bRet = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error Saving File");
                    }
                }
            }
            return(bRet);
        }
Exemple #3
0
        public bool LoadSettingFromFile() //ref TestingForm oTestingForm)
        {
            bool   bRet  = false;
            string sFile = string.Empty;
            string sConnectionSettings = string.Empty;

            //TestSettingsData oTestSettingsData = null;
            this.ClearSettings();
            string sFileContents = string.Empty;

            if (UserIoHelper.PickLoadFromFile(FormDataFilePath, "*.xml", ref sFile, "XML files (*.xml)|*.xml"))
            {
                try
                {
                    sFileContents = System.IO.File.ReadAllText(sFile);
                    SettingsData  = SerialHelper.DeserializeObjectFromString <TestSettingsData>(sFileContents);
                    //SetFormFromData(ref oTestingForm);
                    bRet = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Saving File");
                }
            }
            //oTestSettingsData = null;
            return(bRet);
        }
Exemple #4
0
        /// <summary>
        /// save the current form settings to an xml file
        /// useriohelper is for displaying the save dialog
        /// setconnectionsettingsfromform handles which settings need to be saved
        /// then serialhelper streams that information to the file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mnuFileSaveSettings_Click(object sender, EventArgs e)
        {
            string sFile   = string.Empty;
            string sFilter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";

            string             sConnectionSettings = string.Empty;
            ConnectionSettings oConnectionSetting  = new ConnectionSettings();

            SetConnectionSettingsFromForm(ref oConnectionSetting);

            if (UserIoHelper.PickSaveFileToFolder(AppDomain.CurrentDomain.BaseDirectory, "Email Settings.xml", ref sFile, sFilter))
            {
                sConnectionSettings = SerialHelper.SerializeObjectToString <ConnectionSettings>(oConnectionSetting);
                if (sConnectionSettings != string.Empty)
                {
                    try
                    {
                        File.WriteAllText(sFile, sConnectionSettings);
                    }
                    catch (Exception ex)
                    {
                        txtBoxErrorLog.Clear();
                        txtBoxErrorLog.Text = ex.Message + "Error Saving File";
                    }
                }
            }
        }
Exemple #5
0
        private void cmsInlineFileAttachmentsSaveAs_Click(object sender, EventArgs e)
        {
            if (lvInlineFileAttachments.SelectedItems.Count > 0)
            {
                int    iAttachment  = 0;
                string SelectedFile = string.Empty;
                iAttachment = (int)lvInlineFileAttachments.SelectedItems[0].Tag;
                if (_Item.Attachments[iAttachment] is FileAttachment)
                {
                    FileAttachment oFileAttachment = (FileAttachment)_Item.Attachments[iAttachment];
                    if (UserIoHelper.PickSaveFileToFolder(oFileAttachment.Name, ref SelectedFile))
                    {
                        _Item.Service.ClientRequestId = Guid.NewGuid().ToString(); // Set a new GUID
                        oFileAttachment.Load((SelectedFile));                      // uncomment when testing done

                        //if (oFileAttachment.Name.StartsWith("ATT") && oFileAttachment.ContentType == "application/octet-stream")
                        //{
                        //    MemoryStream o = new MemoryStream();

                        //    oFileAttachment.Load(o);

                        //    System.Drawing.Bitmap x = new Bitmap(o);

                        //    x.Save(SelectedFile+"- out.bmp", ImageFormat.);

                        //}
                        //else
                        //    oFileAttachment.Load((SelectedFile));
                    }
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// this button handles displaying the File Open dialog and loading the settings from an existing xml file
        /// useriohelper is for displaying the dialog and serialhelper is for parsing out the xml for settings
        /// once the settings have been parsed from the xml file, setformfromconnectionsettings is called to populate the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mnuFileLoadSettings_Click(object sender, EventArgs e)
        {
            string sFile               = string.Empty;
            string sFilter             = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
            string sConnectionSettings = string.Empty;

            ConnectionSettings oConnectionSetting = null;
            string             sFileContents      = string.Empty;

            if (UserIoHelper.PickLoadFromFile(AppDomain.CurrentDomain.BaseDirectory, "*.xml", ref sFile, sFilter))
            {
                try
                {
                    sFileContents      = System.IO.File.ReadAllText(sFile);
                    oConnectionSetting = SerialHelper.DeserializeObjectFromString <ConnectionSettings>(sFileContents);
                    if (oConnectionSetting == null)
                    {
                        throw new Exception("Settings file cannot be deserialized.");
                    }
                    SetFormFromConnectionSettings(oConnectionSetting);
                }
                catch (Exception ex)
                {
                    txtBoxErrorLog.Clear();
                    txtBoxErrorLog.Text = ex.ToString() + "Error Loading File";
                }
            }
            oConnectionSetting = null;
        }
Exemple #7
0
        private void btnBrowseForFile_Click(object sender, EventArgs e)
        {
            string sSelectedFile = string.Empty;

            if (UserIoHelper.PickLoadFromFile(Application.UserAppDataPath, "*.png", ref sSelectedFile, "All files (*.*)|*.*"))
            {
                this.txtFile.Text = sSelectedFile;
            }
            ;
        }
Exemple #8
0
        private void btnInstallApp_Click(object sender, EventArgs e)
        {
            string sSelectedFile = string.Empty;

            if (UserIoHelper.PickLoadFromFile(Application.UserAppDataPath, "*.*", ref sSelectedFile, "All files (*.*)|*.*"))
            {
                byte[] baContents = System.IO.File.ReadAllBytes(sSelectedFile);
                System.IO.MemoryStream oStream = new System.IO.MemoryStream(baContents);
                _CurrentService.InstallApp(oStream);
            }
            ;
        }
Exemple #9
0
        private void btnSaveFileSelect_Click(object sender, EventArgs e)
        {
            string sContent = string.Empty;

            string sSuggestedFilename = "*.*";
            string sSelectedfile      = string.Empty;
            string sFilter            = "Jpg files (*.jpg)|*.jpg|XML files (*.xml)|*.xml|All files (*.*)|*.*";

            if (UserIoHelper.PickSaveFileToFolder(txtSaveFile.Text.Trim(), sSuggestedFilename, ref sSelectedfile, sFilter))
            {
                txtSaveFile.Text = sSelectedfile;
            }
        }
Exemple #10
0
 private void cmsFileAttachmentsSaveAs_Click(object sender, EventArgs e)
 {
     if (lvFileAttachments.SelectedItems.Count > 0)
     {
         int    iAttachment  = 0;
         string SelectedFile = string.Empty;
         iAttachment = (int)lvFileAttachments.SelectedItems[0].Tag;
         if (_Item.Attachments[iAttachment] is FileAttachment)
         {
             FileAttachment oFileAttachment = (FileAttachment)_Item.Attachments[iAttachment];
             if (UserIoHelper.PickSaveFileToFolder(oFileAttachment.Name, ref SelectedFile))
             {
                 _Item.Service.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID
                 oFileAttachment.Load((SelectedFile));
             }
         }
     }
 }
Exemple #11
0
        private void btnLoadExample_Click(object sender, EventArgs e)
        {
            string sInitialDirectory = Application.StartupPath + "\\HtmlBodyExamples";

            string sSuggestedFilename = "*.*";
            string sSelectedfile      = string.Empty;
            string sFilter            = "HTM files (*.htm)|*.htm|HTML files (*.html)|*.html|TXT files (*.txt)|*.txt|All files (*.*)|*.*";

            if (UserIoHelper.PickLoadFromFile(sInitialDirectory, sSuggestedFilename, ref sSelectedfile, sFilter))
            {
                try
                {
                    txtBody.Text = System.IO.File.ReadAllText(sSelectedfile);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error reading file.");
                }
            }
        }
Exemple #12
0
        private void cmdLoad_Click(object sender, EventArgs e)
        {
            //bool bLoad = true;
            string sFile = txtFileName.Text.Trim();

            if (sFile == string.Empty)
            {
                MessageBox.Show("File path needs to be set first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                if (!File.Exists(sFile))
                {
                    MessageBox.Show("The file does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    txtFrom.Text = UserIoHelper.GetFileAsString(sFile);
                }
            }
        }
Exemple #13
0
 private void cmsFileAttachmentsViewMime_Click(object sender, EventArgs e)
 {
     if (lvInlineFileAttachments.SelectedItems.Count > 0)
     {
         int    iAttachment  = 0;
         string SelectedFile = string.Empty;
         iAttachment = (int)lvFileAttachments.SelectedItems[0].Tag;
         if (_Item.Attachments[0] is FileAttachment)
         {
             FileAttachment oFileAttachment = (FileAttachment)_Item.Attachments[iAttachment];
             if (UserIoHelper.PickSaveFileToFolder(oFileAttachment.Name, ref SelectedFile))
             {
                 //oFileAttachment.Load((SelectedFile));
                 //oFileAttachment.Load(
                 //_EwsCaller.ExchService.getGetItemMime(oFileAttachment);
                 //ShowTextDocument oForm = new ShowTextDocument();
                 //oForm.txtEntry.Text = sInfo;
                 //oForm.ShowDialog();
                 //oForm = null;
             }
         }
     }
 }
Exemple #14
0
        private void BtnLoadCertificate_Click(object sender, EventArgs e)
        {
            string sFile = string.Empty;
            string sConnectionSettings = string.Empty;
            // PostFormSetting oPostFormSetting = null;
            string sFileContents = string.Empty;

            if (UserIoHelper.PickLoadFromFile(Application.UserAppDataPath, "*.cer", ref sFile, "CER files (*.cer)|*.cer"))
            {
                try
                {
                    txtAuthCertificatePath.Text = sFile;
                    if (!System.IO.File.Exists(sFile))
                    {
                        MessageBox.Show("File does not exist.");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error Loading File");
                }
            }
        }
Exemple #15
0
        private void cmsEmbededItemsAttachmentsSaveAs_Click(object sender, EventArgs e)
        {
            if (lvEmbededItemsAttachments.SelectedItems.Count > 0)
            {
                int    iAttachment  = 0;
                string SelectedFile = string.Empty;
                iAttachment = (int)lvEmbededItemsAttachments.SelectedItems[0].Tag;



                if (_Item.Attachments[iAttachment] is FileAttachment)
                {
                    FileAttachment oFileAttachment = (FileAttachment)_Item.Attachments[iAttachment];
                    if (UserIoHelper.PickSaveFileToFolder(oFileAttachment.Name, ref SelectedFile))
                    {
                        _Item.Service.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID
                        oFileAttachment.Load((SelectedFile));
                    }
                }

                //if (_Item.Attachments[iAttachment] is ItemAttachment)
                //{
                //    ItemAttachment oAttachment = (ItemAttachment)_Item.Attachments[iAttachment];

                //    ItemAttachment oItemAttachment = oAttachment as ItemAttachment;
                //    oItemAttachment.Load();  // Load attachment into memory so we can get to the item properties (such as subject).

                //    //_EwsCaller.GetItemMime(


                //    //PropertySet oMimePropertySet = new PropertySet(ItemSchema.MimeContent);
                //    //Item oAttachmentItem = Item.Bind(_ExchangeService, oItemAttachment.Id, oMimePropertySet);
                //    //string sStuff =  oAttachmentItem.MimeContent.ToString() ;

                //    // string sStuff = _EwsCaller.GetItemMime(oItemAttachment.Id);


                //    //oAttachmentItem.

                //    //EmailMessage email = EmailMessage.Bind(es, current.Id) ;

                //    //Attachment x = (Attachment)ItemAttachment;
                //    // TODO: Get it working.
                //    // Should be able to get the stream of the attachment and save it...
                //    //oItemAttachment = _Item.Service.FileAttachmentContentHandler
                //    //Item oxItem = (Item)oItemAttachment;

                //    if (UserIoHelper.PickSaveFileToFolder(oItemAttachment.Item.Subject + ".msg", ref SelectedFile))
                //    {

                //        byte[] MimeBytes = oItemAttachment.Item.MimeContent.Content;

                //        System.IO.File.WriteAllBytes(SelectedFile, MimeBytes);

                //        //PropertySet mimeSet = new PropertySet(BasePropertySet.IdOnly);

                //        //mimeSet.Add(EmailMessageSchema.MimeContent);
                //        //mimeSet.Add(EmailMessageSchema.Subject);

                //        //FileAttachment fileAttachment = oItemAttachment as FileAttachment;

                //        //FileAttachment oFileAttachment = (FileAttachment)oItemAttachment;
                //        //MemoryStream oMemoryStream = new MemoryStream();
                //        //oFileAttachment.Load(oMemoryStream);
                //        //StreamReader oStreamReader = new StreamReader(oMemoryStream);
                //        //oMemoryStream.Seek(0, SeekOrigin.Begin);
                //        //byte[] bytes = oMemoryStream.GetBuffer();

                //        //PropertySet oMimePropertySet = new PropertySet(ItemSchema.MimeContent);
                //        //oItem.Load(oMimePropertySet);
                //        //sReturn = oItem.MimeContent.ToString();

                //        //Attachment oA = (Attachment)_Item.Attachments[iAttachment];
                //        //FileAttachment oFA = (FileAttachment)oA;
                //        // System.IO.File.WriteAllBytes(SelectedFile, oItemAttachment.Item.Copy();
                //        //oFA.Load(SelectedFile);
                //        //FileStream theStream = new FileStream("C:\\testx\\Stream_" + SelectedFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                //        //theStream.w
                //        //theStream.Close();
                //        //theStream.Dispose();
                //        //System.IO.File.WriteAllBytes("C:\\testx\\Stream_" + SelectedFile, (bytes[])sStuff.ToCharArray());


                //    }
                // }
            }
        }
Exemple #16
0
        private bool LoadMessage(string sLoadType, string sMessage)
        {
            ADODB.Stream objMsgStream = new ADODB.Stream();
            string       sFileName    = "";

            objCDOMsg = null;
            objCDOMsg = new CDO.Message();
            bLoaded   = false;

            try {
                this.Cursor = Cursors.WaitCursor;


                // First Get the Raw Mime and display it.
                string sFileText = null;
                if (sLoadType == "file")
                {
                    //MyApp.AppUtil xObj = new MyApp.AppUtil();
                    sFileName = txtFileName.Text.Trim();
                    sFileText = UserIoHelper.GetFileAsString(sFileName);


                    txtMime.Text = sFileText;


                    // Now Lets read this thing
                    objMsgStream.Open();
                    objMsgStream.LoadFromFile(sFileName);
                    objCDOMsg.BodyPart.DataSource.OpenObject(objMsgStream, "IStream");
                    m_MessageMime = sFileText;
                }
                else
                {
                    sFileName    = Path.GetTempFileName();
                    txtMime.Text = sMessage;


                    UserIoHelper.SaveStringAsFile(sMessage, sFileName);

                    // Ran into problems writing mime text to a message, working around by using a temp file
                    objMsgStream.Open();
                    objMsgStream.LoadFromFile(sFileName);
                    // Read temp file

                    objCDOMsg.BodyPart.DataSource.OpenObject(objMsgStream, "IStream");
                    // read it
                    File.Delete(sFileName);
                    // Get rid of temp file
                    m_MessageMime = sMessage;
                }

                LoadMessageFields();
                //LoadAttachemntsFields();
                ExtractBodyPart(objCDOMsg.BodyPart);


                //Marshal.ReleaseComObject(objMsgStream);
            }
            catch (Exception ex) {
                bLoaded = false;
                MessageBox.Show("Error Loading File: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            try {
                System.Windows.Forms.TreeNode pNode = new System.Windows.Forms.TreeNode();
                TreeView1.Nodes.Clear();
                pNode = TreeView1.Nodes.Add("Root");
                // m_BaseURI
                pNode.Tag = objCDOMsg.BodyPart;



                int iBodyPartCount1 = 1;
                int iBodyPartCount2 = 1;
                int iBodyPartCount3 = 1;
                int iBodyPartCount4 = 1;
                int iBodyPartCount5 = 1;
                int iBodyPartCount6 = 1;
                int iBodyPartCount7 = 1;

                System.Windows.Forms.TreeNode aNode1 = null;
                System.Windows.Forms.TreeNode aNode2 = null;
                System.Windows.Forms.TreeNode aNode3 = null;
                System.Windows.Forms.TreeNode aNode4 = null;
                System.Windows.Forms.TreeNode aNode5 = null;
                System.Windows.Forms.TreeNode aNode6 = null;
                System.Windows.Forms.TreeNode aNode7 = null;

                iBodyPartCount1 = 1;
                // Note: I'm using this big loop because i want to be able to see things better
                // as this code loops through each body part.  Using a recursive call to a method
                // just makes the debugging process more difficult.
                foreach (CDO.IBodyPart objBodypart1 in objCDOMsg.BodyPart.BodyParts)
                {
                    AddNode(objBodypart1, ref pNode, ref aNode1, iBodyPartCount1);

                    iBodyPartCount2 = 1;
                    foreach (CDO.IBodyPart objBodypart2 in objBodypart1.BodyParts)
                    {
                        AddNode(objBodypart2, ref aNode1, ref aNode2, iBodyPartCount2);
                        iBodyPartCount3 = 1;
                        foreach (CDO.IBodyPart objBodypart3 in objBodypart2.BodyParts)
                        {
                            AddNode(objBodypart3, ref aNode2, ref aNode3, iBodyPartCount3);
                            iBodyPartCount4 = 1;
                            foreach (CDO.IBodyPart objBodypart4 in objBodypart3.BodyParts)
                            {
                                AddNode(objBodypart4, ref aNode3, ref aNode4, iBodyPartCount4);
                                iBodyPartCount5 = 1;
                                foreach (CDO.IBodyPart objBodypart5 in objBodypart4.BodyParts)
                                {
                                    AddNode(objBodypart5, ref aNode4, ref aNode5, iBodyPartCount5);
                                    iBodyPartCount6 = 1;
                                    foreach (CDO.IBodyPart objBodypart6 in objBodypart5.BodyParts)
                                    {
                                        AddNode(objBodypart6, ref aNode5, ref aNode6, iBodyPartCount6);
                                        iBodyPartCount7 = 1;
                                        foreach (CDO.IBodyPart objBodypart7 in objBodypart6.BodyParts)
                                        {
                                            AddNode(objBodypart7, ref aNode6, ref aNode7, iBodyPartCount7);
                                            iBodyPartCount7 += 1;
                                            //Marshal.ReleaseComObject(objBodypart7);
                                        }
                                        iBodyPartCount6 += 1;
                                        // Marshal.ReleaseComObject(objBodypart6);
                                    }
                                    iBodyPartCount5 += 1;
                                    //Marshal.ReleaseComObject(objBodypart5);
                                }
                                iBodyPartCount4 += 1;
                                //Marshal.ReleaseComObject(objBodypart4);
                            }
                            iBodyPartCount3 += 1;
                            // Marshal.ReleaseComObject(objBodypart3);
                        }
                        iBodyPartCount2 += 1;
                        //Marshal.ReleaseComObject(objBodypart2);
                    }
                    iBodyPartCount1 += 1;
                    //Marshal.ReleaseComObject(objBodypart1);
                }
                pNode.ExpandAll();

                bLoaded = true;
            } catch (Exception ex) {
                bLoaded = false;
                MessageBox.Show("Error Loading Message Body Parts: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            objMsgStream = null;
            Cursor       = Cursors.Default;
            return(bLoaded);
        }