예제 #1
0
        public async Task <IDataObjectAccess> FindAsync(string dataObjectName, IDictionary <string, string> primaryKeys, params string[] relatedObjects)
        {
            var primaryKeysCollection = new PrimaryKeyCollection();

            foreach (var primaryKey in primaryKeys)
            {
                primaryKeysCollection.Add(primaryKey.Key, primaryKey.Value);
            }

            var fetchArguments = new FetchArguments
            {
                DataObjectType       = dataObjectName,
                PrimaryKeys          = primaryKeysCollection,
                RelatedObjects       = relatedObjects.ToArray(),
                ReturnAccessRights   = true,
                ReturnRequiredFields = true
            };

            using (var objectModelService = CreateServiceClient())
            {
                var result = await objectModelService.FetchAsync(CreateEphorteIdentity(), fetchArguments);

                return(new DataObjectAccess(result.DataObject, result.RequiredFields, result.AccessRights, result.ObjectRights));
            }
        }
        protected FetchArguments GetFetchArguments(string dataObjectName, IDictionary <string, string> primaryKeys, string[] relatedObjects)
        {
#if USE_DTOs
            var primaryKeysCollection = new global::Ephorte.ServiceModel.Contracts.ObjectModel.V3.En.PrimaryKeyCollection();
#else
            var primaryKeysCollection = new PrimaryKeyCollection();
#endif
            foreach (var primaryKey in primaryKeys)
            {
                primaryKeysCollection.Add(primaryKey.Key, primaryKey.Value);
            }

            return(new FetchArguments
            {
                DataObjectName = dataObjectName,
                PrimaryKeys = primaryKeysCollection,
                RelatedObjects = relatedObjects.ToArray(),
                ReturnAccessRights = true,
                ReturnRequiredFields = true
            });
        }
        private static PrimaryKeyCollection CreatePrimaryKeys(DataTable data, ColumnCollection columns)
        {
            var keys = new PrimaryKeyCollection();

            for (var i = 0; i < data.Rows.Count; i++)
            {
                var row = data.Rows[i];

                var key = new PrimaryKey
                {
                    Name = (string)row["CONSTRAINT_NAME"]
                };

                var schema = (string)row["TABLE_SCHEMA"];
                var table  = GetCleanTableName((string)row["TABLE_NAME"]);
                var column = (string)row["COLUMN_NAME"];
                key.Columns.Add(columns.FindByName(schema, table, column));

                var next = i + 1;
                while (next < data.Rows.Count && key.Name == (string)data.Rows[next]["CONSTRAINT_NAME"])
                {
                    row = data.Rows[next];

                    schema = (string)row["TABLE_SCHEMA"];
                    table  = GetCleanTableName((string)row["TABLE_NAME"]);
                    column = (string)row["COLUMN_NAME"];
                    key.Columns.Add(columns.FindByName(schema, table, column));

                    next++;
                    i++;
                }

                keys.Add(key);
            }

            return(keys);
        }