コード例 #1
0
ファイル: VersionManager.cs プロジェクト: eyedia/idpe
        public IdpeVersion GetCurrentVersion(VersionObjectTypes versionObjectType, int referenceId)
        {
            IdpeVersion currentVersion = new IdpeVersion();

            currentVersion.Type = (int)versionObjectType;
            if (versionObjectType == VersionObjectTypes.DataSource)
            {
                DataSourceBundle dsb        = new DataSourceBundle();
                string           serialized = dsb.Export(referenceId, false);
                currentVersion.Data      = new System.Data.Linq.Binary(GZipArchive.Compress(serialized.GetByteArray()));
                currentVersion.CreatedBy = dsb.DataSource.CreatedBy;
                currentVersion.CreatedTS = (DateTime) new Manager().GetDataSourceLastUpdatedTime(referenceId);
                currentVersion.Source    = dsb.DataSource.Source;
            }
            else if (versionObjectType == VersionObjectTypes.Rule)
            {
                IdpeRule rule = new Manager().GetRule(referenceId);
                if (rule == null)
                {
                    return(null);
                }

                DataSourcePatch patch = new DataSourcePatch();
                patch.Rules.Add(rule);
                currentVersion.Data      = new System.Data.Linq.Binary(GZipArchive.Compress(patch.Export().GetByteArray()));
                currentVersion.CreatedBy = rule.CreatedBy;
                currentVersion.CreatedTS = rule.CreatedTS;
                currentVersion.Source    = rule.Source;
            }
            return(currentVersion);
        }
コード例 #2
0
ファイル: VersionControl.cs プロジェクト: eyedia/idpe
        private void compareToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (compareToolStripMenuItem.Text == __Compare)
            {
                if (lvwVersions.SelectedItems.Count == 2)
                {
                    VersionComparer.Compare(VersionObjectType, ObjectName, (IdpeVersion)lvwVersions.SelectedItems[0].Tag, (IdpeVersion)lvwVersions.SelectedItems[1].Tag);
                }
            }
            else if (compareToolStripMenuItem.Text == __SetToTheVersion)
            {
                if (lvwVersions.SelectedItems.Count == 1)
                {
                    IdpeVersion version = lvwVersions.SelectedItems[0].Tag as IdpeVersion;
                    if (MessageBox.Show(string.Format("Are you sure you want to revert '{0}' to Version {1}?", ObjectName, version.Version)
                                        , "Revert Version", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
                    {
                        try
                        {
                            this.Cursor = Cursors.WaitCursor;
                            switch (VersionObjectType)
                            {
                            case VersionObjectTypes.Attribute:
                                break;

                            case VersionObjectTypes.DataSource:
                                DataSourceBundle dataSourceBundle = VersionComparer.ConvertToSreVersionObject(VersionObjectTypes.DataSource, version) as DataSourceBundle;
                                dataSourceBundle.Import();
                                Reverted = true;
                                break;

                            case VersionObjectTypes.Rule:
                                DataSourcePatch dataSourcePatch = VersionComparer.ConvertToSreVersionObject(VersionObjectTypes.Rule, version) as DataSourcePatch;
                                dataSourcePatch.Import();
                                Reverted = true;
                                break;
                            }
                            //this.Close();
                        }
                        catch (Exception ex)
                        {
                            //toolStripStatusLabel1.Text = ex.Message;
                        }
                        finally
                        {
                            this.Cursor = Cursors.Default;
                        }
                    }
                }
            }

            if (Reverted)
            {
                this.ParentForm.DialogResult = DialogResult.OK;
                this.ParentForm.Close();
            }
        }
コード例 #3
0
ファイル: Manager.Version.cs プロジェクト: eyedia/idpe
        private IdpeVersion DataRowToSreVersion(DataRow row)
        {
            IdpeVersion version = new IdpeVersion();

            version.Id          = (int)row["Id"].ToString().ParseInt();
            version.Version     = (int)row["Version"].ToString().ParseInt();
            version.Type        = (int)row["Type"].ToString().ParseInt();
            version.ReferenceId = (int)row["ReferenceId"].ToString().ParseInt();
            version.Data        = new Binary((byte[])row["Data"]);
            version.CreatedBy   = row["CreatedBy"].ToString();
            version.CreatedTS   = (DateTime)row["CreatedTS"].ToString().ParseDateTime();
            version.Source      = row["Source"].ToString();
            return(version);
        }
コード例 #4
0
ファイル: Manager.Version.cs プロジェクト: eyedia/idpe
        private void ValidateVersion(IdpeVersion version)
        {
            string allErrors = string.Empty;

            if (version.Type == (int)VersionObjectTypes.Unknown)
            {
                allErrors += "Version type cannot be unknown!" + Environment.NewLine;
            }

            if (version.ReferenceId == 0)
            {
                allErrors += "Version must have a reference Id!" + Environment.NewLine;
            }
            else
            {
                switch ((VersionObjectTypes)version.Type)
                {
                case VersionObjectTypes.Attribute:
                    IdpeAttribute attribute = GetAttribute(version.ReferenceId);
                    if (attribute.AttributeId == 0)
                    {
                        allErrors += "The INSERT statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database, table IdpeAttribute, column 'Id'." + Environment.NewLine;
                    }
                    break;

                case VersionObjectTypes.DataSource:
                    string dataSourceName = GetApplicationName(version.ReferenceId);
                    if (string.IsNullOrEmpty(dataSourceName))
                    {
                        allErrors += "The INSERT statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database, table IdpeDataSource, column 'Id'." + Environment.NewLine;
                    }
                    break;

                case VersionObjectTypes.Rule:
                    IdpeRule rule = GetRule(version.ReferenceId);
                    if (rule.Id == 0)
                    {
                        allErrors += "The INSERT statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database, table IdpeRule, column 'Id'." + Environment.NewLine;
                    }
                    break;
                }
            }

            if (!string.IsNullOrEmpty(allErrors))
            {
                throw new Exception(allErrors);
            }
        }
コード例 #5
0
ファイル: VersionControl.cs プロジェクト: eyedia/idpe
 private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
 {
     if (lvwVersions.SelectedItems.Count == 2)
     {
         compareToolStripMenuItem.Text = __Compare;
         contextMenuStrip1.Enabled     = true;
     }
     else if (lvwVersions.SelectedItems.Count == 1)
     {
         compareToolStripMenuItem.Text = __SetToTheVersion;
         IdpeVersion version = lvwVersions.SelectedItems[0].Tag as IdpeVersion;
         contextMenuStrip1.Enabled = version.Version == 0 ? false : true;
     }
     else
     {
         e.Cancel = true;
     }
 }
コード例 #6
0
ファイル: VersionManager.cs プロジェクト: eyedia/idpe
        public void KeepVersionInternal(Manager manager, VersionObjectTypes versionObjectType, int referenceId)
        {
            if (referenceId == 0)
            {
                return;
            }

            IdpeVersion version = GetCurrentVersion(versionObjectType, referenceId);

            if (version == null)
            {
                return;
            }

            version.Version     = manager.GetLatestVersionNumber(versionObjectType, referenceId) + 1;
            version.Type        = (int)versionObjectType;
            version.ReferenceId = referenceId;

            switch (versionObjectType)
            {
            case VersionObjectTypes.DataSource:
                IdpeDataSource ds = manager.GetDataSourceDetails(referenceId);
                version.Data      = new Binary(GZipArchive.Compress(new DataSourceBundle().Export(referenceId, false).GetByteArray()));
                version.CreatedTS = ds.CreatedTS;
                break;

            case VersionObjectTypes.Rule:
                IdpeRule        rule  = manager.GetRule(referenceId);
                DataSourcePatch patch = new DataSourcePatch();
                patch.Rules.Add(rule);
                version.Data      = new Binary(GZipArchive.Compress(patch.Export().GetByteArray()));
                version.CreatedTS = rule.CreatedTS;
                break;
            }
            manager.Save(version);
        }
コード例 #7
0
ファイル: Manager.Version.cs プロジェクト: eyedia/idpe
        public int Save(IdpeVersion version, IDal dal = null, IDbConnection connection = null, IDbTransaction transaction = null)
        {
            ValidateVersion(version);
            int  versionId        = 0;
            bool localTransaction = false;

            if (dal == null)
            {
                dal        = new DataAccessLayer(EyediaCoreConfigurationSection.CurrentConfig.Database.DatabaseType).Instance;
                connection = dal.CreateConnection(_ConnectionString);
                connection.Open();
                transaction      = dal.CreateTransaction(connection);
                localTransaction = true;
            }
            IDbCommand command = dal.CreateCommand();

            command.Connection  = connection;
            command.Transaction = transaction;

            try
            {
                command.CommandText  = "INSERT INTO [IdpeVersion]([Version], [Type], [ReferenceId], [Data], [CreatedBy], [CreatedTS], [Source]) ";
                command.CommandText += " VALUES (@Version, @Type, @ReferenceId, @Data, @CreatedBy, @CreatedTS, @Source)";
                command.AddParameterWithValue("Version", version.Version);
                command.AddParameterWithValue("Type", version.Type);
                command.AddParameterWithValue("ReferenceId", version.ReferenceId);
                command.AddParameterWithValue("Data", version.Data.ToArray());
                command.AddParameterWithValue("CreatedBy", Information.LoggedInUser != null ? Information.LoggedInUser.UserName : "******");
                command.AddParameterWithValue("CreatedTS", version.CreatedTS);
                command.AddParameterWithValue("Source", GetSource(version.Source));

                command.ExecuteNonQuery();

                //Deb: I know dirty coding, need to be changed. OUTPUT INSERTED.Id not working @SQL CE
                command.Parameters.Clear();
                command.CommandText = "SELECT max(Id) from [IdpeVersion]";
                versionId           = (Int32)command.ExecuteScalar();

                if (localTransaction)
                {
                    transaction.Commit();
                }
            }
            catch (Exception ex)
            {
                if (localTransaction)
                {
                    transaction.Rollback();
                }
                Trace.TraceError(ex.ToString());
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                if (localTransaction)
                {
                    if (connection.State == ConnectionState.Open)
                    {
                        connection.Close();
                    }
                    connection.Dispose();
                    transaction.Dispose();
                }
            }

            return(versionId);
        }
コード例 #8
0
        public static void Compare(VersionObjectTypes versionObjectType, string objectName, IdpeVersion v1, IdpeVersion v2)
        {
            var toolPath = Information.LoggedInUser.GetUserPreferences().ComparisonToolExecutablePath;

            if (!File.Exists(toolPath))
            {
                if (MessageBox.Show("Comparison tool was not set! Do you want to set it now? You can later change it from Tools->Preferences", "Comparison Tool", MessageBoxButtons.YesNo, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
                    == DialogResult.Yes)
                {
                    if (SetComparisonTool())
                    {
                        toolPath = Information.LoggedInUser.GetUserPreferences().ComparisonToolExecutablePath;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }


            string v1file = Path.Combine(Information.TempDirectoryIdpe, objectName + ".v" + (v1.Version == 0? "Current":v1.Version.ToString()));

            new PrintObject().PrintProperties(ConvertToSreVersionObject(versionObjectType, v1), v1file);
            if (v1.Version == 0)
            {
                PatchVerionZero(v1file);
            }


            string v2file = Path.Combine(Information.TempDirectoryIdpe, objectName + ".v" + (v2.Version == 0 ? "Current" : v2.Version.ToString()));

            new PrintObject().PrintProperties(ConvertToSreVersionObject(versionObjectType, v2), v2file);
            if (v2.Version == 0)
            {
                PatchVerionZero(v1file);
            }

            System.Diagnostics.Process p = System.Diagnostics.Process.Start(toolPath, "/r \"" + v1file + "\" \"" + v2file + "\"");
            p.EnableRaisingEvents = false;
            p.WaitForExit();
            p.Close();

            if (File.Exists(v1file))
            {
                File.Delete(v1file);
            }

            if (File.Exists(v2file))
            {
                File.Delete(v2file);
            }
        }
コード例 #9
0
        public static object ConvertToSreVersionObject(VersionObjectTypes versionObjectType, IdpeVersion version)
        {
            object returnObject = null;

            switch (versionObjectType)
            {
            case VersionObjectTypes.Attribute:
                returnObject = new object();
                break;

            case VersionObjectTypes.DataSource:
                returnObject = new DataSourceBundle(null, GZipArchive.Decompress(version.Data.ToArray()).GetString(), version.Version);
                break;

            case VersionObjectTypes.Rule:
                returnObject = new DataSourcePatch(null, GZipArchive.Decompress(version.Data.ToArray()).GetString(), version.Version);
                break;
            }
            return(returnObject);
        }