Skip to content

Instantly share code, notes, and snippets.

Damir Arh damirarh

View GitHub Profile
@damirarh
damirarh / UpdateAWStats.ps1
Created Oct 4, 2015
Script for downloading IIS logs from Azure and updating AWStats
View UpdateAWStats.ps1
# FTP details
$ftpServer = ''
$ftpUsername = ''
$ftpPassword = ''
# local paths
$perlPath = 'C:\Perl\bin\perl.exe'
$awstatsPath = 'C:\WWW\Internal\awstats-7.3\wwwroot\cgi-bin\awstats.pl'
$downloadDir = 'C:\WWW\_Logs\Azure'
@damirarh
damirarh / SetWinStoreSetting.ps1
Created Jan 17, 2015
Function for changing a windows Store app setting directly in its settings.app file
View SetWinStoreSetting.ps1
function Set-WinStoreSetting {
param (
[Parameter(Mandatory=$true, Position=0)][string]$PackageName,
[Parameter(Mandatory=$true, Position=1)][string]$SettingName,
[Parameter(Mandatory=$true, Position=2)][string]$SettingValue
)
$settingsFile = [IO.Path]::Combine($env:LOCALAPPDATA, 'Packages', $PackageName, 'Settings\settings.dat')
# temporary paths
View DownloadStringAsync.cs
private Task<string> DownloadStringAsync(Uri uri)
{
var taskSource = new TaskCompletionSource<string>();
var webClient = new WebClient();
webClient.DownloadStringCompleted += (sender, args) =>
{
try
{
if (args.Error != null)
View ReadAsync.cs
private async Task<byte[]> ReadAsync(string filename)
{
var fileInfo = new FileInfo(filename);
using (var stream = new FileStream(filename, FileMode.Open))
{
var buffer = new byte[fileInfo.Length];
await Task<int>.Factory.FromAsync(stream.BeginRead, stream.EndRead, buffer, 0, buffer.Length, null);
return buffer;
}
}
View EnumToImageConverter.cs
public class EnumToImageConverter : IValueConverter
{
public string SubFolder { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Enum && targetType == typeof(ImageSource))
{
var enumType = value.GetType();
var format = String.IsNullOrEmpty(SubFolder) ? "/Assets/{0}/{2}.png" : "/Assets/{0}/{1}/{2}.png";
View Tile.xaml
<Grid Width="60" Height="60"
VerticalAlignment="Top"
Background="{StaticResource PhoneAccentBrush}">
<Image Source="{Binding LogType, Converter={StaticResource EnumToImageConverter}}" />
</Grid>
View NameScopeBinding.xaml
<Page.Resources>
<b:NameScopeBinding x:Key="ListView" Source="{Binding ElementName=ListView}" />
</Page.Resources>
<ListView x:Name="ListView"
SelectionMode="Single"
IsItemClickEnabled="True"
ItemsSource="{Binding Items}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="ItemClick">
View InvokeCommandAction.xaml
<ListView IsItemClickEnabled="True"
ItemsSource="{Binding Items}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="ItemClick">
<i:InvokeCommandAction Command="{Binding ItemClickedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListView>
View Behavior.xaml
<ListView IsItemClickEnabled="True"
ItemsSource="{Binding Items}">
<i:Interaction.Behaviors>
<local:ItemClickedBehavior ItemClickedCommand="{Binding ItemClickedCommand}" />
</i:Interaction.Behaviors>
</ListView>
View AttachedProperties.cs
public static class AttachedProperties
{
public static DependencyProperty ItemClickCommandProperty =
DependencyProperty.RegisterAttached("ItemClickCommand",
typeof(ICommand),
typeof(AttachedProperties),
new PropertyMetadata(null, OnItemClickCommandChanged));
public static void SetItemClickCommand(DependencyObject target, ICommand value)
{
You can’t perform that action at this time.