| @@ -1,122 +1,129 @@ | ||
| using System; | ||
| using System.Data.SqlClient; | ||
| using Microsoft.Synchronization; | ||
| using Microsoft.Synchronization.Data; | ||
| using Microsoft.Synchronization.Data.SqlServer; | ||
|
|
||
| namespace MicrosoftSyncFramework_Server | ||
| { | ||
| class Program | ||
| { | ||
| private static string sServerConnection = @"Data Source=THIM-PC;Initial Catalog=SyncClient;Integrated Security=True";//@"Data Source=Server\MSSQL2008;Initial Catalog=Company;Persist Security Info=False;User ID=sa;Password=password;Connect Timeout=60"; | ||
|
|
||
| private static string sClientConnection = @"Data Source=THIM-PC;Initial Catalog=SyncServer;Integrated Security=True";//@"Data Source=Client\MSSQL2008;Initial Catalog=Company;Persist Security Info=False;User ID=sa;Password=password;Connect Timeout=60"; | ||
|
|
||
| static string sScope = "UsersScope"; | ||
|
|
||
| static DateTime timeNow; | ||
|
|
||
| static void Main(string[] args) | ||
| { | ||
| timeNow = DateTime.Now; | ||
|
|
||
| sScope = sScope + "" + timeNow.ToString(); | ||
|
|
||
| ProvisionServer(); | ||
| ProvisionClient(); | ||
|
|
||
| Sync(); | ||
| } | ||
|
|
||
| public static void ProvisionServer() | ||
|
|
||
| { | ||
|
|
||
| SqlConnection serverConn = new SqlConnection(sServerConnection); | ||
|
|
||
|
|
||
|
|
||
| DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(sScope); | ||
|
|
||
|
|
||
|
|
||
| DbSyncTableDescription tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Users", serverConn); | ||
|
|
||
| scopeDesc.Tables.Add(tableDesc); | ||
|
|
||
|
|
||
|
|
||
| SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc); | ||
|
|
||
| serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip); | ||
|
|
||
|
|
||
|
|
||
| serverProvision.Apply(); | ||
|
|
||
| } | ||
|
|
||
| private static void ProvisionClient() | ||
| { | ||
| SqlConnection serverConn = new SqlConnection(sServerConnection); | ||
|
|
||
| SqlConnection clientConn = new SqlConnection(sClientConnection); | ||
|
|
||
|
|
||
|
|
||
| DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(sScope, serverConn); | ||
|
|
||
| SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc); | ||
|
|
||
|
|
||
|
|
||
| clientProvision.Apply(); | ||
| } | ||
|
|
||
| private static void Sync() | ||
| { | ||
| SqlConnection serverConn = new SqlConnection(sServerConnection); | ||
|
|
||
| SqlConnection clientConn = new SqlConnection(sClientConnection); | ||
|
|
||
|
|
||
|
|
||
| SyncOrchestrator syncOrchestrator = new SyncOrchestrator(); | ||
|
|
||
|
|
||
|
|
||
| syncOrchestrator.LocalProvider = new SqlSyncProvider(sScope, clientConn); | ||
|
|
||
| syncOrchestrator.RemoteProvider = new SqlSyncProvider(sScope, serverConn); | ||
|
|
||
|
|
||
|
|
||
| syncOrchestrator.Direction = SyncDirectionOrder.DownloadAndUpload; | ||
|
|
||
|
|
||
|
|
||
| ((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed); | ||
|
|
||
|
|
||
|
|
||
| SyncOperationStatistics syncStats = syncOrchestrator.Synchronize(); | ||
|
|
||
|
|
||
|
|
||
| Console.WriteLine("Start Time: " + syncStats.SyncStartTime); | ||
|
|
||
| Console.WriteLine("Total Changes Uploaded: " + syncStats.UploadChangesTotal); | ||
|
|
||
| Console.WriteLine("Total Changes Downloaded: " + syncStats.DownloadChangesTotal); | ||
|
|
||
| Console.WriteLine("Complete Time: " + syncStats.SyncEndTime); | ||
|
|
||
| Console.WriteLine(String.Empty); | ||
|
|
||
| Console.ReadLine(); | ||
| } | ||
|
|
||
| static void Program_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e) | ||
|
|
||
| { | ||
|
|
||
| Console.WriteLine(e.Conflict.Type); | ||
|
|
||
| Console.WriteLine(e.Error); | ||
|
|
||
| } | ||
| } | ||
| } |
| @@ -1,36 +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("DatabaseSync")] | ||
| [assembly: AssemblyDescription("")] | ||
| [assembly: AssemblyConfiguration("")] | ||
| [assembly: AssemblyCompany("")] | ||
| [assembly: AssemblyProduct("DatabaseSync")] | ||
| [assembly: AssemblyCopyright("Copyright © 2016")] | ||
| [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("01470333-5f2b-4505-8e74-62f81dddaef2")] | ||
|
|
||
| // 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")] |
| @@ -1,22 +1,38 @@ | ||
| <?xml version='1.0' encoding='utf-8'?> | ||
| <SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="DatabaseSync.Properties" GeneratedClassName="Settings"> | ||
| <Profiles /> | ||
| <Settings> | ||
| <Setting Name="ClientConnectionString" Type="(Connection string)" Scope="Application"> | ||
| <DesignTimeValue Profile="(Default)"><?xml version="1.0" encoding="utf-16"?> | ||
| <SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
| <ConnectionString>Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Client.mdf;Integrated Security=True</ConnectionString> | ||
| <ProviderName>System.Data.SqlClient</ProviderName> | ||
| </SerializableConnectionString></DesignTimeValue> | ||
| <Value Profile="(Default)">Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Client.mdf;Integrated Security=True</Value> | ||
| </Setting> | ||
| <Setting Name="ServerConnectionString" Type="(Connection string)" Scope="Application"> | ||
| <DesignTimeValue Profile="(Default)"><?xml version="1.0" encoding="utf-16"?> | ||
| <SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
| <ConnectionString>Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Server.mdf;Integrated Security=True</ConnectionString> | ||
| <ProviderName>System.Data.SqlClient</ProviderName> | ||
| </SerializableConnectionString></DesignTimeValue> | ||
| <Value Profile="(Default)">Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Server.mdf;Integrated Security=True</Value> | ||
| </Setting> | ||
| <Setting Name="SyncClientConnectionString" Type="(Connection string)" Scope="Application"> | ||
| <DesignTimeValue Profile="(Default)"><?xml version="1.0" encoding="utf-16"?> | ||
| <SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
| <ConnectionString>Data Source=THIM-PC;Initial Catalog=SyncClient;Integrated Security=True</ConnectionString> | ||
| <ProviderName>System.Data.SqlClient</ProviderName> | ||
| </SerializableConnectionString></DesignTimeValue> | ||
| <Value Profile="(Default)">Data Source=THIM-PC;Initial Catalog=SyncClient;Integrated Security=True</Value> | ||
| </Setting> | ||
| <Setting Name="SyncServerConnectionString" Type="(Connection string)" Scope="Application"> | ||
| <DesignTimeValue Profile="(Default)"><?xml version="1.0" encoding="utf-16"?> | ||
| <SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
| <ConnectionString>Data Source=THIM-PC;Initial Catalog=SyncServer;Integrated Security=True</ConnectionString> | ||
| <ProviderName>System.Data.SqlClient</ProviderName> | ||
| </SerializableConnectionString></DesignTimeValue> | ||
| <Value Profile="(Default)">Data Source=THIM-PC;Initial Catalog=SyncServer;Integrated Security=True</Value> | ||
| </Setting> | ||
| </Settings> | ||
| </SettingsFile> |
| @@ -0,0 +1 @@ | ||
|  |
| @@ -0,0 +1,102 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <xs:schema id="SyncClientDataSet" targetNamespace="http://tempuri.org/SyncClientDataSet.xsd" xmlns:mstns="http://tempuri.org/SyncClientDataSet.xsd" xmlns="http://tempuri.org/SyncClientDataSet.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified"> | ||
| <xs:annotation> | ||
| <xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource"> | ||
| <DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource"> | ||
| <Connections> | ||
| <Connection AppSettingsObjectName="Settings" AppSettingsPropertyName="SyncClientConnectionString" ConnectionStringObject="" IsAppSettingsProperty="true" Modifier="Assembly" Name="SyncClientConnectionString (Settings)" ParameterPrefix="@" PropertyReference="ApplicationSettings.DatabaseSync.Properties.Settings.GlobalReference.Default.SyncClientConnectionString" Provider="System.Data.SqlClient" /> | ||
| </Connections> | ||
| <Tables> | ||
| <TableAdapter BaseClass="System.ComponentModel.Component" DataAccessorModifier="AutoLayout, AnsiClass, Class, Public" DataAccessorName="UsersTableAdapter" GeneratorDataComponentClassName="UsersTableAdapter" Name="Users" UserDataComponentName="UsersTableAdapter"> | ||
| <MainSource> | ||
| <DbSource ConnectionRef="SyncClientConnectionString (Settings)" DbObjectName="SyncClient.dbo.Users" DbObjectType="Table" FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both" GenerateShortCommands="true" GeneratorGetMethodName="GetData" GeneratorSourceName="Fill" GetMethodModifier="Public" GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" UseOptimisticConcurrency="true" UserGetMethodName="GetData" UserSourceName="Fill"> | ||
| <DeleteCommand> | ||
| <DbCommand CommandType="Text" ModifiedByUser="false"> | ||
| <CommandText>DELETE FROM [dbo].[Users] WHERE (([Id] = @Original_Id) AND ((@IsNull_First_name = 1 AND [First_name] IS NULL) OR ([First_name] = @Original_First_name)) AND ((@IsNull_Last_name = 1 AND [Last_name] IS NULL) OR ([Last_name] = @Original_Last_name)))</CommandText> | ||
| <Parameters> | ||
| <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Original_Id" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Id" SourceColumnNullMapping="false" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@IsNull_First_name" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="First_name" SourceColumnNullMapping="true" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@Original_First_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="First_name" SourceColumnNullMapping="false" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@IsNull_Last_name" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Last_name" SourceColumnNullMapping="true" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@Original_Last_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="Last_name" SourceColumnNullMapping="false" SourceVersion="Original" /> | ||
| </Parameters> | ||
| </DbCommand> | ||
| </DeleteCommand> | ||
| <InsertCommand> | ||
| <DbCommand CommandType="Text" ModifiedByUser="false"> | ||
| <CommandText>INSERT INTO [dbo].[Users] ([First_name], [Last_name]) VALUES (@First_name, @Last_name); | ||
| SELECT Id, First_name, Last_name FROM Users WHERE (Id = SCOPE_IDENTITY())</CommandText> | ||
| <Parameters> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@First_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="First_name" SourceColumnNullMapping="false" SourceVersion="Current" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@Last_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="Last_name" SourceColumnNullMapping="false" SourceVersion="Current" /> | ||
| </Parameters> | ||
| </DbCommand> | ||
| </InsertCommand> | ||
| <SelectCommand> | ||
| <DbCommand CommandType="Text" ModifiedByUser="false"> | ||
| <CommandText>SELECT Id, First_name, Last_name FROM dbo.Users</CommandText> | ||
| <Parameters /> | ||
| </DbCommand> | ||
| </SelectCommand> | ||
| <UpdateCommand> | ||
| <DbCommand CommandType="Text" ModifiedByUser="false"> | ||
| <CommandText>UPDATE [dbo].[Users] SET [First_name] = @First_name, [Last_name] = @Last_name WHERE (([Id] = @Original_Id) AND ((@IsNull_First_name = 1 AND [First_name] IS NULL) OR ([First_name] = @Original_First_name)) AND ((@IsNull_Last_name = 1 AND [Last_name] IS NULL) OR ([Last_name] = @Original_Last_name))); | ||
| SELECT Id, First_name, Last_name FROM Users WHERE (Id = @Id)</CommandText> | ||
| <Parameters> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@First_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="First_name" SourceColumnNullMapping="false" SourceVersion="Current" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@Last_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="Last_name" SourceColumnNullMapping="false" SourceVersion="Current" /> | ||
| <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Original_Id" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Id" SourceColumnNullMapping="false" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@IsNull_First_name" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="First_name" SourceColumnNullMapping="true" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@Original_First_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="First_name" SourceColumnNullMapping="false" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@IsNull_Last_name" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Last_name" SourceColumnNullMapping="true" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@Original_Last_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="Last_name" SourceColumnNullMapping="false" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="false" AutogeneratedName="Id" ColumnName="Id" DataSourceName="SyncClient.dbo.Users" DataTypeServer="int" DbType="Int32" Direction="Input" ParameterName="@Id" Precision="0" ProviderType="Int" Scale="0" Size="4" SourceColumn="Id" SourceColumnNullMapping="false" SourceVersion="Current" /> | ||
| </Parameters> | ||
| </DbCommand> | ||
| </UpdateCommand> | ||
| </DbSource> | ||
| </MainSource> | ||
| <Mappings> | ||
| <Mapping SourceColumn="Id" DataSetColumn="Id" /> | ||
| <Mapping SourceColumn="First_name" DataSetColumn="First_name" /> | ||
| <Mapping SourceColumn="Last_name" DataSetColumn="Last_name" /> | ||
| </Mappings> | ||
| <Sources /> | ||
| </TableAdapter> | ||
| </Tables> | ||
| <Sources /> | ||
| </DataSource> | ||
| </xs:appinfo> | ||
| </xs:annotation> | ||
| <xs:element name="SyncClientDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:EnableTableAdapterManager="True" msprop:Generator_DataSetName="SyncClientDataSet" msprop:Generator_UserDSName="SyncClientDataSet"> | ||
| <xs:complexType> | ||
| <xs:choice minOccurs="0" maxOccurs="unbounded"> | ||
| <xs:element name="Users" msprop:Generator_TableClassName="UsersDataTable" msprop:Generator_TableVarName="tableUsers" msprop:Generator_TablePropName="Users" msprop:Generator_RowDeletingName="UsersRowDeleting" msprop:Generator_RowChangingName="UsersRowChanging" msprop:Generator_RowEvHandlerName="UsersRowChangeEventHandler" msprop:Generator_RowDeletedName="UsersRowDeleted" msprop:Generator_UserTableName="Users" msprop:Generator_RowChangedName="UsersRowChanged" msprop:Generator_RowEvArgName="UsersRowChangeEvent" msprop:Generator_RowClassName="UsersRow"> | ||
| <xs:complexType> | ||
| <xs:sequence> | ||
| <xs:element name="Id" msdata:ReadOnly="true" msdata:AutoIncrement="true" msdata:AutoIncrementSeed="-1" msdata:AutoIncrementStep="-1" msprop:Generator_ColumnVarNameInTable="columnId" msprop:Generator_ColumnPropNameInRow="Id" msprop:Generator_ColumnPropNameInTable="IdColumn" msprop:Generator_UserColumnName="Id" type="xs:int" /> | ||
| <xs:element name="First_name" msprop:Generator_ColumnVarNameInTable="columnFirst_name" msprop:Generator_ColumnPropNameInRow="First_name" msprop:Generator_ColumnPropNameInTable="First_nameColumn" msprop:Generator_UserColumnName="First_name" minOccurs="0"> | ||
| <xs:simpleType> | ||
| <xs:restriction base="xs:string"> | ||
| <xs:maxLength value="50" /> | ||
| </xs:restriction> | ||
| </xs:simpleType> | ||
| </xs:element> | ||
| <xs:element name="Last_name" msprop:Generator_ColumnVarNameInTable="columnLast_name" msprop:Generator_ColumnPropNameInRow="Last_name" msprop:Generator_ColumnPropNameInTable="Last_nameColumn" msprop:Generator_UserColumnName="Last_name" minOccurs="0"> | ||
| <xs:simpleType> | ||
| <xs:restriction base="xs:string"> | ||
| <xs:maxLength value="50" /> | ||
| </xs:restriction> | ||
| </xs:simpleType> | ||
| </xs:element> | ||
| </xs:sequence> | ||
| </xs:complexType> | ||
| </xs:element> | ||
| </xs:choice> | ||
| </xs:complexType> | ||
| <xs:unique name="Constraint1" msdata:PrimaryKey="true"> | ||
| <xs:selector xpath=".//mstns:Users" /> | ||
| <xs:field xpath="mstns:Id" /> | ||
| </xs:unique> | ||
| </xs:element> | ||
| </xs:schema> |
| @@ -0,0 +1 @@ | ||
|  |
| @@ -0,0 +1 @@ | ||
|  |
| @@ -0,0 +1,102 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <xs:schema id="SyncServerDataSet" targetNamespace="http://tempuri.org/SyncServerDataSet.xsd" xmlns:mstns="http://tempuri.org/SyncServerDataSet.xsd" xmlns="http://tempuri.org/SyncServerDataSet.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified"> | ||
| <xs:annotation> | ||
| <xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource"> | ||
| <DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource"> | ||
| <Connections> | ||
| <Connection AppSettingsObjectName="Settings" AppSettingsPropertyName="SyncServerConnectionString" ConnectionStringObject="" IsAppSettingsProperty="true" Modifier="Assembly" Name="SyncServerConnectionString (Settings)" ParameterPrefix="@" PropertyReference="ApplicationSettings.DatabaseSync.Properties.Settings.GlobalReference.Default.SyncServerConnectionString" Provider="System.Data.SqlClient" /> | ||
| </Connections> | ||
| <Tables> | ||
| <TableAdapter BaseClass="System.ComponentModel.Component" DataAccessorModifier="AutoLayout, AnsiClass, Class, Public" DataAccessorName="UsersTableAdapter" GeneratorDataComponentClassName="UsersTableAdapter" Name="Users" UserDataComponentName="UsersTableAdapter"> | ||
| <MainSource> | ||
| <DbSource ConnectionRef="SyncServerConnectionString (Settings)" DbObjectName="SyncServer.dbo.Users" DbObjectType="Table" FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both" GenerateShortCommands="true" GeneratorGetMethodName="GetData" GeneratorSourceName="Fill" GetMethodModifier="Public" GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" UseOptimisticConcurrency="true" UserGetMethodName="GetData" UserSourceName="Fill"> | ||
| <DeleteCommand> | ||
| <DbCommand CommandType="Text" ModifiedByUser="false"> | ||
| <CommandText>DELETE FROM [dbo].[Users] WHERE (([Id] = @Original_Id) AND ((@IsNull_First_name = 1 AND [First_name] IS NULL) OR ([First_name] = @Original_First_name)) AND ((@IsNull_Last_name = 1 AND [Last_name] IS NULL) OR ([Last_name] = @Original_Last_name)))</CommandText> | ||
| <Parameters> | ||
| <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Original_Id" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Id" SourceColumnNullMapping="false" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@IsNull_First_name" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="First_name" SourceColumnNullMapping="true" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@Original_First_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="First_name" SourceColumnNullMapping="false" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@IsNull_Last_name" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Last_name" SourceColumnNullMapping="true" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@Original_Last_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="Last_name" SourceColumnNullMapping="false" SourceVersion="Original" /> | ||
| </Parameters> | ||
| </DbCommand> | ||
| </DeleteCommand> | ||
| <InsertCommand> | ||
| <DbCommand CommandType="Text" ModifiedByUser="false"> | ||
| <CommandText>INSERT INTO [dbo].[Users] ([First_name], [Last_name]) VALUES (@First_name, @Last_name); | ||
| SELECT Id, First_name, Last_name FROM Users WHERE (Id = SCOPE_IDENTITY())</CommandText> | ||
| <Parameters> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@First_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="First_name" SourceColumnNullMapping="false" SourceVersion="Current" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@Last_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="Last_name" SourceColumnNullMapping="false" SourceVersion="Current" /> | ||
| </Parameters> | ||
| </DbCommand> | ||
| </InsertCommand> | ||
| <SelectCommand> | ||
| <DbCommand CommandType="Text" ModifiedByUser="false"> | ||
| <CommandText>SELECT Id, First_name, Last_name FROM dbo.Users</CommandText> | ||
| <Parameters /> | ||
| </DbCommand> | ||
| </SelectCommand> | ||
| <UpdateCommand> | ||
| <DbCommand CommandType="Text" ModifiedByUser="false"> | ||
| <CommandText>UPDATE [dbo].[Users] SET [First_name] = @First_name, [Last_name] = @Last_name WHERE (([Id] = @Original_Id) AND ((@IsNull_First_name = 1 AND [First_name] IS NULL) OR ([First_name] = @Original_First_name)) AND ((@IsNull_Last_name = 1 AND [Last_name] IS NULL) OR ([Last_name] = @Original_Last_name))); | ||
| SELECT Id, First_name, Last_name FROM Users WHERE (Id = @Id)</CommandText> | ||
| <Parameters> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@First_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="First_name" SourceColumnNullMapping="false" SourceVersion="Current" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@Last_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="Last_name" SourceColumnNullMapping="false" SourceVersion="Current" /> | ||
| <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@Original_Id" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Id" SourceColumnNullMapping="false" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@IsNull_First_name" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="First_name" SourceColumnNullMapping="true" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@Original_First_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="First_name" SourceColumnNullMapping="false" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="@IsNull_Last_name" Precision="0" ProviderType="Int" Scale="0" Size="0" SourceColumn="Last_name" SourceColumnNullMapping="true" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="StringFixedLength" Direction="Input" ParameterName="@Original_Last_name" Precision="0" ProviderType="NChar" Scale="0" Size="0" SourceColumn="Last_name" SourceColumnNullMapping="false" SourceVersion="Original" /> | ||
| <Parameter AllowDbNull="false" AutogeneratedName="Id" ColumnName="Id" DataSourceName="SyncServer.dbo.Users" DataTypeServer="int" DbType="Int32" Direction="Input" ParameterName="@Id" Precision="0" ProviderType="Int" Scale="0" Size="4" SourceColumn="Id" SourceColumnNullMapping="false" SourceVersion="Current" /> | ||
| </Parameters> | ||
| </DbCommand> | ||
| </UpdateCommand> | ||
| </DbSource> | ||
| </MainSource> | ||
| <Mappings> | ||
| <Mapping SourceColumn="Id" DataSetColumn="Id" /> | ||
| <Mapping SourceColumn="First_name" DataSetColumn="First_name" /> | ||
| <Mapping SourceColumn="Last_name" DataSetColumn="Last_name" /> | ||
| </Mappings> | ||
| <Sources /> | ||
| </TableAdapter> | ||
| </Tables> | ||
| <Sources /> | ||
| </DataSource> | ||
| </xs:appinfo> | ||
| </xs:annotation> | ||
| <xs:element name="SyncServerDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:EnableTableAdapterManager="True" msprop:Generator_DataSetName="SyncServerDataSet" msprop:Generator_UserDSName="SyncServerDataSet"> | ||
| <xs:complexType> | ||
| <xs:choice minOccurs="0" maxOccurs="unbounded"> | ||
| <xs:element name="Users" msprop:Generator_TableClassName="UsersDataTable" msprop:Generator_TableVarName="tableUsers" msprop:Generator_TablePropName="Users" msprop:Generator_RowDeletingName="UsersRowDeleting" msprop:Generator_RowChangingName="UsersRowChanging" msprop:Generator_RowEvHandlerName="UsersRowChangeEventHandler" msprop:Generator_RowDeletedName="UsersRowDeleted" msprop:Generator_UserTableName="Users" msprop:Generator_RowChangedName="UsersRowChanged" msprop:Generator_RowEvArgName="UsersRowChangeEvent" msprop:Generator_RowClassName="UsersRow"> | ||
| <xs:complexType> | ||
| <xs:sequence> | ||
| <xs:element name="Id" msdata:ReadOnly="true" msdata:AutoIncrement="true" msdata:AutoIncrementSeed="-1" msdata:AutoIncrementStep="-1" msprop:Generator_ColumnVarNameInTable="columnId" msprop:Generator_ColumnPropNameInRow="Id" msprop:Generator_ColumnPropNameInTable="IdColumn" msprop:Generator_UserColumnName="Id" type="xs:int" /> | ||
| <xs:element name="First_name" msprop:Generator_ColumnVarNameInTable="columnFirst_name" msprop:Generator_ColumnPropNameInRow="First_name" msprop:Generator_ColumnPropNameInTable="First_nameColumn" msprop:Generator_UserColumnName="First_name" minOccurs="0"> | ||
| <xs:simpleType> | ||
| <xs:restriction base="xs:string"> | ||
| <xs:maxLength value="50" /> | ||
| </xs:restriction> | ||
| </xs:simpleType> | ||
| </xs:element> | ||
| <xs:element name="Last_name" msprop:Generator_ColumnVarNameInTable="columnLast_name" msprop:Generator_ColumnPropNameInRow="Last_name" msprop:Generator_ColumnPropNameInTable="Last_nameColumn" msprop:Generator_UserColumnName="Last_name" minOccurs="0"> | ||
| <xs:simpleType> | ||
| <xs:restriction base="xs:string"> | ||
| <xs:maxLength value="50" /> | ||
| </xs:restriction> | ||
| </xs:simpleType> | ||
| </xs:element> | ||
| </xs:sequence> | ||
| </xs:complexType> | ||
| </xs:element> | ||
| </xs:choice> | ||
| </xs:complexType> | ||
| <xs:unique name="Constraint1" msdata:PrimaryKey="true"> | ||
| <xs:selector xpath=".//mstns:Users" /> | ||
| <xs:field xpath="mstns:Id" /> | ||
| </xs:unique> | ||
| </xs:element> | ||
| </xs:schema> |
| @@ -0,0 +1 @@ | ||
|  |
| @@ -1,16 +1,16 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <configuration> | ||
| <configSections> | ||
| </configSections> | ||
| <connectionStrings> | ||
| <add name="DatabaseSync.Properties.Settings.SyncClientConnectionString" | ||
| connectionString="Data Source=THIM-PC;Initial Catalog=SyncClient;Integrated Security=True" | ||
| providerName="System.Data.SqlClient" /> | ||
| <add name="DatabaseSync.Properties.Settings.SyncServerConnectionString" | ||
| connectionString="Data Source=THIM-PC;Initial Catalog=SyncServer;Integrated Security=True" | ||
| providerName="System.Data.SqlClient" /> | ||
| </connectionStrings> | ||
| <startup> | ||
| <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
| </startup> | ||
| </configuration> |
| @@ -1,16 +1,16 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <configuration> | ||
| <configSections> | ||
| </configSections> | ||
| <connectionStrings> | ||
| <add name="DatabaseSync.Properties.Settings.SyncClientConnectionString" | ||
| connectionString="Data Source=THIM-PC;Initial Catalog=SyncClient;Integrated Security=True" | ||
| providerName="System.Data.SqlClient" /> | ||
| <add name="DatabaseSync.Properties.Settings.SyncServerConnectionString" | ||
| connectionString="Data Source=THIM-PC;Initial Catalog=SyncServer;Integrated Security=True" | ||
| providerName="System.Data.SqlClient" /> | ||
| </connectionStrings> | ||
| <startup> | ||
| <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
| </startup> | ||
| </configuration> |
| @@ -1,11 +1,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
| <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> | ||
| <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/> | ||
| <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> | ||
| <security> | ||
| <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> | ||
| <requestedExecutionLevel level="asInvoker" uiAccess="false"/> | ||
| </requestedPrivileges> | ||
| </security> | ||
| </trustInfo> | ||
| </assembly> |
| @@ -1,29 +1,22 @@ | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\DatabaseSync.exe.config | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\DatabaseSync.exe | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\DatabaseSync.pdb | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.Data.dll | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.Data.Server.dll | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.Data.SqlServer.dll | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.Data.SqlServerCe.dll | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.dll | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.Files.dll | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.MetadataStorage.dll | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.SimpleProviders.dll | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.xml | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.Data.xml | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.Data.Server.xml | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.Data.SqlServer.xml | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.Data.SqlServerCe.xml | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.Files.xml | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.MetadataStorage.xml | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\bin\Debug\Microsoft.Synchronization.SimpleProviders.xml | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\obj\Debug\DatabaseSync.csprojResolveAssemblyReference.cache | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\obj\Debug\DatabaseSync.exe | ||
| C:\Users\Heider\Desktop\DBSync-v2\DatabaseSync\DatabaseSync\obj\Debug\DatabaseSync.pdb |
| @@ -1,6 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="Microsoft.SyncFramework" version="2.1.0.2" targetFramework="net452" /> | ||
| <package id="Microsoft.SyncFramework.DatabaseProvider" version="3.1.0.0" targetFramework="net452" /> | ||
| <package id="Microsoft.SyncFramework.ProviderServices" version="2.1.0.0" targetFramework="net452" /> | ||
| </packages> |
| @@ -1,70 +1,70 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Gets uninstall records from the registry. | ||
| .DESCRIPTION | ||
| This function returns information similar to the "Add or remove programs" | ||
| Windows tool. The function normally works much faster and gets some more | ||
| information. | ||
| Another way to get installed products is: Get-WmiObject Win32_Product. But | ||
| this command is usually slow and it returns only products installed by | ||
| Windows Installer. | ||
| x64 notes. 32 bit process: this function does not get installed 64 bit | ||
| products. 64 bit process: this function gets both 32 and 64 bit products. | ||
| #> | ||
| function Get-Uninstall | ||
| { | ||
| #$path = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | ||
| $path = @( | ||
| 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | ||
| 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | ||
| ) | ||
|
|
||
|
|
||
|
|
||
| # get all data | ||
| Get-ItemProperty $path | ForEach-Object { $_.DisplayName } | ||
|
|
||
| # use only with name and unistall information | ||
| .{process{ if ($_.DisplayName) { $_ } }} | | ||
| # select more or less common subset of properties | ||
| Select-Object DisplayName | | ||
| # and finally sort by name | ||
| Sort-Object DisplayName | ||
| } | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Returns whether a program with the specified display name (case insensitive) is currently installed, by checking for a registry key. | ||
| .DESCRIPTION | ||
| This function checks similar information that is displayed by the "Add or remove programs" | ||
| Windows tool. If it finds an entry with a matching case insensitive display name, it returns true. | ||
| #> | ||
| function Is-Installed($displayname) | ||
| { | ||
| $found = $false | ||
| $(Get-Uninstall | ForEach-Object { | ||
| IF ($_) | ||
| { | ||
| $b = $displayname.ToLower() | ||
| $c = $_.ToLower().StartsWith($b) | ||
| IF ($c) | ||
| { | ||
| $found = $true | ||
| } | ||
| ELSE | ||
| { | ||
| } | ||
| } | ||
| ELSE | ||
| { | ||
| } | ||
| } | ||
| ) | ||
| return $found | ||
| } | ||
|
|
||
| Export-ModuleMember Is-Installed |
| @@ -1,25 +1,25 @@ | ||
| param($installPath, $toolsPath, $package, $project) | ||
|
|
||
| Import-Module (Join-Path $toolsPath commands.psm1) | ||
|
|
||
| # Required Sync Framework Redistributables. | ||
| $requiredRedistributables = @{ | ||
| "microsoft sync framework 2.1 core components (x86) enu" = "x86\Synchronization-v2.1-x86-ENU.msi" | ||
| "microsoft sync framework 2.1 core components (x64) enu" = "x64\Synchronization-v2.1-x64-ENU.msi" | ||
| } | ||
|
|
||
| # Ensure redistributables are installed. | ||
| foreach ($redistributable in $requiredRedistributables.GetEnumerator()) { | ||
| Write-Host "Checking whether $($redistributable.Name) is installed. " | ||
| $isInstalled = $(Is-Installed($redistributable.Name)) | ||
|
|
||
| if(!$isInstalled) | ||
| { | ||
| # TODO: Only run x64 bit version if current environment processor architecture is 64 bit? | ||
| # Run MSI | ||
| $msifilename = join-path $toolsPath "$($redistributable.Value)" | ||
| Write-Host "Installing $($redistributable.Name) from path: $($msifilename)" | ||
| Start-Process -FilePath "$env:systemroot\system32\msiexec.exe" -ArgumentList "/i `"$msifilename`" /qn /passive" -Wait | ||
| } | ||
|
|
||
| } |
| @@ -1,70 +1,70 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Gets uninstall records from the registry. | ||
| .DESCRIPTION | ||
| This function returns information similar to the "Add or remove programs" | ||
| Windows tool. The function normally works much faster and gets some more | ||
| information. | ||
| Another way to get installed products is: Get-WmiObject Win32_Product. But | ||
| this command is usually slow and it returns only products installed by | ||
| Windows Installer. | ||
| x64 notes. 32 bit process: this function does not get installed 64 bit | ||
| products. 64 bit process: this function gets both 32 and 64 bit products. | ||
| #> | ||
| function Get-Uninstall | ||
| { | ||
| #$path = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | ||
| $path = @( | ||
| 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | ||
| 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | ||
| ) | ||
|
|
||
|
|
||
|
|
||
| # get all data | ||
| Get-ItemProperty $path | ForEach-Object { $_.DisplayName } | ||
|
|
||
| # use only with name and unistall information | ||
| .{process{ if ($_.DisplayName) { $_ } }} | | ||
| # select more or less common subset of properties | ||
| Select-Object DisplayName | | ||
| # and finally sort by name | ||
| Sort-Object DisplayName | ||
| } | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Returns whether a program with the specified display name (case insensitive) is currently installed, by checking for a registry key. | ||
| .DESCRIPTION | ||
| This function checks similar information that is displayed by the "Add or remove programs" | ||
| Windows tool. If it finds an entry with a matching case insensitive display name, it returns true. | ||
| #> | ||
| function Is-Installed($displayname) | ||
| { | ||
| $found = $false | ||
| $(Get-Uninstall | ForEach-Object { | ||
| IF ($_) | ||
| { | ||
| $b = $displayname.ToLower() | ||
| $c = $_.ToLower().StartsWith($b) | ||
| IF ($c) | ||
| { | ||
| $found = $true | ||
| } | ||
| ELSE | ||
| { | ||
| } | ||
| } | ||
| ELSE | ||
| { | ||
| } | ||
| } | ||
| ) | ||
| return $found | ||
| } | ||
|
|
||
| Export-ModuleMember Is-Installed |
| @@ -1,25 +1,25 @@ | ||
| param($installPath, $toolsPath, $package, $project) | ||
|
|
||
| Import-Module (Join-Path $toolsPath commands.psm1) | ||
|
|
||
| # Required Sync Framework Redistributables. | ||
| $requiredRedistributables = @{ | ||
| "microsoft sync framework 2.1 database providers (x86) enu" = "x86\DatabaseProviders-v3.1-x86-ENU.msi" | ||
| "microsoft sync framework 2.1 database providers (x64) enu" = "x64\DatabaseProviders-v3.1-x64-ENU.msi" | ||
| } | ||
|
|
||
| # Ensure redistributables are installed. | ||
| foreach ($redistributable in $requiredRedistributables.GetEnumerator()) { | ||
| Write-Host "Checking whether $($redistributable.Name) is installed. " | ||
| $isInstalled = $(Is-Installed($redistributable.Name)) | ||
|
|
||
| if(!$isInstalled) | ||
| { | ||
| # TODO: Only run x64 bit version if current environment processor architecture is 64 bit? | ||
| # Run MSI | ||
| $msifilename = join-path $toolsPath "$($redistributable.Value)" | ||
| Write-Host "Installing $($redistributable.Name) from path: $($msifilename)" | ||
| Start-Process -FilePath "$env:systemroot\system32\msiexec.exe" -ArgumentList "/i `"$msifilename`" /qn /passive" -Wait | ||
| } | ||
|
|
||
| } |
| @@ -1,70 +1,70 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Gets uninstall records from the registry. | ||
| .DESCRIPTION | ||
| This function returns information similar to the "Add or remove programs" | ||
| Windows tool. The function normally works much faster and gets some more | ||
| information. | ||
| Another way to get installed products is: Get-WmiObject Win32_Product. But | ||
| this command is usually slow and it returns only products installed by | ||
| Windows Installer. | ||
| x64 notes. 32 bit process: this function does not get installed 64 bit | ||
| products. 64 bit process: this function gets both 32 and 64 bit products. | ||
| #> | ||
| function Get-Uninstall | ||
| { | ||
| #$path = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | ||
| $path = @( | ||
| 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | ||
| 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | ||
| ) | ||
|
|
||
|
|
||
|
|
||
| # get all data | ||
| Get-ItemProperty $path | ForEach-Object { $_.DisplayName } | ||
|
|
||
| # use only with name and unistall information | ||
| .{process{ if ($_.DisplayName) { $_ } }} | | ||
| # select more or less common subset of properties | ||
| Select-Object DisplayName | | ||
| # and finally sort by name | ||
| Sort-Object DisplayName | ||
| } | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Returns whether a program with the specified display name (case insensitive) is currently installed, by checking for a registry key. | ||
| .DESCRIPTION | ||
| This function checks similar information that is displayed by the "Add or remove programs" | ||
| Windows tool. If it finds an entry with a matching case insensitive display name, it returns true. | ||
| #> | ||
| function Is-Installed($displayname) | ||
| { | ||
| $found = $false | ||
| $(Get-Uninstall | ForEach-Object { | ||
| IF ($_) | ||
| { | ||
| $b = $displayname.ToLower() | ||
| $c = $_.ToLower().StartsWith($b) | ||
| IF ($c) | ||
| { | ||
| $found = $true | ||
| } | ||
| ELSE | ||
| { | ||
| } | ||
| } | ||
| ELSE | ||
| { | ||
| } | ||
| } | ||
| ) | ||
| return $found | ||
| } | ||
|
|
||
| Export-ModuleMember Is-Installed |
| @@ -1,25 +1,25 @@ | ||
| param($installPath, $toolsPath, $package, $project) | ||
|
|
||
| Import-Module (Join-Path $toolsPath commands.psm1) | ||
|
|
||
| # Required Sync Framework Redistributables. | ||
| $requiredRedistributables = @{ | ||
| "microsoft sync framework 2.1 provider services (x86) enu" = "x86\ProviderServices-v2.1-x86-ENU.msi" | ||
| "microsoft sync framework 2.1 provider services (x64) enu" = "x64\ProviderServices-v2.1-x64-ENU.msi" | ||
| } | ||
|
|
||
| # Ensure redistributables are installed. | ||
| foreach ($redistributable in $requiredRedistributables.GetEnumerator()) { | ||
| Write-Host "Checking whether $($redistributable.Name) is installed. " | ||
| $isInstalled = $(Is-Installed($redistributable.Name)) | ||
|
|
||
| if(!$isInstalled) | ||
| { | ||
| # TODO: Only run x64 bit version if current environment processor architecture is 64 bit? | ||
| # Run MSI | ||
| $msifilename = join-path $toolsPath "$($redistributable.Value)" | ||
| Write-Host "Installing $($redistributable.Name) from path: $($msifilename)" | ||
| Start-Process -FilePath "$env:systemroot\system32\msiexec.exe" -ArgumentList "/i `"$msifilename`" /qn /passive" -Wait | ||
| } | ||
|
|
||
| } |