DI implementation started with registry class and filing class
This commit is contained in:
@ -1,13 +1,33 @@
|
|||||||
using System;
|
using ImageHandlingLibrary.InterFaces;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
namespace ImageHandlingLibrary
|
namespace ImageHandlingLibrary
|
||||||
{
|
{
|
||||||
public class Filing
|
public class Filing : IFiling
|
||||||
{
|
{
|
||||||
|
public BitmapImage ConvertFromDrawImage(System.Drawing.Image _image)
|
||||||
|
{
|
||||||
|
using (var ms = new MemoryStream())
|
||||||
|
{
|
||||||
|
//System.Drawing.Image.FromFile(@"D:\CsharpDevelop\PictureHandlingProject\pictures\AgueroVillage.JPG").Save(ms, ImageFormat.Bmp);
|
||||||
|
_image.Save(ms, ImageFormat.Bmp);
|
||||||
|
ms.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
var bitmapImage = new BitmapImage();
|
||||||
|
bitmapImage.BeginInit();
|
||||||
|
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
bitmapImage.StreamSource = ms;
|
||||||
|
bitmapImage.EndInit();
|
||||||
|
|
||||||
|
return bitmapImage;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,17 +31,21 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="PresentationCore" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Net.Http" />
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="WindowsBase" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Filing.cs" />
|
<Compile Include="Filing.cs" />
|
||||||
|
<Compile Include="InterFaces\IFiling.cs" />
|
||||||
<Compile Include="InterFaces\IRegistring.cs" />
|
<Compile Include="InterFaces\IRegistring.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Registring.cs" />
|
<Compile Include="Registring.cs" />
|
||||||
|
|||||||
15
ImageHandlingLibrary/InterFaces/IFiling.cs
Normal file
15
ImageHandlingLibrary/InterFaces/IFiling.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
|
namespace ImageHandlingLibrary.InterFaces
|
||||||
|
{
|
||||||
|
public interface IFiling
|
||||||
|
{
|
||||||
|
BitmapImage ConvertFromDrawImage(Image _image);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,6 @@
|
|||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
|
using ImageHandlingLibrary;
|
||||||
|
using ImageHandlingLibrary.InterFaces;
|
||||||
using ImageHandlingUI.ViewModels;
|
using ImageHandlingUI.ViewModels;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -29,12 +31,19 @@ namespace ImageHandlingUI
|
|||||||
.Singleton<IWindowManager, WindowManager>()
|
.Singleton<IWindowManager, WindowManager>()
|
||||||
.Singleton<IEventAggregator, EventAggregator>();
|
.Singleton<IEventAggregator, EventAggregator>();
|
||||||
|
|
||||||
|
_container
|
||||||
|
.PerRequest<IRegistring, Registring>()
|
||||||
|
.PerRequest<IFiling, Filing>();
|
||||||
|
|
||||||
GetType().Assembly.GetTypes()
|
GetType().Assembly.GetTypes()
|
||||||
.Where(type => type.IsClass)
|
.Where(type => type.IsClass)
|
||||||
.Where(type => type.Name.EndsWith("ViewModel"))
|
.Where(type => type.Name.EndsWith("ViewModel"))
|
||||||
.ToList()
|
.ToList()
|
||||||
.ForEach(viewModelType => _container.RegisterPerRequest(
|
.ForEach(viewModelType => _container.RegisterPerRequest(
|
||||||
viewModelType, viewModelType.ToString(), viewModelType));
|
viewModelType, viewModelType.ToString(), viewModelType));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// implementing SimpleContainer (dependency injection system in Caliburn micro)
|
// implementing SimpleContainer (dependency injection system in Caliburn micro)
|
||||||
|
|||||||
@ -112,5 +112,11 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Models\" />
|
<Folder Include="Models\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ImageHandlingLibrary\ImageHandlingLibrary.csproj">
|
||||||
|
<Project>{cf1c98b6-5093-4b93-8b14-a0278b1af724}</Project>
|
||||||
|
<Name>ImageHandlingLibrary</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
@ -1,10 +1,12 @@
|
|||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
|
using ImageHandlingLibrary.InterFaces;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
@ -14,29 +16,21 @@ namespace ImageHandlingUI.ViewModels
|
|||||||
{
|
{
|
||||||
public class ShellViewModel : Conductor<object>
|
public class ShellViewModel : Conductor<object>
|
||||||
{
|
{
|
||||||
public ShellViewModel()
|
private string _rootCatalog;
|
||||||
|
private readonly IRegistring _registring;
|
||||||
|
private readonly IFiling _filing;
|
||||||
|
private string initialFileName;
|
||||||
|
ImageSource _selectedImage = null;
|
||||||
|
|
||||||
|
public ShellViewModel(IRegistring registring, IFiling filing)
|
||||||
{
|
{
|
||||||
//using (var ms = new MemoryStream())
|
|
||||||
//{
|
|
||||||
// System.Drawing.Image.FromFile(@"D:\CsharpDevelop\PictureHandlingProject\pictures\AgueroVillage.JPG").Save(ms, ImageFormat.Bmp);
|
|
||||||
// ms.Seek(0, SeekOrigin.Begin);
|
|
||||||
|
|
||||||
// var bitmapImage = new BitmapImage();
|
|
||||||
// bitmapImage.BeginInit();
|
|
||||||
// bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
|
||||||
// bitmapImage.StreamSource = ms;
|
|
||||||
// bitmapImage.EndInit();
|
|
||||||
|
|
||||||
// _selectedImage = bitmapImage;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//_selectedImage = System.Drawing.Image.FromFile(@"D:\CsharpDevelop\PictureHandlingProject\pictures\AgueroVillage.JPG");
|
|
||||||
|
|
||||||
initialFileName = @"D:\CsharpDevelop\PictureHandlingProject\pictures\AgueroVillage.JPG";
|
initialFileName = @"D:\CsharpDevelop\PictureHandlingProject\pictures\AgueroVillage.JPG";
|
||||||
_selectedImage = ConvertFromDrawImage(System.Drawing.Image.FromFile(InitialFileName));
|
_selectedImage = filing.ConvertFromDrawImage(System.Drawing.Image.FromFile(InitialFileName));
|
||||||
|
_registring = registring;
|
||||||
|
_filing = filing;
|
||||||
}
|
}
|
||||||
ImageSource _selectedImage = null;
|
|
||||||
private string initialFileName;
|
|
||||||
|
|
||||||
public ImageSource SelectedImage
|
public ImageSource SelectedImage
|
||||||
{
|
{
|
||||||
@ -50,22 +44,22 @@ namespace ImageHandlingUI.ViewModels
|
|||||||
|
|
||||||
public string InitialFileName { get => initialFileName; set => initialFileName = value; }
|
public string InitialFileName { get => initialFileName; set => initialFileName = value; }
|
||||||
|
|
||||||
private static BitmapImage ConvertFromDrawImage(System.Drawing.Image _image)
|
|
||||||
|
public string RootCatalog
|
||||||
{
|
{
|
||||||
using (var ms = new MemoryStream())
|
get {
|
||||||
{
|
_rootCatalog = _registring.GetRegistryRootDir();
|
||||||
//System.Drawing.Image.FromFile(@"D:\CsharpDevelop\PictureHandlingProject\pictures\AgueroVillage.JPG").Save(ms, ImageFormat.Bmp);
|
return _rootCatalog;
|
||||||
_image.Save(ms, ImageFormat.Bmp);
|
|
||||||
ms.Seek(0, SeekOrigin.Begin);
|
|
||||||
|
|
||||||
var bitmapImage = new BitmapImage();
|
|
||||||
bitmapImage.BeginInit();
|
|
||||||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
|
||||||
bitmapImage.StreamSource = ms;
|
|
||||||
bitmapImage.EndInit();
|
|
||||||
|
|
||||||
return bitmapImage;
|
|
||||||
}
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != _rootCatalog)
|
||||||
|
{
|
||||||
|
_registring.SetRegistryValues(value);
|
||||||
|
}
|
||||||
|
_rootCatalog = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user