294 lines
38 KiB
HTML
294 lines
38 KiB
HTML
<html>
|
|
|
|
<head>
|
|
<title>Get Messages Example (C#)</title>
|
|
<meta http-equiv="Content-Language" content="en-us">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
|
<link rel="stylesheet" type="text/css" href="ApiHelp.css">
|
|
</head>
|
|
<meta name=MS-HKWD content="C# examples,messages">
|
|
|
|
<body>
|
|
<h1><span style="font-weight: normal; font-size: 7.5pt;">SOLIDWORKS PDM Professional API Help</span></h1>
|
|
<h1>Get Messages Example (C#)</h1>
|
|
<p><a name="Top"></a>This example shows how to get and encapsulate text messages
|
|
in the Admin's inbox in a vault.</p>
|
|
<p><b>NOTE</b>: If using the primary interop assembly
|
|
provided with SOLIDWORKS PDM Professional, see
|
|
<a href="Using_NET_Framework_in_Applications.htm">Using .NET Framework 4.0 in
|
|
Stand-alone Applications</a>.</p>
|
|
<p><img border="0" src="GetMessages.gif" width="259" height="168"></p>
|
|
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color:green;">//----------------------------------------------------------------------------</span>
|
|
<span style="color:green;">// Preconditions:</span>
|
|
<span style="color:green;">// 1. Start Microsoft Visual Studio.</span>
|
|
<span style="color:green;">// a. Click <b>File > New > Project > Visual C# > Windows Forms Application</b>.</span>
|
|
<span style="color:green;">// b. Type <b>MessageCSharp</b> in <b>Name</b>.</span>
|
|
<span style="color:green;">// c. Click <b>Browse</b> and browse to the folder where to create the </span><span style="color: #008000">project.</span>
|
|
<span style="color:green;">// d. Click <b>OK</b>. </span>
|
|
<span style="color:green;">// e. Click <b>Show All Files </b>in the Solution Explorer toolbar and expand </span>
|
|
<span style="color:green;">// <b>Form1.cs </b>in the Solution Explorer.</span>
|
|
<span style="color:green;">// f. Replace the code in <b>Form1.cs</b> with <a href="#Form1">this code</a>.</span>
|
|
<span style="color:green;">// g. To create the form, replace the code in <b>Form1.Designer.cs</b> with <a href="#Designer">this code</a>.</span>
|
|
<span style="color:green;">// 2. Add <b>EPDM.Interop.epdm.dll</b> as a reference (right-click the project</span>
|
|
<span style="color:green;">// name in the Solution Explorer, click <b>Add Reference</b>, click </span>
|
|
<span style="color:green;">// <b>Assembly > Framework</b> in the left-side panel, browse to the top folder </span>
|
|
<span style="color:green;">// </span><span style="color: green">of your </span><span style="color:green;">SOLIDWORKS PDM Professional installation, locate and click </span>
|
|
<span style="color:green;">// <b>EPDM.Interop.epdm.dll</b>, click <b>Open</b>, click <b>Add</b>, and click <b>Close</b>).</span>
|
|
<span style="color:green;">// 3. Right-click <b>EPDM.Interop.epdm</b> in References, click <b>Properties</b>, and set </span>
|
|
<span style="color:green;">// <b>Embed Interop Types</b> to <b>False</b> to handle methods that pass arrays of </span>
|
|
<span style="color:green;">// structures.</span>
|
|
<span style="color:green;">// 4. Ensure that one or more text messages exist in the inbox of </span>
|
|
<span style="color:green;">// Admin in a vault.</span>
|
|
<span style="color:green;">// a. Log into a vault as Admin.</span>
|
|
<span style="color:green;">// b. Open a File Explorer window for that vault.</span>
|
|
<span style="color:green;">// c. Click <b>Tools > Inbox</b>.</span>
|
|
<span style="color:green;">// d. Click <b>Text Messages</b>.</span>
|
|
<span style="color:green;">// e. If no text messages are listed, send a text message to Admin.</span>
|
|
<span style="color:green;">// 1. Click <b>New mail message</b>.</span>
|
|
<span style="color:green;">// 2. Type <b>Admin</b> in <b>To</b>.</span>
|
|
<span style="color:green;">// 3. Type <b>Test Get messages </b>in <b>Subject</b>.</span>
|
|
<span style="color:green;">// 4. Type <b>Testing Get messages</b> in the body of the message.</span>
|
|
<span style="color:green;">// 5. Click <b>Send</b>.</span>
|
|
<span style="color:green;">// 6. Wait until you receive the SOLIDWORKS PDM Professional</span>
|
|
<span style="color:green;">// message notification before executing the next step.</span>
|
|
<span style="color:green;">// 5. Click <b>Debug > Start Debugging</b> or press F5.</span>
|
|
<span style="color:green;">//</span>
|
|
<span style="color:green;">// Postconditions: </span>
|
|
<span style="color:green;">// 1. Displays the Get Messages dialog.</span>
|
|
<span style="color:green;">// 2. Select the vault that you examined or where you sent Admin </span>
|
|
<span style="color:green;">// </span><span style="color: green">a text message </span><span style="color:green;">in Preconditions step 4.</span>
|
|
<span style="color:green;">// 3. Click <b>Get messages</b>.</span>
|
|
<span style="color:green;">// 4. Displays a message box for each text message in Admin's inbox </span>
|
|
<span style="color:green;">// in the selected vault. The message box contains encapsulated</span><font style="font-size: 8pt"><span style="color:green;"> </span></font><span style="font-size: 8pt; color: green"> </span>
|
|
<span style="color:green;">// information about the text message.</span>
|
|
<span style="color:green;">// 5. Click <b>OK</b> to close each message box.</span>
|
|
<span style="color:green;">// 6. Close the Get Messages dialog box.</span>
|
|
<span style="color:green;">//----------------------------------------------------------------------------</span></pre>
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color: #008000"><a name="Form1"></a>//Form1.cs</span>
|
|
<span style="color:blue;">using</span> System;
|
|
<span style="color:blue;">using</span> System.Windows.Forms;
|
|
<span style="color:blue;">using</span> EPDM.Interop.epdm;
|
|
|
|
<span style="color:blue;">namespace</span> MessageCSharp
|
|
{
|
|
<span style="color:blue;">public</span> <span style="color:blue;">partial</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Form1</span> : <span style="color:#2b91af;">Form</span>
|
|
{
|
|
<span style="color:blue;">public</span> Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
<span style="color:#2b91af;">IEdmVault5</span> vault1 = <span style="color:blue;">null</span>;
|
|
|
|
<span style="color:blue;">private</span> <span style="color:blue;">void</span> Form1_Load(System.<span style="color:#2b91af;">Object</span> sender, System.<span style="color:#2b91af;">EventArgs</span> e)
|
|
{
|
|
|
|
<span style="color:blue;">try</span>
|
|
{
|
|
<span style="color:#2b91af;">IEdmVault5</span> vault1 = <span style="color:blue;">new</span> <span style="color:#2b91af;">EdmVault5</span>();
|
|
<span style="color:#2b91af;">IEdmVault8</span> vault = (<span style="color:#2b91af;">IEdmVault8</span>)vault1;
|
|
<span style="color:#2b91af;">EdmViewInfo</span>[] Views = <span style="color:blue;">null</span>;
|
|
|
|
vault.<b>GetVaultViews</b>(<span style="color:blue;">out</span> Views, <span style="color:blue;">false</span>);
|
|
VaultsComboBox.Items.Clear();
|
|
<span style="color:blue;">foreach</span> (<span style="color:#2b91af;">EdmViewInfo</span> View <span style="color:blue;">in</span> Views)
|
|
{
|
|
VaultsComboBox.Items.Add(View.<b>mbsVaultName</b>);
|
|
}
|
|
<span style="color:blue;">if</span> (VaultsComboBox.Items.Count > 0)
|
|
{
|
|
VaultsComboBox.Text = (<span style="color:blue;">string</span>)VaultsComboBox.Items[0];
|
|
}
|
|
|
|
}
|
|
<span style="color:blue;">catch</span> (System.Runtime.InteropServices.<span style="color:#2b91af;">COMException</span> ex)
|
|
{
|
|
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"HRESULT = 0x"</span> + ex.ErrorCode.ToString(<span style="color:#a31515;">"X"</span>) + <span style="color:#a31515;">"\n"</span> + ex.Message);
|
|
}
|
|
<span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)
|
|
{
|
|
<span style="color:#2b91af;">MessageBox</span>.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
<span style="color:blue;">private</span> <span style="color:blue;">void</span> GetMessagesButton_Click(System.<span style="color:#2b91af;">Object</span> sender, System.<span style="color:#2b91af;">EventArgs</span> e)
|
|
{
|
|
|
|
<span style="color:blue;">try</span>
|
|
{
|
|
<span style="color:green;">//Only create a new vault object</span>
|
|
<span style="color:green;">//if one hasn't been created yet</span>
|
|
<span style="color:blue;">if</span> (vault1 == <span style="color:blue;">null</span>)
|
|
{
|
|
vault1 = <span style="color:blue;">new</span> <span style="color:#2b91af;">EdmVault5</span>();
|
|
}
|
|
|
|
<span style="color:blue;">if</span> (!vault1.<b>IsLoggedIn</b>)
|
|
{
|
|
<span style="color:green;">//Log into selected vault as the current user</span>
|
|
vault1.<b>LoginAuto</b>(VaultsComboBox.Text, <span style="color:blue;">this</span>.Handle.ToInt32());
|
|
}
|
|
|
|
|
|
<span style="color:green;">//Declare an IEdmUserMgr5 object</span>
|
|
<span style="color:#2b91af;">IEdmUserMgr5</span> userMgr = <span style="color:blue;">default</span>(<span style="color:#2b91af;">IEdmUserMgr5</span>);
|
|
|
|
<span style="color:green;">//The IEdmUserMgr5 interface is implemented by the</span>
|
|
<span style="color:green;">//same class as the IEdmVault5 interface,</span>
|
|
<span style="color:green;">//so you can assign the value of</span>
|
|
<span style="color:green;">//the IEdmVault5 object</span>
|
|
userMgr = (<span style="color:#2b91af;">IEdmUserMgr5</span>)vault1;
|
|
|
|
<span style="color:#2b91af;">IEdmUser5</span> user = <span style="color:blue;">default</span>(<span style="color:#2b91af;">IEdmUser5</span>);
|
|
user = userMgr.<b>GetLoggedInUser</b>();
|
|
<span style="color:#2b91af;">IEdmInbox5</span> inbox = (<span style="color:#2b91af;">IEdmInbox5</span>)user;
|
|
|
|
<span style="color:green;">//Get first text message in Admin's inbox</span>
|
|
<span style="color:#2b91af;">IEdmMessage5</span> message = <span style="color:blue;">default</span>(<span style="color:#2b91af;">IEdmMessage5</span>);
|
|
<span style="color:#2b91af;">IEdmPos5</span> pos = <span style="color:blue;">default</span>(<span style="color:#2b91af;">IEdmPos5</span>);
|
|
pos = inbox.<b>GetFirstMessagePosition</b>((<span style="color:blue;">int</span>)<span style="color:#2b91af;">EdmGetMsgFlag</span>.EdmGetMsg_UserMessages);
|
|
|
|
<span style="color:green;">//If no text messages in Admin's inbox, exit application</span>
|
|
<span style="color:blue;">if</span> (pos.<b>IsNull</b>)
|
|
{
|
|
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"No messages in Admin's inbox."</span>);
|
|
<span style="color:blue;">return</span>;
|
|
}
|
|
|
|
<span style="color:green;">//Otherwise, iterate through Admin's inbox and</span>
|
|
<span style="color:green;">//display a message box with each encapsulated text message</span>
|
|
<span style="color:blue;">while</span> (!pos.<b>IsNull</b>)
|
|
{
|
|
message = inbox.<b>GetNextMessage</b>(pos);
|
|
<span style="color:blue;">bool</span> readStatus = <span style="color:blue;">false</span>;
|
|
readStatus = message.<b>IsRead</b>;
|
|
System.<span style="color:#2b91af;">DateTime</span> messageDate;
|
|
messageDate = message.<b>Date</b>;
|
|
|
|
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"Sender name = "</span> + message.<b>SenderName</b> + <span style="color:#a31515;">"\n"</span> +
|
|
<span style="color:#a31515;">"Send ID = "</span> + message.<b>SenderID</b>.ToString() + <span style="color:#a31515;">"\n"</span> +
|
|
<span style="color:#a31515;">"Is read = "</span> + readStatus + <span style="color:#a31515;">"\n"</span> +
|
|
<span style="color:#a31515;">"Type = "</span> + message.<b>MessageType</b>.ToString() + <span style="color:#a31515;">"\n"</span> +
|
|
<span style="color:#a31515;">"Date = "</span> + messageDate.ToString() + <span style="color:#a31515;">"\n"</span> +
|
|
<span style="color:#a31515;">"Subject = "</span> + message.<b>Subject</b> + <span style="color:#a31515;">"\n"</span> +
|
|
<span style="color:#a31515;">"Body = "</span> + message.<b>Body</b> + <span style="color:#a31515;">"\n"</span>);
|
|
|
|
}
|
|
|
|
}
|
|
<span style="color:blue;">catch</span> (System.Runtime.InteropServices.<span style="color:#2b91af;">COMException</span> ex)
|
|
{
|
|
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"HRESULT = 0x"</span> + ex.ErrorCode.ToString(<span style="color:#a31515;">"X"</span>) + <span style="color:#a31515;">"\n"</span> + ex.Message);
|
|
}
|
|
<span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)
|
|
{
|
|
<span style="color:#2b91af;">MessageBox</span>.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
}
|
|
}</pre>
|
|
<div align="center">
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><font face="Calibri"><a href="#Top">Back to top</a></font></pre>
|
|
</div>
|
|
<div align="left">
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><font color="#008000"><a name="Designer"></a>//Form1.Designer.cs</font></pre>
|
|
</div>
|
|
<div align="left">
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color:blue;">namespace</span> MessageCSharp
|
|
{
|
|
<span style="color:blue;">partial</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Form1</span>
|
|
{
|
|
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"><summary></span>
|
|
<span style="color:gray;">///</span><span style="color:green;"> Required designer variable.</span>
|
|
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"></summary></span>
|
|
<span style="color:blue;">private</span> System.ComponentModel.<span style="color:#2b91af;">IContainer</span> components = <span style="color:blue;">null</span>;
|
|
|
|
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"><summary></span>
|
|
<span style="color:gray;">///</span><span style="color:green;"> Clean up any resources being used.</span>
|
|
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"></summary></span>
|
|
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"><param name="disposing"></span><span style="color:green;">true if managed resources should be disposed; otherwise, false.</span><span style="color:gray;"></param></span>
|
|
<span style="color:blue;">protected</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> Dispose(<span style="color:blue;">bool</span> disposing)
|
|
{
|
|
<span style="color:blue;">if</span> (disposing && (components != <span style="color:blue;">null</span>))
|
|
{
|
|
components.Dispose();
|
|
}
|
|
<span style="color:blue;">base</span>.Dispose(disposing);
|
|
}
|
|
|
|
<span style="color:blue;"> #region</span> Windows Form Designer generated code
|
|
|
|
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"><summary></span>
|
|
<span style="color:gray;">///</span><span style="color:green;"> Required method for Designer support - do not modify</span>
|
|
<span style="color:gray;">///</span><span style="color:green;"> the contents of this method with the code editor.</span>
|
|
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"></summary></span>
|
|
<span style="color:blue;">private</span> <span style="color:blue;">void</span> InitializeComponent()
|
|
{
|
|
<span style="color:blue;">this</span>.VaultsLabel = <span style="color:blue;">new</span> System.Windows.Forms.<span style="color:#2b91af;">Label</span>();
|
|
<span style="color:blue;">this</span>.VaultsComboBox = <span style="color:blue;">new</span> System.Windows.Forms.<span style="color:#2b91af;">ComboBox</span>();
|
|
<span style="color:blue;">this</span>.GetMessagesButton = <span style="color:blue;">new</span> System.Windows.Forms.<span style="color:#2b91af;">Button</span>();
|
|
<span style="color:blue;">this</span>.SuspendLayout();
|
|
<span style="color:green;">// </span>
|
|
<span style="color:green;">// VaultsLabel</span>
|
|
<span style="color:green;">// </span>
|
|
<span style="color:blue;">this</span>.VaultsLabel.AutoSize = <span style="color:blue;">true</span>;
|
|
<span style="color:blue;">this</span>.VaultsLabel.Location = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Point</span>(13, 26);
|
|
<span style="color:blue;">this</span>.VaultsLabel.Name = <span style="color:#a31515;">"VaultsLabel"</span>;
|
|
<span style="color:blue;">this</span>.VaultsLabel.Size = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Size</span>(91, 13);
|
|
<span style="color:blue;">this</span>.VaultsLabel.TabIndex = 0;
|
|
<span style="color:blue;">this</span>.VaultsLabel.Text = <span style="color:#a31515;">"Select vault view:"</span>;
|
|
<span style="color:green;">// </span>
|
|
<span style="color:green;">// VaultsComboBox</span>
|
|
<span style="color:green;">// </span>
|
|
<span style="color:blue;">this</span>.VaultsComboBox.FormattingEnabled = <span style="color:blue;">true</span>;
|
|
<span style="color:blue;">this</span>.VaultsComboBox.Location = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Point</span>(16, 54);
|
|
<span style="color:blue;">this</span>.VaultsComboBox.Name = <span style="color:#a31515;">"VaultsComboBox"</span>;
|
|
<span style="color:blue;">this</span>.VaultsComboBox.Size = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Size</span>(189, 21);
|
|
<span style="color:blue;">this</span>.VaultsComboBox.TabIndex = 1;
|
|
<span style="color:green;">// </span>
|
|
<span style="color:green;">// GetMessagesButton</span>
|
|
<span style="color:green;">// </span>
|
|
<span style="color:blue;">this</span>.GetMessagesButton.Location = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Point</span>(16, 93);
|
|
<span style="color:blue;">this</span>.GetMessagesButton.Name = <span style="color:#a31515;">"GetMessagesButton"</span>;
|
|
<span style="color:blue;">this</span>.GetMessagesButton.Size = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Size</span>(130, 23);
|
|
<span style="color:blue;">this</span>.GetMessagesButton.TabIndex = 2;
|
|
<span style="color:blue;">this</span>.GetMessagesButton.Text = <span style="color:#a31515;">"Get messages"</span>;
|
|
<span style="color:blue;">this</span>.GetMessagesButton.TextAlign = System.Drawing.<span style="color:#2b91af;">ContentAlignment</span>.MiddleLeft;
|
|
<span style="color:blue;">this</span>.GetMessagesButton.UseVisualStyleBackColor = <span style="color:blue;">true</span>;
|
|
<span style="color:blue;">this</span>.GetMessagesButton.Click += <span style="color:blue;">new</span> System.<span style="color:#2b91af;">EventHandler</span>(<span style="color:blue;">this</span>.GetMessagesButton_Click);
|
|
<span style="color:green;">// </span>
|
|
<span style="color:green;">// Form1</span>
|
|
<span style="color:green;">// </span>
|
|
<span style="color:blue;">this</span>.AutoScaleDimensions = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">SizeF</span>(6F, 13F);
|
|
<span style="color:blue;">this</span>.AutoScaleMode = System.Windows.Forms.<span style="color:#2b91af;">AutoScaleMode</span>.Font;
|
|
<span style="color:blue;">this</span>.ClientSize = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Size</span>(241, 142);
|
|
<span style="color:blue;">this</span>.Controls.Add(<span style="color:blue;">this</span>.GetMessagesButton);
|
|
<span style="color:blue;">this</span>.Controls.Add(<span style="color:blue;">this</span>.VaultsComboBox);
|
|
<span style="color:blue;">this</span>.Controls.Add(<span style="color:blue;">this</span>.VaultsLabel);
|
|
<span style="color:blue;">this</span>.Name = <span style="color:#a31515;">"Form1"</span>;
|
|
<span style="color:blue;">this</span>.Text = <span style="color:#a31515;">"Get Messages"</span>;
|
|
<span style="color:blue;">this</span>.Load += <span style="color:blue;">new</span> System.<span style="color:#2b91af;">EventHandler</span>(<span style="color:blue;">this</span>.Form1_Load);
|
|
<span style="color:blue;">this</span>.ResumeLayout(<span style="color:blue;">false</span>);
|
|
<span style="color:blue;">this</span>.PerformLayout();
|
|
|
|
}
|
|
|
|
<span style="color:blue;"> #endregion</span>
|
|
|
|
<span style="color:blue;">private</span> System.Windows.Forms.<span style="color:#2b91af;">Label</span> VaultsLabel;
|
|
<span style="color:blue;">private</span> System.Windows.Forms.<span style="color:#2b91af;">ComboBox</span> VaultsComboBox;
|
|
<span style="color:blue;">private</span> System.Windows.Forms.<span style="color:#2b91af;">Button</span> GetMessagesButton;
|
|
}
|
|
}</pre>
|
|
</div>
|
|
<div align="center">
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white">
|
|
<font face="Calibri"><a href="#Top">Back to top</a></font></pre>
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|