none
Test Code

    Discussion générale

  • gfdgsdgdfgdfg
    fgdasfgdfsgfadgads
    dsgsadgsgadsgas
    dsagdsgsadgdsgasd
    classYoutubeDownload
        {
            public string string_result;
            Boolean string_downloaded = false;
            public YoutubeDownload()
            {
                webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
            }
            private WebClient webClient = new WebClient();
            public delegate void DownloadVideoCompletedEventhandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
            public event DownloadVideoCompletedEventhandler DownloadVideoCompleted;
            public delegate void DownloadVideoProgressChangedEventhandler(object sender, DownloadProgressChangedEventArgs e);
            public event DownloadVideoProgressChangedEventhandler DownloadVideoProgressChanged;
            public string GetYoutubeUrl(string youtubeUrl)
            {
                string flashvars = "";
                string fmt_stream_map = "";
                string[] seperator = { "%7C" };
                Regex flashvarsRegex = new Regex("(?<flashvars>flashvars=\".*\")");
                Regex fmt_stream_mapRegex = new Regex("(?<fmt_stream_map>fmt_stream_map=.*\")");
                webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
                webClient.DownloadStringAsync(new Uri(youtubeUrl));
                *while (!string_downloaded) { }
                flashvars = flashvarsRegex.Match(string_result).Groups["flashvars"].Value;
                string_downloaded = false;*
                fmt_stream_map = fmt_stream_mapRegex.Match(flashvars).Groups["fmt_stream_map"].Value;
                return HttpUtility.UrlDecode(fmt_stream_map.Split(seperator, StringSplitOptions.RemoveEmptyEntries)[5]);
            }
            *void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
            {
                string_result = e.Result;
                string_downloaded = true;
            }*
            *public void DownloadVideo(string downloadUrl, string fullFilename)
            {
                webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_DownloadFileCompleted);
                webClient.OpenReadAsync(new Uri(downloadUrl), fullFilename); 
            }*
            private void webClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
            {
                if (DownloadVideoProgressChanged != null)
                {
                    DownloadVideoProgressChanged(sender, e);
                }
            }
            private void webClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
            {
                if (DownloadVideoCompleted != null)
                {
                    DownloadVideoCompleted(sender, e);
                    MessageBox.Show("File Downloaded");
                }
            }
        }
    asdgasdgsdgasdAAA
    asdfasdgasdgdsa
    asdgadsgasdgasdgsdag
    sadgadsgsadgsdgasd
    asdgsadgdgsadgga
    lundi 20 février 2012 09:47

Toutes les réponses

  • class YoutubeDownload
        {
            public string string_result;
            Boolean string_downloaded = false;
    
            public YoutubeDownload()
            {
                webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
            }
    
            private WebClient webClient = new WebClient();
    
            public delegate void DownloadVideoCompletedEventhandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
            public event DownloadVideoCompletedEventhandler DownloadVideoCompleted;
    
            public delegate void DownloadVideoProgressChangedEventhandler(object sender, DownloadProgressChangedEventArgs e);
            public event DownloadVideoProgressChangedEventhandler DownloadVideoProgressChanged;
    
            public string GetYoutubeUrl(string youtubeUrl)
            {
                string flashvars = "";
                string fmt_stream_map = "";
                string[] seperator = { "%7C" };
    
                Regex flashvarsRegex = new Regex("(?<flashvars>flashvars=\".*\")");
                Regex fmt_stream_mapRegex = new Regex("(?<fmt_stream_map>fmt_stream_map=.*\")");
                webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
                webClient.DownloadStringAsync(new Uri(youtubeUrl));
                *while (!string_downloaded) { }
                flashvars = flashvarsRegex.Match(string_result).Groups["flashvars"].Value;
                string_downloaded = false;*
                fmt_stream_map = fmt_stream_mapRegex.Match(flashvars).Groups["fmt_stream_map"].Value;
                return HttpUtility.UrlDecode(fmt_stream_map.Split(seperator, StringSplitOptions.RemoveEmptyEntries)[5]);
            }
    
            *void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
            {
                string_result = e.Result;
                string_downloaded = true;
            }*
    
            *public void DownloadVideo(string downloadUrl, string fullFilename)
            {
                webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_DownloadFileCompleted);
                webClient.OpenReadAsync(new Uri(downloadUrl), fullFilename);  
            }*
    
            private void webClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
            {
                if (DownloadVideoProgressChanged != null)
                {
                    DownloadVideoProgressChanged(sender, e);
                }
            }
    
            private void webClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
            {
                if (DownloadVideoCompleted != null)
                {
                    DownloadVideoCompleted(sender, e);
                    MessageBox.Show("File Downloaded");
                }
            }
        }


    Robert Breitenhofer, MICROSOFT  Twitter Facebook
    Bitte haben Sie Verständnis dafür, dass im Rahmen dieses Forums, welches auf dem Community-Prinzip „Entwickler helfen Entwickler“ beruht, kein technischer Support geleistet werden kann oder sonst welche garantierten Maßnahmen seitens Microsoft zugesichert werden können.

    lundi 20 février 2012 09:55
  • Imports System.Drawing
    Imports System.IO
    Imports System.Runtime.Serialization.Formatters.Soap
    
    <serializable()> _
    Public Class MySerializable
        Implements ISerializable
        Public name As String
        Public description As String
        Public statusbool As Boolean
        Public samevalues() As Single
        Public morevalues() As Single
        Public Color As Color
        'runtime field
        <nonserialized()> _
        Private path As String
        'new fields
        Private string1 As String
        Private boolea1 As Boolean
        Private string2 As String
        Private boolea2 As Boolean
    
        Public Sub New()
            name = "amazing name"
            description = "awesome description"
            statusbool = True
            samevalues = {0, 1, 2, 3, 4, 5, 6.5}
            morevalues = {0, 1, 1, 2, 3, 5, 8}
            Color = Color.Yellow
            path = String.Empty
            string1 = "foo"
            boolea1 = True
            string2 = "bar"
            boolea2 = True
        End Sub
    
        <security.permissions.securitypermissionattribute(security.permissions.securityaction.linkdemand,> _
        Protected Overridable Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext) _
                Implements ISerializable.GetObjectData
            If (info Is Nothing) Then Throw New ArgumentNullException("info")
            info.AddValue("name", name)
            info.AddValue("description", description)
            info.AddValue("statusbool", statusbool)
            info.AddValue("samevalues", samevalues)
            info.AddValue("morevalues", morevalues)
            info.AddValue("Color", Color)
            info.AddValue("path", path)
            info.AddValue("string1", string1)
            info.AddValue("boolea1", boolea1)
            info.AddValue("string2", string2)
            info.AddValue("boolea2", boolea2)
        End Sub
    
        Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
            If (info Is Nothing) Then Throw New ArgumentNullException("info")
            name = info.GetValue("name", name.GetType)
            description = info.GetValue("description", description.GetType)
            statusbool = info.GetValue("statusbool", statusbool.GetType)
            samevalues = info.GetValue("samevalues", samevalues.GetType)
            morevalues = info.GetValue("morevalues", morevalues.GetType)
            Color = info.GetValue("Color", Color.GetType)
            path = info.GetValue("path", path.GetType)
            Try
                string1 = info.GetValue("string1", string1.GetType)
                boolea1 = info.GetValue("boolea1", boolea1.GetType)
                string2 = info.GetValue("string2", string2.GetType)
                boolea2 = info.GetValue("boolea2", boolea2.GetType)
            Catch e As Exception
            End Try
        End Sub
    
        Public Function SaveAs(ByVal fn As String) As Boolean
            Dim ms As FileStream = Nothing
            Try
                ms = New FileStream(fn, FileMode.Create, FileAccess.Write)
                Dim frmt As New SoapFormatter()
                frmt.Serialize(ms, Me)
                path = fn
                Return True
            Catch ex As Exception
                Console.WriteLine("Error while saving " + fn)
                Console.WriteLine(ex.GetType.Name)
                Console.WriteLine(ex.Message)
                Return False
            Finally
                If ms IsNot Nothing Then ms.Close()
            End Try
        End Function
    
        Public Shared Function LoadFrom(ByVal fn As String) As MySerializable
            Dim ms As FileStream = Nothing
            Try
                ms = New FileStream(fn, FileMode.Open, FileAccess.Read)
                Dim p As MySerializable
                Dim frmt As New SoapFormatter()
                ms.Seek(0, SeekOrigin.Begin)
                Dim r = frmt.Deserialize(ms)
                p = TryCast(r, MySerializable)
                If p Is Nothing Then Throw New SerializationException("Cast failed")
                p.path = fn
                Return p
            Catch ex As Exception
                Console.WriteLine("Error while loading " + fn)
                Console.WriteLine(ex.GetType.Name)
                Console.WriteLine(ex.Message)
                Return Nothing
            Finally
                If ms IsNot Nothing Then ms.Close()
            End Try
        End Function
    
    End Class
    
    <serializable()> _
    Public Structure MyColor
        Public name As String
        Public Value As UInt32
        Public knownColor As KnownColor
        Public state As Byte
    
        <xml.serialization.xmlignore()> _
        Public ReadOnly Property col() As Color
            Get
                If Not String.IsNullOrEmpty(name) Then Return Color.FromName(name)
                If knownColor > 1 Then Return Color.FromKnownColor(knownColor)
                If Value > 0 Then Return Color.FromArgb(Value)
                Return Color.FromArgb(0)
            End Get
        End Property
    
    End Structure
    
    Module Module1
        Public msIn As MySerializable
        Public msOut As MySerializable
        Public lastsaved As String
    
        Sub Main()
            load()
            save()
            load()
        End Sub
    
        Private Sub save()
            msIn = New MySerializable
            Dim lastsaved As String = "DarkSide.Cookie"
            Dim i As Integer = 1
            While New FileInfo(lastsaved).Exists
                i += 1
                lastsaved = String.Format("DarkSide{0}.Cookie", i)
            End While
            msIn.SaveAs(lastsaved)
        End Sub
    
        Private Sub load()
            Dim fn As String
            fn = IIf(String.IsNullOrEmpty(lastsaved), "DarkSide.Cookie", lastsaved)
            msOut = MySerializable.LoadFrom(fn)
        End Sub
    
    End Module</xml.serialization.xmlignore()></serializable()></security.permissions.securitypermissionattribute(security.permissions.securityaction.linkdemand,></nonserialized()></serializable()>



    jeudi 23 février 2012 13:45
  • ImportsSystem.Drawing
    ImportsSystem.IO
    ImportsSystem.Runtime.Serialization.Formatters.Soap
    <Serializable()> _
    PublicClassMySerializable
        Implements ISerializable
        Public name As String
        Public description As String
        Public statusbool As Boolean
        Public samevalues() As Single
        Public morevalues() As Single
        Public Color As Color
        'runtime field
        <NonSerialized()> _
        Private path As String
        'new fields
        Private string1 As String
        Private boolea1 As Boolean
        Private string2 As String
        Private boolea2 As Boolean
        Public Sub New()
            name = "amazing name"
            description = "awesome description"
            statusbool = True
            samevalues = {0, 1, 2, 3, 4, 5, 6.5}
            morevalues = {0, 1, 1, 2, 3, 5, 8}
            Color = Color.Yellow
            path = String.Empty
            string1 = "foo"
            boolea1 = True
            string2 = "bar"
            boolea2 = True
        End Sub
        <Security.Permissions.SecurityPermissionAttribute(Security.Permissions.SecurityAction.LinkDemand, Flags:=Security.Permissions.SecurityPermissionFlag.SerializationFormatter)> _
        Protected Overridable Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext) _
                Implements ISerializable.GetObjectData
            If (info Is Nothing) Then Throw New ArgumentNullException("info")
            info.AddValue("name", name)
            info.AddValue("description", description)
            info.AddValue("statusbool", statusbool)
            info.AddValue("samevalues", samevalues)
            info.AddValue("morevalues", morevalues)
            info.AddValue("Color", Color)
            info.AddValue("path", path)
            info.AddValue("string1", string1)
            info.AddValue("boolea1", boolea1)
            info.AddValue("string2", string2)
            info.AddValue("boolea2", boolea2)
        End Sub
        Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
            If (info Is Nothing) Then Throw New ArgumentNullException("info")
            name = info.GetValue("name", name.GetType)
            description = info.GetValue("description", description.GetType)
            statusbool = info.GetValue("statusbool", statusbool.GetType)
            samevalues = info.GetValue("samevalues", samevalues.GetType)
            morevalues = info.GetValue("morevalues", morevalues.GetType)
            Color = info.GetValue("Color", Color.GetType)
            path = info.GetValue("path", path.GetType)
            Try
                string1 = info.GetValue("string1", string1.GetType)
                boolea1 = info.GetValue("boolea1", boolea1.GetType)
                string2 = info.GetValue("string2", string2.GetType)
                boolea2 = info.GetValue("boolea2", boolea2.GetType)
            Catch e As Exception
            End Try
        End Sub
        Public Function SaveAs(ByVal fn As String) As Boolean
            Dim ms As FileStream = Nothing
            Try
                ms = New FileStream(fn, FileMode.Create, FileAccess.Write)
                Dim frmt As New SoapFormatter()
                frmt.Serialize(ms, Me)
                path = fn
                Return True
            Catch ex As Exception
                Console.WriteLine("Error while saving " + fn)
                Console.WriteLine(ex.GetType.Name)
                Console.WriteLine(ex.Message)
                Return False
            Finally
                If ms IsNot Nothing Then ms.Close()
            End Try
        End Function
        Public Shared Function LoadFrom(ByVal fn As String) As MySerializable
            Dim ms As FileStream = Nothing
            Try
                ms = New FileStream(fn, FileMode.Open, FileAccess.Read)
                Dim p As MySerializable
                Dim frmt As New SoapFormatter()
                ms.Seek(0, SeekOrigin.Begin)
                Dim r = frmt.Deserialize(ms)
                p = TryCast(r, MySerializable)
                If p Is Nothing Then Throw New SerializationException("Cast failed")
                p.path = fn
                Return p
            Catch ex As Exception
                Console.WriteLine("Error while loading " + fn)
                Console.WriteLine(ex.GetType.Name)
                Console.WriteLine(ex.Message)
                Return Nothing
            Finally
                If ms IsNot Nothing Then ms.Close()
            End Try
        End Function
    EndClass
    <Serializable()> _
    PublicStructureMyColor
        Public name As String
        Public Value As UInt32
        Public knownColor As KnownColor
        Public state As Byte
        <Xml.Serialization.XmlIgnore()> _
        Public ReadOnly Property col() As Color
            Get
                If Not String.IsNullOrEmpty(name) Then Return Color.FromName(name)
                If knownColor > 1 Then Return Color.FromKnownColor(knownColor)
                If Value > 0 Then Return Color.FromArgb(Value)
                Return Color.FromArgb(0)
            End Get
        End Property
    EndStructure
    ModuleModule1
        Public msIn As MySerializable
        Public msOut As MySerializable
        Public lastsaved As String
        Sub Main()
            load()
            save()
            load()
        End Sub
        Private Sub save()
            msIn = New MySerializable
            Dim lastsaved As String = "DarkSide.Cookie"
            Dim i As Integer = 1
            While New FileInfo(lastsaved).Exists
                i += 1
                lastsaved = String.Format("DarkSide{0}.Cookie", i)
            End While
            msIn.SaveAs(lastsaved)
        End Sub
        Private Sub load()
            Dim fn As String
            fn = IIf(String.IsNullOrEmpty(lastsaved), "DarkSide.Cookie", lastsaved)
            msOut = MySerializable.LoadFrom(fn)
        End Sub
    EndModule

    Robert Breitenhofer, MICROSOFT  Twitter Facebook
    Bitte haben Sie Verständnis dafür, dass im Rahmen dieses Forums, welches auf dem Community-Prinzip „Entwickler helfen Entwickler“ beruht, kein technischer Support geleistet werden kann oder sonst welche garantierten Maßnahmen seitens Microsoft zugesichert werden können.

    jeudi 23 février 2012 13:52
  • Danke für diesen Beitrag. Manches davon kann ich brauchen...
    vendredi 24 février 2012 13:12
  • Hallo Ninjalooter,

    Vielen Dank für Deine Frage und Beitrag!

    Das ist nur ein Beitrag im Test Forum: Hier können die Funktionen des Forums (beispielsweise wie füge ich Screenshots ein, wie sieht mein CodeSnippet aus usw.) oder die Funktionsweise der NNTP-Bridge ausgiebig getestet werden.

    Ich habe den Test gemacht weil die VB.NET Code-Formatierung scheint einige Probleme zu haben mit den Attributen (z.B. <security.permissions.securitypermissionattribute(security.permissions.securityaction.linkdemand,> _wurde abgeschnitten).

    Bitte habe Verständnis dafür, dass wir uns hier in einem Test-Forum von
    MSDN Online, dem Microsoft Developer Network, befinden.

    Wenn  Du entwicklerrelevante Fragen hast kannst Du auf die MSDN DE-DE Forum kommen. Eine Übersicht über alle verfügbaren Microsoft Foren findest Du unter http://www.microsoft.de/Community/Foren

    Eine Übersicht über alle verfügbaren Microsoft Hilfe & Support-Angebot findest Du unter http://www.msdn-support.de

    Ich danke Dir für Dein Verständnis!

    Grüße,

    Robert


    Robert Breitenhofer, MICROSOFT  Twitter Facebook
    Bitte haben Sie Verständnis dafür, dass im Rahmen dieses Forums, welches auf dem Community-Prinzip„Entwickler helfen Entwickler“ beruht, kein technischer Support geleistet werden kann oder sonst welche garantierten Maßnahmen seitens Microsoft zugesichert werden können.

    vendredi 24 février 2012 14:09