本篇文章给大家谈谈c#–ExchangeWeb服务:为什么ItemId不是常量?,以及c#items的知识点,同时本文还将给你拓展.net–使用ExchangeWeb服务(EWS)托管API为其他用户
本篇文章给大家谈谈c# – Exchange Web服务:为什么ItemId不是常量?,以及c#items的知识点,同时本文还将给你拓展.net – 使用Exchange Web服务(EWS)托管API为其他用户创建任务、.net – 使用Exchange Web服务发送包含特殊字符的电子邮件、android – EditText afterTextChanged不起作用、c – 为什么字符串文字是常量?等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:- c# – Exchange Web服务:为什么ItemId不是常量?(c#items)
- .net – 使用Exchange Web服务(EWS)托管API为其他用户创建任务
- .net – 使用Exchange Web服务发送包含特殊字符的电子邮件
- android – EditText afterTextChanged不起作用
- c – 为什么字符串文字是常量?
c# – Exchange Web服务:为什么ItemId不是常量?(c#items)
我想使用ItemID来创建这个元数据和特定电子邮件之间的链接,而且我刚刚发现这个ItemId不是常量.例如,如果电子邮件从公用文件夹移动到另一个文件夹,它将收到另一个ItemId.这意味着,电子邮件和关联的元数据之间的链接丢失.
那么问题是,如何在元数据和特定的电子邮件之间建立链接?
解决方法
虽然这里不适用,但由于Exchange在某些情况下破坏并重新创建约会,因此日历条目更复杂,从而更改唯一的ID.
此页面(http://msdn.microsoft.com/en-us/library/cc815908.aspx)包含可用于标识对象的MAPI属性概述.另一种替代方法是您可以将自己的id属性添加到Exchange元素(通过扩展属性).
.net – 使用Exchange Web服务(EWS)托管API为其他用户创建任务
我已经设法为自己创建了一个没有问题的任务.但是,我真的需要能够做到以下几点 – 如果有人能给我任何指示,我真的很感激…
>创建任务并将其分配给其他用户.
>能够在分配给该用户时查询该任务的状态(完成百分比等).
>随时更新任务说明.
提前感谢任何指针!
解决方法
为后代粘贴代码:
public string CreateTaskItem(string targetMailId) { string itemId = null; task.Subject = "Amit: sample task created from SDE and EWS"; task.Body = new BodyType(); task.Body.BodyType1 = BodyTypeType.Text; task.Body.Value = "Amit created task for you!"; task.StartDate = DateTime.Now; task.StartDateSpecified = true; // Create the request to make a new task item. CreateItemType createItemRequest = new CreateItemType(); createItemRequest.Items = new NonEmptyArrayOfAllItemsType(); createItemRequest.Items.Items = new ItemType[1]; createItemRequest.Items.Items[0] = task; /** code from create appointment **/ distinguishedFolderIdType defTasksFolder = new distinguishedFolderIdType(); defTasksFolder.Id = distinguishedFolderIdNameType.tasks; defTasksFolder.MailBox = new EmailAddresstype(); defTasksFolder.MailBox.EmailAddress = targetMailId; TargetFolderIdType target = new TargetFolderIdType(); target.Item = defTasksFolder; createItemRequest.SavedItemFolderId = target; try { // Send the request and get the response. CreateItemResponseType createItemResponse = _esb.CreateItem(createItemRequest); // Get the response messages. ResponseMessageType[] rmta = createItemResponse.ResponseMessages.Items; foreach (ResponseMessageType rmt in rmta) { ArrayOfRealItemsType itemArray = ((ItemInfoResponseMessageType)rmt).Items; ItemType[] items = itemArray.Items; // Get the item identifier and change key for each item. foreach (ItemType item in items) { //the task id Console.WriteLine("Item identifier: " + item.ItemId.Id); //the change key for that task,would be used if you want to track changes ... Console.WriteLine("Item change key: " + item.ItemId.ChangeKey); } } } catch (Exception e) { Console.WriteLine("Error Message: " + e.Message); } return itemId; }
.net – 使用Exchange Web服务发送包含特殊字符的电子邮件
这些字符是不允许在电子邮件地址的本地部分,还是我应该以某种方式编码地址?
更新:这是测试源代码和跟踪数据:
var service = new ExchangeService(ExchangeVersion.Exchange2010_SP1); service.AutodiscoverUrl("my@email.com"); EmailMessage email = new EmailMessage(service); email.Body = "Test"; email.Subject = "Test"; email.ToRecipients.Add("æøå@domain.com"); email.Send();
来自EWS的跟踪数据显示以下内容:
请求标头:
POST /EWS/Exchange.asmx HTTP/1.1 Content-Type: text/xml; charset=utf-8 Accept: text/xml User-Agent: ExchangeServicesClient/14.03.0032.000 Accept-Encoding: gzip,deflate
请求:
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <t:RequestServerVersion Version="Exchange2010_SP1" /> </soap:Header> <soap:Body> <m:CreateItem Messagedisposition="SendOnly"> <m:Items> <t:Message> <t:Subject>Test</t:Subject> <t:Body BodyType="HTML">Test</t:Body> <t:ToRecipients> <t:MailBox> <t:EmailAddress>æøå@domain.com</t:EmailAddress> </t:MailBox> </t:ToRecipients> </t:Message> </m:Items> </m:CreateItem> </soap:Body> </soap:Envelope>
响应:
<?xml version="1.0" encoding="utf-8"?> <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="438" MinorBuildNumber="0" Version="Exchange2010_SP1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /> </s:Header> <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <m:CreateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> <m:ResponseMessages> <m:CreateItemResponseMessage Response> <m:MessageText>One or more recipients are invalid.</m:MessageText> <m:ResponseCode>ErrorInvalidRecipients</m:ResponseCode> <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey> <m:Items /> </m:CreateItemResponseMessage> </m:ResponseMessages> </m:CreateItemResponse> </s:Body> </s:Envelope>
最后,在Outlook中创建一个这样的地址的电子邮件给出了这样的信息:
解决方法
Alphanumeric characters,the equal sign (=) and the hyphen (-) don’t
require encoding. Other characters use the following encoding Syntax:
A forward slash (/) is replaced by an underscore (_). Other US-ASCII
characters are replaced by a plus sign (+) and the two digits of its
ASCII value are written in hexadecimal. For example,the space
character has the encoded value +20.
http://technet.microsoft.com/en-us/library/bb430743(v=exchg.141).aspx
所以你的“æøå@domain.com”的例子将成为“e6 f8 e5@domain.com”
编辑:
如果地址的“域”部分使用特殊字符,则还需要使用不同的方法对其进行编码.
这是一个GetExchangeEncodedRecipient助手方法,我把它放在一起使用RFC 5321和RFC 3461规范对电子邮件地址进行编码.
public static string GetExchangeEncodedRecipient(string recipient) { int atIdx = recipient.LastIndexOf('@'); if (atIdx < 0) { throw new ArgumentException("Unable to parse domain portion of \"recipient\" email address."); } string namepart = recipient.Substring(0,atIdx); string domainPart = recipient.Substring(atIdx + 1); //need to encode any special characters in the domain name System.Globalization.IdnMapping punycode = new System.Globalization.IdnMapping(); domainPart = "@" + punycode.GetAscii(domainPart); return String.Concat(namepart.Select(c => GetExchangeEncodedChar(c))) + domainPart; } private static string GetExchangeEncodedChar(char c) { string encodedChar = c.ToString(); int charaSCIICode = (int)c; //Encode according to RFC5321,https://tools.ietf.org/html/rfc5321#section-4.1.2 // which references rfc3461 "xtext" format. https://tools.ietf.org/html/rfc3461#section-4 if(charaSCIICode >= 33 && charaSCIICode <= 126 && c != '+' && c != '=') { //This is a character in the valid 33-126 ASCII range for email addresses,which does not need encoded. return c.ToString(); } else if(c == '/'){ //A forward slash (/) is replaced by an underscore (_). return "_"; } else { return "+" + ((int)c).ToString("x2").toupper(); } }
然后,您可以使用GetExchangeEncodedRecipient对地址进行编码.这是一个例子:
string recipient = @"user1æøå@dømain.com"; string encodedAddress = GetExchangeEncodedRecipient(recipient); Console.WriteLine("Original: {0},Encoded: {1}",recipient,encodedAddress);
对于上面的示例收件人,将输出:
Original: user1æøå@dømain.com,Encoded: user1+E6+F8+E5@xn--dmain-vua.com
如果您使用的“普通”电子邮件地址不包含“普通”ASCII范围之外的任何字符,那么它将返回相同的字符串.
Original: jsmith01@gmail.com,Encoded: jsmith01@gmail.com
android – EditText afterTextChanged不起作用
寄存器
private void insertData( String name,String pass,Uri image) throws sqliteException { database = mdb.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(MyDatabaseHelper.KEY_NAME,name); cv.put(MyDatabaseHelper.KEY_PASSWORD,pass); try { database = mdb.getWritableDatabase(); InputStream iStream = getContentResolver().openInputStream(image); byte[] inputData = Utils.getBytes(iStream); cv.put(MyDatabaseHelper.KEY_IMAGE,inputData); }catch(IOException ioe) { Log.e(TAG,"<saveImageInDB> Error : " + ioe.getLocalizedMessage()); } database.insert(MyDatabaseHelper.TABLE_USER,null,cv); Toast.makeText(getApplicationContext(),"Database Created",Toast.LENGTH_SHORT).show(); database.close(); }
当我获得Database Created时,我假设数据库已成功创建并插入了数据.
在Login中,我想要根据用户名从sqlite中检索图像.
name = (EditText) findViewById(R.id.name); name.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s,int start,int before,int count) { } @Override public void beforeTextChanged(CharSequence s,int count,int after) { } @Override public void afterTextChanged(Editable editable) { String personName = name.getText().toString(); database = mdb.getWritableDatabase(); String selectQuery = " SELECT " + MyDatabaseHelper.KEY_IMAGE + " FROM " + MyDatabaseHelper.TABLE_USER + " WHERE " + MyDatabaseHelper.KEY_NAME + " = ' " + personName + " ' "; Cursor cursor = database.rawQuery(selectQuery,null); if (cursor.movetoFirst()) { byte[] blob = cursor.getBlob(cursor.getColumnIndex("Image")); Log.e("A",blob+""); cursor.close(); mdb.close(); imageView.setimageBitmap(getRoundedBitmap(Utils.getimage(blob))); } else { Toast.makeText(getApplication(),"NULL",Toast.LENGTH_SHORT).show(); } } }); public Bitmap getRoundedBitmap(Bitmap bitmap){ Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),Bitmap.Config.ARGB_8888); BitmapShader shader = new BitmapShader(bitmap,Shader.TileMode.CLAMP,Shader.TileMode.CLAMP); Paint paint = new Paint(); paint.setShader(shader); paint.setAntiAlias(true); Canvas c = new Canvas(circleBitmap); c.drawCircle(bitmap.getWidth() / 2,bitmap.getHeight() / 2,bitmap.getWidth() / 2,paint); return circleBitmap; }
MyDatabaseHelper
public class MyDatabaseHelper extends sqliteOpenHelper { public static final int DATABASE_VERSION=1; public static final String DATABASE_NAME="mm.db"; public static final String TABLE_USER="User"; public static final String KEY_NAME="Name"; public static final String KEY_PASSWORD="Password"; public static final String KEY_IMAGE="Image"; public static final String ID="id"; public void onCreate(sqliteDatabase db) { db.execsql("create table " + TABLE_USER + " ( " + ID + " INTEGER PRIMARY KEY,Name TEXT,Password TEXT,Image BLOB )"); } public void onUpgrade(sqliteDatabase db,int oldVersion,int newVersion) { Log.w(MyDatabaseHelper.class.getName(),"Upgrading database from version" + oldVersion + "to" + newVersion + ",which will destroy all old data"); db.execsql("Drop TABLE IF EXISTS " + TABLE_USER); onCreate(db); } public MyDatabaseHelper(Context context) { super(context,DATABASE_NAME,1); } }
utils的
public class Utils { public static byte[] getimageBytes(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG,100,stream); return stream.toByteArray(); } public static Bitmap getimage(byte[] image) { return BitmapFactory.decodeByteArray(image,image.length); } public static byte[] getBytes(InputStream inputStream) throws IOException { ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; int len = 0; while ((len = inputStream.read(buffer)) != -1) { byteBuffer.write(buffer,len); } return byteBuffer.toByteArray(); } }
用户在EditText上键入他/她的名字,名称为name,图片没有检索,但是向我显示Null消息!这有什么不对?
解决方法
因此,即使在输入整个用户名之前,也会多次调用afterTextChanged(),从而调用null游标.但是,只要用户名被完全输入,光标就应该提供正确的行,在您的情况下,是图像blob.
正如您所提到的,它是一个登录页面,因此必须有一个密码editText以及用户名editText.
我建议更好的方法是使用setonFocuschangelistener()检测用户名EditText的焦点更改.用户完成输入用户名后立即触发SQL查询,焦点现在是密码editText.
name = (EditText) findViewById(R.id.name); name.setonFocuschangelistener(new OnFocuschangelistener() { public void onFocusChange(View v,boolean hasFocus) { if(!hasFocus) { //Fire Query when focus is lost String personName = name.getText().toString(); database = mdb.getWritableDatabase(); String selectQuery = " SELECT " + MyDatabaseHelper.KEY_IMAGE + " FROM " + MyDatabaseHelper.TABLE_USER + " WHERE " + MyDatabaseHelper.KEY_NAME + " = ' " + personName + " ' "; Cursor cursor = database.rawQuery(selectQuery,null); if (cursor.movetoFirst()) { byte[] blob = cursor.getBlob(cursor.getColumnIndex("Image")); Log.e("A",blob+""); cursor.close(); mdb.close(); imageView.setimageBitmap(getRoundedBitmap(Utils.getimage(blob))); } else { Toast.makeText(getApplication(),Toast.LENGTH_SHORT).show(); } } });
如果有效,请告诉我们.
c – 为什么字符串文字是常量?
char * str = "Hello!"; str[1] = 'a';
这将带来不确定的行为.
除了字符串文字放在静态内存中.因此它们存在于整个程序中.我想知道为什么字符串文字有这样的属性.
解决方法
一种是允许将字符串文字存储在只读存储器中(正如其他人已经提到的那样).
另一种方法是允许合并字符串文字.如果一个程序在几个不同的地方使用相同的字符串文字,那么允许(但不一定要求)编译器将它们合并是很好的,因此您可以获得指向同一内存的多个指针,而不是每个指针占用一个单独的内存块.当两个字符串文字不一定相同但具有相同的结尾时,这也适用:
char *foo = "long string"; char *bar = "string";
在这样的情况下,bar可能是foo 5(如果我计算正确的话).
在任何一种情况下,如果允许修改字符串文字,它可以修改恰好具有相同内容的其他字符串文字.同时,老实说也没有太多的要点 – 要么有足够的字符串文字可以重叠,大多数人可能希望编译器运行得更慢只是为了保存(可能)几十个字节记忆的左右.
在编写第一个标准时,已经有编译器使用了所有这三种技术(可能还有其他几种).由于没有办法描述你从修改字符串文字中获得的一种行为,并且没有人显然认为它是一种重要的支持能力,所以他们做了显而易见的事实:即使尝试这样做也会导致未定义的行为.
关于c# – Exchange Web服务:为什么ItemId不是常量?和c#items的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于.net – 使用Exchange Web服务(EWS)托管API为其他用户创建任务、.net – 使用Exchange Web服务发送包含特殊字符的电子邮件、android – EditText afterTextChanged不起作用、c – 为什么字符串文字是常量?的相关知识,请在本站寻找。
本文标签: