DR HACK

Davide Rosa Hack

131959
OggiOggi23
IeriIeri37
Questa settimanaQuesta settimana124
Questo MeseQuesto Mese823
TuttoTutto131959
Utenti 0
Visitatori 2

WebGate

Ecco il porting dell'app WebGate for Android su Windows Phone 7

MainPage.xaml

<phone:PhoneApplicationPage 
    x:Class="WebGate.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait" shell:SystemTray.IsVisible="True">
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar Mode="Minimized" IsMenuEnabled="False">
            <shell:ApplicationBarIconButton IconUri="/Assets/AppBar/appbar.feature.settings.rest.png" IsEnabled="True" Text="Opzioni" Click="ApplicationBarIconButton_Click"/>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0" Height="696" VerticalAlignment="Top">
            <Grid.Background>
                <ImageBrush ImageSource="/WebGate;component/Images/webgate_2.png" Stretch="UniformToFill" />
            </Grid.Background>
            <Button Margin="56,69,252,0" Name="btnOne" BorderThickness="0" Height="254" VerticalAlignment="Top" />
            <Button Margin="253,69,52,0" Name="btnTwo" BorderThickness="0" Height="254" VerticalAlignment="Top" />
            <TextBlock x:Name="txbToast" Margin="68,36,61,0" TextWrapping="Wrap" Text="..." VerticalAlignment="Top" TextAlignment="Center" Height="33"/>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>

MainPage.xaml.vb

Imports System.IO.IsolatedStorage
Imports System.IO

Partial Public Class MainPage
    Inherits PhoneApplicationPage

    Dim WithEvents _WebClient_ As WebClient
    Dim WithEvents _DispatcherTimer_ As System.Windows.Threading.DispatcherTimer
    Dim strBtnOne As String
    Dim strBtnTwo As String

    ' Constructor
    Public Sub New()
        InitializeComponent()

        _WebClient_ = New Net.WebClient
        _WebClient_.UseDefaultCredentials = True

        _WebClient_.Headers.Item("Cache-Control") = "no-cache"

        _DispatcherTimer_ = New Windows.Threading.DispatcherTimer()
        _DispatcherTimer_.Interval = New TimeSpan(0, 0, 0, 1, 0)

        Me.txbToast.Visibility = Windows.Visibility.Collapsed

    End Sub

    Private Sub btnOne_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnOne.Click

        _WebClient_.DownloadStringAsync(New System.Uri(Me.strBtnOne & "&junk=" & Guid.NewGuid().ToString()))

    End Sub

    Private Sub btnTwo_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnTwo.Click

        _WebClient_.DownloadStringAsync(New System.Uri(Me.strBtnTwo & "&junk=" & Guid.NewGuid().ToString()))

    End Sub

    Private Sub request_DownloadStringCompleted(sender As Object, e As System.Net.DownloadStringCompletedEventArgs) Handles _WebClient_.DownloadStringCompleted
        If e.Error IsNot Nothing Then
            Me.txbToast.Text = "ERRORE"
        Else
            Me.txbToast.Text = (Not e.Result.StartsWith("")).ToString.Trim.ToUpper.Replace("TRUE", "OK").Replace("FALSE", "ERRORE")
        End If
        Me.txbToast.Visibility = Windows.Visibility.Visible
        _DispatcherTimer_.Start()
    End Sub

    Private Sub dt_Tick(sender As Object, e As System.EventArgs) Handles _DispatcherTimer_.Tick
        Me.txbToast.Visibility = Windows.Visibility.Collapsed
        Me.txbToast.Text = String.Empty
        CType(sender, System.Windows.Threading.DispatcherTimer).Stop()
    End Sub

    Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded

        Dim xdoc As Xml.Linq.XDocument

        Using store = IsolatedStorageFile.GetUserStoreForApplication
            If store.FileExists(My.Resources.Risorse.DB) = True Then
                Using stream As New StreamReader(store.OpenFile(My.Resources.Risorse.DB, FileMode.Open))
                    xdoc = Xml.Linq.XDocument.Load(stream)
                End Using
            Else
                xdoc = Xml.Linq.XDocument.Load(My.Resources.Risorse.DB)
            End If

            Me.strBtnOne = xdoc.Descendants("btnone").First.Value
            Me.strBtnTwo = xdoc.Descendants("btntwo").First.Value

        End Using

    End Sub

    Private Sub ApplicationBarIconButton_Click(sender As Object, e As EventArgs)
        NavigationService.Navigate(New Uri("/OpzioniPage.xaml", UriKind.Relative))
    End Sub

End Class

OpzioniPage.xaml

<phone:PhoneApplicationPage
    x:Class="WebGate.OpzioniPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsMenuEnabled="False">
            <shell:ApplicationBarIconButton IconUri="/Assets/AppBar/appbar.save.rest.png" IsEnabled="True" Text="Salva" Click="ApplicationBarIconButton_Click"/>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

    <!--LayoutRoot è la griglia radice in cui viene inserito tutto il contenuto della pagina-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contiene il nome dell'applicazione e il titolo della pagina-->
        <StackPanel Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="OPZIIONI WebGate" Style="{StaticResource PhoneTextNormalStyle}"/>
        </StackPanel>

        <!--ContentPanel - inserire ulteriore contenuto qui-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="URL Bottone 1 :" VerticalAlignment="Top"/>
            <TextBox x:Name="txbBtnOne" Height="170" Margin="0,42,0,0" TextWrapping="Wrap" VerticalAlignment="Top"/>
            <TextBlock HorizontalAlignment="Left" Margin="10,217,0,0" TextWrapping="Wrap" Text="URL Bottone 2 :" VerticalAlignment="Top"/>
            <TextBox x:Name="txbBtnTwo" Height="170" Margin="0,249,0,0" TextWrapping="Wrap" VerticalAlignment="Top"/>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>

OpzioniPage.xaml

Imports System.IO.IsolatedStorage
Imports System.IO

Partial Public Class OpzioniPage
    Inherits PhoneApplicationPage

    Dim WithEvents xdoc As Xml.Linq.XDocument

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub OpzioniPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded

        Using store = IsolatedStorageFile.GetUserStoreForApplication
            If store.FileExists(My.Resources.Risorse.DB) = True Then
                Using stream As New StreamReader(store.OpenFile(My.Resources.Risorse.DB, FileMode.Open))
                    xdoc = Xml.Linq.XDocument.Load(stream)
                End Using
            Else
                xdoc = Xml.Linq.XDocument.Load(My.Resources.Risorse.DB)
            End If

            Me.txbBtnOne.Text = xdoc.Descendants("btnone").First.Value
            Me.txbBtnTwo.Text = xdoc.Descendants("btntwo").First.Value

        End Using

    End Sub

    Private Sub ApplicationBarIconButton_Click(sender As Object, e As EventArgs)

        xdoc.Descendants("btnone").First.Value = Me.txbBtnOne.Text
        xdoc.Descendants("btntwo").First.Value = Me.txbBtnTwo.Text

        Using store = IsolatedStorageFile.GetUserStoreForApplication
            Using stream As New IsolatedStorageFileStream(My.Resources.Risorse.DB, FileMode.Create, FileAccess.Write, store)
                xdoc.Save(stream)
            End Using
        End Using

        NavigationService.GoBack()

    End Sub
End Class

DB.xml

<?xml version="1.0" encoding="utf-8" ?>
<setup>
  <btnone><![CDATA[http://127.0.0.1/BTNONE]]></btnone>
  <btntwo><![CDATA[http://127.0.0.1/BTNTWO]]></btntwo>
</setup>
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
visit counter
visit counter
visit counter
visit counter
Accept
Decline