Skip to content

Commit

Permalink
Basic Drag&Drop Behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
FakeEmperor committed Mar 10, 2015
1 parent bba84d6 commit 817806f
Show file tree
Hide file tree
Showing 12 changed files with 410 additions and 81 deletions.
12 changes: 11 additions & 1 deletion AutoShare/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
<section name="AutoShare.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="AutoShare.Settings1" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="AutoShare.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<applicationSettings>
<AutoShare.Properties.Settings>
<setting name="FolderPath" serializeAs="String">
<value>"C:/"</value>
<value>AutoShare</value>
</setting>
</AutoShare.Properties.Settings>
<AutoShare.Settings1>
Expand All @@ -24,4 +27,11 @@
</setting>
</AutoShare.Settings1>
</applicationSettings>
<userSettings>
<AutoShare.Properties.Settings>
<setting name="UseDocFolder" serializeAs="String">
<value>True</value>
</setting>
</AutoShare.Properties.Settings>
</userSettings>
</configuration>
9 changes: 6 additions & 3 deletions AutoShare/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="Resources/Icons.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Clean/CleanWindow.xaml" />
<ResourceDictionary Source="pack://application:,,,/Mahapps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Orange.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

Expand Down
19 changes: 19 additions & 0 deletions AutoShare/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Navigation;
using System.IO;
using System.Windows.Shapes;
using System.Security.Permissions;


namespace AutoShare
{
Expand All @@ -13,5 +18,19 @@ namespace AutoShare
/// </summary>
public partial class App : Application
{
public AutoShare.Engine.IO.FilesFolderChecker FolderWatchdog;
App()
{
#region Initialization Block
string path;
if (AutoShare.Properties.Settings.Default.UseDocFolder)
path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + System.IO.Path.DirectorySeparatorChar + AutoShare.Properties.Settings.Default.FolderPath;
else
path = AutoShare.Properties.Settings.Default.FolderPath;
FolderWatchdog = new Engine.IO.FilesFolderChecker(path, true);
#endregion

}

}
}
3 changes: 3 additions & 0 deletions AutoShare/AutoShare.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,15 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Engine\IO\FileSystem.cs" />
<Compile Include="Engine\Network\NetworkServer.cs" />
<Compile Include="Engine\Network\AutoClient.cs" />
<Compile Include="Engine\Network\Sharing\SharedFile.cs" />
<Compile Include="Engine\XAMLConverters\ImageToSourceConverter.cs" />
<Compile Include="Engine\XAMLConverters\MultiIntToBoolConverter.cs" />
<Compile Include="Engine\XAMLConverters\PercentageConverter.cs" />
<Compile Include="Engine\XAMLConverters\VisibilityConverter.cs" />
<Compile Include="Settings.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
209 changes: 209 additions & 0 deletions AutoShare/Engine/IO/FileSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Security.Permissions;
using System.Threading;

namespace AutoShare.Engine.IO
{
public class FileCheckEntry
{
string FilePath;

bool IsShared;
bool IsChanged;
bool IsDeleted;
bool IsRenamed;

FileCheckEntry(string FilePath, bool IsShared, bool IsChanged, bool IsRenamed, bool IsDeleted)
{
this.FilePath = FilePath;
this.IsShared = IsShared;
this.IsShared = IsRenamed;
this.IsDeleted = IsDeleted;
}
}

public class FileList
{
List<FileCheckEntry> FList;

void Add() { }
void Remove() { }
void SyncFileList() { }
}


[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public class FilesFolderChecker
{
#region Helper Classes
public enum StatusInfo {
SI_STAT_OK = 0x00,
//ACTIONS DONE IMPLICITLY
SI_ACTN_DIR_CREATED = 0x01,
SI_ACTN_FILE_REM_DUP = 0x02,
//STATUSES DURING WORK
SI_STAT_DIR_NOTFOUND = 0x10,
SI_STAT_DIR_DENIED = 0x20,
}
public enum LoadType
{
FLT_UPDATE,
FLT_STUB,
}
#endregion
#region Private Entities

FileSystemWatcher watcher;
ManualResetEventSlim halt_event;
DirectoryInfo dir;
bool is_ok = true;
bool allow_imp_actions;
StatusInfo status = StatusInfo.SI_STAT_OK;
#endregion
#region Protected Functions
/// <summary>
/// Every API Call will start with this function call. It will throw an error, if state is invalid
/// </summary>
void PassOrThrow()
{
if (!this.is_ok)
throw new InvalidOperationException("FilesFolderChecker class instance is in invalid state");
}

protected void OnOccure(object source, FileSystemEventArgs e)
{
switch (e.ChangeType)
{
//notify about that
//rescan folders
}
}
#endregion
#region Constructors and Destructor
public FilesFolderChecker(string FolderPath, bool AllowImplicitActions = true/*, FileSharedList StubList*/)
{
this.allow_imp_actions = AllowImplicitActions;

try
{
dir = new DirectoryInfo(FolderPath);
if (!dir.Exists)
{
this.status |= StatusInfo.SI_STAT_DIR_NOTFOUND;
if (AllowImplicitActions)
{
this.status |= StatusInfo.SI_ACTN_DIR_CREATED;
dir.Create();
}
else
is_ok = false;
}

}
catch (DirectoryNotFoundException)
{
status |= StatusInfo.SI_STAT_DIR_NOTFOUND;
//create folder
if(AllowImplicitActions)
try
{
dir = Directory.CreateDirectory(FolderPath, new System.Security.AccessControl.DirectorySecurity(FolderPath, System.Security.AccessControl.AccessControlSections.All));
}
catch (UnauthorizedAccessException)
{
is_ok = false;
status |= StatusInfo.SI_STAT_DIR_DENIED;
}
else
is_ok = false;

}
catch (UnauthorizedAccessException) {
is_ok = false;
status |= StatusInfo.SI_STAT_DIR_DENIED;
}


watcher = new FileSystemWatcher(FolderPath);
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
//watcher.Filter = "*.*";
watcher.Changed += OnOccure;
watcher.Created += OnOccure;
watcher.Deleted += OnOccure;
watcher.Renamed += OnOccure;

watcher.EnableRaisingEvents = true;

}
~FilesFolderChecker()
{
//do something here
watcher.Changed -= OnOccure;
watcher.Created -= OnOccure;
watcher.Deleted -= OnOccure;
watcher.Renamed -= OnOccure;
watcher.EnableRaisingEvents = false;
watcher.Dispose();
}
#endregion
#region API CALLS
//DRAG AND DROP OPERATIONS
public bool IsInSyncFolder(string FilePath)
{
string root = Path.GetDirectoryName(FilePath);
return (root == this.dir.FullName);
}
public bool HasFileName(string FilePath)
{
FileInfo fi = new FileInfo(this.dir.FullName + Path.DirectorySeparatorChar + Path.GetFileName(FilePath));
return fi.Exists;
}
public bool DropFile(string FilePath){
PassOrThrow();
//so, open stream for read
try
{
System.IO.File.Copy(FilePath, this.dir.FullName + Path.DirectorySeparatorChar + Path.GetFileName(FilePath), true);
}
catch
{
return false;
}

return true;
}
public int DropFiles(string[] FileNames)
{
int i = 0;
PassOrThrow();

throw new NotImplementedException();
return i;
}
void BeginDropFiles(string[] FileNames)
{
PassOrThrow();
throw new NotImplementedException();
}
void EndDropFiles(string[] FileNames)
{
PassOrThrow();
throw new NotImplementedException();
}


//CHECK FOLDER OPERATIONS
void LoadFileList( )
{
PassOrThrow();
throw new NotImplementedException();
}
#endregion

}
}
19 changes: 13 additions & 6 deletions AutoShare/Engine/Network/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@
using System.Text;
using System.Threading;

namespace Autoshare.Engine.Network
namespace AutoShare.Engine.Network
{
class NewtworkServer
{
TcpListener Listener; // Îáúåêò, ïðèíèìàþùèé TCP-êëèåíòîâ



// Çàïóñê ñåðâåðà
ManualResetEvent Hevent;

TcpListener WaitForClient()
{
while (true)
{
Listener.AcceptTcpClient();
}
}
// Çàïóñê ñåðâåðà
public NewtworkServer(int Port)
{
// Ñîçäàåì "ñëóøàòåëÿ" äëÿ óêàçàííîãî ïîðòà

Listener = new TcpListener(IPAddress.Any, Port);
Listener.Start(); // Çàïóñêàåì åãî

//  áåñêîíå÷íîì öèêëå
//  áåñêîíå÷íîì öèêëå
while (true)
{
// Ïðèíèìàåì íîâûõ êëèåíòîâ
Expand Down
Loading

0 comments on commit 817806f

Please sign in to comment.