示例#1
0
        /// <summary>
        ///     Updates the column index on the row with the value when the original value and the specified
        ///     <paramref name="value" /> are different.
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="index">The index of the field.</param>
        /// <param name="value">The value for the field.</param>
        /// <param name="equalityComparer">
        ///     The equality comparer to use to determine whether or not values are equal.
        ///     If null, the default equality comparer for object is used.
        /// </param>
        /// <returns>
        ///     Returns a <see cref="bool" /> representing <c>true</c> when the row updated; otherwise <c>false</c>
        /// </returns>
        /// <exception cref="IndexOutOfRangeException"></exception>
        private static bool Update <TValue>(this IRowBuffer source, int index, TValue value, IEqualityComparer <TValue> equalityComparer)
        {
            bool pendingChanges = true;

            if (equalityComparer != null)
            {
                IRowChanges rowChanges    = (IRowChanges)source;
                object      originalValue = rowChanges.OriginalValue[index];

                TValue oldValue = TypeCast.Cast(originalValue, default(TValue));
                pendingChanges = !equalityComparer.Equals(oldValue, value);
            }

            if (pendingChanges)
            {
                if (Equals(value, default(TValue)) && source.Fields.Field[index].IsNullable)
                {
                    source.Value[index] = DBNull.Value;
                }
                else
                {
                    source.Value[index] = value;
                }
            }

            return(pendingChanges);
        }
示例#2
0
        /// <summary>
        ///     Returns the property value with the specified property name (if it exists), otherwise the fallback value is
        ///     returned.
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="source">The propset.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="fallbackValue">The fallback value.</param>
        /// <returns>
        ///     Returns the <see cref="object" /> casted to the specified
        ///     <param ref="TValue" />
        ///     for the property.
        /// </returns>
        public static TValue GetValue <TValue>(this IMMWMSPropertySet source, string propertyName, TValue fallbackValue)
        {
            if (source == null || !source.Exists(propertyName))
            {
                return(fallbackValue);
            }

            return(TypeCast.Cast(source.GetProperty(propertyName), fallbackValue));
        }
示例#3
0
        public User GetByUsername(string username)
        {
            TblUsers user;

            using (var imisContext = new ImisDB())
            {
                user = imisContext.TblUsers.Where(u => u.LoginName == username).FirstOrDefault();
            }
            return(TypeCast.Cast <User>(user));
        }
示例#4
0
 /// <summary>
 ///     Creates an <see cref="IEnumerable{T}" /> from an <see cref="ICodedValueDomain" />
 /// </summary>
 /// <param name="source">An <see cref="ICodedValueDomain" /> to create an <see cref="IEnumerable{T}" /> from.</param>
 /// <returns>An <see cref="IEnumerable{T}" /> that contains the domain from the input source.</returns>
 public static IEnumerable <KeyValuePair <string, string> > AsEnumerable(this ICodedValueDomain source)
 {
     if (source != null)
     {
         for (int i = 0; i < source.CodeCount; i++)
         {
             yield return(new KeyValuePair <string, string>(source.Name[i], TypeCast.Cast(source.Value[i], string.Empty)));
         }
     }
 }
示例#5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="IntermediateRow" /> struct.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="relClass">The relationship class.</param>
        public IntermediateRow(IRow row, IRelationshipClass relClass)
        {
            this.Row   = row;
            this.Items = new Dictionary <string, object>();

            ITable table = (ITable)relClass;

            this.OriginForeignKey      = TypeCast.Cast(row.get_Value(table.FindField(relClass.OriginForeignKey)), string.Empty);
            this.DestinationForeignKey = TypeCast.Cast(row.get_Value(table.FindField(relClass.DestinationForeignKey)), string.Empty);
        }
示例#6
0
        public async Task <User> GetByUsernameAsync(string username)
        {
            TblUsers user;

            using (var imisContext = new ImisDB())
            {
                user = await imisContext.TblUsers.Where(u => u.LoginName == username).FirstOrDefaultAsync();
            }
            return(TypeCast.Cast <User>(user));
        }
示例#7
0
        /// <summary>
        ///     Gets the configuration value that is stored in the MM_PX_CONFIG table and converts the value to the specified type.
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="source">The helper application reference.</param>
        /// <param name="configName">Name of the configuration.</param>
        /// <param name="fallbackValue">The fallback value.</param>
        /// <returns>
        ///     Returns an object representing the configuration value.
        /// </returns>
        public static TValue GetConfigValue <TValue>(this IMMPxHelper2 source, string configName, TValue fallbackValue)
        {
            if (source == null)
            {
                return(default(TValue));
            }

            object configValue = source.GetConfigValue(configName);

            return(TypeCast.Cast(configValue, fallbackValue));
        }
示例#8
0
        /// <summary>
        ///     Retrieves a single value (for example, an aggregate value) from a database using the specified
        ///     <paramref name="commandText" /> statement.
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="commandText">The command text.</param>
        /// <returns>
        ///     The value from the statement.
        /// </returns>
        public static TValue ExecuteScalar <TValue>(this DbConnection source, string commandText)
        {
            // Create a new select command for the connection.
            using (DbCommand cmd = source.CreateCommand())
            {
                cmd.CommandText = commandText;
                cmd.CommandType = CommandType.Text;

                return(TypeCast.Cast(cmd.ExecuteScalar(), default(TValue)));
            }
        }
示例#9
0
        /// <summary>
        ///     Implementation of Auto Updater Execute Ex method for derived classes.
        /// </summary>
        /// <param name="obj">The object that triggered the Auto Udpater.</param>
        /// <param name="eAUMode">The auto updater mode.</param>
        /// <param name="editEvent">The edit event.</param>
        /// <exception cref="NotSupportedException">
        ///     The sequence generator is only supported on an ORACLE workspace (remote
        ///     geodatabase).
        /// </exception>
        /// <exception cref="ArgumentNullException">obj;@The field model name is not assigned on the object.</exception>
        /// <remarks>
        ///     This method will be called from IMMSpecialAUStrategy::ExecuteEx
        ///     and is wrapped within the exception handling for that method.
        /// </remarks>
        protected override void InternalExecute(IObject obj, mmAutoUpdaterMode eAUMode, mmEditEvent editEvent)
        {
            if (obj == null)
            {
                return;
            }

            IDataset   dataset   = (IDataset)obj.Class;
            IWorkspace workspace = dataset.Workspace;

            if (workspace.IsDBMS(DBMS.Oracle))
            {
                throw new NotSupportedException("The sequence generator is only supported on an ORACLE workspace (remote geodatabase).");
            }

            string fieldName = obj.Class.GetFieldName(_FieldModelName);

            if (string.IsNullOrEmpty(fieldName))
            {
                throw new ArgumentNullException("obj", @"The field model name is not assigned on the object.");
            }

            // Create a queryDef from the feature workspace
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
            IQueryDef         queryDef         = featureWorkspace.CreateQueryDef();

            // Set the query def to point to the sequence
            queryDef.SubFields = _SequenceName + ".NEXTVAL";
            queryDef.Tables    = "SYS.DUAL";

            // Define a cursor and row, for destroy in finally
            using (ComReleaser cr = new ComReleaser())
            {
                // Fill the cursor via the query def
                ICursor cursor = queryDef.Evaluate();
                cr.ManageLifetime(cursor);

                // Now get the row from the cursor
                IRow row = cursor.NextRow();
                if (row == null)
                {
                    return;
                }

                // Store the formatted value if it's configured.
                int    val            = TypeCast.Cast(row.get_Value(0), -1);
                string formattedValue = this.Format(val, obj);

                int pos = obj.Class.FindField(fieldName);
                obj.set_Value(pos, formattedValue);
            }
        }
示例#10
0
        /// <summary>
        ///     Returns the field value that at the specified <paramref name="index" /> for the <paramref name="source" />.
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="source">The row.</param>
        /// <param name="index">The index.</param>
        /// <param name="fallbackValue">The default value.</param>
        /// <returns>
        ///     Returns an <see cref="object" /> representing the converted value to the specified type.
        /// </returns>
        /// <exception cref="IndexOutOfRangeException"></exception>
        public static TValue GetValue <TValue>(this IRowBuffer source, int index, TValue fallbackValue)
        {
            if (source == null)
            {
                return(fallbackValue);
            }
            if (index < 0 || index > source.Fields.FieldCount - 1)
            {
                throw new IndexOutOfRangeException();
            }

            return(TypeCast.Cast(source.Value[index], fallbackValue));
        }
        /// <summary>
        /// Get user by username and password by asychronious call
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <User> GetByUsernameAndPasswordAsync(string username, string password)
        {
            TblUsers user;

            using (var imisContext = new ImisDB())
            {
                var userParameter     = new SqlParameter("user", username);
                var passwordParameter = new SqlParameter("password", password);

                user = await imisContext.TblUsers.FromSql(GetByUsernameAndPasswordSQL(), userParameter, passwordParameter).SingleOrDefaultAsync();
            }
            return(TypeCast.Cast <User>(user));
        }
示例#12
0
        /// <summary>
        ///     Gets the value from the property set that has the given <paramref name="name" />.
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="source">The property set.</param>
        /// <param name="name">The name.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns>
        ///     Returns the value for the property with the specified name; otherwise the <paramref name="defaultValue" /> will be
        ///     returned.
        /// </returns>
        public static TValue GetProperty <TValue>(this IPropertySet source, string name, TValue defaultValue)
        {
            if (source != null)
            {
                foreach (var entry in source.AsEnumerable())
                {
                    if (string.Equals(name, entry.Key, StringComparison.CurrentCultureIgnoreCase))
                    {
                        return(TypeCast.Cast(entry.Value, defaultValue));
                    }
                }
            }

            return(defaultValue);
        }
示例#13
0
        /// <summary>
        ///     Executes the given statement which is usually an Insert, Update or Delete statement and returns the number of rows
        ///     affected.
        /// </summary>
        /// <param name="source">The process application reference.</param>
        /// <param name="commandText">The command text.</param>
        /// <returns>
        ///     Returns a <see cref="int" /> representing the number of rows affected.
        /// </returns>
        /// <exception cref="ArgumentNullException">commandText</exception>
        public static int ExecuteNonQuery(this IMMPxApplication source, string commandText)
        {
            if (source == null)
            {
                return(-1);
            }
            if (commandText == null)
            {
                throw new ArgumentNullException("commandText");
            }

            object recordsEffected;

            source.Connection.Execute(commandText, out recordsEffected, (int)CommandTypeEnum.adCmdText | (int)ExecuteOptionEnum.adExecuteNoRecords);

            return(TypeCast.Cast(recordsEffected, -1));
        }
示例#14
0
        /// <summary>
        /// Get user by username and password by asychronious call
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <User> GetByUsernameAndPasswordAsync(string username, string password)
        {
            TblUsers user;

            using (var imisContext = new ImisDB())
            {
                user = await imisContext.TblUsers.Where(u => u.LoginName == username).FirstOrDefaultAsync();

                if (user != null)
                {
                    if (!ValidateLogin(user.StoredPassword, user.PrivateKey, password))
                    {
                        user = null;
                    }
                }
            }
            return(TypeCast.Cast <User>(user));
        }
示例#15
0
        /// <summary>
        ///     Creates record in the intermediate table for the relationship that is linked to the
        ///     <paramref name="originObject" /> and <paramref name="destinationObject" />.
        /// </summary>
        /// <param name="originObject">The origin object.</param>
        /// <param name="destinationObject">The destination object.</param>
        /// <returns>
        ///     Returns the <see cref="IntermediateRow" /> struct for the new row.
        /// </returns>
        public IIntermediateRow Create(IObject originObject, IObject destinationObject)
        {
            int originPrimaryIndex      = originObject.Fields.FindField(this.RelationshipClass.OriginPrimaryKey);
            int destinationPrimaryIndex = destinationObject.Fields.FindField(this.RelationshipClass.DestinationPrimaryKey);

            string originForeignKey      = TypeCast.Cast(originObject.get_Value(originPrimaryIndex), string.Empty);
            string destinationForeignKey = TypeCast.Cast(destinationObject.get_Value(destinationPrimaryIndex), string.Empty);

            ITable table = (ITable)this.RelationshipClass;
            int    originForeignIndex      = table.Fields.FindField(this.RelationshipClass.OriginForeignKey);
            int    destinationForeignIndex = table.Fields.FindField(this.RelationshipClass.DestinationForeignKey);

            IRow row = table.CreateRow();

            row.set_Value(originForeignIndex, originForeignKey);
            row.set_Value(destinationForeignIndex, destinationForeignKey);

            return(GetRow(row));
        }
示例#16
0
        /// <summary>
        ///     Retrieves a single value (for example, an aggregate value) from a database.
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="source">The process application reference.</param>
        /// <param name="commandText">The command text.</param>
        /// <param name="fallbackValue">The fallback value.</param>
        /// <returns>
        ///     Returns an <see cref="object" /> representing the results of the single value from the database, or the fallback
        ///     value.
        /// </returns>
        /// <exception cref="ArgumentNullException">commandText</exception>
        public static TValue ExecuteScalar <TValue>(this IMMPxApplication source, string commandText, TValue fallbackValue)
        {
            if (source == null)
            {
                return(fallbackValue);
            }
            if (commandText == null)
            {
                throw new ArgumentNullException("commandText");
            }

            TValue value      = fallbackValue;
            object parameters = Type.Missing;

            Command command = new CommandClass();

            command.ActiveConnection = source.Connection;
            command.CommandType      = CommandTypeEnum.adCmdText;
            command.CommandText      = commandText;

            var table = new DataTable();

            table.Locale = CultureInfo.InvariantCulture;

            using (var cr = new ComReleaser())
            {
                object    recordsAffected;
                Recordset recordset = command.Execute(out recordsAffected, ref parameters, (int)CommandTypeEnum.adCmdText);
                cr.ManageLifetime(recordset);

                var adapter = new OleDbDataAdapter();
                adapter.Fill(table, recordset);
                recordset.Close();

                if (table.Rows.Count == 1 && table.Columns.Count == 1)
                {
                    value = TypeCast.Cast(table.Rows[0][0], fallbackValue);
                }
            }

            return(value);
        }
示例#17
0
        /// <summary>
        ///     Returns the field value that has been assigned the <paramref name="modelName" /> that is within the specified
        ///     <paramref name="source" />.
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="source">The row.</param>
        /// <param name="modelName">Name of the model.</param>
        /// <param name="fallbackValue">The default value.</param>
        /// <param name="throwException">
        ///     if set to <c>true</c> if an exception should be thrown when the model name is not
        ///     assigned.
        /// </param>
        /// <returns>
        ///     Returns an <see cref="object" /> representing the converted value to the specified type.
        /// </returns>
        /// <exception cref="ArgumentNullException">modelName</exception>
        /// <exception cref="IndexOutOfRangeException"></exception>
        /// <exception cref="MissingFieldModelNameException"></exception>
        public static TValue GetValue <TValue>(this IRow source, string modelName, TValue fallbackValue, bool throwException)
        {
            if (source == null)
            {
                return(fallbackValue);
            }
            if (modelName == null)
            {
                throw new ArgumentNullException("modelName");
            }

            int index = source.Table.GetFieldIndex(modelName, throwException);

            if (index == -1)
            {
                throw new IndexOutOfRangeException();
            }

            return(TypeCast.Cast(source.Value[index], fallbackValue));
        }
示例#18
0
        /// <summary>
        ///     Updates the column index on the row with the value when the original value and the specified
        ///     <paramref name="value" /> are different.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="index">The index of the field.</param>
        /// <param name="value">The value for the field.</param>
        /// <param name="equalityCompare">if set to <c>true</c> when the changes need to be compared prior to updating.</param>
        /// <returns>
        ///     Returns a <see cref="bool" /> representing <c>true</c> when the row updated; otherwise <c>false</c>
        /// </returns>
        /// <exception cref="IndexOutOfRangeException"></exception>
        public static bool Update(this IRowBuffer source, int index, object value, bool equalityCompare)
        {
            if (source == null)
            {
                return(false);
            }
            if (index < 0 || index > source.Fields.FieldCount - 1)
            {
                throw new IndexOutOfRangeException();
            }

            if (equalityCompare)
            {
                switch (source.Fields.Field[index].Type)
                {
                case esriFieldType.esriFieldTypeOID:
                case esriFieldType.esriFieldTypeInteger:
                    return(source.Update(index, TypeCast.Cast(value, default(long)), EqualityComparer <long> .Default));

                case esriFieldType.esriFieldTypeSmallInteger:
                    return(source.Update(index, TypeCast.Cast(value, default(int)), EqualityComparer <int> .Default));

                case esriFieldType.esriFieldTypeSingle:
                    return(source.Update(index, TypeCast.Cast(value, default(float)), EqualityComparer <float> .Default));

                case esriFieldType.esriFieldTypeDouble:
                    return(source.Update(index, TypeCast.Cast(value, default(double)), EqualityComparer <double> .Default));

                case esriFieldType.esriFieldTypeString:
                case esriFieldType.esriFieldTypeDate:
                case esriFieldType.esriFieldTypeGUID:
                case esriFieldType.esriFieldTypeGlobalID:
                    return(source.Update(index, TypeCast.Cast(value, default(string)), EqualityComparer <string> .Default));

                default:
                    return(source.Update(index, value, EqualityComparer <object> .Default));
                }
            }

            return(source.Update(index, value, null));
        }
示例#19
0
        /// <summary>
        ///     Finds the value in the domain that matches the specified <paramref name="name" />
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="name">The name.</param>
        /// <param name="fallbackValue">The fallback value.</param>
        /// <returns>
        ///     Returns the value representing the name (or description) otherwise the fallback value is used.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">name</exception>
        public static TValue GetValue <TValue>(this ICodedValueDomain source, string name, TValue fallbackValue)
        {
            if (source == null)
            {
                return(fallbackValue);
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            object o = null;

            foreach (KeyValuePair <string, string> entry in source.AsEnumerable())
            {
                if (entry.Key.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                {
                    o = entry.Value;
                    break;
                }
            }
            return(TypeCast.Cast(o, fallbackValue));
        }
示例#20
0
        /// <summary>
        ///     Gets the registration identifier.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns>Returns a <see cref="int" /> representing the registation identifier.</returns>
        public static int GetRegistrationId(this ITable source)
        {
            if (source == null)
            {
                return(-1);
            }

            string className = ((IDataset)source).Name;
            int    index     = className.IndexOf('.');

            if (index > 0)
            {
                string ownerName = source.GetSchemaName();
                string tableName = source.GetTableName();

                using (var cr = new ComReleaser())
                {
                    IWorkspace workspace    = ((IDataset)source).Workspace;
                    var        fws          = (IFeatureWorkspace)workspace;
                    var        syntax       = (ISQLSyntax)workspace;
                    string     functionName = syntax.GetFunctionName(esriSQLFunctionName.esriSQL_UPPER);

                    IQueryDef queryDef = fws.CreateQueryDef();
                    queryDef.Tables      = "sde.table_registry";
                    queryDef.SubFields   = "registration_id";
                    queryDef.WhereClause = string.Format("{2}(table_name) = {2}('{0}') AND {2}(owner) = {2}('{1}')", tableName, ownerName, functionName);

                    ICursor cursor = queryDef.Evaluate();
                    cr.ManageLifetime(cursor);

                    IRow row = cursor.NextRow();
                    return((row != null) ? TypeCast.Cast(row.Value[0], -1) : -1);
                }
            }

            return(-1);
        }
示例#21
0
        /// <summary>
        ///     Casts an object to the type of the given default value. If the object is null
        ///     or DBNull, the default value specified will be returned. If the object is
        ///     convertible to the type of the default value, the explicit conversion will
        ///     be performed.
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="fallbackValue">The fallback value.</param>
        /// <returns>
        ///     The value of the object cast to the type of the default value.
        /// </returns>
        /// <exception cref="System.InvalidCastException">
        ///     Thrown if the type of the object
        ///     cannot be cast to the type of the default value.
        /// </exception>
        public static TValue Cast <TValue>(this IGPValue source, TValue fallbackValue)
        {
            string value = source.GetAsText();

            return(TypeCast.Cast(value, fallbackValue));
        }
示例#22
0
 /// <summary>
 ///     Gets the value for the configuration parameter at the subtask level.
 /// </summary>
 /// <typeparam name="TValue">The type of the value.</typeparam>
 /// <param name="key">The key.</param>
 /// <param name="defaultValue">The default value.</param>
 /// <returns>
 ///     Returns a value representing the configuration parameter.
 /// </returns>
 protected TValue GetParameter <TValue>(string key, TValue defaultValue)
 {
     return(TypeCast.Cast(this.GetParameter(key), defaultValue));
 }