<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Column="1" Grid.Row="0" Grid.RowSpan="2">
<Button Width="100" Height="23" Margin="2" Content="Ingest stats" Command="{Binding StatsIngest}" />
<Button Width="100" Height="23" Margin="2" Content="Query stats" Command="{Binding StatsQuery}" />
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="0">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Clicks:" Margin="2" />
<TextBlock Text="{Binding Clicks}" Margin="2" />
</StackPanel>
<Button HorizontalAlignment="Left" Width="100" Height="23" Margin="2" Content="Add click" Command="{Binding StatsClick}" />
</StackPanel>
</Grid>
public partial class StatsView : UserControl
{
public StatsViewModel ViewModel { get { return ViewModelLocator.Stats; } }
public StatsView()
{
InitializeComponent();
DataContext = ViewModel;
}
}
StatsViewModel.cs 클래스를 ViewModels 폴더에 추가합니다.
public class StatsViewModel : BindableBase
{
private int _clicks;
public int Clicks
{
get { return _clicks; }
set { SetProperty(ref _clicks, value); }
}
}
private static StatsViewModel _statsViewModel;
public static StatsViewModel Stats
{
get { return _statsViewModel ??= new StatsViewModel(); }
}
public class StatsClickCommand : CommandBase
{
public override bool CanExecute(object parameter)
{
return !string.IsNullOrWhiteSpace(ViewModelLocator.Main.ProductUserId);
}
public override void Execute(object parameter)
{
ViewModelLocator.Stats.Clicks++;
}
}
public StatsClickCommand StatsClick { get; set; }
public StatsViewModel()
{
StatsClick = new StatsClickCommand();
}
Stats.StatsClick.RaiseCanExecuteChanged();
<TabItem x:Name="Stats" Header="Stats">
<views:StatsView />
</TabItem>
public static class StatsService
{
public static void Ingest(int count)
{
var ingestStatOptions = new IngestStatOptions()
{
LocalUserId = ProductUserId.FromString(ViewModelLocator.Main.ProductUserId),
TargetUserId = ProductUserId.FromString(ViewModelLocator.Main.ProductUserId),
Stats = new IngestData[]
{
new IngestData() { StatName = "SumStat", IngestAmount = count },
new IngestData() { StatName = "LatestStat", IngestAmount = count },
new IngestData() { StatName = "MinStat", IngestAmount = count },
new IngestData() { StatName = "MaxStat", IngestAmount = count }
}
};
ViewModelLocator.Main.StatusBarText = $"Ingesting stats (count: <{count}>)...";
App.Settings.PlatformInterface.GetStatsInterface()
.IngestStat(ingestStatOptions, null, (IngestStatCompleteCallbackInfo ingestStatCompleteCallbackInfo) =>
{
Debug.WriteLine($"IngestStat {ingestStatCompleteCallbackInfo.ResultCode}");
if (ingestStatCompleteCallbackInfo.ResultCode == Result.Success)
{
ViewModelLocator.Stats.Clicks = 0;
}
ViewModelLocator.Main.StatusBarText = string.Empty;
});
}
}
public class StatsIngestCommand : CommandBase
{
public override bool CanExecute(object parameter)
{
return !string.IsNullOrWhiteSpace(ViewModelLocator.Main.ProductUserId);
}
public override void Execute(object parameter)
{
StatsService.Ingest(ViewModelLocator.Stats.Clicks);
}
}
public StatsClickCommand StatsClick { get; set; }
public StatsIngestCommand StatsIngest { get; set; }
public StatsViewModel()
{
StatsClick = new StatsClickCommand();
StatsIngest = new StatsIngestCommand();
}
Stats.StatsIngest.RaiseCanExecuteChanged();
<ListView x:Name="StatsListView" Grid.Row="1" Margin="2" ItemsSource="{Binding Stats}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="200" DisplayMemberBinding="{Binding Name}">
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Left" />
</Style>
</GridViewColumn.HeaderContainerStyle>
</GridViewColumn>
<GridViewColumn Header="StartTime" Width="150" DisplayMemberBinding="{Binding StartTime}">
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Left" />
</Style>
</GridViewColumn.HeaderContainerStyle>
</GridViewColumn>
<GridViewColumn Header="EndTime" Width="150" DisplayMemberBinding="{Binding EndTime}">
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Left" />
</Style>
</GridViewColumn.HeaderContainerStyle>
</GridViewColumn>
<GridViewColumn Header="Value" Width="100" DisplayMemberBinding="{Binding Value}">
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Left" />
</Style>
</GridViewColumn.HeaderContainerStyle>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
private ObservableCollection<Stat> _stats;
public ObservableCollection<Stat> Stats
{
get { return _stats; }
set { SetProperty(ref _stats, value); }
}
public static void Query()
{
var queryStatsOptions = new QueryStatsOptions()
{
LocalUserId = ProductUserId.FromString(ViewModelLocator.Main.ProductUserId),
TargetUserId = ProductUserId.FromString(ViewModelLocator.Main.ProductUserId)
};
ViewModelLocator.Main.StatusBarText = $"Querying stats...";
App.Settings.PlatformInterface.GetStatsInterface()
.QueryStats(queryStatsOptions, null, (OnQueryStatsCompleteCallbackInfo onQueryStatsCompleteCallbackInfo) =>
{
Debug.WriteLine($"QueryStats {onQueryStatsCompleteCallbackInfo.ResultCode}");
if (onQueryStatsCompleteCallbackInfo.ResultCode == Result.Success)
{
var getStatCountOptions = new GetStatCountOptions()
{
TargetUserId = ProductUserId.FromString(ViewModelLocator.Main.ProductUserId)
};
var statCount = App.Settings.PlatformInterface
.GetStatsInterface().GetStatsCount(getStatCountOptions);
for (uint i = 0; i < statCount; i++)
{
var copyStatByIndexOptions = new CopyStatByIndexOptions()
{
StatIndex = i,
TargetUserId = ProductUserId.FromString(ViewModelLocator.Main.ProductUserId)
};
var result = App.Settings.PlatformInterface.GetStatsInterface()
.CopyStatByIndex(copyStatByIndexOptions, out var stat);
if (result == Result.Success)
{
ViewModelLocator.Stats.Stats.Add(stat);
}
}
}
ViewModelLocator.Main.StatusBarText = string.Empty;
});
}
public class StatsQueryCommand : CommandBase
{
public override bool CanExecute(object parameter)
{
return !string.IsNullOrWhiteSpace(ViewModelLocator.Main.ProductUserId);
}
public override void Execute(object parameter)
{
ViewModelLocator.Stats.Stats = new ObservableCollection<Stat>();
StatsService.Query();
}
}
public StatsClickCommand StatsClick { get; set; }
public StatsIngestCommand StatsIngest { get; set; }
public StatsQueryCommand StatsQuery { get; set; }
public StatsViewModel()
{
StatsClick = new StatsClickCommand();
StatsIngest = new StatsIngestCommand();
StatsQuery = new StatsQueryCommand();
}
Stats.StatsQuery.RaiseCanExecuteChanged();