This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1 @@
12

View File

@@ -0,0 +1 @@
12

View File

@@ -0,0 +1,252 @@
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using System.Windows.Media;
using DTS.Common.Enums.Database;
using DTS.Common.Events;
using DTS.Common.Events.Database;
using Prism.Events;
using Prism.Regions;
using Unity;
using DTS.Common.Interactivity;
using Prism.Commands;
using DTS.Common.Interface.Database;
using DTS.Common.Storage;
// ReSharper disable CheckNamespace
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable InconsistentNaming
namespace DatabaseServices
{
/// <summary>
/// this class handles DatabaseCopy functionality
/// </summary>
[PartCreationPolicy(CreationPolicy.Shared)]
public class DatabaseStatusBarViewModel : IDatabaseStatusBarViewModel
{
/// <summary>
/// The DatabaseCopy view
/// </summary>
public IDatabaseStatusBarView View { get; set; }
private IEventAggregator _eventAggregator { get; }
private IRegionManager _regionManager;
private IUnityContainer UnityContainer { get; }
public InteractionRequest<Notification> NotificationRequest { get; }
public InteractionRequest<Confirmation> ConfirmationRequest { get; }
/// <inheritdoc />
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#region constructors and initializers
/// <summary>
/// Creates a new instance of the DatabaseCopyViewModel
/// </summary>
/// <param name="view"></param>
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
/// <param name="eventAggregator">The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other.</param>
/// <param name="unityContainer">The unityContainer.</param>
public DatabaseStatusBarViewModel(IDatabaseStatusBarView view, IRegionManager regionManager,
IEventAggregator eventAggregator, IUnityContainer unityContainer)
{
View = view;
View.DataContext = this;
NotificationRequest = new InteractionRequest<Notification>();
ConfirmationRequest = new InteractionRequest<Confirmation>();
_eventAggregator = eventAggregator;
UnityContainer = unityContainer;
_regionManager = regionManager;
_eventAggregator.GetEvent<RaiseNotification>().Subscribe(OnRaiseNotification);
_eventAggregator.GetEvent<BusyIndicatorChangeNotification>()
.Subscribe(OnBusyIndicatorNotification, ThreadOption.PublisherThread, true);
_eventAggregator.GetEvent<DbStatusEvent>().Subscribe(OnDbEvent);
}
public DatabaseStatusBarViewModel()
{
}
#endregion
#region Methods
private void OnDbEvent(DbStatusArg args)
{
if (args.Status == DbStatusArg.EventTypes.LegacyStatus)
{
if (RemoteConnected)
{
ServerName = DbOperations.Connection.Server;
}
else
{
ServerName = "Local";
}
OnPropertyChanged("ActiveDbName");
OnPropertyChanged("BackgroundBrush");
}
}
public void Unset()
{
}
public DbType DatabaseType { get; private set; }
public void InitializeValues(DbType dbType, string serverName, bool remoteConnected)
{
DatabaseType = dbType;
ServerName = serverName;
OnPropertyChanged("ActiveDbName");
OnPropertyChanged("BackgroundBrush");
}
public bool RemoteConnected => DbOperations._usingCentralizedDB;
public string ServerName { get; private set; }
public string ActiveDbName
{
get
{
switch (DatabaseType)
{
case DbType.LocalOnly: return Resources.StringResources.Local;
case DbType.RemoteOnly: return ServerName;
case DbType.RemoteLocalHybrid:
{
return RemoteConnected ? ServerName : Resources.StringResources.Local;
}
}
return "";
}
}
public Brush BackgroundBrush
{
get
{
switch (DatabaseType)
{
case DbType.RemoteLocalHybrid:
return RemoteConnected ? Brushes.Transparent : Brushes.Red;
}
return Brushes.Transparent;
}
}
public void Cleanup()
{
}
public Task CleanupAsync()
{
return Task.CompletedTask;
}
public void Initialize()
{
}
public void Initialize(object parameter)
{
}
public void Initialize(object parameter, object model)
{
}
public Task InitializeAsync()
{
return Task.CompletedTask;
}
public Task InitializeAsync(object parameter)
{
return Task.CompletedTask;
}
public void Activated()
{
}
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnBusyIndicatorNotification(bool eventArg)
{
IsBusy = eventArg;
}
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
{
// The NotificationRequest.Raise triggers the Invoke() method of the PopupWindowAction object to show the NotificationWindow window
// Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string.
var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message, "",
eventArgsWithTitle.Image, string.Empty);
NotificationRequest.Raise(new Notification
{
Content = eventArgsWithoutTitle,
Title = eventArgsWithTitle.Title
});
}
#endregion
#region Properties
public bool IsDirty { get; private set; }
private bool _isBusy = false;
public bool IsBusy
{
get => _isBusy;
set
{
_isBusy = value;
OnPropertyChanged("IsBusy");
}
}
private bool _isMenuIncluded;
public bool IsMenuIncluded
{
get => _isMenuIncluded;
set
{
_isMenuIncluded = value;
OnPropertyChanged("IsMenuIncluded");
}
}
private bool _isNavigationIncluded;
public bool IsNavigationIncluded
{
get => _isNavigationIncluded;
set
{
_isNavigationIncluded = value;
OnPropertyChanged("IsNavigationIncluded");
}
}
#endregion Properties
#region Commands
#endregion
}
}

View File

@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="DatabaseServices.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
</Settings>
</SettingsFile>

View File

@@ -0,0 +1,38 @@
<base:BaseView x:Class="DatabaseServices.DatabaseSwitchView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="clr-namespace:DTS.Common.Base;assembly=DTS.Common"
xmlns:controls="clr-namespace:DTS.Common.Controls;assembly=DTS.Common"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:strings="clr-namespace:DatabaseServices"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="768" d:DesignWidth="1366"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:converters="clr-namespace:DTS.Common.Converters;assembly=DTS.Common"
x:Name="DatabaseSwitch" Background="White">
<base:BaseView.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Themes/CommonStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Controls/combobox.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="ListView">
<Setter Property="ItemContainerStyle" Value="{StaticResource TTS_ListViewItemStyle}"/>
</Style>
<Style TargetType="TextBox" BasedOn="{StaticResource TTS_TextBoxStyle}"/>
<Style TargetType="TextBlock" BasedOn="{StaticResource TTS_TextBlockStyle}"/>
<Style TargetType="CheckBox" BasedOn="{StaticResource PageContentCheckBoxStyle}" />
<Style TargetType="ComboBox" BasedOn="{StaticResource TTS_ComboBoxStyle}"/>
<Style TargetType="Button" BasedOn="{StaticResource TTS_ButtonStyle}"/>
<Style TargetType="GridViewColumnHeader" BasedOn="{StaticResource Gray_GridViewColumnHeaderStyle}"/>
<converters:InverseBooleanConverter x:Key="InverseConverter" />
</ResourceDictionary>
</base:BaseView.Resources>
<WrapPanel Background="White" Orientation="Horizontal">
<Button Content="{strings:TranslateExtension SwitchToLocal}" IsEnabled="{Binding RemoteIsActive, UpdateSourceTrigger=PropertyChanged}" AutomationProperties.AutomationId="SwitchToLocalButton" Click="SwitchToLocal_Click" />
<Button Content="{strings:TranslateExtension SwitchToRemote}" IsEnabled="{Binding RemoteIsActive, Converter={StaticResource InverseConverter}, UpdateSourceTrigger=PropertyChanged}" AutomationProperties.AutomationId="SwitchToRemoteButton" Click="SwitchToRemote_Click" />
</WrapPanel>
</base:BaseView>

View File

@@ -0,0 +1,45 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using DTS.Common.Enums.Database;
namespace DatabaseServices.Converters
{
public class DbTypeToVisibilityConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var dbType = (DbType)((int)values[0]);
var view = (DatabaseStatusBarView)values[1];
if (null == view.DataContext)
{
return Visibility.Collapsed;
}
var vm = (DatabaseStatusBarViewModel)view.DataContext;
switch (vm.DatabaseType)
{
case DbType.RemoteOnly:
return dbType == DbType.RemoteOnly ? Visibility.Visible : Visibility.Collapsed;
case DbType.LocalOnly:
return dbType == DbType.LocalOnly ? Visibility.Visible : Visibility.Collapsed;
case DbType.RemoteLocalHybrid:
{
if (vm.RemoteConnected)
{
return dbType == DbType.RemoteOnly ? Visibility.Visible : Visibility.Collapsed;
}
return dbType == DbType.RemoteLocalHybrid ? Visibility.Visible : Visibility.Collapsed;
}
default:
return Visibility.Collapsed;
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,145 @@
using System;
using System.ComponentModel.Composition;
using System.Windows.Media.Imaging;
using DTS.Common;
using DTS.Common.Interface;
using Prism.Modularity;
using Unity;
using DatabaseServices;
using DTS.Common.Interface.Database;
using Prism.Ioc;
// ReSharper disable CheckNamespace
// ReSharper disable RedundantAttributeUsageProperty
// ReSharper disable UnusedParameter.Local
[assembly: DatabaseServicesModuleName]
[assembly: DatabaseServicesModuleImageAttribute]
namespace DatabaseServices
{
[Export(typeof(IModule))]
[Module(ModuleName = "DatabaseServicesModule")]
public class DatabaseServicesModule : IModule
{
/// <summary>
/// Injected unity container
/// </summary>
private readonly IUnityContainer _unityContainer;
/// <summary>
/// Initializes a new instance of the <see cref="DatabaseServicesModule"/> class.
/// </summary>
/// <param name="unityContainer">Obtained reference of the unity container by using dependency injection.</param>
public DatabaseServicesModule(IUnityContainer unityContainer)
{
_unityContainer = unityContainer;
}
public void Initialize()
{
// Register View & View-Model with Unity dependency injection container as a singleton.
_unityContainer.RegisterType<IDatabaseCopyView, DatabaseCopyView>();
_unityContainer.RegisterType<IDatabaseCopyViewModel, DatabaseCopyViewModel>();
_unityContainer.RegisterType<IDatabaseStatusBarView, DatabaseStatusBarView>();
_unityContainer.RegisterType<IDatabaseStatusBarViewModel, DatabaseStatusBarViewModel>();
_unityContainer.RegisterType<IDatabaseSwitchView, DatabaseSwitchView>();
_unityContainer.RegisterType<IDatabaseSwitchViewModel, DatabaseSwitchViewModel>();
}
public void OnInitialized(IContainerProvider containerProvider)
{
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
Initialize();
}
}
/// <summary>
/// Attribute class contains assembly name
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
public class DatabaseServicesModuleNameAttribute : TextAttribute
{
public DatabaseServicesModuleNameAttribute() : this(null) { }
public DatabaseServicesModuleNameAttribute(string s)
{
AssemblyName = AssemblyNames.DatabaseServices.ToString();
}
public override string AssemblyName { get; }
public override Type GetAttributeType()
{
return typeof(TextAttribute);
}
public override string GetAssemblyName()
{
return AssemblyName;
}
}
/// <summary>
/// Attribute class contains assembly image and name - used on the Main screen to SummaryModule available components
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
public class DatabaseServicesModuleImageAttribute : ImageAttribute
{
private BitmapImage _img;
public DatabaseServicesModuleImageAttribute() : this(null) { }
public override BitmapImage AssemblyImage
{
get { _img = AssemblyInfo.GetImage(AssemblyNames.DatabaseServices.ToString()); return _img; }
}
public DatabaseServicesModuleImageAttribute(string s)
{
_img = AssemblyInfo.GetImage(AssemblyNames.DatabaseServices.ToString());
}
public override Type GetAttributeType()
{
return typeof(ImageAttribute);
}
public override BitmapImage GetAssemblyImage()
{
return AssemblyImage;
}
private string _name;
public override string AssemblyName
{
get { _name = AssemblyNames.DatabaseServices.ToString(); return _name; }
}
public override string GetAssemblyName()
{
return AssemblyName;
}
private string _group;
public override string AssemblyGroup
{
get { _group = eAssemblyGroups.Prepare.ToString(); return _group; }
}
public override string GetAssemblyGroup()
{
return AssemblyGroup;
}
private eAssemblyRegion _region;
public override eAssemblyRegion AssemblyRegion
{
get { _region = eAssemblyRegion.DatabaseServicesRegion; return _region; }
}
public override eAssemblyRegion GetAssemblyRegion()
{
return AssemblyRegion;
}
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="DatabaseServices.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<userSettings>
<DatabaseServices.Properties.Settings>
</DatabaseServices.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>

View File

@@ -0,0 +1,153 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DatabaseServices.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class StringResources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal StringResources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DatabaseServices.Resources.StringResources", typeof(StringResources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Clearing local db.
/// </summary>
internal static string ClearingLocalDb {
get {
return ResourceManager.GetString("ClearingLocalDb", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Connected to: .
/// </summary>
internal static string ConnectedTo {
get {
return ResourceManager.GetString("ConnectedTo", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Copy from remote server to local.
/// </summary>
internal static string CopyFromRemoteServer {
get {
return ResourceManager.GetString("CopyFromRemoteServer", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Copying.
/// </summary>
internal static string CopyingTable {
get {
return ResourceManager.GetString("CopyingTable", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Finishing up.
/// </summary>
internal static string EnablingConstraints {
get {
return ResourceManager.GetString("EnablingConstraints", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Local.
/// </summary>
internal static string Local {
get {
return ResourceManager.GetString("Local", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Remote.
/// </summary>
internal static string Remote {
get {
return ResourceManager.GetString("Remote", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not switch to local - File not found:.
/// </summary>
internal static string SwitchFileNotFound {
get {
return ResourceManager.GetString("SwitchFileNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Switch to local.
/// </summary>
internal static string SwitchToLocal {
get {
return ResourceManager.GetString("SwitchToLocal", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Switch to remote.
/// </summary>
internal static string SwitchToRemote {
get {
return ResourceManager.GetString("SwitchToRemote", resourceCulture);
}
}
}
}

View File

@@ -0,0 +1,18 @@
using DTS.Common.Interface.Database;
// ReSharper disable CheckNamespace
namespace DatabaseServices
{
/// <inheritdoc cref="DatabaseStatusBarView" />
/// <summary>
/// Interaction logic for DatabaseStatusBarView.xaml
/// </summary>
public partial class DatabaseStatusBarView : IDatabaseStatusBarView
{
public DatabaseStatusBarView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,200 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2329447B-8A00-4CF3-B0FF-4F960EACFE97}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DatabaseServices</RootNamespace>
<AssemblyName>DatabaseServices</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>CODE_ANALYSIS;DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<RunCodeAnalysis>false</RunCodeAnalysis>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>CODE_ANALYSIS;DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<RunCodeAnalysis>true</RunCodeAnalysis>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Microsoft.Xaml.Behaviors">
<HintPath>..\..\..\..\Common\DTS.Common\lib\PrismLibrary\Microsoft.Xaml.Behaviors.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Prism">
<HintPath>..\..\..\..\Common\DTS.Common\lib\PrismLibrary\Prism.dll</HintPath>
</Reference>
<Reference Include="Prism.Unity.Wpf">
<HintPath>..\..\..\..\Common\DTS.Common\lib\PrismLibrary\Prism.Unity.Wpf.dll</HintPath>
</Reference>
<Reference Include="Prism.Wpf">
<HintPath>..\..\..\..\Common\DTS.Common\lib\PrismLibrary\Prism.Wpf.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Security" />
<Reference Include="System.Web" />
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Unity.Abstractions">
<HintPath>..\..\..\..\Common\DTS.Common\lib\PrismLibrary\Unity.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Unity.Container">
<HintPath>..\..\..\..\Common\DTS.Common\lib\PrismLibrary\Unity.Container.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="Xceed.Wpf.Toolkit">
<HintPath>..\..\..\..\Common\DTS.Common\lib\Xceed.Wpf.Toolkit\Xceed.Wpf.Toolkit.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Converters\DbTypeToVisibilityConverter.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="DatabaseServicesModule.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\StringResources.Designer.cs">
<DependentUpon>StringResources.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Resources\TranslateExtension.cs" />
<Compile Include="ViewModel\DatabaseSwitchViewModel.cs" />
<Compile Include="ViewModel\DatabaseStatusBarViewModel.cs" />
<Compile Include="ViewModel\DatabaseCopyViewModel.cs" />
<Compile Include="View\DatabaseSwitchView.xaml.cs">
<DependentUpon>DatabaseSwitchView.xaml</DependentUpon>
</Compile>
<Compile Include="View\DatabaseStatusBarView.xaml.cs">
<DependentUpon>DatabaseStatusBarView.xaml</DependentUpon>
</Compile>
<Compile Include="View\DatabaseCopyView.xaml.cs">
<DependentUpon>DatabaseCopyView.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\StringResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>StringResources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Common\DTS.Common.Core\DTS.Common.Core.csproj">
<Project>{fab1f470-1574-4301-b56e-d3364aa93679}</Project>
<Name>DTS.Common.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Common\DTS.Common.DAS.Concepts\DTS.Common.DAS.Concepts.csproj">
<Project>{03D8C736-36EB-4CD1-A6D9-130452B23239}</Project>
<Name>DTS.Common.DAS.Concepts</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Common\DTS.Common.ISO\DTS.Common.ISO.csproj">
<Project>{4dccddd1-032f-430c-9a6f-231daca4fbd0}</Project>
<Name>DTS.Common.ISO</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Common\DTS.Common.Storage\DTS.Common.Storage.csproj">
<Project>{e0d1a7d0-dce8-403d-ba85-5a5d66ba1313}</Project>
<Name>DTS.Common.Storage</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Common\DTS.Common.Utilities\DTS.Common.Utilities.csproj">
<Project>{03eace47-ea59-44ac-b49d-956e4dc4d618}</Project>
<Name>DTS.Common.Utilities</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Common\DTS.Common\DTS.Common.csproj">
<Project>{114edc77-f3b5-4576-a91b-40818d503b55}</Project>
<Name>DTS.Common</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\IService\IService.csproj">
<Project>{c9c45b72-05a3-4962-bc13-a78b1f4b1925}</Project>
<Name>IService</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\SensorDB\SensorDB.csproj">
<Project>{444ef10c-046e-47ad-a9a5-17318d488723}</Project>
<Name>SensorDB</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Users\Users.csproj">
<Project>{BE8D217D-6DA9-4BCA-B62A-A82325B33979}</Project>
<Name>Users</Name>
</ProjectReference>
<ProjectReference Include="..\..\StatusAndProgressBar\StatusAndProgressBar.csproj">
<Project>{1f817d85-4ec6-4300-ab35-085765b97a9a}</Project>
<Name>StatusAndProgressBar</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Page Include="View\DatabaseSwitchView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="View\DatabaseStatusBarView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="View\DatabaseCopyView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,2 @@
Use DataPRO;
UPDATE [dbo].[Users] SET [Password]='Onl79FZmtkwYRi5DfMV46DDfS0HMOpURgIxeUvhswuY=' WHERE ID=1;

View File

@@ -0,0 +1,31 @@
using System.Windows.Controls;
using DTS.Common.Interface.Database;
// ReSharper disable CheckNamespace
namespace DatabaseServices
{
/// <inheritdoc cref="IDatabaseSwitchView" />
/// <summary>
/// Interaction logic for DatabaseSwitchView.xaml
/// </summary>
public partial class DatabaseSwitchView : IDatabaseSwitchView
{
public DatabaseSwitchView()
{
InitializeComponent();
}
private void SwitchToLocal_Click(object sender, System.Windows.RoutedEventArgs e)
{
var vm = (IDatabaseSwitchViewModel)((Control)sender).DataContext;
vm.SwitchLocal();
}
private void SwitchToRemote_Click(object sender, System.Windows.RoutedEventArgs e)
{
var vm = (IDatabaseSwitchViewModel)((Control)sender).DataContext;
vm.SwitchRemote();
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Windows.Markup;
using DatabaseServices.Resources;
namespace DatabaseServices
{
[MarkupExtensionReturnType(typeof(string))]
public class TranslateExtension : MarkupExtension
{
private readonly string _key;
public TranslateExtension(string key) { _key = key; }
private const string NotFound = "#stringnotfound#";
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (string.IsNullOrEmpty(_key)) { return NotFound; }
return StringResources.ResourceManager.GetString(_key) ?? NotFound + " " + _key;
}
}
}

View File

@@ -0,0 +1,48 @@
<base:BaseView x:Class="DatabaseServices.DatabaseCopyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="clr-namespace:DTS.Common.Base;assembly=DTS.Common"
xmlns:controls="clr-namespace:DTS.Common.Controls;assembly=DTS.Common"
xmlns:commonconverters="clr-namespace:DTS.Common.Converters;assembly=DTS.Common"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:strings="clr-namespace:DatabaseServices"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="768" d:DesignWidth="1366"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
x:Name="DatabaseCopy" Background="White">
<base:BaseView.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Themes/CommonStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Controls/combobox.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="ListView">
<Setter Property="ItemContainerStyle" Value="{StaticResource TTS_ListViewItemStyle}"/>
</Style>
<Style TargetType="TextBox" BasedOn="{StaticResource TTS_TextBoxStyle}"/>
<Style TargetType="TextBlock" BasedOn="{StaticResource TTS_TextBlockStyle}"/>
<Style TargetType="CheckBox" BasedOn="{StaticResource PageContentCheckBoxStyle}" />
<Style TargetType="ComboBox" BasedOn="{StaticResource TTS_ComboBoxStyle}"/>
<Style TargetType="Button" BasedOn="{StaticResource TTS_ButtonStyle}"/>
<Style TargetType="GridViewColumnHeader" BasedOn="{StaticResource Gray_GridViewColumnHeaderStyle}"/>
<commonconverters:BooleanToVisibilityConverter x:Key="BoolToVisConverter" />
</ResourceDictionary>
</base:BaseView.Resources>
<Grid Background="White" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<controls:CommonStatusRibbon AutomationProperties.AutomationId="ImmediateProgress" Grid.Row="0" Margin="0,5,0,5" ProgressBarName="CurrentTaskStatus"
Content="{Binding CurrentTaskProgressBarView}" />
<controls:CommonStatusRibbon AutomationProperties.AutomationId="OverallProgress" Grid.Row="1" Margin="0,5,0,5" ProgressBarName="OverallStatus"
Content="{Binding OverallProgressBarView}" />
<Button AutomationProperties.AutomationId="Copy Button" Content="{strings:Translate CopyFromRemoteServer}"
MinWidth="200" Grid.Row="2" HorizontalAlignment="Left" Click="Copy_Click" IsEnabled="{Binding CopyEnabled, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding IsCopyVisible, Converter={StaticResource BoolToVisConverter}}"/>
</Grid>
</base:BaseView>

View File

@@ -0,0 +1,632 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using DTS.Common.Events;
using DTS.Common.Events.Database;
using Prism.Events;
using Prism.Regions;
using Unity;
using DTS.Common.Interactivity;
using Prism.Commands;
using DTS.Common.Interface.Database;
using DTS.Common.Storage;
using DTS.Common.Utilities.Logging;
using DTS.Common.Interface;
// ReSharper disable CheckNamespace
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable InconsistentNaming
namespace DatabaseServices
{
/// <summary>
/// this class handles DatabaseCopy functionality
/// </summary>
[PartCreationPolicy(CreationPolicy.Shared)]
public class DatabaseCopyViewModel : IDatabaseCopyViewModel
{
/// <summary>
/// The DatabaseCopy view
/// </summary>
public IDatabaseCopyView View { get; set; }
private IEventAggregator _eventAggregator { get; }
private IUnityContainer UnityContainer { get; }
public InteractionRequest<Notification> NotificationRequest { get; }
public InteractionRequest<Confirmation> ConfirmationRequest { get; }
/// <inheritdoc />
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#region constructors and initializers
/// <summary>
/// Creates a new instance of the DatabaseCopyViewModel
/// </summary>
/// <param name="view"></param>
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
/// <param name="eventAggregator">The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other.</param>
/// <param name="unityContainer">The unityContainer.</param>
public DatabaseCopyViewModel(IDatabaseCopyView view, IRegionManager regionManager,
IEventAggregator eventAggregator, IUnityContainer unityContainer)
{
View = view;
View.DataContext = this;
NotificationRequest = new InteractionRequest<Notification>();
ConfirmationRequest = new InteractionRequest<Confirmation>();
_eventAggregator = eventAggregator;
UnityContainer = unityContainer;
_eventAggregator.GetEvent<RaiseNotification>().Subscribe(OnRaiseNotification);
_eventAggregator.GetEvent<BusyIndicatorChangeNotification>().Subscribe(OnBusyIndicatorNotification);
}
#endregion
#region Methods
public void Unset()
{
}
public void CopyDatabase()
{
_eventAggregator.GetEvent<AppStatusEvent>().Publish(AppStatusArg.Busy);
_ = Task.Run(() => { CopyFunc(); });
}
public void InitializeState(DTS.Common.Enums.Database.DbType dbType, string dbName)
{
DbName = dbName;
DatabaseType = dbType;
_eventAggregator.GetEvent<ProgressBarEvent>().Publish(new ProgressBarEventArg(CurrentTaskBar, Colors.White,
System.Windows.Visibility.Collapsed, 0D, ""));
_eventAggregator.GetEvent<ProgressBarEvent>().Publish(new ProgressBarEventArg(OverallTaskBar, Colors.White,
System.Windows.Visibility.Collapsed, 0D, ""));
OnPropertyChanged("CopyEnabled");
}
private void SetStatus(string bar, double percentage, string text)
{
_eventAggregator.GetEvent<ProgressBarEvent>()
.Publish(new ProgressBarEventArg(bar, Colors.White, System.Windows.Visibility.Visible, percentage, text));
}
private static readonly List<string> _allDBTables = new List<string>()
{
"AddOrRemove",
"AnalogDiagnostics",
"CalculatedChannelOperation",
"CalculatedChannels",
"CalibrationType",
"ChannelCodes",
"ChannelCodeType",
"Channels",
"ChannelSettings",
"CustomerDetails",
"DAS",
"DASChannels",
"DataPRODbVersion",
"DbTableVersions",
"DefaultProperties",
"DiagnosticRuns",
"GroupChannelSettings",
"GroupHardware",
"Groups",
"LabratoryDetails",
"LastUsedHardware",
"LevelTriggers",
"LockedItemCategories",
"LockedItems",
"RecordingMode",
"RecordingModes",
"ROIPeriodChannels",
"SensorBridgeLegMode",
"SensorBridgeType",
"SensorCalibrationRecord",
"SensorCalibrationRecordIRTracc",
"SensorCalibrationRecordPolynomial",
"SensorCalibrations",
"SensorChangeHistory",
"SensorChangeType",
"SensorCouplingMode",
"SensorDigitalOutputMode",
"SensorModels",
"Sensors",
"SensorsAnalog",
"SensorsDigitalIn",
"SensorsDigitalOut",
"SensorSettingMode",
"SensorShunt",
"SensorSquibFireMode",
"SensorSquibMeasurementType",
"SensorsSquib",
"SensorsStreamInput",
"SensorsStreamOutput",
"SensorStatus",
"SensorsType",
"SensorsUART",
"SensorTestHistory",
"Settings",
"SoftwareFilters",
"StoredProcedureVersions",
"TagAssignments",
"TagObjectType",
"Tags",
"tblDataPRODbVersion",
"TestEngineerDetails",
"TestGraphs",
"TestHistory",
"TestSetupGroups",
"TestSetupHardware",
"TestSetupObjectMetaData",
"TestSetupROIs",
"TestSetups",
"TestSetupSettings",
"UIItems",
"UIItemSettings",
"UserProperties",
"Users",
"UsersRoles"
};
private static readonly HashSet<string> _tablesWithIdentities = new HashSet<string>()
{
"AnalogDiagnostics",
"CalculatedChannels",
"ChannelCodes",
"ChannelCodeType",
"Channels",
"ChannelSettings",
"CustomerDetails",
"DAS",
"DASChannels",
"DiagnosticRuns",
"GroupHardware",
"Groups",
"LabratoryDetails",
"LastUsedHardware",
"LevelTriggers",
"LockedItemCategories",
"LockedItems",
"ROIPeriodChannels",
"SensorCalibrationRecord",
"SensorCalibrationRecordIRTracc",
"SensorCalibrationRecordPolynomial",
"SensorCalibrations",
"SensorChangeHistory",
"SensorChangeType",
"SensorModels",
"Sensors",
"SensorsAnalog",
"SensorsDigitalIn",
"SensorsDigitalOut",
"SensorsSquib",
"SensorsStreamInput",
"SensorsStreamOutput",
"SensorsUART",
"SensorTestHistory",
"Settings",
"SoftwareFilters",
"Tags",
"TestEngineerDetails",
"TestGraphs",
"TestHistory",
"TestSetupGroups",
"TestSetupHardware",
"TestSetupObjectMetaData",
"TestSetupROIs",
"TestSetups",
"UIItems",
"UIItemSettings",
"Users"
};
private void CopyFunc()
{
try
{
DTS.Common.Storage.DatabaseServices.BackupLocalDatabase(DbName);
}
catch (System.IO.FileNotFoundException ex)
{
_eventAggregator.GetEvent<DbStatusEvent>()
.Publish(new DbStatusArg(DbStatusArg.EventTypes.FailedToBackupLocalFileNotFound, ex));
APILogger.Log(ex);
return;
}
catch (Exception ex)
{
_eventAggregator.GetEvent<DbStatusEvent>()
.Publish(new DbStatusArg(DbStatusArg.EventTypes.FailedToBackupLocal, null));
APILogger.Log(ex);
return;
}
try
{
//get list of all tables
//I'd like to do this through SQL, but ran into problems
var allTables = _allDBTables;
SetStatus(OverallTaskBar, 0, "");
SetStatus(CurrentTaskBar, 0, "");
double steps = 2 + allTables.Count;
//turn off all constraints
SetStatus(OverallTaskBar, 0, Resources.StringResources.ClearingLocalDb);
using (var cmd = LocalOnlyOperations.GetSQLCommand(true))
{
try
{
cmd.CommandText = "EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
finally
{
cmd.Connection.Dispose();
}
}
double currentStep = 1;
SetStatus(OverallTaskBar, 100D * currentStep / steps, "");
//Copy remote table to local)
foreach (var table in allTables)
{
SetStatus(OverallTaskBar, 100D * currentStep / steps,
$"{Resources.StringResources.CopyingTable} {table}");
SetStatus(CurrentTaskBar, 0D, "");
CopyRemoteTable(table, _tablesWithIdentities.Contains(table));
currentStep++;
}
//Change any DASId columns in the Channels table from 0 to NULL
try
{
using (var cmd = LocalOnlyOperations.GetSQLCommand(true))
{
try
{
cmd.CommandText = "UPDATE Channels SET DASId = NULL WHERE DASId = 0";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
finally { cmd.Connection.Dispose(); }
}
}
catch (Exception ex)
{
APILogger.Log(ex);
}
//turn on all constraints
SetStatus(OverallTaskBar, 100D * currentStep / steps, Resources.StringResources.EnablingConstraints);
try
{
using (var cmd = LocalOnlyOperations.GetSQLCommand(true))
{
try
{
cmd.CommandText = "EXEC sp_msforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
_eventAggregator.GetEvent<DbStatusEvent>().Publish(new DbStatusArg(DbStatusArg.EventTypes.Complete, null));
}
finally
{
cmd.Connection.Dispose();
}
}
}
catch (Exception ex)
{
APILogger.Log(ex);
}
}
catch (Exception ex)
{
APILogger.Log(ex);
_eventAggregator.GetEvent<DbStatusEvent>()
.Publish(new DbStatusArg(DbStatusArg.EventTypes.FailedToCopy, ex));
try
{
DTS.Common.Storage.DatabaseServices.RestoreLocalDatabase(DbName);
}
catch (Exception)
{
APILogger.Log(ex);
_eventAggregator.GetEvent<DbStatusEvent>().Publish(
new DbStatusArg(DbStatusArg.EventTypes.FailedToRestoreLocal, null));
}
}
finally
{
_eventAggregator.GetEvent<ProgressBarEvent>().Publish(new ProgressBarEventArg(OverallTaskBar,
Colors.White, System.Windows.Visibility.Collapsed, 0D, ""));
_eventAggregator.GetEvent<ProgressBarEvent>().Publish(new ProgressBarEventArg(CurrentTaskBar,
Colors.White, System.Windows.Visibility.Collapsed, 0D, ""));
_eventAggregator.GetEvent<AppStatusEvent>().Publish(AppStatusArg.Available);
}
}
private void CopyRemoteTable(string tableName, bool bIndentityTable)
{
using (var cmd = LocalOnlyOperations.GetSQLCommand(true))
{
cmd.CommandText = $"DELETE FROM [dbo].[{tableName}]";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
cmd.Connection.Dispose();
}
DataColumnCollection columns = null;
var objects = new List<object[]>();
using (var cmd = DbOperations.GetSQLCommand(true))
{
cmd.CommandText = $"SELECT * from [dbo].[{tableName}]";
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
{
if (ds.Tables[0].Rows.Count > 0)
{
columns = ds.Tables[0].Columns;
foreach (DataRow row in ds.Tables[0].Rows)
{
var rowObjects = new object[columns.Count];
for (var i = 0; i < rowObjects.Length; i++)
{
rowObjects[i] = row[i];
}
objects.Add(rowObjects);
}
}
}
cmd.Connection.Dispose();
}
if (null != columns)
{
InsertIntoLocalTable(tableName, columns, objects, bIndentityTable);
}
}
private void InsertIntoLocalTable(string tableName, DataColumnCollection columns, List<object[]> data, bool bIdentity)
{
SqlCommand cmd = null;
var index = 0;
StringBuilder sb = null;
var countSoFar = 0;
foreach (var row in data)
{
if (null == cmd)
{
index = 0;
cmd = LocalOnlyOperations.GetSQLCommand(true);
sb = new StringBuilder(500);
sb.Append(LocalOnlyOperations.BeginStatement);
if (bIdentity)
{
sb.Append($"SET IDENTITY_INSERT [dbo].[{tableName}] ON;");
}
}
sb.Append($"INSERT INTO [dbo].[{tableName}] (");
for (var i = 0; i < columns.Count; i++)
{
if (i > 0)
{
sb.Append(",");
}
sb.AppendFormat("[{0}]", columns[i].ColumnName);
}
sb.Append(") VALUES (");
for (var i = 0; i < columns.Count; i++)
{
if (i > 0)
{
sb.Append(",");
}
var key = $"@{index}_{i}";
sb.Append(key);
var dataType = TypeConvertor.ToSqlDbType(columns[i].DataType);
LocalOnlyOperations.CreateParam(cmd, key, dataType, row[i]);
}
sb.Append(");");
index++;
//18744 To avoid "The incoming request has too many parameters. The server supports a
//maximum of 2100 parameters. Reduce the number of parameters and resend the request."
//ensure that the number of parameters will not exceed 2100 if another row is added to sb.
if ((index * columns.Count >= (2100 - columns.Count)) ||
(MAX_BATCH_SIZE == index))
{
countSoFar += index;
if (bIdentity)
{
sb.Append($"SET IDENTITY_INSERT [dbo].[{tableName}] OFF;");
}
sb.Append(LocalOnlyOperations.CommitStatement);
cmd.CommandText = sb.ToString();
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
cmd.Connection.Dispose();
cmd.Dispose();
cmd = null;
SetStatus(CurrentTaskBar, 100D * countSoFar / data.Count, $"{countSoFar}/{data.Count}");
}
}
if (null != cmd)
{
if (bIdentity)
{
sb.Append($"SET IDENTITY_INSERT [dbo].[{tableName}] OFF;");
}
sb.Append(LocalOnlyOperations.CommitStatement);
cmd.CommandText = sb.ToString();
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
cmd.Connection.Dispose();
cmd.Dispose();
cmd = null;
SetStatus(CurrentTaskBar, 100D, "");
}
}
public void Cleanup()
{
}
public Task CleanupAsync()
{
return Task.CompletedTask;
}
public void Initialize()
{
}
public void Initialize(object parameter)
{
}
public void Initialize(object parameter, object model)
{
}
public Task InitializeAsync()
{
//this is existing code that was here, I was worried if I did make it async it might have issues
//so I'm just correcting a warning by not returning null at the end
try
{
var view = UnityContainer.Resolve<IStatusAndProgressBarView>();
var viewModel = UnityContainer.Resolve<IStatusAndProgressBarViewModel>();
viewModel.ProgressBarName = OverallTaskBar;
view.DataContext = viewModel;
viewModel.Initialize(this);
OverallProgressBarView = view;
view = UnityContainer.Resolve<IStatusAndProgressBarView>();
viewModel = UnityContainer.Resolve<IStatusAndProgressBarViewModel>();
view.DataContext = viewModel;
viewModel.ProgressBarName = CurrentTaskBar;
viewModel.Initialize(this);
CurrentTaskProgressBarView = view;
}
catch (Exception ex)
{
APILogger.Log(ex);
}
return Task.CompletedTask;
}
public Task InitializeAsync(object parameter)
{
return Task.CompletedTask;
}
public void Activated()
{
}
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnBusyIndicatorNotification(bool eventArg)
{
IsBusy = eventArg;
}
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
{
// The NotificationRequest.Raise triggers the Invoke() method of the PopupWindowAction object to show the NotificationWindow window
// Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string.
var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message, "",
eventArgsWithTitle.Image, string.Empty);
NotificationRequest.Raise(new Notification
{
Content = eventArgsWithoutTitle,
Title = eventArgsWithTitle.Title
});
}
#endregion
#region Properties
public DTS.Common.Enums.Database.DbType DatabaseType { get; private set; }
public bool CopyEnabled => DatabaseType == DTS.Common.Enums.Database.DbType.RemoteLocalHybrid &&
DbOperations._usingCentralizedDB;
public bool IsDirty { get; private set; }
private bool _isBusy = false;
public bool IsBusy
{
get => _isBusy;
set
{
_isBusy = value;
OnPropertyChanged("IsBusy");
}
}
private bool _isMenuIncluded;
public bool IsMenuIncluded
{
get => _isMenuIncluded;
set
{
_isMenuIncluded = value;
OnPropertyChanged("IsMenuIncluded");
}
}
private bool _isNavigationIncluded;
public bool IsNavigationIncluded
{
get => _isNavigationIncluded;
set
{
_isNavigationIncluded = value;
OnPropertyChanged("IsNavigationIncluded");
}
}
public IStatusAndProgressBarView OverallProgressBarView { get; private set; }
public IStatusAndProgressBarView CurrentTaskProgressBarView { get; private set; }
private const string CurrentTaskBar = "CurrentTaskStatus";
private const string OverallTaskBar = "OverallStatus";
/// <summary>
/// the size of each batch of inserts
/// I played around with this for efficiency, but it seemed smaller sizes in general did better
/// the max size would be 2100 parameters (so column count*rows must be less than 2100 )
/// </summary>
private const int MAX_BATCH_SIZE = 20;
public string DbName { get; private set; }
private bool _isCopyVisible = true;
public bool IsCopyVisible
{
get => _isCopyVisible;
set { _isCopyVisible = value; OnPropertyChanged("IsCopyVisible"); }
}
#endregion Properties
#region Commands
#endregion
}
}

View File

@@ -0,0 +1,27 @@
using System.Windows;
using System.Windows.Controls;
using DTS.Common.Interface.Database;
// ReSharper disable CheckNamespace
namespace DatabaseServices
{
/// <inheritdoc cref="IDatabaseCopyView" />
/// <summary>
/// Interaction logic for DatabaseCopyView.xaml
/// </summary>
public partial class DatabaseCopyView : IDatabaseCopyView
{
public DatabaseCopyView()
{
InitializeComponent();
}
private void Copy_Click(object sender, RoutedEventArgs e)
{
var button = (Control)sender;
var vm = (IDatabaseCopyViewModel)button.DataContext;
vm.CopyDatabase();
}
}
}

View File

@@ -0,0 +1,48 @@
<base:BaseView x:Class="DatabaseServices.DatabaseStatusBarView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="clr-namespace:DTS.Common.Base;assembly=DTS.Common"
xmlns:controls="clr-namespace:DTS.Common.Controls;assembly=DTS.Common"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:strings="clr-namespace:DatabaseServices"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:converters="clr-namespace:DatabaseServices.Converters"
xmlns:local="clr-namespace:DatabaseServices"
xmlns:enums="clr-namespace:DTS.Common.Enums.Database;assembly=DTS.Common"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="1366"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
x:Name="DatabaseStatusBar">
<base:BaseView.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Themes/CommonStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Controls/combobox.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="ListView">
<Setter Property="ItemContainerStyle" Value="{StaticResource TTS_ListViewItemStyle}"/>
</Style>
<Style TargetType="TextBox" BasedOn="{StaticResource TTS_TextBoxStyle}"/>
<Style TargetType="TextBlock" BasedOn="{StaticResource TTS_TextBlockStyle}"/>
<Style TargetType="CheckBox" BasedOn="{StaticResource PageContentCheckBoxStyle}" />
<Style TargetType="ComboBox" BasedOn="{StaticResource TTS_ComboBoxStyle}"/>
<Style TargetType="Button" BasedOn="{StaticResource TTS_ButtonStyle}"/>
<Style TargetType="GridViewColumnHeader" BasedOn="{StaticResource Gray_GridViewColumnHeaderStyle}"/>
<converters:DbTypeToVisibilityConverter x:Key="DbTypeConverter" />
<!--<local:DatabaseStatusBarViewModel x:Key="MainViewModel" />-->
</ResourceDictionary>
</base:BaseView.Resources>
<StackPanel Orientation="Horizontal" Background="Transparent" x:Name="MainStackPanel" VerticalAlignment="Center">
<TextBlock Foreground="White"
Text="{strings:TranslateExtension ConnectedTo}"
Background="{Binding BackgroundBrush,UpdateSourceTrigger=PropertyChanged}"
FontSize="12" VerticalAlignment="Center" Padding="5,0,5,0"/>
<TextBlock Foreground="White" AutomationProperties.AutomationId="ServerTextBlock"
Text="{Binding ActiveDbName,UpdateSourceTrigger=PropertyChanged}"
Background="{Binding BackgroundBrush,UpdateSourceTrigger=PropertyChanged}"
FontSize="12" VerticalAlignment="Center" Padding="0,0,5,0"/>
</StackPanel>
</base:BaseView>

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DatabaseServices")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("DTS")]
[assembly: AssemblyProduct("DatabaseServices")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f1a366bc-6128-4c10-be7f-f62628895d8f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,259 @@
using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using DTS.Common.Events;
using DTS.Common.Events.Database;
using Prism.Events;
using Prism.Regions;
using Unity;
using DTS.Common.Interactivity;
using Prism.Commands;
using DTS.Common.Interface.Database;
using DTS.Common.Storage;
using DTS.Common.Utilities.Logging;
// ReSharper disable CheckNamespace
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable InconsistentNaming
namespace DatabaseServices
{
/// <summary>
/// this class handles DatabaseCopy functionality
/// </summary>
[PartCreationPolicy(CreationPolicy.Shared)]
public class DatabaseSwitchViewModel : IDatabaseSwitchViewModel
{
/// <summary>
/// The DatabaseCopy view
/// </summary>
public IDatabaseSwitchView View { get; set; }
private IEventAggregator _eventAggregator { get; }
private IUnityContainer UnityContainer { get; }
public InteractionRequest<Notification> NotificationRequest { get; }
public InteractionRequest<Confirmation> ConfirmationRequest { get; }
/// <inheritdoc />
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#region constructors and initializers
/// <summary>
/// Creates a new instance of the DatabaseCopyViewModel
/// </summary>
/// <param name="view"></param>
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
/// <param name="eventAggregator">The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other.</param>
/// <param name="unityContainer">The unityContainer.</param>
public DatabaseSwitchViewModel(IDatabaseSwitchView view, IRegionManager regionManager,
IEventAggregator eventAggregator, IUnityContainer unityContainer)
{
View = view;
View.DataContext = this;
NotificationRequest = new InteractionRequest<Notification>();
ConfirmationRequest = new InteractionRequest<Confirmation>();
_eventAggregator = eventAggregator;
UnityContainer = unityContainer;
_eventAggregator.GetEvent<RaiseNotification>().Subscribe(OnRaiseNotification);
_eventAggregator.GetEvent<BusyIndicatorChangeNotification>()
.Subscribe(OnBusyIndicatorNotification, ThreadOption.PublisherThread, true);
}
#endregion
#region Methods
public void Unset()
{
}
public void Cleanup()
{
}
public Task CleanupAsync()
{
return Task.CompletedTask;
}
public void Initialize()
{
}
public void Initialize(object parameter)
{
}
public void Initialize(object parameter, object model)
{
}
public Task InitializeAsync()
{
return Task.CompletedTask;
}
public Task InitializeAsync(object parameter)
{
return Task.CompletedTask;
}
public void Activated()
{
}
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnBusyIndicatorNotification(bool eventArg)
{
IsBusy = eventArg;
}
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
{
// The NotificationRequest.Raise triggers the Invoke() method of the PopupWindowAction object to show the NotificationWindow window
// Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string.
var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message, "",
eventArgsWithTitle.Image, string.Empty);
NotificationRequest.Raise(new Notification
{
Content = eventArgsWithoutTitle,
Title = eventArgsWithTitle.Title
});
}
public void SwitchRemote()
{
_eventAggregator.GetEvent<AppStatusEvent>().Publish(AppStatusArg.Busy);
try
{
DTS.Common.Storage.DatabaseServices.SetupForRemoteDb(DbHost, NTLMAuthentication, DbUser, DbPassword, DefaultDbName);
if (!DTS.Common.Storage.DatabaseServices.SimpleDbTest())
{
_eventAggregator.GetEvent<DbStatusEvent>().Publish(
new DbStatusArg(DbStatusArg.EventTypes.FailedToConnectToRemote, null));
SwitchLocal();
return;
}
}
catch (Exception ex)
{
_eventAggregator.GetEvent<DbStatusEvent>()
.Publish(new DbStatusArg(DbStatusArg.EventTypes.FailedToConnectToRemote, ex));
APILogger.Log(ex);
SwitchLocal();
return;
}
OnPropertyChanged("RemoteIsActive");
_eventAggregator.GetEvent<DbStatusEvent>().Publish(new DbStatusArg(DbStatusArg.EventTypes.LegacyStatus, null));
_eventAggregator.GetEvent<AppStatusEvent>().Publish(AppStatusArg.Available);
//http://manuscript.dts.local/f/cases/39203/Local-mode-interacts-with-central-db
//we are switching to a different database connection, make sure we make the user log in again
//we aren't guaranteed the user details are sync'd between local and remote
_eventAggregator.GetEvent<LogoutUserEvent>().Publish(new LogoutUserArg(LogoutUserArg.Reasons.DatabaseSwitch));
}
public void SwitchLocal()
{
try
{
DTS.Common.Utils.Database.CheckLocalDatabaseFilesExist(DefaultDbName, DTS.Common.Storage.DatabaseServices.LOCAL_DB_FOLDER);
}
catch (System.IO.FileNotFoundException ex)
{
_eventAggregator.GetEvent<PageErrorEvent>().Publish(new PageErrorArg(new[] { Resources.StringResources.SwitchFileNotFound, ex.Message }, null));
return;
}
_eventAggregator.GetEvent<AppStatusEvent>().Publish(AppStatusArg.Busy);
DTS.Common.Storage.DatabaseServices.SetupLocal(DefaultDbName);
OnPropertyChanged("RemoteIsActive");
_eventAggregator.GetEvent<DbStatusEvent>().Publish(new DbStatusArg(DbStatusArg.EventTypes.LegacyStatus, null));
_eventAggregator.GetEvent<AppStatusEvent>().Publish(AppStatusArg.Available);
_eventAggregator.GetEvent<LogoutUserEvent>()
.Publish(new LogoutUserArg(LogoutUserArg.Reasons.DatabaseSwitch));
}
public void InitializeDbSettings(string defaultDbName, string dbHost, bool ntlmAuthentication, string dbUser,
string dbPassword)
{
DefaultDbName = defaultDbName;
DbHost = dbHost;
NTLMAuthentication = ntlmAuthentication;
DbUser = dbUser;
DbPassword = dbPassword;
}
#endregion
#region Properties
public string DefaultDbName
{
get;
private set;
}
public bool RemoteIsActive => DbOperations._usingCentralizedDB;
public bool IsDirty { get; private set; }
private bool _isBusy = false;
public bool IsBusy
{
get => _isBusy;
set
{
_isBusy = value;
OnPropertyChanged("IsBusy");
}
}
private bool _isMenuIncluded;
public bool IsMenuIncluded
{
get => _isMenuIncluded;
set
{
_isMenuIncluded = value;
OnPropertyChanged("IsMenuIncluded");
}
}
private bool _isNavigationIncluded;
public bool IsNavigationIncluded
{
get => _isNavigationIncluded;
set
{
_isNavigationIncluded = value;
OnPropertyChanged("IsNavigationIncluded");
}
}
public string DbHost { get; private set; }
public bool NTLMAuthentication { get; private set; }
public string DbUser { get; private set; }
public string DbPassword { get; private set; }
#endregion Properties
#region Commands
#endregion
}
}

View File

@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ClearingLocalDb" xml:space="preserve">
<value>Clearing local db</value>
</data>
<data name="ConnectedTo" xml:space="preserve">
<value>Connected to: </value>
</data>
<data name="CopyFromRemoteServer" xml:space="preserve">
<value>Copy from remote server to local</value>
</data>
<data name="CopyingTable" xml:space="preserve">
<value>Copying</value>
</data>
<data name="EnablingConstraints" xml:space="preserve">
<value>Finishing up</value>
</data>
<data name="Local" xml:space="preserve">
<value>Local</value>
</data>
<data name="Remote" xml:space="preserve">
<value>Remote</value>
</data>
<data name="SwitchFileNotFound" xml:space="preserve">
<value>Could not switch to local - File not found:</value>
</data>
<data name="SwitchToLocal" xml:space="preserve">
<value>Switch to local</value>
</data>
<data name="SwitchToRemote" xml:space="preserve">
<value>Switch to remote</value>
</data>
</root>

View File

@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DatabaseServices.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@@ -0,0 +1,7 @@
rem this file resets the admin password for datapro
rem the basic format to connect and run the command is as follows
rem sqlcmd -S ComputerName\InstanceName -U UserName -P Password -i ResetAdmin.sql -o SQL.log
rem if using NT authentication user name and password is unnecessary
rem adjust the server name, instance name, or database name in resetadmin.sql as needed
sqlcmd -S (localdb)\DataPROInstance -i ResetAdmin.sql -o "SQL.log"

Binary file not shown.

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="DatabaseServices.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<userSettings>
<DatabaseServices.Properties.Settings>
</DatabaseServices.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>

View File

@@ -0,0 +1,45 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using DTS.Common.Enums.Database;
namespace DatabaseServices.Converters
{
public class DbTypeToVisibilityConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var dbType = (DbType)((int)values[0]);
var view = (DatabaseStatusBarView)values[1];
if (null == view.DataContext)
{
return Visibility.Collapsed;
}
var vm = (DatabaseStatusBarViewModel)view.DataContext;
switch (vm.DatabaseType)
{
case DbType.RemoteOnly:
return dbType == DbType.RemoteOnly ? Visibility.Visible : Visibility.Collapsed;
case DbType.LocalOnly:
return dbType == DbType.LocalOnly ? Visibility.Visible : Visibility.Collapsed;
case DbType.RemoteLocalHybrid:
{
if (vm.RemoteConnected)
{
return dbType == DbType.RemoteOnly ? Visibility.Visible : Visibility.Collapsed;
}
return dbType == DbType.RemoteLocalHybrid ? Visibility.Visible : Visibility.Collapsed;
}
default:
return Visibility.Collapsed;
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,200 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2329447B-8A00-4CF3-B0FF-4F960EACFE97}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DatabaseServices</RootNamespace>
<AssemblyName>DatabaseServices</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>CODE_ANALYSIS;DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<RunCodeAnalysis>false</RunCodeAnalysis>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>CODE_ANALYSIS;DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<RunCodeAnalysis>true</RunCodeAnalysis>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Microsoft.Xaml.Behaviors">
<HintPath>..\..\..\..\Common\DTS.Common\lib\PrismLibrary\Microsoft.Xaml.Behaviors.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Prism">
<HintPath>..\..\..\..\Common\DTS.Common\lib\PrismLibrary\Prism.dll</HintPath>
</Reference>
<Reference Include="Prism.Unity.Wpf">
<HintPath>..\..\..\..\Common\DTS.Common\lib\PrismLibrary\Prism.Unity.Wpf.dll</HintPath>
</Reference>
<Reference Include="Prism.Wpf">
<HintPath>..\..\..\..\Common\DTS.Common\lib\PrismLibrary\Prism.Wpf.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Security" />
<Reference Include="System.Web" />
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Unity.Abstractions">
<HintPath>..\..\..\..\Common\DTS.Common\lib\PrismLibrary\Unity.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Unity.Container">
<HintPath>..\..\..\..\Common\DTS.Common\lib\PrismLibrary\Unity.Container.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="Xceed.Wpf.Toolkit">
<HintPath>..\..\..\..\Common\DTS.Common\lib\Xceed.Wpf.Toolkit\Xceed.Wpf.Toolkit.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Converters\DbTypeToVisibilityConverter.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="DatabaseServicesModule.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\StringResources.Designer.cs">
<DependentUpon>StringResources.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Resources\TranslateExtension.cs" />
<Compile Include="ViewModel\DatabaseSwitchViewModel.cs" />
<Compile Include="ViewModel\DatabaseStatusBarViewModel.cs" />
<Compile Include="ViewModel\DatabaseCopyViewModel.cs" />
<Compile Include="View\DatabaseSwitchView.xaml.cs">
<DependentUpon>DatabaseSwitchView.xaml</DependentUpon>
</Compile>
<Compile Include="View\DatabaseStatusBarView.xaml.cs">
<DependentUpon>DatabaseStatusBarView.xaml</DependentUpon>
</Compile>
<Compile Include="View\DatabaseCopyView.xaml.cs">
<DependentUpon>DatabaseCopyView.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\StringResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>StringResources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Common\DTS.Common.Core\DTS.Common.Core.csproj">
<Project>{fab1f470-1574-4301-b56e-d3364aa93679}</Project>
<Name>DTS.Common.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Common\DTS.Common.DAS.Concepts\DTS.Common.DAS.Concepts.csproj">
<Project>{03D8C736-36EB-4CD1-A6D9-130452B23239}</Project>
<Name>DTS.Common.DAS.Concepts</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Common\DTS.Common.ISO\DTS.Common.ISO.csproj">
<Project>{4dccddd1-032f-430c-9a6f-231daca4fbd0}</Project>
<Name>DTS.Common.ISO</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Common\DTS.Common.Storage\DTS.Common.Storage.csproj">
<Project>{e0d1a7d0-dce8-403d-ba85-5a5d66ba1313}</Project>
<Name>DTS.Common.Storage</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Common\DTS.Common.Utilities\DTS.Common.Utilities.csproj">
<Project>{03eace47-ea59-44ac-b49d-956e4dc4d618}</Project>
<Name>DTS.Common.Utilities</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Common\DTS.Common\DTS.Common.csproj">
<Project>{114edc77-f3b5-4576-a91b-40818d503b55}</Project>
<Name>DTS.Common</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\IService\IService.csproj">
<Project>{c9c45b72-05a3-4962-bc13-a78b1f4b1925}</Project>
<Name>IService</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\SensorDB\SensorDB.csproj">
<Project>{444ef10c-046e-47ad-a9a5-17318d488723}</Project>
<Name>SensorDB</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Users\Users.csproj">
<Project>{BE8D217D-6DA9-4BCA-B62A-A82325B33979}</Project>
<Name>Users</Name>
</ProjectReference>
<ProjectReference Include="..\..\StatusAndProgressBar\StatusAndProgressBar.csproj">
<Project>{1f817d85-4ec6-4300-ab35-085765b97a9a}</Project>
<Name>StatusAndProgressBar</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Page Include="View\DatabaseSwitchView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="View\DatabaseStatusBarView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="View\DatabaseCopyView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,145 @@
using System;
using System.ComponentModel.Composition;
using System.Windows.Media.Imaging;
using DTS.Common;
using DTS.Common.Interface;
using Prism.Modularity;
using Unity;
using DatabaseServices;
using DTS.Common.Interface.Database;
using Prism.Ioc;
// ReSharper disable CheckNamespace
// ReSharper disable RedundantAttributeUsageProperty
// ReSharper disable UnusedParameter.Local
[assembly: DatabaseServicesModuleName]
[assembly: DatabaseServicesModuleImageAttribute]
namespace DatabaseServices
{
[Export(typeof(IModule))]
[Module(ModuleName = "DatabaseServicesModule")]
public class DatabaseServicesModule : IModule
{
/// <summary>
/// Injected unity container
/// </summary>
private readonly IUnityContainer _unityContainer;
/// <summary>
/// Initializes a new instance of the <see cref="DatabaseServicesModule"/> class.
/// </summary>
/// <param name="unityContainer">Obtained reference of the unity container by using dependency injection.</param>
public DatabaseServicesModule(IUnityContainer unityContainer)
{
_unityContainer = unityContainer;
}
public void Initialize()
{
// Register View & View-Model with Unity dependency injection container as a singleton.
_unityContainer.RegisterType<IDatabaseCopyView, DatabaseCopyView>();
_unityContainer.RegisterType<IDatabaseCopyViewModel, DatabaseCopyViewModel>();
_unityContainer.RegisterType<IDatabaseStatusBarView, DatabaseStatusBarView>();
_unityContainer.RegisterType<IDatabaseStatusBarViewModel, DatabaseStatusBarViewModel>();
_unityContainer.RegisterType<IDatabaseSwitchView, DatabaseSwitchView>();
_unityContainer.RegisterType<IDatabaseSwitchViewModel, DatabaseSwitchViewModel>();
}
public void OnInitialized(IContainerProvider containerProvider)
{
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
Initialize();
}
}
/// <summary>
/// Attribute class contains assembly name
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
public class DatabaseServicesModuleNameAttribute : TextAttribute
{
public DatabaseServicesModuleNameAttribute() : this(null) { }
public DatabaseServicesModuleNameAttribute(string s)
{
AssemblyName = AssemblyNames.DatabaseServices.ToString();
}
public override string AssemblyName { get; }
public override Type GetAttributeType()
{
return typeof(TextAttribute);
}
public override string GetAssemblyName()
{
return AssemblyName;
}
}
/// <summary>
/// Attribute class contains assembly image and name - used on the Main screen to SummaryModule available components
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
public class DatabaseServicesModuleImageAttribute : ImageAttribute
{
private BitmapImage _img;
public DatabaseServicesModuleImageAttribute() : this(null) { }
public override BitmapImage AssemblyImage
{
get { _img = AssemblyInfo.GetImage(AssemblyNames.DatabaseServices.ToString()); return _img; }
}
public DatabaseServicesModuleImageAttribute(string s)
{
_img = AssemblyInfo.GetImage(AssemblyNames.DatabaseServices.ToString());
}
public override Type GetAttributeType()
{
return typeof(ImageAttribute);
}
public override BitmapImage GetAssemblyImage()
{
return AssemblyImage;
}
private string _name;
public override string AssemblyName
{
get { _name = AssemblyNames.DatabaseServices.ToString(); return _name; }
}
public override string GetAssemblyName()
{
return AssemblyName;
}
private string _group;
public override string AssemblyGroup
{
get { _group = eAssemblyGroups.Prepare.ToString(); return _group; }
}
public override string GetAssemblyGroup()
{
return AssemblyGroup;
}
private eAssemblyRegion _region;
public override eAssemblyRegion AssemblyRegion
{
get { _region = eAssemblyRegion.DatabaseServicesRegion; return _region; }
}
public override eAssemblyRegion GetAssemblyRegion()
{
return AssemblyRegion;
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DatabaseServices")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("DTS")]
[assembly: AssemblyProduct("DatabaseServices")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f1a366bc-6128-4c10-be7f-f62628895d8f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DatabaseServices.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="DatabaseServices.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
</Settings>
</SettingsFile>

View File

@@ -0,0 +1,7 @@
rem this file resets the admin password for datapro
rem the basic format to connect and run the command is as follows
rem sqlcmd -S ComputerName\InstanceName -U UserName -P Password -i ResetAdmin.sql -o SQL.log
rem if using NT authentication user name and password is unnecessary
rem adjust the server name, instance name, or database name in resetadmin.sql as needed
sqlcmd -S (localdb)\DataPROInstance -i ResetAdmin.sql -o "SQL.log"

View File

@@ -0,0 +1,2 @@
Use DataPRO;
UPDATE [dbo].[Users] SET [Password]='Onl79FZmtkwYRi5DfMV46DDfS0HMOpURgIxeUvhswuY=' WHERE ID=1;

View File

@@ -0,0 +1,153 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DatabaseServices.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class StringResources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal StringResources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DatabaseServices.Resources.StringResources", typeof(StringResources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Clearing local db.
/// </summary>
internal static string ClearingLocalDb {
get {
return ResourceManager.GetString("ClearingLocalDb", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Connected to: .
/// </summary>
internal static string ConnectedTo {
get {
return ResourceManager.GetString("ConnectedTo", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Copy from remote server to local.
/// </summary>
internal static string CopyFromRemoteServer {
get {
return ResourceManager.GetString("CopyFromRemoteServer", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Copying.
/// </summary>
internal static string CopyingTable {
get {
return ResourceManager.GetString("CopyingTable", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Finishing up.
/// </summary>
internal static string EnablingConstraints {
get {
return ResourceManager.GetString("EnablingConstraints", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Local.
/// </summary>
internal static string Local {
get {
return ResourceManager.GetString("Local", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Remote.
/// </summary>
internal static string Remote {
get {
return ResourceManager.GetString("Remote", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not switch to local - File not found:.
/// </summary>
internal static string SwitchFileNotFound {
get {
return ResourceManager.GetString("SwitchFileNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Switch to local.
/// </summary>
internal static string SwitchToLocal {
get {
return ResourceManager.GetString("SwitchToLocal", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Switch to remote.
/// </summary>
internal static string SwitchToRemote {
get {
return ResourceManager.GetString("SwitchToRemote", resourceCulture);
}
}
}
}

View File

@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ClearingLocalDb" xml:space="preserve">
<value>Clearing local db</value>
</data>
<data name="ConnectedTo" xml:space="preserve">
<value>Connected to: </value>
</data>
<data name="CopyFromRemoteServer" xml:space="preserve">
<value>Copy from remote server to local</value>
</data>
<data name="CopyingTable" xml:space="preserve">
<value>Copying</value>
</data>
<data name="EnablingConstraints" xml:space="preserve">
<value>Finishing up</value>
</data>
<data name="Local" xml:space="preserve">
<value>Local</value>
</data>
<data name="Remote" xml:space="preserve">
<value>Remote</value>
</data>
<data name="SwitchFileNotFound" xml:space="preserve">
<value>Could not switch to local - File not found:</value>
</data>
<data name="SwitchToLocal" xml:space="preserve">
<value>Switch to local</value>
</data>
<data name="SwitchToRemote" xml:space="preserve">
<value>Switch to remote</value>
</data>
</root>

View File

@@ -0,0 +1,21 @@
using System;
using System.Windows.Markup;
using DatabaseServices.Resources;
namespace DatabaseServices
{
[MarkupExtensionReturnType(typeof(string))]
public class TranslateExtension : MarkupExtension
{
private readonly string _key;
public TranslateExtension(string key) { _key = key; }
private const string NotFound = "#stringnotfound#";
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (string.IsNullOrEmpty(_key)) { return NotFound; }
return StringResources.ResourceManager.GetString(_key) ?? NotFound + " " + _key;
}
}
}

View File

@@ -0,0 +1,48 @@
<base:BaseView x:Class="DatabaseServices.DatabaseCopyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="clr-namespace:DTS.Common.Base;assembly=DTS.Common"
xmlns:controls="clr-namespace:DTS.Common.Controls;assembly=DTS.Common"
xmlns:commonconverters="clr-namespace:DTS.Common.Converters;assembly=DTS.Common"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:strings="clr-namespace:DatabaseServices"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="768" d:DesignWidth="1366"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
x:Name="DatabaseCopy" Background="White">
<base:BaseView.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Themes/CommonStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Controls/combobox.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="ListView">
<Setter Property="ItemContainerStyle" Value="{StaticResource TTS_ListViewItemStyle}"/>
</Style>
<Style TargetType="TextBox" BasedOn="{StaticResource TTS_TextBoxStyle}"/>
<Style TargetType="TextBlock" BasedOn="{StaticResource TTS_TextBlockStyle}"/>
<Style TargetType="CheckBox" BasedOn="{StaticResource PageContentCheckBoxStyle}" />
<Style TargetType="ComboBox" BasedOn="{StaticResource TTS_ComboBoxStyle}"/>
<Style TargetType="Button" BasedOn="{StaticResource TTS_ButtonStyle}"/>
<Style TargetType="GridViewColumnHeader" BasedOn="{StaticResource Gray_GridViewColumnHeaderStyle}"/>
<commonconverters:BooleanToVisibilityConverter x:Key="BoolToVisConverter" />
</ResourceDictionary>
</base:BaseView.Resources>
<Grid Background="White" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<controls:CommonStatusRibbon AutomationProperties.AutomationId="ImmediateProgress" Grid.Row="0" Margin="0,5,0,5" ProgressBarName="CurrentTaskStatus"
Content="{Binding CurrentTaskProgressBarView}" />
<controls:CommonStatusRibbon AutomationProperties.AutomationId="OverallProgress" Grid.Row="1" Margin="0,5,0,5" ProgressBarName="OverallStatus"
Content="{Binding OverallProgressBarView}" />
<Button AutomationProperties.AutomationId="Copy Button" Content="{strings:Translate CopyFromRemoteServer}"
MinWidth="200" Grid.Row="2" HorizontalAlignment="Left" Click="Copy_Click" IsEnabled="{Binding CopyEnabled, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding IsCopyVisible, Converter={StaticResource BoolToVisConverter}}"/>
</Grid>
</base:BaseView>

View File

@@ -0,0 +1,27 @@
using System.Windows;
using System.Windows.Controls;
using DTS.Common.Interface.Database;
// ReSharper disable CheckNamespace
namespace DatabaseServices
{
/// <inheritdoc cref="IDatabaseCopyView" />
/// <summary>
/// Interaction logic for DatabaseCopyView.xaml
/// </summary>
public partial class DatabaseCopyView : IDatabaseCopyView
{
public DatabaseCopyView()
{
InitializeComponent();
}
private void Copy_Click(object sender, RoutedEventArgs e)
{
var button = (Control)sender;
var vm = (IDatabaseCopyViewModel)button.DataContext;
vm.CopyDatabase();
}
}
}

View File

@@ -0,0 +1,48 @@
<base:BaseView x:Class="DatabaseServices.DatabaseStatusBarView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="clr-namespace:DTS.Common.Base;assembly=DTS.Common"
xmlns:controls="clr-namespace:DTS.Common.Controls;assembly=DTS.Common"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:strings="clr-namespace:DatabaseServices"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:converters="clr-namespace:DatabaseServices.Converters"
xmlns:local="clr-namespace:DatabaseServices"
xmlns:enums="clr-namespace:DTS.Common.Enums.Database;assembly=DTS.Common"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="1366"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
x:Name="DatabaseStatusBar">
<base:BaseView.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Themes/CommonStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Controls/combobox.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="ListView">
<Setter Property="ItemContainerStyle" Value="{StaticResource TTS_ListViewItemStyle}"/>
</Style>
<Style TargetType="TextBox" BasedOn="{StaticResource TTS_TextBoxStyle}"/>
<Style TargetType="TextBlock" BasedOn="{StaticResource TTS_TextBlockStyle}"/>
<Style TargetType="CheckBox" BasedOn="{StaticResource PageContentCheckBoxStyle}" />
<Style TargetType="ComboBox" BasedOn="{StaticResource TTS_ComboBoxStyle}"/>
<Style TargetType="Button" BasedOn="{StaticResource TTS_ButtonStyle}"/>
<Style TargetType="GridViewColumnHeader" BasedOn="{StaticResource Gray_GridViewColumnHeaderStyle}"/>
<converters:DbTypeToVisibilityConverter x:Key="DbTypeConverter" />
<!--<local:DatabaseStatusBarViewModel x:Key="MainViewModel" />-->
</ResourceDictionary>
</base:BaseView.Resources>
<StackPanel Orientation="Horizontal" Background="Transparent" x:Name="MainStackPanel" VerticalAlignment="Center">
<TextBlock Foreground="White"
Text="{strings:TranslateExtension ConnectedTo}"
Background="{Binding BackgroundBrush,UpdateSourceTrigger=PropertyChanged}"
FontSize="12" VerticalAlignment="Center" Padding="5,0,5,0"/>
<TextBlock Foreground="White" AutomationProperties.AutomationId="ServerTextBlock"
Text="{Binding ActiveDbName,UpdateSourceTrigger=PropertyChanged}"
Background="{Binding BackgroundBrush,UpdateSourceTrigger=PropertyChanged}"
FontSize="12" VerticalAlignment="Center" Padding="0,0,5,0"/>
</StackPanel>
</base:BaseView>

View File

@@ -0,0 +1,18 @@
using DTS.Common.Interface.Database;
// ReSharper disable CheckNamespace
namespace DatabaseServices
{
/// <inheritdoc cref="DatabaseStatusBarView" />
/// <summary>
/// Interaction logic for DatabaseStatusBarView.xaml
/// </summary>
public partial class DatabaseStatusBarView : IDatabaseStatusBarView
{
public DatabaseStatusBarView()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,38 @@
<base:BaseView x:Class="DatabaseServices.DatabaseSwitchView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:base="clr-namespace:DTS.Common.Base;assembly=DTS.Common"
xmlns:controls="clr-namespace:DTS.Common.Controls;assembly=DTS.Common"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:strings="clr-namespace:DatabaseServices"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="768" d:DesignWidth="1366"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:converters="clr-namespace:DTS.Common.Converters;assembly=DTS.Common"
x:Name="DatabaseSwitch" Background="White">
<base:BaseView.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Themes/CommonStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/DTS.Common;component/Controls/combobox.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="ListView">
<Setter Property="ItemContainerStyle" Value="{StaticResource TTS_ListViewItemStyle}"/>
</Style>
<Style TargetType="TextBox" BasedOn="{StaticResource TTS_TextBoxStyle}"/>
<Style TargetType="TextBlock" BasedOn="{StaticResource TTS_TextBlockStyle}"/>
<Style TargetType="CheckBox" BasedOn="{StaticResource PageContentCheckBoxStyle}" />
<Style TargetType="ComboBox" BasedOn="{StaticResource TTS_ComboBoxStyle}"/>
<Style TargetType="Button" BasedOn="{StaticResource TTS_ButtonStyle}"/>
<Style TargetType="GridViewColumnHeader" BasedOn="{StaticResource Gray_GridViewColumnHeaderStyle}"/>
<converters:InverseBooleanConverter x:Key="InverseConverter" />
</ResourceDictionary>
</base:BaseView.Resources>
<WrapPanel Background="White" Orientation="Horizontal">
<Button Content="{strings:TranslateExtension SwitchToLocal}" IsEnabled="{Binding RemoteIsActive, UpdateSourceTrigger=PropertyChanged}" AutomationProperties.AutomationId="SwitchToLocalButton" Click="SwitchToLocal_Click" />
<Button Content="{strings:TranslateExtension SwitchToRemote}" IsEnabled="{Binding RemoteIsActive, Converter={StaticResource InverseConverter}, UpdateSourceTrigger=PropertyChanged}" AutomationProperties.AutomationId="SwitchToRemoteButton" Click="SwitchToRemote_Click" />
</WrapPanel>
</base:BaseView>

View File

@@ -0,0 +1,31 @@
using System.Windows.Controls;
using DTS.Common.Interface.Database;
// ReSharper disable CheckNamespace
namespace DatabaseServices
{
/// <inheritdoc cref="IDatabaseSwitchView" />
/// <summary>
/// Interaction logic for DatabaseSwitchView.xaml
/// </summary>
public partial class DatabaseSwitchView : IDatabaseSwitchView
{
public DatabaseSwitchView()
{
InitializeComponent();
}
private void SwitchToLocal_Click(object sender, System.Windows.RoutedEventArgs e)
{
var vm = (IDatabaseSwitchViewModel)((Control)sender).DataContext;
vm.SwitchLocal();
}
private void SwitchToRemote_Click(object sender, System.Windows.RoutedEventArgs e)
{
var vm = (IDatabaseSwitchViewModel)((Control)sender).DataContext;
vm.SwitchRemote();
}
}
}

View File

@@ -0,0 +1,632 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using DTS.Common.Events;
using DTS.Common.Events.Database;
using Prism.Events;
using Prism.Regions;
using Unity;
using DTS.Common.Interactivity;
using Prism.Commands;
using DTS.Common.Interface.Database;
using DTS.Common.Storage;
using DTS.Common.Utilities.Logging;
using DTS.Common.Interface;
// ReSharper disable CheckNamespace
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable InconsistentNaming
namespace DatabaseServices
{
/// <summary>
/// this class handles DatabaseCopy functionality
/// </summary>
[PartCreationPolicy(CreationPolicy.Shared)]
public class DatabaseCopyViewModel : IDatabaseCopyViewModel
{
/// <summary>
/// The DatabaseCopy view
/// </summary>
public IDatabaseCopyView View { get; set; }
private IEventAggregator _eventAggregator { get; }
private IUnityContainer UnityContainer { get; }
public InteractionRequest<Notification> NotificationRequest { get; }
public InteractionRequest<Confirmation> ConfirmationRequest { get; }
/// <inheritdoc />
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#region constructors and initializers
/// <summary>
/// Creates a new instance of the DatabaseCopyViewModel
/// </summary>
/// <param name="view"></param>
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
/// <param name="eventAggregator">The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other.</param>
/// <param name="unityContainer">The unityContainer.</param>
public DatabaseCopyViewModel(IDatabaseCopyView view, IRegionManager regionManager,
IEventAggregator eventAggregator, IUnityContainer unityContainer)
{
View = view;
View.DataContext = this;
NotificationRequest = new InteractionRequest<Notification>();
ConfirmationRequest = new InteractionRequest<Confirmation>();
_eventAggregator = eventAggregator;
UnityContainer = unityContainer;
_eventAggregator.GetEvent<RaiseNotification>().Subscribe(OnRaiseNotification);
_eventAggregator.GetEvent<BusyIndicatorChangeNotification>().Subscribe(OnBusyIndicatorNotification);
}
#endregion
#region Methods
public void Unset()
{
}
public void CopyDatabase()
{
_eventAggregator.GetEvent<AppStatusEvent>().Publish(AppStatusArg.Busy);
_ = Task.Run(() => { CopyFunc(); });
}
public void InitializeState(DTS.Common.Enums.Database.DbType dbType, string dbName)
{
DbName = dbName;
DatabaseType = dbType;
_eventAggregator.GetEvent<ProgressBarEvent>().Publish(new ProgressBarEventArg(CurrentTaskBar, Colors.White,
System.Windows.Visibility.Collapsed, 0D, ""));
_eventAggregator.GetEvent<ProgressBarEvent>().Publish(new ProgressBarEventArg(OverallTaskBar, Colors.White,
System.Windows.Visibility.Collapsed, 0D, ""));
OnPropertyChanged("CopyEnabled");
}
private void SetStatus(string bar, double percentage, string text)
{
_eventAggregator.GetEvent<ProgressBarEvent>()
.Publish(new ProgressBarEventArg(bar, Colors.White, System.Windows.Visibility.Visible, percentage, text));
}
private static readonly List<string> _allDBTables = new List<string>()
{
"AddOrRemove",
"AnalogDiagnostics",
"CalculatedChannelOperation",
"CalculatedChannels",
"CalibrationType",
"ChannelCodes",
"ChannelCodeType",
"Channels",
"ChannelSettings",
"CustomerDetails",
"DAS",
"DASChannels",
"DataPRODbVersion",
"DbTableVersions",
"DefaultProperties",
"DiagnosticRuns",
"GroupChannelSettings",
"GroupHardware",
"Groups",
"LabratoryDetails",
"LastUsedHardware",
"LevelTriggers",
"LockedItemCategories",
"LockedItems",
"RecordingMode",
"RecordingModes",
"ROIPeriodChannels",
"SensorBridgeLegMode",
"SensorBridgeType",
"SensorCalibrationRecord",
"SensorCalibrationRecordIRTracc",
"SensorCalibrationRecordPolynomial",
"SensorCalibrations",
"SensorChangeHistory",
"SensorChangeType",
"SensorCouplingMode",
"SensorDigitalOutputMode",
"SensorModels",
"Sensors",
"SensorsAnalog",
"SensorsDigitalIn",
"SensorsDigitalOut",
"SensorSettingMode",
"SensorShunt",
"SensorSquibFireMode",
"SensorSquibMeasurementType",
"SensorsSquib",
"SensorsStreamInput",
"SensorsStreamOutput",
"SensorStatus",
"SensorsType",
"SensorsUART",
"SensorTestHistory",
"Settings",
"SoftwareFilters",
"StoredProcedureVersions",
"TagAssignments",
"TagObjectType",
"Tags",
"tblDataPRODbVersion",
"TestEngineerDetails",
"TestGraphs",
"TestHistory",
"TestSetupGroups",
"TestSetupHardware",
"TestSetupObjectMetaData",
"TestSetupROIs",
"TestSetups",
"TestSetupSettings",
"UIItems",
"UIItemSettings",
"UserProperties",
"Users",
"UsersRoles"
};
private static readonly HashSet<string> _tablesWithIdentities = new HashSet<string>()
{
"AnalogDiagnostics",
"CalculatedChannels",
"ChannelCodes",
"ChannelCodeType",
"Channels",
"ChannelSettings",
"CustomerDetails",
"DAS",
"DASChannels",
"DiagnosticRuns",
"GroupHardware",
"Groups",
"LabratoryDetails",
"LastUsedHardware",
"LevelTriggers",
"LockedItemCategories",
"LockedItems",
"ROIPeriodChannels",
"SensorCalibrationRecord",
"SensorCalibrationRecordIRTracc",
"SensorCalibrationRecordPolynomial",
"SensorCalibrations",
"SensorChangeHistory",
"SensorChangeType",
"SensorModels",
"Sensors",
"SensorsAnalog",
"SensorsDigitalIn",
"SensorsDigitalOut",
"SensorsSquib",
"SensorsStreamInput",
"SensorsStreamOutput",
"SensorsUART",
"SensorTestHistory",
"Settings",
"SoftwareFilters",
"Tags",
"TestEngineerDetails",
"TestGraphs",
"TestHistory",
"TestSetupGroups",
"TestSetupHardware",
"TestSetupObjectMetaData",
"TestSetupROIs",
"TestSetups",
"UIItems",
"UIItemSettings",
"Users"
};
private void CopyFunc()
{
try
{
DTS.Common.Storage.DatabaseServices.BackupLocalDatabase(DbName);
}
catch (System.IO.FileNotFoundException ex)
{
_eventAggregator.GetEvent<DbStatusEvent>()
.Publish(new DbStatusArg(DbStatusArg.EventTypes.FailedToBackupLocalFileNotFound, ex));
APILogger.Log(ex);
return;
}
catch (Exception ex)
{
_eventAggregator.GetEvent<DbStatusEvent>()
.Publish(new DbStatusArg(DbStatusArg.EventTypes.FailedToBackupLocal, null));
APILogger.Log(ex);
return;
}
try
{
//get list of all tables
//I'd like to do this through SQL, but ran into problems
var allTables = _allDBTables;
SetStatus(OverallTaskBar, 0, "");
SetStatus(CurrentTaskBar, 0, "");
double steps = 2 + allTables.Count;
//turn off all constraints
SetStatus(OverallTaskBar, 0, Resources.StringResources.ClearingLocalDb);
using (var cmd = LocalOnlyOperations.GetSQLCommand(true))
{
try
{
cmd.CommandText = "EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
finally
{
cmd.Connection.Dispose();
}
}
double currentStep = 1;
SetStatus(OverallTaskBar, 100D * currentStep / steps, "");
//Copy remote table to local)
foreach (var table in allTables)
{
SetStatus(OverallTaskBar, 100D * currentStep / steps,
$"{Resources.StringResources.CopyingTable} {table}");
SetStatus(CurrentTaskBar, 0D, "");
CopyRemoteTable(table, _tablesWithIdentities.Contains(table));
currentStep++;
}
//Change any DASId columns in the Channels table from 0 to NULL
try
{
using (var cmd = LocalOnlyOperations.GetSQLCommand(true))
{
try
{
cmd.CommandText = "UPDATE Channels SET DASId = NULL WHERE DASId = 0";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
finally { cmd.Connection.Dispose(); }
}
}
catch (Exception ex)
{
APILogger.Log(ex);
}
//turn on all constraints
SetStatus(OverallTaskBar, 100D * currentStep / steps, Resources.StringResources.EnablingConstraints);
try
{
using (var cmd = LocalOnlyOperations.GetSQLCommand(true))
{
try
{
cmd.CommandText = "EXEC sp_msforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
_eventAggregator.GetEvent<DbStatusEvent>().Publish(new DbStatusArg(DbStatusArg.EventTypes.Complete, null));
}
finally
{
cmd.Connection.Dispose();
}
}
}
catch (Exception ex)
{
APILogger.Log(ex);
}
}
catch (Exception ex)
{
APILogger.Log(ex);
_eventAggregator.GetEvent<DbStatusEvent>()
.Publish(new DbStatusArg(DbStatusArg.EventTypes.FailedToCopy, ex));
try
{
DTS.Common.Storage.DatabaseServices.RestoreLocalDatabase(DbName);
}
catch (Exception)
{
APILogger.Log(ex);
_eventAggregator.GetEvent<DbStatusEvent>().Publish(
new DbStatusArg(DbStatusArg.EventTypes.FailedToRestoreLocal, null));
}
}
finally
{
_eventAggregator.GetEvent<ProgressBarEvent>().Publish(new ProgressBarEventArg(OverallTaskBar,
Colors.White, System.Windows.Visibility.Collapsed, 0D, ""));
_eventAggregator.GetEvent<ProgressBarEvent>().Publish(new ProgressBarEventArg(CurrentTaskBar,
Colors.White, System.Windows.Visibility.Collapsed, 0D, ""));
_eventAggregator.GetEvent<AppStatusEvent>().Publish(AppStatusArg.Available);
}
}
private void CopyRemoteTable(string tableName, bool bIndentityTable)
{
using (var cmd = LocalOnlyOperations.GetSQLCommand(true))
{
cmd.CommandText = $"DELETE FROM [dbo].[{tableName}]";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
cmd.Connection.Dispose();
}
DataColumnCollection columns = null;
var objects = new List<object[]>();
using (var cmd = DbOperations.GetSQLCommand(true))
{
cmd.CommandText = $"SELECT * from [dbo].[{tableName}]";
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
{
if (ds.Tables[0].Rows.Count > 0)
{
columns = ds.Tables[0].Columns;
foreach (DataRow row in ds.Tables[0].Rows)
{
var rowObjects = new object[columns.Count];
for (var i = 0; i < rowObjects.Length; i++)
{
rowObjects[i] = row[i];
}
objects.Add(rowObjects);
}
}
}
cmd.Connection.Dispose();
}
if (null != columns)
{
InsertIntoLocalTable(tableName, columns, objects, bIndentityTable);
}
}
private void InsertIntoLocalTable(string tableName, DataColumnCollection columns, List<object[]> data, bool bIdentity)
{
SqlCommand cmd = null;
var index = 0;
StringBuilder sb = null;
var countSoFar = 0;
foreach (var row in data)
{
if (null == cmd)
{
index = 0;
cmd = LocalOnlyOperations.GetSQLCommand(true);
sb = new StringBuilder(500);
sb.Append(LocalOnlyOperations.BeginStatement);
if (bIdentity)
{
sb.Append($"SET IDENTITY_INSERT [dbo].[{tableName}] ON;");
}
}
sb.Append($"INSERT INTO [dbo].[{tableName}] (");
for (var i = 0; i < columns.Count; i++)
{
if (i > 0)
{
sb.Append(",");
}
sb.AppendFormat("[{0}]", columns[i].ColumnName);
}
sb.Append(") VALUES (");
for (var i = 0; i < columns.Count; i++)
{
if (i > 0)
{
sb.Append(",");
}
var key = $"@{index}_{i}";
sb.Append(key);
var dataType = TypeConvertor.ToSqlDbType(columns[i].DataType);
LocalOnlyOperations.CreateParam(cmd, key, dataType, row[i]);
}
sb.Append(");");
index++;
//18744 To avoid "The incoming request has too many parameters. The server supports a
//maximum of 2100 parameters. Reduce the number of parameters and resend the request."
//ensure that the number of parameters will not exceed 2100 if another row is added to sb.
if ((index * columns.Count >= (2100 - columns.Count)) ||
(MAX_BATCH_SIZE == index))
{
countSoFar += index;
if (bIdentity)
{
sb.Append($"SET IDENTITY_INSERT [dbo].[{tableName}] OFF;");
}
sb.Append(LocalOnlyOperations.CommitStatement);
cmd.CommandText = sb.ToString();
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
cmd.Connection.Dispose();
cmd.Dispose();
cmd = null;
SetStatus(CurrentTaskBar, 100D * countSoFar / data.Count, $"{countSoFar}/{data.Count}");
}
}
if (null != cmd)
{
if (bIdentity)
{
sb.Append($"SET IDENTITY_INSERT [dbo].[{tableName}] OFF;");
}
sb.Append(LocalOnlyOperations.CommitStatement);
cmd.CommandText = sb.ToString();
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
cmd.Connection.Dispose();
cmd.Dispose();
cmd = null;
SetStatus(CurrentTaskBar, 100D, "");
}
}
public void Cleanup()
{
}
public Task CleanupAsync()
{
return Task.CompletedTask;
}
public void Initialize()
{
}
public void Initialize(object parameter)
{
}
public void Initialize(object parameter, object model)
{
}
public Task InitializeAsync()
{
//this is existing code that was here, I was worried if I did make it async it might have issues
//so I'm just correcting a warning by not returning null at the end
try
{
var view = UnityContainer.Resolve<IStatusAndProgressBarView>();
var viewModel = UnityContainer.Resolve<IStatusAndProgressBarViewModel>();
viewModel.ProgressBarName = OverallTaskBar;
view.DataContext = viewModel;
viewModel.Initialize(this);
OverallProgressBarView = view;
view = UnityContainer.Resolve<IStatusAndProgressBarView>();
viewModel = UnityContainer.Resolve<IStatusAndProgressBarViewModel>();
view.DataContext = viewModel;
viewModel.ProgressBarName = CurrentTaskBar;
viewModel.Initialize(this);
CurrentTaskProgressBarView = view;
}
catch (Exception ex)
{
APILogger.Log(ex);
}
return Task.CompletedTask;
}
public Task InitializeAsync(object parameter)
{
return Task.CompletedTask;
}
public void Activated()
{
}
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnBusyIndicatorNotification(bool eventArg)
{
IsBusy = eventArg;
}
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
{
// The NotificationRequest.Raise triggers the Invoke() method of the PopupWindowAction object to show the NotificationWindow window
// Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string.
var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message, "",
eventArgsWithTitle.Image, string.Empty);
NotificationRequest.Raise(new Notification
{
Content = eventArgsWithoutTitle,
Title = eventArgsWithTitle.Title
});
}
#endregion
#region Properties
public DTS.Common.Enums.Database.DbType DatabaseType { get; private set; }
public bool CopyEnabled => DatabaseType == DTS.Common.Enums.Database.DbType.RemoteLocalHybrid &&
DbOperations._usingCentralizedDB;
public bool IsDirty { get; private set; }
private bool _isBusy = false;
public bool IsBusy
{
get => _isBusy;
set
{
_isBusy = value;
OnPropertyChanged("IsBusy");
}
}
private bool _isMenuIncluded;
public bool IsMenuIncluded
{
get => _isMenuIncluded;
set
{
_isMenuIncluded = value;
OnPropertyChanged("IsMenuIncluded");
}
}
private bool _isNavigationIncluded;
public bool IsNavigationIncluded
{
get => _isNavigationIncluded;
set
{
_isNavigationIncluded = value;
OnPropertyChanged("IsNavigationIncluded");
}
}
public IStatusAndProgressBarView OverallProgressBarView { get; private set; }
public IStatusAndProgressBarView CurrentTaskProgressBarView { get; private set; }
private const string CurrentTaskBar = "CurrentTaskStatus";
private const string OverallTaskBar = "OverallStatus";
/// <summary>
/// the size of each batch of inserts
/// I played around with this for efficiency, but it seemed smaller sizes in general did better
/// the max size would be 2100 parameters (so column count*rows must be less than 2100 )
/// </summary>
private const int MAX_BATCH_SIZE = 20;
public string DbName { get; private set; }
private bool _isCopyVisible = true;
public bool IsCopyVisible
{
get => _isCopyVisible;
set { _isCopyVisible = value; OnPropertyChanged("IsCopyVisible"); }
}
#endregion Properties
#region Commands
#endregion
}
}

View File

@@ -0,0 +1,252 @@
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using System.Windows.Media;
using DTS.Common.Enums.Database;
using DTS.Common.Events;
using DTS.Common.Events.Database;
using Prism.Events;
using Prism.Regions;
using Unity;
using DTS.Common.Interactivity;
using Prism.Commands;
using DTS.Common.Interface.Database;
using DTS.Common.Storage;
// ReSharper disable CheckNamespace
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable InconsistentNaming
namespace DatabaseServices
{
/// <summary>
/// this class handles DatabaseCopy functionality
/// </summary>
[PartCreationPolicy(CreationPolicy.Shared)]
public class DatabaseStatusBarViewModel : IDatabaseStatusBarViewModel
{
/// <summary>
/// The DatabaseCopy view
/// </summary>
public IDatabaseStatusBarView View { get; set; }
private IEventAggregator _eventAggregator { get; }
private IRegionManager _regionManager;
private IUnityContainer UnityContainer { get; }
public InteractionRequest<Notification> NotificationRequest { get; }
public InteractionRequest<Confirmation> ConfirmationRequest { get; }
/// <inheritdoc />
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#region constructors and initializers
/// <summary>
/// Creates a new instance of the DatabaseCopyViewModel
/// </summary>
/// <param name="view"></param>
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
/// <param name="eventAggregator">The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other.</param>
/// <param name="unityContainer">The unityContainer.</param>
public DatabaseStatusBarViewModel(IDatabaseStatusBarView view, IRegionManager regionManager,
IEventAggregator eventAggregator, IUnityContainer unityContainer)
{
View = view;
View.DataContext = this;
NotificationRequest = new InteractionRequest<Notification>();
ConfirmationRequest = new InteractionRequest<Confirmation>();
_eventAggregator = eventAggregator;
UnityContainer = unityContainer;
_regionManager = regionManager;
_eventAggregator.GetEvent<RaiseNotification>().Subscribe(OnRaiseNotification);
_eventAggregator.GetEvent<BusyIndicatorChangeNotification>()
.Subscribe(OnBusyIndicatorNotification, ThreadOption.PublisherThread, true);
_eventAggregator.GetEvent<DbStatusEvent>().Subscribe(OnDbEvent);
}
public DatabaseStatusBarViewModel()
{
}
#endregion
#region Methods
private void OnDbEvent(DbStatusArg args)
{
if (args.Status == DbStatusArg.EventTypes.LegacyStatus)
{
if (RemoteConnected)
{
ServerName = DbOperations.Connection.Server;
}
else
{
ServerName = "Local";
}
OnPropertyChanged("ActiveDbName");
OnPropertyChanged("BackgroundBrush");
}
}
public void Unset()
{
}
public DbType DatabaseType { get; private set; }
public void InitializeValues(DbType dbType, string serverName, bool remoteConnected)
{
DatabaseType = dbType;
ServerName = serverName;
OnPropertyChanged("ActiveDbName");
OnPropertyChanged("BackgroundBrush");
}
public bool RemoteConnected => DbOperations._usingCentralizedDB;
public string ServerName { get; private set; }
public string ActiveDbName
{
get
{
switch (DatabaseType)
{
case DbType.LocalOnly: return Resources.StringResources.Local;
case DbType.RemoteOnly: return ServerName;
case DbType.RemoteLocalHybrid:
{
return RemoteConnected ? ServerName : Resources.StringResources.Local;
}
}
return "";
}
}
public Brush BackgroundBrush
{
get
{
switch (DatabaseType)
{
case DbType.RemoteLocalHybrid:
return RemoteConnected ? Brushes.Transparent : Brushes.Red;
}
return Brushes.Transparent;
}
}
public void Cleanup()
{
}
public Task CleanupAsync()
{
return Task.CompletedTask;
}
public void Initialize()
{
}
public void Initialize(object parameter)
{
}
public void Initialize(object parameter, object model)
{
}
public Task InitializeAsync()
{
return Task.CompletedTask;
}
public Task InitializeAsync(object parameter)
{
return Task.CompletedTask;
}
public void Activated()
{
}
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnBusyIndicatorNotification(bool eventArg)
{
IsBusy = eventArg;
}
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
{
// The NotificationRequest.Raise triggers the Invoke() method of the PopupWindowAction object to show the NotificationWindow window
// Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string.
var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message, "",
eventArgsWithTitle.Image, string.Empty);
NotificationRequest.Raise(new Notification
{
Content = eventArgsWithoutTitle,
Title = eventArgsWithTitle.Title
});
}
#endregion
#region Properties
public bool IsDirty { get; private set; }
private bool _isBusy = false;
public bool IsBusy
{
get => _isBusy;
set
{
_isBusy = value;
OnPropertyChanged("IsBusy");
}
}
private bool _isMenuIncluded;
public bool IsMenuIncluded
{
get => _isMenuIncluded;
set
{
_isMenuIncluded = value;
OnPropertyChanged("IsMenuIncluded");
}
}
private bool _isNavigationIncluded;
public bool IsNavigationIncluded
{
get => _isNavigationIncluded;
set
{
_isNavigationIncluded = value;
OnPropertyChanged("IsNavigationIncluded");
}
}
#endregion Properties
#region Commands
#endregion
}
}

View File

@@ -0,0 +1,259 @@
using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using DTS.Common.Events;
using DTS.Common.Events.Database;
using Prism.Events;
using Prism.Regions;
using Unity;
using DTS.Common.Interactivity;
using Prism.Commands;
using DTS.Common.Interface.Database;
using DTS.Common.Storage;
using DTS.Common.Utilities.Logging;
// ReSharper disable CheckNamespace
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable InconsistentNaming
namespace DatabaseServices
{
/// <summary>
/// this class handles DatabaseCopy functionality
/// </summary>
[PartCreationPolicy(CreationPolicy.Shared)]
public class DatabaseSwitchViewModel : IDatabaseSwitchViewModel
{
/// <summary>
/// The DatabaseCopy view
/// </summary>
public IDatabaseSwitchView View { get; set; }
private IEventAggregator _eventAggregator { get; }
private IUnityContainer UnityContainer { get; }
public InteractionRequest<Notification> NotificationRequest { get; }
public InteractionRequest<Confirmation> ConfirmationRequest { get; }
/// <inheritdoc />
/// <summary>
/// Occurs when a property value changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#region constructors and initializers
/// <summary>
/// Creates a new instance of the DatabaseCopyViewModel
/// </summary>
/// <param name="view"></param>
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
/// <param name="eventAggregator">The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other.</param>
/// <param name="unityContainer">The unityContainer.</param>
public DatabaseSwitchViewModel(IDatabaseSwitchView view, IRegionManager regionManager,
IEventAggregator eventAggregator, IUnityContainer unityContainer)
{
View = view;
View.DataContext = this;
NotificationRequest = new InteractionRequest<Notification>();
ConfirmationRequest = new InteractionRequest<Confirmation>();
_eventAggregator = eventAggregator;
UnityContainer = unityContainer;
_eventAggregator.GetEvent<RaiseNotification>().Subscribe(OnRaiseNotification);
_eventAggregator.GetEvent<BusyIndicatorChangeNotification>()
.Subscribe(OnBusyIndicatorNotification, ThreadOption.PublisherThread, true);
}
#endregion
#region Methods
public void Unset()
{
}
public void Cleanup()
{
}
public Task CleanupAsync()
{
return Task.CompletedTask;
}
public void Initialize()
{
}
public void Initialize(object parameter)
{
}
public void Initialize(object parameter, object model)
{
}
public Task InitializeAsync()
{
return Task.CompletedTask;
}
public Task InitializeAsync(object parameter)
{
return Task.CompletedTask;
}
public void Activated()
{
}
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnBusyIndicatorNotification(bool eventArg)
{
IsBusy = eventArg;
}
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
{
// The NotificationRequest.Raise triggers the Invoke() method of the PopupWindowAction object to show the NotificationWindow window
// Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string.
var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message, "",
eventArgsWithTitle.Image, string.Empty);
NotificationRequest.Raise(new Notification
{
Content = eventArgsWithoutTitle,
Title = eventArgsWithTitle.Title
});
}
public void SwitchRemote()
{
_eventAggregator.GetEvent<AppStatusEvent>().Publish(AppStatusArg.Busy);
try
{
DTS.Common.Storage.DatabaseServices.SetupForRemoteDb(DbHost, NTLMAuthentication, DbUser, DbPassword, DefaultDbName);
if (!DTS.Common.Storage.DatabaseServices.SimpleDbTest())
{
_eventAggregator.GetEvent<DbStatusEvent>().Publish(
new DbStatusArg(DbStatusArg.EventTypes.FailedToConnectToRemote, null));
SwitchLocal();
return;
}
}
catch (Exception ex)
{
_eventAggregator.GetEvent<DbStatusEvent>()
.Publish(new DbStatusArg(DbStatusArg.EventTypes.FailedToConnectToRemote, ex));
APILogger.Log(ex);
SwitchLocal();
return;
}
OnPropertyChanged("RemoteIsActive");
_eventAggregator.GetEvent<DbStatusEvent>().Publish(new DbStatusArg(DbStatusArg.EventTypes.LegacyStatus, null));
_eventAggregator.GetEvent<AppStatusEvent>().Publish(AppStatusArg.Available);
//http://manuscript.dts.local/f/cases/39203/Local-mode-interacts-with-central-db
//we are switching to a different database connection, make sure we make the user log in again
//we aren't guaranteed the user details are sync'd between local and remote
_eventAggregator.GetEvent<LogoutUserEvent>().Publish(new LogoutUserArg(LogoutUserArg.Reasons.DatabaseSwitch));
}
public void SwitchLocal()
{
try
{
DTS.Common.Utils.Database.CheckLocalDatabaseFilesExist(DefaultDbName, DTS.Common.Storage.DatabaseServices.LOCAL_DB_FOLDER);
}
catch (System.IO.FileNotFoundException ex)
{
_eventAggregator.GetEvent<PageErrorEvent>().Publish(new PageErrorArg(new[] { Resources.StringResources.SwitchFileNotFound, ex.Message }, null));
return;
}
_eventAggregator.GetEvent<AppStatusEvent>().Publish(AppStatusArg.Busy);
DTS.Common.Storage.DatabaseServices.SetupLocal(DefaultDbName);
OnPropertyChanged("RemoteIsActive");
_eventAggregator.GetEvent<DbStatusEvent>().Publish(new DbStatusArg(DbStatusArg.EventTypes.LegacyStatus, null));
_eventAggregator.GetEvent<AppStatusEvent>().Publish(AppStatusArg.Available);
_eventAggregator.GetEvent<LogoutUserEvent>()
.Publish(new LogoutUserArg(LogoutUserArg.Reasons.DatabaseSwitch));
}
public void InitializeDbSettings(string defaultDbName, string dbHost, bool ntlmAuthentication, string dbUser,
string dbPassword)
{
DefaultDbName = defaultDbName;
DbHost = dbHost;
NTLMAuthentication = ntlmAuthentication;
DbUser = dbUser;
DbPassword = dbPassword;
}
#endregion
#region Properties
public string DefaultDbName
{
get;
private set;
}
public bool RemoteIsActive => DbOperations._usingCentralizedDB;
public bool IsDirty { get; private set; }
private bool _isBusy = false;
public bool IsBusy
{
get => _isBusy;
set
{
_isBusy = value;
OnPropertyChanged("IsBusy");
}
}
private bool _isMenuIncluded;
public bool IsMenuIncluded
{
get => _isMenuIncluded;
set
{
_isMenuIncluded = value;
OnPropertyChanged("IsMenuIncluded");
}
}
private bool _isNavigationIncluded;
public bool IsNavigationIncluded
{
get => _isNavigationIncluded;
set
{
_isNavigationIncluded = value;
OnPropertyChanged("IsNavigationIncluded");
}
}
public string DbHost { get; private set; }
public bool NTLMAuthentication { get; private set; }
public string DbUser { get; private set; }
public string DbPassword { get; private set; }
#endregion Properties
#region Commands
#endregion
}
}

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = "")]

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]