Silverlight 4.0 未触发ContentSharingModality ContentAdded事件(Lync silverlight应用程序)

Silverlight 4.0 未触发ContentSharingModality ContentAdded事件(Lync silverlight应用程序),silverlight-4.0,lync,lync-client-sdk,Silverlight 4.0,Lync,Lync Client Sdk,我的最终目标是将文件从一个Lync客户端传输到另一个客户端。我有以下代码 首先,我注册了以下两个事件 一, 二, 这些事件的代码是 void _sharingModality_ContentAdded(object sender, ContentCollectionChangedEventArgs e) { MessageBox.Show("content added\n"+e.Item); } void Modality_

我的最终目标是将文件从一个Lync客户端传输到另一个客户端。我有以下代码

首先,我注册了以下两个事件 一,

二,

这些事件的代码是

void _sharingModality_ContentAdded(object sender, ContentCollectionChangedEventArgs e)
        {
            MessageBox.Show("content added\n"+e.Item);
        }
        void Modality_ModalityStateChanged(object sender, ModalityStateChangedEventArgs e)
        {
            if (e.NewState == ModalityState.Connected)
            {
                textBox1.Text += "\nconnected";
                send_file();
            }
            if (e.NewState == ModalityState.Connecting)
            {
                textBox1.Text += "\nconnecting";
            }
        }
然后我有一个方法,它在名为“abc.txt”的独立存储中创建一个文件。 接下来是一个连接内容共享模式的代码

private void button4_Click(object sender, RoutedEventArgs e)
    {
        if (_conversation.State == ConversationState.Active)
        {
                ((Modality)_conversation.Modalities[ModalityTypes.ContentSharing])
                .BeginConnect((ar) =>{((Modality)_conversation.Modalities[ModalityTypes.ContentSharing]).EndConnect(ar);              }
                , null);

        else { MessageBox.Show("conversation not active"); }
    }
在此之后,有一个“发送文件”的方法,实际上传文件。(该方法id以前在模态状态更改为“已连接”时调用,但(我认为)对话更改为多方,并且该方法在“canInvoke”语句中返回false。因此,我再次调用它,这次成功。如下所示

void send_file()
        {
            if (((ContentSharingModality)_conversation.Modalities[ModalityTypes.ContentSharing]).State == ModalityState.Connected)
            {
                try
                {
                    if (((ContentSharingModality)_conversation.Modalities[ModalityTypes.ContentSharing]).CanInvoke(ModalityAction.CreateShareableNativeFileOnlyContent))
                    {
                        ContentSharingModality contentSharingModality = (ContentSharingModality)_conversation.Modalities[ModalityTypes.ContentSharing];
                        contentSharingModality.BeginCreateContentFromFile(ShareableContentType.NativeFile, "samplefile.txt", fileNameFromIsolatedStorage, true,
                            (ar) =>
                            {
                                ShareableContent sContent = contentSharingModality.EndCreateContentFromFile(ar);
                                //_NativeFileNameAndPath = string.Empty;
                                sContent.Upload();
                            }
                            , null);
                        MessageBox.Show("upload done");
                    }
                    else { MessageBox.Show("u cannot invoke"); }
                }
                catch (Exception e1) { MessageBox.Show(e1.Message); }
            }
            else { MessageBox.Show("modality inactive"); }
        }

最后,这就是我要做的。发送方和接收方机器上都会有相同的代码。我是lync开发的新手,对出现的问题感到非常困惑。请帮助。谢谢!

我看到lync报告的问题,它已连接,但似乎还没有准备好。只需抛出一个厚脸皮的线程。sleep(1000);在canInvoke之前,查看是否有帮助。我尝试过,但没有成功。您对代码有何看法?正确吗?有什么建议吗?另一端的客户端是否需要连接到内容共享模式才能接收文件?我对提供的文件路径表示怀疑。我正在上载的文件是在独立存储的根目录中,所以我只是提供它的名称作为上传代码的参数。这是正确的方法吗?谢谢!当我提供本地文件路径以开始EncreateContentFromFile方法时,代码是正确的,工作正常。我的怀疑是正确的。现在唯一的问题是如何在独立存储中获得该文件路径以使其工作。(我指的不是微软所说的物理路径,即“您不需要知道磁盘上孤立存储文件的实际路径”。
private void button4_Click(object sender, RoutedEventArgs e)
    {
        if (_conversation.State == ConversationState.Active)
        {
                ((Modality)_conversation.Modalities[ModalityTypes.ContentSharing])
                .BeginConnect((ar) =>{((Modality)_conversation.Modalities[ModalityTypes.ContentSharing]).EndConnect(ar);              }
                , null);

        else { MessageBox.Show("conversation not active"); }
    }
void send_file()
        {
            if (((ContentSharingModality)_conversation.Modalities[ModalityTypes.ContentSharing]).State == ModalityState.Connected)
            {
                try
                {
                    if (((ContentSharingModality)_conversation.Modalities[ModalityTypes.ContentSharing]).CanInvoke(ModalityAction.CreateShareableNativeFileOnlyContent))
                    {
                        ContentSharingModality contentSharingModality = (ContentSharingModality)_conversation.Modalities[ModalityTypes.ContentSharing];
                        contentSharingModality.BeginCreateContentFromFile(ShareableContentType.NativeFile, "samplefile.txt", fileNameFromIsolatedStorage, true,
                            (ar) =>
                            {
                                ShareableContent sContent = contentSharingModality.EndCreateContentFromFile(ar);
                                //_NativeFileNameAndPath = string.Empty;
                                sContent.Upload();
                            }
                            , null);
                        MessageBox.Show("upload done");
                    }
                    else { MessageBox.Show("u cannot invoke"); }
                }
                catch (Exception e1) { MessageBox.Show(e1.Message); }
            }
            else { MessageBox.Show("modality inactive"); }
        }