none
.NET 中SkyDrive 疑问,急!!! RRS feed

  • 问题

  • 我在codeplex上的第三方的一个skydrive:

    http://skydriveapiclient.codeplex.com/SourceControl/changeset/view/76924

    可是按照他的源码,导入dll,并且写好代码后运行就一直登陆超时请问该如何解决呢 ?

    到底是什么问题呢?请能人帮助下!谢谢!

            public static readonly Uri SkyDocsServiceUri = new Uri("https://docs.live.net/SkyDocsService.svc");
    
            private const string TestWebFolderName = "msiSkyDriveFolder";
            private const string TestWebFileName1 = "sample.txt";
            private const string TestWebFileName2 = "sample.png";
            private const string TestWebFileName3 = "sample.url";
    
            //private static string userName = "jackslateryu@hotmail.com";
            //private static string passWord = "yulicheng23";
    
            static void Main(string[] args)
            {
                // Instantiate SkyDrive API client
                SkyDriveServiceClient srvSkyDrive = new SkyDriveServiceClient();
                WebFolderInfo testWebFolder = null;
    
                  
    
                try
                {
                    // Log on to a user account
                    //srvSkyDrive.LogOn(userName, passWord);
                    srvSkyDrive.LogOn(ConfigurationSettings.AppSettings["UserName"], ConfigurationSettings.AppSettings["Password"]);
    
                    // Get SkyDrive storage info
                    var webDriveInfo = srvSkyDrive.GetWebDriveInfo();
    
                    // Create a folder in SkyDrive's root
                    testWebFolder = srvSkyDrive.CreateRootWebFolder(TestWebFolderName,WebFolderCategoryType.Documents,WebFolderItemShareType.Private);
    
                    // List folders in SkyDrive's root
                    var rootWebFolders = srvSkyDrive.ListRootWebFolders();
    
                    // Serialize root folders into binary format
                    var serializerBinary = new BinaryFormatter();
                    using (var fs = new FileStream("RootFolders.dat", FileMode.Create))
                    {
                        serializerBinary.Serialize(fs, rootWebFolders);
                    }
    
                    // Deserialize root folders
                    using (var fs = new FileStream("RootFolders.dat", FileMode.Open))
                    {
                        var webFolders = serializerBinary.Deserialize(fs) as WebFolderInfo[];
                    }
    
                    // Serialize root folders into XML format
                    var serializerXml = new XmlSerializer(typeof(WebFolderInfo[]));
                    using (var fs = new FileStream("RootFolders.xml", FileMode.Create))
                    {
                        serializerXml.Serialize(fs, rootWebFolders);
                    }
    
                    // Deserialize root folders
                    using (var fs = new FileStream("RootFolders.xml", FileMode.Open))
                    {
                        var webFolders = serializerXml.Deserialize(fs) as WebFolderInfo[];
                    }
    
                    foreach (WebFolderInfo rootWebFolder in rootWebFolders)
                    {
                        if (rootWebFolder.Name == TestWebFolderName)
                        {
                            testWebFolder = rootWebFolder;
                            break;
                        }
                    }
    
                    //// Change folder ContentType to Documents
                    //srvSkyDrive.ChangeRootWebFolderContentType(testWebFolder, WebFolderContentType.Favorites);
                    //srvSkyDrive.ChangeRootWebFolderContentType(testWebFolder, WebFolderContentType.Documents);
    
                    //// Refresh test webfolder entity
                    //testWebFolder = srvSkyDrive.GetWebFolder(testWebFolder);
    
                    //// Download test webfolder icon
                    //System.Drawing.Image imgTestContentType = srvSkyDrive.DownloadWebFolderItemImage(testWebFolder.WebIcon.ContentTypeWebImage);
                    //if (imgTestContentType != null)
                    //    imgTestContentType.Save("TestWebFolder.ContentType.png", System.Drawing.Imaging.ImageFormat.Png);
                    //System.Drawing.Image imgTestContent = srvSkyDrive.DownloadWebFolderItemImage(testWebFolder.WebIcon.ContentWebImage);
                    //if (imgTestContent != null)
                    //    imgTestContent.Save("TestWebFolder.Content.png", System.Drawing.Imaging.ImageFormat.Png);
                    //System.Drawing.Image imgTestShareType = srvSkyDrive.DownloadWebFolderItemImage(testWebFolder.WebIcon.ShareTypeWebImage);
                    //if (imgTestShareType != null)
                    //    imgTestShareType.Save("TestWebFolder.ShareType.png", System.Drawing.Imaging.ImageFormat.Png);
                    //System.Drawing.Image imgTestIcon = srvSkyDrive.DownloadWebFolderItemIcon(testWebFolder.WebIcon);
                    //imgTestIcon.Save("TestWebFolder.Icon.png", System.Drawing.Imaging.ImageFormat.Png);
    
                    // Create a sub folder
                    var testSubWebFolder = srvSkyDrive.CreateSubWebFolder(TestWebFolderName, testWebFolder);
    
                    // List test folder's sub folders
                    var testWebFolders = srvSkyDrive.ListSubWebFolders(testWebFolder);
                    //foreach (WebFolderInfo webFolder in testWebFolders)
                    //{
                    //    srvSkyDrive.ChangeWebFolderDescription(
                    //        webFolder,
                    //        String.Format("Description for {0}.", webFolder.Name));
                    //    srvSkyDrive.GetWebFolder(webFolder);
                    //}
    
                    // Upload sample files
                    var testWebFile1 = srvSkyDrive.UploadWebFile(TestWebFileName1, testWebFolder);
                    var testWebFile2 = srvSkyDrive.UploadWebFile(TestWebFileName2, testWebFolder);
                    var testWebFile3 = srvSkyDrive.UploadWebFile(TestWebFileName3, testWebFolder);
    
                    // List test folder's files
                    var testWebFiles = srvSkyDrive.ListSubWebFiles(testWebFolder);
    
                    // Serializing files of Test folder into binary format
                    using (var fs = new FileStream("TestFolderFiles.dat", FileMode.Create))
                        serializerBinary.Serialize(fs, testWebFiles);
                    // Deserializing files of Test folder
                    using (var fs = new FileStream("TestFolderFiles.dat", FileMode.Open))
                    {
                        var webFiles = serializerBinary.Deserialize(fs) as WebFileInfo[];
                    }
    
                    // Serializing files of Test folder into XML format
                    serializerXml = new XmlSerializer(typeof(WebFileInfo[]));
                    using (var fs = new FileStream("TestFolderFiles.xml", FileMode.Create))
                        serializerXml.Serialize(fs, testWebFiles);
                    // Deserializing files of Test folder
                    using (var fs = new FileStream("TestFolderFiles.xml", FileMode.Open))
                    {
                        var webFiles = serializerXml.Deserialize(fs) as WebFileInfo[];
                    }
    
                    //foreach (WebFileInfo webFile in testWebFiles)
                    //{
                    //    srvSkyDrive.ChangeWebFileDescription(
                    //        webFile,
                    //        String.Format("Description for {0}.", webFile.Name));
                    //    srvSkyDrive.GetWebFile(webFile);
                    //}
    
                    // List test folder's items
                    var testWebFolderItems = srvSkyDrive.ListSubWebFolderItems(testWebFolder);
    
                    // Serializing items of Test folder into binary format
                    using (var fs = new FileStream("TestFolderItems.dat", FileMode.Create))
                        serializerBinary.Serialize(fs, testWebFiles);
                    // Deserializing items of Test folder
                    using (var fs = new FileStream("TestFolderItems.dat", FileMode.Open))
                    {
                        var webFolderItems = serializerBinary.Deserialize(fs) as WebFolderItemInfo[];
                    }
    
                    // Serializing items of Test folder into XML format
                    serializerXml = new XmlSerializer(typeof(WebFolderItemInfo[]));
                    using (var fs = new FileStream("TestFolderItems.xml", FileMode.Create))
                        serializerXml.Serialize(fs, testWebFiles);
                    // Deserializing items of Test folder
                    using (var fs = new FileStream("TestFolderItems.xml", FileMode.Open))
                    {
                        var webFolderItems = serializerXml.Deserialize(fs) as WebFolderItemInfo[];
                    }
    
                    //// Download test folder as a .zip file
                    //using (Stream sr = srvSkyDrive.DownloadWebFolder(testWebFolder))
                    //using (FileStream fs = new FileStream(String.Format("{0}.zip", testWebFolder.Name), FileMode.OpenOrCreate))
                    //{
                    //    byte[] buffer = new byte[64 * 1024];
                    //    int count = 0;
                    //    while ((count = sr.Read(buffer, 0, buffer.Length)) > 0)
                    //        fs.Write(buffer, 0, count);
                    //}
                }
                catch (LogOnFailedException ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.Data);
                    Console.ReadLine();
                }
                finally
                {
                    //if (testWebFolder != null)
                    //{
                    //    // Delete test folder recursively
                    //    srvSkyDrive.DeleteWebFolder(testWebFolder);
                    //}
                }
    
                Console.WriteLine("SkyDrive");
                Console.ReadLine();
    
    
            }

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
        </startup>
        <appSettings>
          <add key="UserName" value="***@hotmail.com" />
          <add key="Password" value="***" />
        </appSettings>
    </configuration>

    • 已移动 Mike Feng 2012年11月8日 15:30 (发件人:.NET Framework 一般性问题讨论区)
    2012年11月2日 5:03

全部回复