Permalink
Browse files

update

  • Loading branch information...
1 parent df36cca commit 14852513dbcf7a71df67a4288bbce699057400c9 Steven Houben committed Dec 14, 2012
View
7 NooSphere/ActivityDesk/ActivityDesk.csproj
@@ -94,6 +94,9 @@
<Compile Include="Note.xaml.cs">
<DependentUpon>Note.xaml</DependentUpon>
</Compile>
+ <Compile Include="ResourceViewer.xaml.cs">
+ <DependentUpon>ResourceViewer.xaml</DependentUpon>
+ </Compile>
<Compile Include="Visualizer\Definitions\SmartPhoneDefinition.cs" />
<Compile Include="Visualizer\Definitions\TabletDefinition.cs" />
<Compile Include="Visualizer\Visualizations\SmartPhone.xaml.cs">
@@ -140,6 +143,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
+ <Page Include="ResourceViewer.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="Visualizer\Visualizations\SmartPhone.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
View
129 NooSphere/ActivityDesk/Desk.xaml.cs
@@ -51,17 +51,18 @@ public partial class Desk : SurfaceWindow
private ActivityClient _pairedManager;
private string _pairedTag;
+
private GenericHost _host;
private DiscoveryManager _disc;
+
private readonly User _user;
private readonly Device _device;
+
private DeskState _deskState;
private Activity _currentActivity;
private readonly List<string> _lockedTags = new List<string>();
private readonly List<string> _connectedDeviceTags = new List<string>();
- private Dictionary<Guid, SurfaceButton> _proxies = new Dictionary<Guid, SurfaceButton>();
- private Dictionary<string, ScatterViewItem> _lockedTagTumbnails = new Dictionary<string, ScatterViewItem>();
- private DocumentContainer documentContainer = new DocumentContainer();
+ private DocumentContainer _documentContainer = new DocumentContainer();
#endregion
@@ -75,13 +76,13 @@ public Desk()
//Initializes design-time components
InitializeComponent();
- TouchVisualizer.SetShowsVisualizations(documentContainer, false);
+ TouchVisualizer.SetShowsVisualizations(_documentContainer, false);
Visualizer.VisualizationInitialized += new TagVisualizerEventHandler(Visualizer_VisualizationInitialized);
//Initializes tag definitions
InitializeTags();
- this.documentViewContainer.Children.Add(documentContainer);
+ this.documentViewContainer.Children.Add(_documentContainer);
SetDeskState(DeskState.Ready);
@@ -132,22 +133,6 @@ private void SetDeskState(ActivityDesk.DeskState deskState)
this.Dispatcher.Invoke(DispatcherPriority.Background, new System.Action(() =>
{
- //switch (deskState)
- //{
- // case ActivityDesk.DeskState.Active:
- // this.Background = (ImageBrush)this.Resources["green"];
- // break;
- // case ActivityDesk.DeskState.Locked:
- // this.Background = (ImageBrush)this.Resources["red"];
- // break;
- // case ActivityDesk.DeskState.Occupied:
- // this.Background = (ImageBrush)this.Resources["yellow"];
- // break;
- // case ActivityDesk.DeskState.Ready:
- // this.Background = (ImageBrush)this.Resources["blue"];
- // break;
- //}
-
this.Background = (ImageBrush)this.Resources["back"];
}));
}
@@ -160,24 +145,29 @@ private void SetDeskState(ActivityDesk.DeskState deskState)
private void InitializeUI()
{
SetDeskState(ActivityDesk.DeskState.Occupied);
+
}
/// <summary>
/// Initializes the tag defintions
/// </summary>
private void InitializeTags()
{
- TagVisualizationDefinition definition = new SmartPhoneDefinition();
- definition.Source = new Uri("Visualizer/Visualizations/SmartPhone.xaml", UriKind.Relative);
- definition.TagRemovedBehavior = TagRemovedBehavior.Disappear;
- definition.LostTagTimeout = 1000;
-
- TagVisualizationDefinition definition2 = new TabletDefinition();
- definition2.Source = new Uri("Visualizer/Visualizations/VisualizationTablet.xaml", UriKind.Relative);
- definition2.LostTagTimeout = 1000;
- Visualizer.Definitions.Add(definition);
- Visualizer.Definitions.Add(definition2);
+ Visualizer.Definitions.Add(
+ new SmartPhoneDefinition()
+ {
+ Source = new Uri("Visualizer/Visualizations/SmartPhone.xaml", UriKind.Relative),
+ TagRemovedBehavior = TagRemovedBehavior.Disappear,
+ LostTagTimeout = 1000
+ });
+ Visualizer.Definitions.Add(
+ new TabletDefinition()
+ {
+ Source = new Uri("Visualizer/Visualizations/VisualizationTablet.xaml", UriKind.Relative),
+ LostTagTimeout = 1000
+ }
+ );
}
#endregion
@@ -207,6 +197,7 @@ private void StartClient(string addr,string tag)
_pairedManager.FileAdded += new FileAddedHandler(_client_FileAdded);
_pairedManager.ServiceIsDown += new ServiceDownHandler(_client_ServiceIsDown);
_pairedManager.ActivitySwitched += new ActivitySwitchedHandler(_client_ActivitySwitched);
+ _pairedManager.DeviceAdded += new DeviceAddedHandler(_pairedManager_DeviceAdded);
_pairedManager.Open(addr);
InitializeUI();
}
@@ -224,6 +215,11 @@ private void StartClient(string addr,string tag)
}
+ void _pairedManager_DeviceAdded(object sender, DeviceEventArgs e)
+ {
+
+ }
+
private void StartRoleChangeProcedure(string addr)
{
try
@@ -234,7 +230,6 @@ private void StartRoleChangeProcedure(string addr)
}
catch (Exception ex)
{
-
MessageBox.Show(ex.ToString());
}
}
@@ -275,17 +270,17 @@ private void DiscDiscoveryAddressAdded(object o, DiscoveryAddressAddedEventArgs
{
StartClient(e.ServiceInfo.Address, e.ServiceInfo.Code);
}
+ return;
}
}));
}
private void host_HostLaunched(object sender, EventArgs e)
{
- //StartClient(_host.Address,);
+
}
private void _client_ActivitySwitched(object sender, ActivityEventArgs e)
{
_currentActivity = e.Activity;
- documentContainer.Clear();
if (e.Activity.Resources.Count != 0)
foreach (Resource res in e.Activity.Resources)
VisualizeResouce(res, _pairedManager.LocalPath + res.RelativePath);
@@ -301,7 +296,7 @@ private void _client_ServiceIsDown(object sender, EventArgs e)
}
this.Dispatcher.Invoke(DispatcherPriority.Background, new System.Action(() =>
{
- documentContainer.Clear();
+
}));
}
private void _client_FileAdded(object sender, FileEventArgs e)
@@ -332,20 +327,21 @@ private void ClientActivityRemoved(object sender, ActivityRemovedEventArgs e)
#region UI
private void VisualizeResouce(Resource res, string path)
{
- //try
- //{
- // var i = new Image();
- // var src = new BitmapImage();
- // src.BeginInit();
- // src.UriSource = new Uri(path, UriKind.Relative);
- // src.CacheOption = BitmapCacheOption.OnLoad;
- // src.EndInit();
- // i.Source = src;
- // i.Stretch = Stretch.Uniform;
-
- // documentContainer.Add(i);
- //}
- //catch { }
+
+ try
+ {
+ var i = new Image();
+ var src = new BitmapImage();
+ src.BeginInit();
+ src.UriSource = new Uri(path, UriKind.Relative);
+ src.CacheOption = BitmapCacheOption.OnLoad;
+ src.EndInit();
+ i.Source = src;
+ i.Stretch = Stretch.Uniform;
+
+ _documentContainer.AddResource(i,res.Name);
+ }
+ catch { }
}
#endregion
@@ -358,7 +354,6 @@ void Visualizer_VisualizationInitialized(object sender, TagVisualizerEventArgs e
private void Visualizer_VisualizationAdded(object sender, TagVisualizerEventArgs e)
{
-
if (lblStart.Visibility == System.Windows.Visibility.Visible)
lblStart.Visibility = System.Windows.Visibility.Hidden;
@@ -371,8 +366,7 @@ private void Visualizer_VisualizationAdded(object sender, TagVisualizerEventArgs
}
else
{
- if(_lockedTagTumbnails.ContainsKey(e.TagVisualization.VisualizedTag.Value.ToString()))
- RemoveTagThumbnail(e.TagVisualization.VisualizedTag.Value.ToString());
+ _documentContainer.RemoveDevice(e.TagVisualization.VisualizedTag.Value.ToString());
}
((BaseVisualization)e.TagVisualization).Locked += new LockedEventHandler(Desk_Locked);
RunDiscovery();
@@ -382,8 +376,7 @@ private void Desk_Locked(object sender, LockedEventArgs e)
if (_lockedTags.Contains(e.VisualizedTag))
{
_lockedTags.Remove(e.VisualizedTag);
- if (_lockedTagTumbnails.ContainsKey(e.VisualizedTag))
- RemoveTagThumbnail(e.VisualizedTag);
+ _documentContainer.RemoveDevice(e.VisualizedTag);
Log.Out("ActivityDesk", String.Format("{0} unlocked", e.VisualizedTag));
}
else
@@ -393,21 +386,6 @@ private void Desk_Locked(object sender, LockedEventArgs e)
}
}
- private void RemoveTagThumbnail(string tag)
- {
- documentContainer.Remove(_lockedTagTumbnails[tag]);
- _lockedTagTumbnails.Remove(tag);
- }
-
- private void AddTagTumbnail(string name, Point p)
- {
- var btn = new DeviceTumbnail();
- btn.Name = name;
- btn.Center = p;
- documentContainer.Add(btn);
- _lockedTagTumbnails.Add(name, btn);
- }
-
private void Visualizer_VisualizationRemoved(object sender, TagVisualizerEventArgs e)
{
if (!_lockedTags.Contains(e.TagVisualization.VisualizedTag.Value.ToString()))
@@ -427,11 +405,11 @@ private void Visualizer_VisualizationRemoved(object sender, TagVisualizerEventAr
this.Dispatcher.Invoke(DispatcherPriority.Background, new System.Action(() =>
{
- documentContainer.Clear();
+ //documentContainer.Clear();
}));
}
else
- AddTagTumbnail(e.TagVisualization.VisualizedTag.Value.ToString(), e.TagVisualization.Center);
+ _documentContainer.AddDevice(new Device(){TagValue=e.TagVisualization.VisualizedTag.Value},e.TagVisualization.Center);
}
private void Visualizer_VisualizationMoved(object sender, TagVisualizerEventArgs e)
@@ -444,17 +422,10 @@ private void button1_PreviewTouchDown(object sender, TouchEventArgs e)
Console.WriteLine(e.TouchDevice.GetIsFingerRecognized().ToString());
if (e.TouchDevice.GetIsFingerRecognized())
{
- var ink = new Note();
- ink.Close += new EventHandler(ink_Close);
- documentContainer.Add(ink);
+ _documentContainer.AddNote();
}
}
- void ink_Close(object sender, EventArgs e)
- {
- documentContainer.Remove(sender);
- }
-
private void SurfaceWindow_PreviewTouchDown(object sender, TouchEventArgs e)
{
}
View
4 NooSphere/ActivityDesk/DeviceTumbnail.xaml
@@ -7,7 +7,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="ActivityDesk.DeviceTumbnail"
- x:Name="UserControl">
+ x:Name="UserControl" MinHeight="150" MinWidth="150">
<s:ScatterViewItem.Resources>
<ControlTemplate x:Key="Floating">
<Grid x:Name="LayoutRoot" Height="150" Width="300">
@@ -37,7 +37,7 @@
<Border x:Name="btnBody" BorderBrush="Black" BorderThickness="15" Margin="0,0,0,0" Background="#6B5A5A5A" CornerRadius="10">
<Label x:Name="lblName" Content="{Binding Name}" RenderTransformOrigin="0.5,0.5" Foreground="White"
Background="#00000000" FontSize="18.667" FontWeight="Bold"
- d:LayoutOverrides="Height" HorizontalAlignment="Center">
+ d:LayoutOverrides="Height" HorizontalAlignment="Center" VerticalAlignment="Center">
<Label.RenderTransform>
<TransformGroup>
<ScaleTransform/>
View
11 NooSphere/ActivityDesk/DeviceTumbnail.xaml.cs
@@ -20,10 +20,16 @@ namespace ActivityDesk
/// </summary>
public partial class DeviceTumbnail : ScatterViewItem
{
+ private string _name;
public string Name
{
- get;
- set;
+ get{return _name;}
+ set
+ {
+ _name = value;
+ if(_label != null)
+ _label.Content = Name;
+ }
}
private Label _label;
@@ -41,7 +47,6 @@ public override void OnApplyTemplate()
public DeviceTumbnail()
{
this.InitializeComponent();
- CanScale = true;
}
}
}
View
105 NooSphere/ActivityDesk/DocumentContainer.xaml.cs
@@ -12,6 +12,8 @@
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Surface.Presentation.Controls;
+using System.Collections.ObjectModel;
+using NooSphere.Core.Devices;
namespace ActivityDesk
{
@@ -37,41 +39,75 @@ public static void SetDockState(DependencyObject obj, DockStates value)
#endregion
private readonly int _dockSize = 150;
- private readonly int _rightDockX = 75;
- private readonly int _leftDockX = 1845;
- private int _leftDockTreshhold = 100;
- private int _rightDockTreshhold = 1820;
+ private readonly int _rightDockX = 1845;
+ private readonly int _leftDockX = 75;
+ private readonly int _upperDockY = 75;
+ private readonly int _upperDockThreshold = 100;
+ private readonly int _leftDockTreshhold = 100;
+ private readonly int _rightDockTreshhold = 1820;
+
+ public Collection<Note> Notes = new Collection<Note>();
+ public Collection<ResourceViewer> ResourceViewers = new Collection<ResourceViewer>();
+ public Dictionary<string, DeviceTumbnail> Devices = new Dictionary<string, DeviceTumbnail>();
public DocumentContainer()
{
InitializeComponent();
//register dockstate dependency property
- var metadata = new FrameworkPropertyMetadata(DockStates.Free);
+ var metadata = new FrameworkPropertyMetadata(DockStates.Floating);
DockState = DependencyProperty.RegisterAttached("DockState",
typeof(DockStates),
typeof(DocumentContainer), metadata);
}
-
public void Clear()
{
this.view.Items.Clear();
}
+ public void AddNote()
+ {
+ var ink = new Note();
+ ink.Center = new Point(450, 450);
+ ink.Close += new EventHandler(ink_Close);
+ Notes.Add(ink);
+ this.Add(ink);
+ }
+ public void AddResource(Image img,string text)
+ {
+ var res = new ResourceViewer(img,text);
+ ResourceViewers.Add(res);
+ this.Add(res);
+ }
+ public void AddDevice(Device device,Point position)
+ {
+ var dev = new DeviceTumbnail();
+ dev.Name = device.Name;
+ dev.Center = position;
+ Devices.Add(device.TagValue.ToString(),dev);
+ this.Add(dev);
+ }
+ public void UpdateDevice(Device device)
+ {
+ Devices[device.TagValue.ToString()].Name = device.Name;
+ }
+ private void ink_Close(object sender, EventArgs e)
+ {
- public void Add(ScatterViewItem element)
+ }
+ private void Add(ScatterViewItem element)
{
- DocumentContainer.SetDockState(element, DockStates.Free);
+ DocumentContainer.SetDockState(element, DockStates.Floating);
element.AddHandler(UIElement.ManipulationCompletedEvent, new EventHandler<ManipulationCompletedEventArgs>(element_ManipulationDelta), true);
element.PreviewTouchMove += new EventHandler<TouchEventArgs>(element_PreviewTouchMove);
((ScatterViewItem)element).Template = (ControlTemplate)element.FindResource("Floating");
+ element.Orientation = 0;
+ element.CanRotate = false;
this.view.Items.Add(element);
}
-
private void element_PreviewTouchMove(object sender, TouchEventArgs e)
{
HandleDockingFromTouch((ScatterViewItem)sender,e.GetTouchPoint(view).Position);
}
-
private void HandleDockingFromTouch(ScatterViewItem item,Point p)
{
if (p.X < _leftDockTreshhold)
@@ -84,53 +120,40 @@ private void HandleDockingFromTouch(ScatterViewItem item,Point p)
item.Template = (ControlTemplate)item.FindResource("Docked");
DocumentContainer.SetDockState(item, DockStates.Right);
}
- else
- {
- item.Template = (ControlTemplate)item.FindResource("Floating");
- DocumentContainer.SetDockState(item, DockStates.Free);
- }
- UpdateDock(item);
- }
- private void HandleDocking(ScatterViewItem item)
- {
- if (item.Center.X < _leftDockTreshhold)
- {
- item.Template = (ControlTemplate)item.FindResource("Docked");
- DocumentContainer.SetDockState(item, DockStates.Left);
- }
- else if (item.Center.X > _rightDockTreshhold)
+ else if (p.Y < _upperDockThreshold)
{
item.Template = (ControlTemplate)item.FindResource("Docked");
- DocumentContainer.SetDockState(item, DockStates.Right);
+ DocumentContainer.SetDockState(item, DockStates.Top);
}
else
{
item.Template = (ControlTemplate)item.FindResource("Floating");
- DocumentContainer.SetDockState(item, DockStates.Free);
+ DocumentContainer.SetDockState(item, DockStates.Floating);
}
UpdateDock(item);
}
+ private void HandleDocking(ScatterViewItem item)
+ {
+ HandleDockingFromTouch(item,item.Center);
+ }
private void UpdateDock(ScatterViewItem item)
{
var state = DocumentContainer.GetDockState(item);
- if (state == DockStates.Free)
- {
+ if (state == DockStates.Floating)
item.CanMove = true;
- item.CanRotate = true;
- }
else
{
if (state == DockStates.Left)
+ item.Center = new Point(_leftDockX, item.Center.Y);
+ else if(state == DockStates.Right)
item.Center = new Point(_rightDockX, item.Center.Y);
else
- item.Center = new Point(_leftDockTreshhold, item.Center.Y);
+ item.Center = new Point(item.Center.X, _upperDockY);
item.Orientation = 0;
item.CanMove = true;
- item.CanRotate = false;
- Console.WriteLine(item.Center.X.ToString() + " -> " + item.Width.ToString());
+ //item.CanRotate = false;
}
}
-
void element_ManipulationDelta(object sender, ManipulationCompletedEventArgs e)
{
HandleDocking((ScatterViewItem)sender);
@@ -140,11 +163,21 @@ public void Remove(object element)
{
this.view.Items.Remove(element);
}
+
+ public void RemoveDevice(string p)
+ {
+ if(Devices.ContainsKey(p))
+ {
+ view.Items.Remove(Devices[p]);
+ Devices.Remove(p);
+ }
+ }
}
public enum DockStates
{
Left,
Right,
- Free
+ Floating,
+ Top
}
}
View
12 NooSphere/ActivityDesk/Note.xaml
@@ -7,22 +7,22 @@
xmlns:Custom="http://schemas.microsoft.com/surface/2008"
mc:Ignorable="d"
x:Class="ActivityDesk.Note"
- x:Name="UserControl">
+ x:Name="UserControl" Template="{DynamicResource Floating}" d:DesignWidth="408" Height="448" MinHeight="150" MinWidth="150" MaxHeight="600" MaxWidth="800">
<s:ScatterViewItem.Resources>
<ControlTemplate x:Key="Floating" >
<Grid x:Name="LayoutRoot" Background="#E6171616" Height="auto" Width="auto">
- <Custom:SurfaceInkCanvas x:Name="Painter" Margin="20,60,20,60" Background="White"/>
+ <s:SurfaceTextBox Width="auto" Height="50" VerticalAlignment="Top" Margin="20,50,20,20" Name="txtName"></s:SurfaceTextBox>
+ <Custom:SurfaceInkCanvas x:Name="Painter" Margin="20,120,20,60" Background="White"/>
<Custom:SurfaceButton Content="Reset" HorizontalAlignment="Left" Margin="8,8,0,0" VerticalAlignment="Top" Width="104.827" Style="{DynamicResource Invert}" x:Name="btnReset" Click="btnReset_Click" />
- <Custom:SurfaceButton Content="Save" HorizontalAlignment="Left" Margin="126,8,0,0" VerticalAlignment="Top" Width="104.827" x:Name="btnSave" Click="btnSave_Click" />
<Custom:SurfaceButton Content="Close" HorizontalAlignment="Right" Margin="0,8,8,0" VerticalAlignment="Top" Width="104.827" x:Name="btnClose" PreviewTouchDown="btnClose_PreviewTouchDown" />
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="Docked">
<Grid x:Name="LayoutRoot" Height="150" Width="150">
- <Border x:Name="btnBody" BorderBrush="Black" BorderThickness="15" Margin="0,0,0,0" Background="Yellow" CornerRadius="10">
- <Label x:Name="lblName" Content="{Binding Name}" RenderTransformOrigin="0.5,0.5" Foreground="White"
+ <Border x:Name="btnBody" BorderBrush="Black" BorderThickness="15" Margin="0,0,0,0" Background="#30FFFF00" CornerRadius="10">
+ <Label x:Name="lblName" Content="{Binding Name}" RenderTransformOrigin="0.5,0.5" Foreground="Black"
Background="#00000000" FontSize="18.667" FontWeight="Bold"
- d:LayoutOverrides="Height" HorizontalAlignment="Center">
+ d:LayoutOverrides="Height" HorizontalAlignment="Center" VerticalAlignment="Center">
<Label.RenderTransform>
<TransformGroup>
<ScaleTransform/>
View
43 NooSphere/ActivityDesk/Note.xaml.cs
@@ -23,26 +23,48 @@ public partial class Note : ScatterViewItem
public event EventHandler Save = null;
public event EventHandler Close = null;
+ public string Name { get; set; }
+ public StrokeCollection Strokes { get; set; }
+
public Note()
{
this.InitializeComponent();
}
private SurfaceButton reset;
private SurfaceInkCanvas painter;
+ private SurfaceTextBox text;
+ private Label label;
public override void OnApplyTemplate()
{
- DependencyObject d = GetTemplateChild("btnReset");
- if (d != null)
+ if (painter != null)
+ Strokes = painter.Strokes;
+
+ if (text != null)
+ Name = text.Text;
+
+ if (GetTemplateChild("btnReset") != null)
{
- reset = d as SurfaceButton;
+ reset = GetTemplateChild("btnReset") as SurfaceButton;
reset.Click += new RoutedEventHandler(btnReset_Click);
}
- DependencyObject e = GetTemplateChild("Painter");
- if (e != null)
+ if (GetTemplateChild("txtName") != null)
+ {
+ text = GetTemplateChild("txtName") as SurfaceTextBox;
+ text.TextChanged += new TextChangedEventHandler(text_TextChanged);
+ text.Text = Name;
+ }
+
+ if (GetTemplateChild("lblName") != null)
+ {
+ label = GetTemplateChild("lblName") as Label;
+ label.Content = Name;
+ }
+
+ if (GetTemplateChild("Painter") != null)
{
- painter = e as SurfaceInkCanvas;
+ painter = GetTemplateChild("Painter") as SurfaceInkCanvas;
// Set up the DrawingAttributes for the pen.
var inkDA = new DrawingAttributes();
inkDA.Color = Colors.Black;
@@ -52,11 +74,16 @@ public override void OnApplyTemplate()
painter.UsesTouchShape = false;
painter.DefaultDrawingAttributes = inkDA;
+ if(Strokes != null)
+ painter.Strokes = Strokes;
}
-
-
base.OnApplyTemplate();
}
+
+ void text_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ Name = text.Text;
+ }
private void btnReset_Click(object sender, RoutedEventArgs e)
{
painter.Strokes.Clear();
View
38 NooSphere/ActivityDesk/ResourceViewer.xaml
@@ -0,0 +1,38 @@
+<s:ScatterViewItem x:Class="ActivityDesk.ResourceViewer"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:s="http://schemas.microsoft.com/surface/2008"
+ mc:Ignorable="d"
+ d:DesignHeight="300" d:DesignWidth="300" MinHeight="150" MinWidth="150">
+ <s:ScatterViewItem.Resources>
+ <ControlTemplate x:Key="Floating" >
+ <Grid x:Name="grid" Background="#E6171616" Height="auto" Width="auto">
+ <Border x:Name="body" Margin="0,0,0,0">
+ </Border>
+ </Grid>
+ </ControlTemplate>
+ <ControlTemplate x:Key="Docked">
+ <Grid x:Name="grid" Height="150" Width="150">
+ <Border x:Name="body" BorderBrush="Black" BorderThickness="15" Margin="0,0,0,0" CornerRadius="10">
+ <Label x:Name="lblName" Content="{Binding Name}" RenderTransformOrigin="0.5,0.5" Foreground="Black"
+ Background="#00000000" FontSize="18.667" FontWeight="Bold"
+ d:LayoutOverrides="Height" HorizontalAlignment="Center" VerticalAlignment="Center">
+ <Label.RenderTransform>
+ <TransformGroup>
+ <ScaleTransform/>
+ <SkewTransform/>
+ <RotateTransform Angle="0.033"/>
+ <TranslateTransform/>
+ </TransformGroup>
+ </Label.RenderTransform>
+ </Label>
+ </Border>
+ </Grid>
+ </ControlTemplate>
+ </s:ScatterViewItem.Resources>
+ <Grid>
+
+ </Grid>
+</s:ScatterViewItem>
View
45 NooSphere/ActivityDesk/ResourceViewer.xaml.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using Microsoft.Surface.Presentation.Controls;
+
+namespace ActivityDesk
+{
+ /// <summary>
+ /// Interaction logic for ResourceViewer.xaml
+ /// </summary>
+ public partial class ResourceViewer : ScatterViewItem
+ {
+ public string Name { get; set; }
+ public Image Resource { get; set; }
+ private Label label;
+ private bool _initialized = false;
+ public ResourceViewer(Image img,string name)
+ {
+ InitializeComponent();
+ this.Resource = img;
+ this.Name = name;
+ }
+
+ Border border;
+ public override void OnApplyTemplate()
+ {
+ if (GetTemplateChild("body") != null)
+ {
+ border = GetTemplateChild("body") as Border;
+ border.Background = new ImageBrush(Resource.Source);
+ }
+ base.OnApplyTemplate();
+ }
+ }
+}
View
8 NooSphere/ModelingProject1/Graph1.dgml
@@ -0,0 +1,8 @@
+<DirectedGraph xmlns="http://schemas.microsoft.com/vs/2009/dgml">
+ <Nodes>
+ </Nodes>
+ <Links>
+ </Links>
+ <Categories>
+ </Categories>
+</DirectedGraph>
View
44 NooSphere/ModelingProject1/ModelDefinition/ModelingProject1.uml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<modelStoreModel xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" xmlns:dm1="http://schemas.microsoft.com/dsltools/Kernel" xmlns:dm2="http://schemas.microsoft.com/dsltools/Component" xmlns:dm3="http://schemas.microsoft.com/dsltools/Activity" xmlns:dm4="http://schemas.microsoft.com/dsltools/Interaction" xmlns:dm5="http://schemas.microsoft.com/dsltools/UseCase" xmlns:dm6="http://schemas.microsoft.com/dsltools/UmlModelLibrary" xmlns:dm7="http://schemas.microsoft.com/dsltools/UmlDiagrams" xmlns:dm8="http://schemas.microsoft.com/dsltools/LogicalClassDesigner"
+ dslVersion="1.0.0.0"
+ Id="dbfa1bed-1b38-419c-b3e9-3bec51a05100"
+ name="ModelingProject1" xmlns="http://schemas.microsoft.com/dsltools/ModelStore">
+ <profileInstances>
+ <packageHasProfileInstances
+ Id="0caec977-1f8c-4ba3-a7db-8cc9ad9cc73b">
+ <profileInstance
+ Id="e34d544e-0fea-4ed6-ac5e-1b74119ac791"
+ name="StandardProfileL2" />
+ </packageHasProfileInstances>
+ <packageHasProfileInstances
+ Id="29349502-908c-4fda-9054-c48619c59ed0">
+ <profileInstance
+ Id="532ea607-fb19-44b8-8502-3351b05452be"
+ name="StandardProfileL3" />
+ </packageHasProfileInstances>
+ </profileInstances>
+ <primitiveType
+ Id="220a3521-e091-4221-bae9-3ef9018e845c"
+ name="Integer"
+ isAbstract="false"
+ isTemplate="false"
+ isLeaf="false" />
+ <primitiveType
+ Id="8943dc84-709e-4f62-b15a-a3273aa6f165"
+ name="Boolean"
+ isAbstract="false"
+ isTemplate="false"
+ isLeaf="false" />
+ <primitiveType
+ Id="59259974-6d55-42c6-b7bd-763d77ac8ef9"
+ name="String"
+ isAbstract="false"
+ isTemplate="false"
+ isLeaf="false" />
+ <primitiveType
+ Id="3ab42e7d-4969-445a-b209-471f5cb8209c"
+ name="UnlimitedNatural"
+ isAbstract="false"
+ isTemplate="false"
+ isLeaf="false" />
+</modelStoreModel>
View
1 NooSphere/ModelingProject1/ModelDefinition/Package_1433.uml
@@ -0,0 +1 @@
+
View
25 NooSphere/ModelingProject1/ModelingProject1.modelproj
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{00000000-0000-0000-0000-000000000000}</ProjectGuid>
+ <ArchitectureToolsVersion>1.0.0.0</ArchitectureToolsVersion>
+ <Name>ModelingProject1</Name>
+ <RootNamespace>ModelingProject1</RootNamespace>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <OutputPath>bin\Debug\</OutputPath>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <OutputPath>bin\Release\</OutputPath>
+ </PropertyGroup>
+ <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\ArchitectureTools\Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets" />
+ <ItemGroup>
+ <Folder Include="ModelDefinition\" />
+ <Content Include="ModelDefinition\ModelingProject1.uml">
+ <SubType>Content</SubType>
+ </Content>
+ </ItemGroup>
+</Project>
View
1 NooSphere/ModelingProject1/UMLClassDiagram1.classdiagram
@@ -0,0 +1 @@
+
View
1 NooSphere/ModelingProject1/UMLClassDiagram1.classdiagram.layout
@@ -0,0 +1 @@
+
View
1 NooSphere/ModelingProject1/UMLClassDiagram2.classdiagram
@@ -0,0 +1 @@
+
View
1 NooSphere/ModelingProject1/UMLClassDiagram2.classdiagram.layout
@@ -0,0 +1 @@
+
View
38 NooSphere/NooSphere.ActivitySystem/Base/Client/NetEventHandler.cs
@@ -213,32 +213,32 @@ private void Respond(HttpListenerContext context, int statusCode, string content
#region Events
- public event ActivityAddedHandler ActivityAdded;
- public event ActivityRemovedHandler ActivityRemoved;
- public event ActivityChangedHandler ActivityChanged;
- public event ActivitySwitchedHandler ActivitySwitched = null;
+ public event ActivityAddedHandler ActivityAdded = delegate{};
+ public event ActivityRemovedHandler ActivityRemoved = delegate { };
+ public event ActivityChangedHandler ActivityChanged = delegate { };
+ public event ActivitySwitchedHandler ActivitySwitched = delegate { };
- public event DeviceAddedHandler DeviceAdded;
- public event DeviceRemovedHandler DeviceRemoved;
- public event DeviceRoleChangedHandler DeviceRoleChanged;
+ public event DeviceAddedHandler DeviceAdded = delegate { };
+ public event DeviceRemovedHandler DeviceRemoved = delegate { };
+ public event DeviceRoleChangedHandler DeviceRoleChanged = delegate { };
- public event MessageReceivedHandler MessageReceived;
+ public event MessageReceivedHandler MessageReceived = delegate { };
- protected event FileDownloadRequestHandler FileDownloadRequest;
- protected event FileUploadRequestHandler FileUploadRequest;
- protected event FileDeleteRequestHandler FileDeleteRequest;
+ protected event FileDownloadRequestHandler FileDownloadRequest = delegate { };
+ protected event FileUploadRequestHandler FileUploadRequest = delegate { };
+ protected event FileDeleteRequestHandler FileDeleteRequest = delegate { };
- public event FriendAddedHandler FriendAdded;
- public event FriendDeletedHandler FriendDeleted;
- public event FriendRequestReceivedHandler FriendRequestReceived;
+ public event FriendAddedHandler FriendAdded = delegate { };
+ public event FriendDeletedHandler FriendDeleted = delegate { };
+ public event FriendRequestReceivedHandler FriendRequestReceived = delegate { };
- public event ParticipantAddedHandler ParticipantAdded;
- public event ParticipantRemovedHandler ParticipantRemoved;
+ public event ParticipantAddedHandler ParticipantAdded = delegate { };
+ public event ParticipantRemovedHandler ParticipantRemoved = delegate { };
- public event EventHandler UserOnline;
- public event EventHandler UserOffline;
+ public event EventHandler UserOnline = delegate { };
+ public event EventHandler UserOffline = delegate { };
- public event ServiceDownHandler ServiceIsDown;
+ public event ServiceDownHandler ServiceIsDown = delegate { };
#endregion
#region Net Event handlers
View
515 NooSphere/NooSphere.ActivitySystem/FileServer/FileStore.cs
@@ -1,255 +1,262 @@
-/****************************************************************************
- (c) 2012 Steven Houben(shou@itu.dk) and Søren Nielsen(snielsen@itu.dk)
-
- Pervasive Interaction Technology Laboratory (pIT lab)
- IT University of Copenhagen
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU GENERAL PUBLIC LICENSE V3 or later,
- as published by the Free Software Foundation. Check
- http://www.gnu.org/licenses/gpl.html for details.
-****************************************************************************/
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-#if ANDROID
-using Microsoft.Http;
-#else
-using System.Net.Http;
-#endif
-using System.Threading.Tasks;
-using NooSphere.ActivitySystem.Helpers;
-using NooSphere.Core.ActivityModel;
-using NooSphere.ActivitySystem.Base;
-
-namespace NooSphere.ActivitySystem.FileServer
-{
- public class FileStore:IFileStore
- {
- #region Events
- public event FileAddedHandler FileAdded;
- public event FileChangedHandler FileChanged;
- public event FileAddedHandler FileCopied;
- public event FileRemovedHandler FileRemoved;
- public event FileDownloadRequestHandler FileDownloadedFromCloud;
- #endregion
-
- #region Properties
- public string BasePath { get; set; }
- #endregion
-
- #region Private Members
- private readonly HttpClient _httpClient = new HttpClient();
- private readonly Dictionary<Guid, Resource> _files = new Dictionary<Guid, Resource>();
- private readonly object _lookUpLock = new object();
- private readonly object _fileLock = new object();
-
- #endregion
-
- #region Public Methods
- public FileStore(string path)
- {
- BasePath = path;
- }
- public void AddFile(Resource resource, byte[] fileInBytes,FileSource source)
- {
- //Check if we have a valid file
- Check(resource, fileInBytes);
-
- //See if we have file
- if (_files.ContainsKey(resource.Id))
- {
- if (IsNewer(_files[resource.Id], resource))
- UpdateFile(resource, fileInBytes, source);
- else return;
- }
- else
- {
- SaveToDisk(fileInBytes, resource);
- _files.Add(resource.Id, resource);
- }
-
- //Check what the source is and who we should inform
- switch (source)
- {
- case FileSource.ActivityCloud:
- if (FileDownloadedFromCloud != null)
- FileDownloadedFromCloud(this, new FileEventArgs(resource));
- break;
- case FileSource.ActivityManager:
- if (FileAdded != null)
- FileAdded(this, new FileEventArgs(resource));
- break;
- case FileSource.ActivityClient:
- if (FileCopied != null)
- FileCopied(this, new FileEventArgs(resource));
- break;
- }
- Log.Out("FileStore", string.Format("Added file {0} to store", resource.Name), LogCode.Log);
- }
- public void DownloadFile(Resource resource, string path, FileSource source, string _connectionId = null)
- {
- Rest.DownloadStream(path, _connectionId).ContinueWith(stream =>
- {
- Log.Out("FileStore", string.Format("Finished download for {0}", resource.Name), LogCode.Log);
- AddFile(resource, stream.Result, source);
- });
- Log.Out("FileStore", string.Format("Started download for {0}", resource.Name), LogCode.Log);
- }
- private bool IsNewer(Resource resourceInFileStore, Resource requestedResource)
- {
- return false;
- }
- public void AddFile(Resource resource, Stream stream, FileSource source)
- {
- AddFile(resource, GetBytesFromStream(resource, stream), source);
- }
- public void UpdateFile(Resource resource,Stream stream,FileSource source)
- {
- UpdateFile(resource, GetBytesFromStream(resource, stream), source);
- }
- public void UpdateFile(Resource resource, byte[] fileInBytes, FileSource source)
- {
- SaveToDisk(fileInBytes, resource);
- _files[resource.Id] = resource;
-
- switch (source)
- {
- case FileSource.ActivityCloud:
- if (FileDownloadedFromCloud != null)
- FileDownloadedFromCloud(this, new FileEventArgs(resource));
- break;
- case FileSource.ActivityManager:
- if (FileChanged != null)
- FileChanged(this, new FileEventArgs(resource));
- break;
- }
- Log.Out("FileStore", string.Format("Updated file {0} to store", resource.Name), LogCode.Log);
- }
- public void RemoveFile(Resource resource)
- {
- _files.Remove(resource.Id);
- File.Delete(BasePath+resource.RelativePath);
- if (FileRemoved != null)
- FileRemoved(this, new FileEventArgs(resource));
- Log.Out("FileStore", string.Format("FileStore: Removed file {0} from store", resource.Name), LogCode.Log);
- }
- public bool LookUp(Guid id)
- {
- lock(_lookUpLock)
- return _files.ContainsKey(id);
- }
- public Stream GetStreamFromFile(Resource resource)
- {
- lock(_fileLock)
- return new FileStream(BasePath + resource.RelativePath, FileMode.Open, FileAccess.Read, FileShare.Read);
- }
- public byte[] GetBytesFromFile(Resource resource)
- {
- var fi = new FileInfo(BasePath + resource.RelativePath);
- var buffer = new byte[fi.Length];
-
- lock (_fileLock)
- using (var fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
- fs.Read(buffer, 0, (int)fs.Length);
-
- return buffer;
- }
- public void Updatefile(Resource resource, byte[] fileInBytes)
- {
- Task.Factory.StartNew(
- delegate
- {
- _files[resource.Id] = resource;
- SaveToDisk(fileInBytes, resource);
- if (FileChanged != null)
- FileChanged(this, new FileEventArgs(resource));
- Log.Out("FileStore", string.Format("FileStore: Updated file {0} in store", resource.Name), LogCode.Log);
- });
- }
-
- /// <summary>
- /// Initializes a directory for future file saving. It uses the implicitly
- /// called ToString() method to convert the object to a path
- /// </summary>
- /// <param name="relative"> </param>
- public void IntializePath(object relative)
- {
- var path = Path.Combine(BasePath, relative.ToString());
- //In case the activity path does not exist yet, we'll create one
- if (!Directory.Exists(path))
- {
- var dInfo = Directory.CreateDirectory(path);
- }
- }
- public void CleanUp(string path)
- {
- if(Directory.Exists(Path.Combine(BasePath,path)))
- Directory.Delete(Path.Combine(BasePath, path), true);
- }
-
- #endregion
-
- #region Private Methods
- private byte[] GetBytesFromStream(Resource resource, Stream stream)
- {
- var buffer = new byte[resource.Size];
- var ms = new MemoryStream();
- int bytesRead;
- do
- {
- bytesRead = stream.Read(buffer, 0, buffer.Length);
- ms.Write(buffer, 0, bytesRead);
- } while (bytesRead > 0);
- ms.Close();
- return buffer;
- }
- private void Check(Resource resource, byte[] fileInBytes)
- {
- if (_files == null)
- throw new Exception("Filestore: Not initialized");
- if (resource == null)
- throw new Exception(("Filestore: Resource not found"));
- if (fileInBytes == null)
- throw new Exception(("Filestore: Bytearray null"));
- if (fileInBytes.Length == 0)
- throw new Exception(("Filestore: Bytearray empty"));
- }
- private void SaveToDisk(byte[] fileInBytes, Resource resource)
- {
- var path = Path.Combine(BasePath, resource.RelativePath);
- var dir = Path.GetDirectoryName(path);
- if (dir != null && !Directory.Exists(dir)) Directory.CreateDirectory(dir);
-
- lock (_fileLock)
- {
- using (var fileToupload = new FileStream(@path, FileMode.OpenOrCreate))
- {
- fileToupload.Write(fileInBytes, 0, fileInBytes.Length);
- fileToupload.Close();
- fileToupload.Dispose();
-
- //File.SetCreationTimeUtc(path, DateTime.Parse(resource.CreationTime));
- //File.SetLastWriteTimeUtc(path, DateTime.Parse(resource.LastWriteTime));
- Console.WriteLine("FileStore: Saved file {0} to disk at {1}", resource.Name,
- path);
- Log.Out("FileStore", string.Format("FileStore: Saved file {0} to disk at {1}", resource.Name,
- path), LogCode.Log);
- }
- }
- }
- #endregion
- }
- internal class DownloadState
- {
- public Resource Resource { get; set; }
- public FileSource FileSource { get; set; }
-
- public DownloadState(Resource resource, FileSource fileSource)
- {
- Resource = resource;
- FileSource = fileSource;
- }
- }
+/****************************************************************************
+ (c) 2012 Steven Houben(shou@itu.dk) and Søren Nielsen(snielsen@itu.dk)
+
+ Pervasive Interaction Technology Laboratory (pIT lab)
+ IT University of Copenhagen
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU GENERAL PUBLIC LICENSE V3 or later,
+ as published by the Free Software Foundation. Check
+ http://www.gnu.org/licenses/gpl.html for details.
+****************************************************************************/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+#if ANDROID
+using Microsoft.Http;
+#else
+using System.Net.Http;
+#endif
+using System.Threading.Tasks;
+using NooSphere.ActivitySystem.Helpers;
+using NooSphere.Core.ActivityModel;
+using NooSphere.ActivitySystem.Base;
+
+namespace NooSphere.ActivitySystem.FileServer
+{
+ public class FileStore:IFileStore
+ {
+ #region Events
+ public event FileAddedHandler FileAdded;
+ public event FileChangedHandler FileChanged;
+ public event FileAddedHandler FileCopied;
+ public event FileRemovedHandler FileRemoved;
+ public event FileDownloadRequestHandler FileDownloadedFromCloud;
+ #endregion
+
+ #region Properties
+ public string BasePath { get; set; }
+ #endregion
+
+ #region Private Members
+ private readonly HttpClient _httpClient = new HttpClient();
+ private readonly Dictionary<Guid, Resource> _files = new Dictionary<Guid, Resource>();
+ private readonly object _lookUpLock = new object();
+ private readonly object _fileLock = new object();
+
+ #endregion
+
+ #region Public Methods
+ public FileStore(string path)
+ {
+ BasePath = path;
+ }
+ public void AddFile(Resource resource, byte[] fileInBytes,FileSource source)
+ {
+ //Check if we have a valid file
+ Check(resource, fileInBytes);
+
+ //See if we have file
+ if (_files.ContainsKey(resource.Id))
+ {
+ if (IsNewer(_files[resource.Id], resource))
+ UpdateFile(resource, fileInBytes, source);
+ else return;
+ }
+ else
+ {
+ SaveToDisk(fileInBytes, resource);
+ _files.Add(resource.Id, resource);
+ }
+
+ //Check what the source is and who we should inform
+ switch (source)
+ {
+ case FileSource.ActivityCloud:
+ if (FileDownloadedFromCloud != null)
+ FileDownloadedFromCloud(this, new FileEventArgs(resource));
+ break;
+ case FileSource.ActivityManager:
+ if (FileAdded != null)
+ FileAdded(this, new FileEventArgs(resource));
+ break;
+ case FileSource.ActivityClient:
+ if (FileCopied != null)
+ FileCopied(this, new FileEventArgs(resource));
+ break;
+ }
+ Log.Out("FileStore", string.Format("Added file {0} to store", resource.Name), LogCode.Log);
+ }
+ public void DownloadFile(Resource resource, string path, FileSource source, string _connectionId = null)
+ {
+ Rest.DownloadStream(path, _connectionId).ContinueWith(stream =>
+ {
+ Log.Out("FileStore", string.Format("Finished download for {0}", resource.Name), LogCode.Log);
+ AddFile(resource, stream.Result, source);
+ });
+ Log.Out("FileStore", string.Format("Started download for {0}", resource.Name), LogCode.Log);
+ }
+ private bool IsNewer(Resource resourceInFileStore, Resource requestedResource)
+ {
+ return false;
+ }
+ public void AddFile(Resource resource, Stream stream, FileSource source)
+ {
+ AddFile(resource, GetBytesFromStream(resource, stream), source);
+ }
+ public void UpdateFile(Resource resource,Stream stream,FileSource source)
+ {
+ UpdateFile(resource, GetBytesFromStream(resource, stream), source);
+ }
+ public void UpdateFile(Resource resource, byte[] fileInBytes, FileSource source)
+ {
+ SaveToDisk(fileInBytes, resource);
+ _files[resource.Id] = resource;
+
+ switch (source)
+ {
+ case FileSource.ActivityCloud:
+ if (FileDownloadedFromCloud != null)
+ FileDownloadedFromCloud(this, new FileEventArgs(resource));
+ break;
+ case FileSource.ActivityManager:
+ if (FileChanged != null)
+ FileChanged(this, new FileEventArgs(resource));
+ break;
+ }
+ Log.Out("FileStore", string.Format("Updated file {0} to store", resource.Name), LogCode.Log);
+ }
+ public void RemoveFile(Resource resource)
+ {
+ _files.Remove(resource.Id);
+ File.Delete(BasePath+resource.RelativePath);
+ if (FileRemoved != null)
+ FileRemoved(this, new FileEventArgs(resource));
+ Log.Out("FileStore", string.Format("FileStore: Removed file {0} from store", resource.Name), LogCode.Log);
+ }
+ public bool LookUp(Guid id)
+ {
+ lock(_lookUpLock)
+ return _files.ContainsKey(id);
+ }
+ public Stream GetStreamFromFile(Resource resource)
+ {
+ lock(_fileLock)
+ return new FileStream(BasePath + resource.RelativePath, FileMode.Open, FileAccess.Read, FileShare.Read);
+ }
+ public byte[] GetBytesFromFile(Resource resource)
+ {
+ var fi = new FileInfo(BasePath + resource.RelativePath);
+ var buffer = new byte[fi.Length];
+
+ lock (_fileLock)
+ using (var fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
+ fs.Read(buffer, 0, (int)fs.Length);
+
+ return buffer;
+ }
+ public void Updatefile(Resource resource, byte[] fileInBytes)
+ {
+ Task.Factory.StartNew(
+ delegate
+ {
+ _files[resource.Id] = resource;
+ SaveToDisk(fileInBytes, resource);
+ if (FileChanged != null)
+ FileChanged(this, new FileEventArgs(resource));
+ Log.Out("FileStore", string.Format("FileStore: Updated file {0} in store", resource.Name), LogCode.Log);
+ });
+ }
+
+ /// <summary>
+ /// Initializes a directory for future file saving. It uses the implicitly
+ /// called ToString() method to convert the object to a path
+ /// </summary>
+ /// <param name="relative"> </param>
+ public void IntializePath(object relative)
+ {
+ var path = Path.Combine(BasePath, relative.ToString());
+ //In case the activity path does not exist yet, we'll create one
+ if (!Directory.Exists(path))
+ {
+ var dInfo = Directory.CreateDirectory(path);
+ }
+ }
+ public void CleanUp(string path)
+ {
+ if(Directory.Exists(Path.Combine(BasePath,path)))
+ Directory.Delete(Path.Combine(BasePath, path), true);
+ }
+
+ #endregion
+
+ #region Private Methods
+ private byte[] GetBytesFromStream(Resource resource, Stream stream)
+ {
+ var buffer = new byte[resource.Size];
+ var ms = new MemoryStream();
+ int bytesRead;
+ do
+ {
+ bytesRead = stream.Read(buffer, 0, buffer.Length);
+ ms.Write(buffer, 0, bytesRead);
+ } while (bytesRead > 0);
+ ms.Close();
+ return buffer;
+ }
+ private void Check(Resource resource, byte[] fileInBytes)
+ {
+ if (_files == null)
+ throw new Exception("Filestore: Not initialized");
+ if (resource == null)
+ throw new Exception(("Filestore: Resource not found"));
+ if (fileInBytes == null)
+ throw new Exception(("Filestore: Bytearray null"));
+ if (fileInBytes.Length == 0)
+ throw new Exception(("Filestore: Bytearray empty"));
+ }
+ private void SaveToDisk(byte[] fileInBytes, Resource resource)
+ {
+ var path = Path.Combine(BasePath, resource.RelativePath);
+ var dir = Path.GetDirectoryName(path);
+ if (dir != null && !Directory.Exists(dir)) Directory.CreateDirectory(dir);
+
+ lock (_fileLock)
+ {
+ if(!File.Exists(@path))
+ {
+ using (var fileToupload = new FileStream(@path, FileMode.OpenOrCreate))
+ {
+ fileToupload.Write(fileInBytes, 0, fileInBytes.Length);
+ fileToupload.Close();
+ fileToupload.Dispose();
+
+ //File.SetCreationTimeUtc(path, DateTime.Parse(resource.CreationTime));
+ //File.SetLastWriteTimeUtc(path, DateTime.Parse(resource.LastWriteTime));
+ Console.WriteLine("FileStore: Saved file {0} to disk at {1}", resource.Name,
+ path);
+ Log.Out("FileStore", string.Format("FileStore: Saved file {0} to disk at {1}", resource.Name,
+ path), LogCode.Log);
+ }
+ }
+ else
+ Log.Out("FileStore", string.Format("FileStore: file {0} already in store", resource.Name,
+ path), LogCode.Log);
+
+ }
+ }
+ #endregion
+ }
+ internal class DownloadState
+ {
+ public Resource Resource { get; set; }
+ public FileSource FileSource { get; set; }
+
+ public DownloadState(Resource resource, FileSource fileSource)
+ {
+ Resource = resource;
+ FileSource = fileSource;
+ }
+ }
}
View
1 NooSphere/NooSphere.Core/ClassDiagram1.cd
@@ -0,0 +1 @@
+
View
98 NooSphere/NooSphere.Core/Devices/Device.cs
@@ -1,49 +1,49 @@
-/****************************************************************************
- (c) 2012 Steven Houben(shou@itu.dk) and Søren Nielsen(snielsen@itu.dk)
-
- Pervasive Interaction Technology Laboratory (pIT lab)
- IT University of Copenhagen
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU GENERAL PUBLIC LICENSE V3 or later,
- as published by the Free Software Foundation. Check
- http://www.gnu.org/licenses/gpl.html for details.
-****************************************************************************/
-
-using NooSphere.Core.Primitives;
-
-namespace NooSphere.Core.Devices
-{
- public class Device : Noo
- {
- public DeviceType DeviceType { get; set; }
- public DeviceRole DeviceRole { get; set; }
- public DevicePortability DevicePortability { get; set; }
- public int TagValue { get; set; }
-
- public string Location { get; set; }
- public string BaseAddress { get; set; }
- }
- public enum DeviceType
- {
- Desktop,
- Laptop,
- SmartPhone,
- Tablet,
- Tabletop,
- WallDisplay,
- Custom,
- Unknown
- }
- public enum DevicePortability
- {
- Stationary,
- Mobile
- }
- public enum DeviceRole
- {
- Master,
- Slave,
- Mediator
- }
-}
+/****************************************************************************
+ (c) 2012 Steven Houben(shou@itu.dk) and Søren Nielsen(snielsen@itu.dk)
+
+ Pervasive Interaction Technology Laboratory (pIT lab)
+ IT University of Copenhagen
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU GENERAL PUBLIC LICENSE V3 or later,
+ as published by the Free Software Foundation. Check
+ http://www.gnu.org/licenses/gpl.html for details.
+****************************************************************************/
+
+using NooSphere.Core.Primitives;
+
+namespace NooSphere.Core.Devices
+{
+ public class Device : Noo
+ {
+ public DeviceType DeviceType { get; set; }
+ public DeviceRole DeviceRole { get; set; }
+ public DevicePortability DevicePortability { get; set; }
+ public long TagValue { get; set; }
+
+ public string Location { get; set; }
+ public string BaseAddress { get; set; }
+ }
+ public enum DeviceType
+ {
+ Desktop,
+ Laptop,
+ SmartPhone,
+ Tablet,
+ Tabletop,
+ WallDisplay,
+ Custom,
+ Unknown
+ }
+ public enum DevicePortability
+ {
+ Stationary,
+ Mobile
+ }
+ public enum DeviceRole
+ {
+ Master,
+ Slave,
+ Mediator
+ }
+}

0 comments on commit 1485251

Please sign in to comment.