首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在linux上使用mono的不同输出,就像调用webservice在win7上的visual studio上的输出一样

在linux上使用mono的不同输出,就像调用webservice在win7上的visual studio上的输出一样
EN

Stack Overflow用户
提问于 2012-05-09 12:40:47
回答 1查看 546关注 0票数 0

我使用Exchange use服务从exchange邮件服务器提取附件。当我用mono调用linux上的代码时,某个文本附件包含一些混合字符串。

就像这样

“山姆·温林vz”变成"sainglin vz“->,所以它缺少了"m”。我在一个150 in的文件中看到了大约3次。linux输出中缺少3个字节,而windows输出中缺少3个字节。

当我从视觉工作室提取它时,文本附件是完美的。

它就像下面的示例从exchange收件箱中保存附件

知道我该往哪个方向去解决这个问题吗?

代码:

代码语言:javascript
复制
#r "Microsoft.Exchange.WebServices.dll"

open Microsoft
open Microsoft.Exchange.WebServices.Data
open System
open System.Net

type PgzExchangeService(url,user,password) =
    let service = new ExchangeService(ExchangeVersion.Exchange2007_SP1,
                                      TimeZoneInfo.CreateCustomTimeZone("Central Standard Time",new TimeSpan(-6, 0, 0),"(GMT-06:00) Central Time (US & Canada)","Central Standard Time"))


    do
       ServicePointManager.ServerCertificateValidationCallback <- ( fun _ _ _ _ -> true )
       service.Url <- new Uri(url)
       service.Credentials <- new WebCredentials(user, password, "domain")

    member this.Service with get() = service
    member this.InboxItems = this.Service.FindItems(WellKnownFolderName.Inbox, new ItemView(10))
    member this.GetFileAttachments ( item : Item ) =        
           let emailMessage = 
               EmailMessage.Bind( this.Service, 
                                  item.Id, 
                                  new PropertySet(BasePropertySet.IdOnly,    ItemSchema.Attachments))
           item, emailMessage.Attachments |> Seq.choose (fun attachment -> match box attachment with  
                                                                       | :? FileAttachment as x -> Some(x) | _ -> None)   

let mailAtdomain = new PgzExchangeService("https://xx.xx.XX.XX/EWS/Exchange.asmx", "user", "passw")

let printsave (item : Item ,att : seq<FileAttachment>) =
    if (Seq.length att) > 0 then
        printfn "%A - saving %i attachments" item.Subject (Seq.length att)        
        att |> Seq.iter ( fun attachment -> printfn "%A" attachment.Name 
                                            attachment.Load(@"/tmp/test/" + attachment.Name ) )   

// filter so we only have items with attachements and ...
let itemsWithAttachments = mailAtdomain.InboxItems                            
                           |> Seq.map mailAtdomain.GetFileAttachments 
                           |> Seq.iter printsave

由于TimeZoneInfo中有一个bug,该代码不能在Windows上运行

此示例代码在linux上运行,但在windows上不运行。因为TimeZoneInfo的错误。但是有了这个,在linux上工作的代码就可以提取附件。试试csv附件,看看结果是否相同。我弄丢了数据!大约每一行3个字节

如果您需要提供问题的csv附件示例,请发送邮件给我。

下面是我用来测试的c#版本。从VS2010运行它工作得很完美,但是在linux上附件大小错误,缺少一些字节?!

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Exchange.WebServices.Data;
using System.Net;

namespace Exchange_SDP_Attachment_Extracter
{
    public class PgzExchangeService
    {
        public void Extract()
        {            
            ExchangeService service = new ExchangeService  (ExchangeVersion.Exchange2007_SP1,TimeZoneInfo.Local);
            service.Credentials = new NetworkCredential("user", "pass", "domain");
            service.Url = new Uri("https://xx.xx.xx.xx/EWS/Exchange.asmx");
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

            FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
            foreach (Item item in findResults.Items)
            {
                EmailMessage e = EmailMessage.Bind
                                 (service,
                                   item.Id,
                                   new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
                foreach ( Attachment att in e.Attachments )
                {

                    if (att is FileAttachment)
                    {
                        FileAttachment fileAttachment = (FileAttachment)att;
                        fileAttachment.Load(@"/tmp/testsdp/" + fileAttachment.Name);                        
                    }
                }

            }
        }
    }

    class Program
    {
         static void Main(string[] args)
         {
             PgzExchangeService pgz = new PgzExchangeService();
             pgz.Extract();
         }
      }
}
EN

回答 1

Stack Overflow用户

发布于 2012-05-10 16:59:45

我的建议是尝试使用十六进制编辑器检查文本附件。这三起事件有一些不同寻常之处。你需要找出这三条线有什么共同之处,然后我们中的任何人才能向你推荐一个行动方针。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10516317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档