GetConnectionKey() public static method

public static GetConnectionKey ( Row row ) : string
row Row
return string
        static StaticInfo EnsureInfo()
        {
            var newInfo = info;

            if (newInfo != null)
            {
                return(newInfo);
            }

            var logTableAttr = typeof(TRow).GetCustomAttribute <CaptureLogAttribute>(false);

            if (logTableAttr == null || logTableAttr.LogTable.IsTrimmedEmpty())
            {
                throw new InvalidOperationException(String.Format("{0} row type has no capture log table attribute defined!", typeof(TRow).Name));
            }

            schemaName = RowRegistry.GetConnectionKey(typeof(TRow));
            var instance = RowRegistry.GetConnectionRow(schemaName, logTableAttr.LogTable);

            if (instance == null)
            {
                throw new InvalidOperationException(String.Format("Can't locate {0} capture log table in schema {1} for {2} row type!",
                                                                  logTableAttr.LogTable, schemaName, typeof(TRow).Name));
            }

            var captureLogRow = instance as ICaptureLogRow;

            if (captureLogRow == null)
            {
                throw new InvalidOperationException(String.Format("Capture log table {0} doesn't implement ICaptureLogRow interface!",
                                                                  logTableAttr.LogTable, schemaName, typeof(TRow).Name));
            }

            if (!(captureLogRow is IIsActiveRow))
            {
                throw new InvalidOperationException(String.Format("Capture log table {0} doesn't implement IIsActiveRow interface!",
                                                                  logTableAttr.LogTable, schemaName, typeof(TRow).Name));
            }

            newInfo = new StaticInfo();
            newInfo.logRowInstance       = instance;
            newInfo.captureLogInstance   = captureLogRow;
            newInfo.rowInstance          = new TRow();
            newInfo.rowFieldPrefixLength = PrefixHelper.DeterminePrefixLength(newInfo.rowInstance.EnumerateTableFields(), x => x.Name);
            newInfo.logFieldPrefixLength = PrefixHelper.DeterminePrefixLength(instance.EnumerateTableFields(), x => x.Name);
            newInfo.mappedIdField        = ((Row)captureLogRow).FindField(logTableAttr.MappedIdField) as IIdField;
            if (newInfo.mappedIdField == null)
            {
                throw new InvalidOperationException(String.Format("Can't locate capture log table mapped ID field for {0}!",
                                                                  ((Row)captureLogRow).Table));
            }

            info = newInfo;
            return(newInfo);
        }
Example #2
0
        static StaticInfo EnsureInfo()
        {
            var newInfo = info;

            if (newInfo != null)
            {
                return(newInfo);
            }

            var localAttr = typeof(TRow).GetCustomAttribute <LocalizationRowAttribute>(false);

            if (localAttr == null || localAttr.LocalizationTable.IsTrimmedEmpty())
            {
                throw new InvalidOperationException(String.Format("{0} row type has no localization attribute defined!", typeof(TRow).Name));
            }

            schemaName = RowRegistry.GetConnectionKey(typeof(TRow));
            var localInstance = RowRegistry.GetConnectionRow(schemaName, localAttr.LocalizationTable);

            if (localInstance == null)
            {
                throw new InvalidOperationException(String.Format("Can't locate {0} localization table in schema {1} for {2} row type!",
                                                                  localAttr.LocalizationTable, schemaName, typeof(TRow).Name));
            }

            var localRow = localInstance as ILocalizationRow;

            if (localRow == null)
            {
                throw new InvalidOperationException(String.Format("Localization table {0} doesn't implement ILocalizationRow interface!",
                                                                  localAttr.LocalizationTable, schemaName, typeof(TRow).Name));
            }


            newInfo = new StaticInfo();
            newInfo.localRowInterface         = localRow;
            newInfo.localRowInstance          = localInstance;
            newInfo.rowInstance               = new TRow();
            newInfo.rowFieldPrefixLength      = PrefixHelper.DeterminePrefixLength(newInfo.rowInstance.EnumerateTableFields(), x => x.Name);
            newInfo.localRowFieldPrefixLength = PrefixHelper.DeterminePrefixLength(localInstance.EnumerateTableFields(), x => x.Name);
            newInfo.mappedIdField             = (IIdField)((Row)localInstance).FindField(localAttr.MappedIdField);
            if (newInfo.mappedIdField == null)
            {
                throw new InvalidOperationException(String.Format("Can't locate localization table mapped ID field for {0}!",
                                                                  localInstance.Table));
            }

            info = newInfo;
            return(newInfo);
        }