Example #1
0
        protected IDataContext CreateDataContext(DbConnection connection, string name, string connectionType)
        {
            DataContextType dcType = DataContextType.None;

            if (connectionType.ToUpper().Contains("META"))
            {
                dcType |= DataContextType.Meta;
            }
            if (connectionType.ToUpper().Contains("ACCOUNT"))
            {
                dcType |= DataContextType.Account;
            }
            if (connectionType.ToUpper().Contains("DOCUMENT"))
            {
                dcType |= DataContextType.Document;
            }

            if (!dcType.HasFlag(DataContextType.Document))
            {
                return(new MetaDataContext(connection, name));
            }
            if (!dcType.HasFlag(DataContextType.Meta) && !dcType.HasFlag(DataContextType.Account))
            {
                return(new DocumentDataContext(connection, name /*, dcType*/));
            }

            return(new DataContext(connection, name));
        }
Example #2
0
        public static IScriptCommand IfHasDataContext(
            string sourceElementVariable = "{EventArgs.OriginalSource}",
            DataContextType type         = DataContextType.SupportDrag,
            IScriptCommand nextCommand   = null, IScriptCommand otherwiseCommand = null)
        {
            string destVariable    = "{Temp_DataContextDest}";
            string destEleVariable = "{Temp_DataContextDestEle}";

            return(AssignDataContext(sourceElementVariable, type, destVariable, destEleVariable, false,
                                     ScriptCommands.IfAssigned(destVariable, nextCommand, otherwiseCommand)));
        }
Example #3
0
    public override bool IsValid(object value)
    {
        string str = (string)value;

        if (String.IsNullOrWhiteSpace(str))
        {
            return(true);
        }

        // Cleanup the string
        str = str.Trim();

        // Construct the data context
        ConstructorInfo constructor = DataContextType.GetConstructor(new Type[0]);
        DataContext     dataContext = (DataContext)constructor.Invoke(new object[0]);

        // Get the table
        ITable table = dataContext.GetTable(EntityType);

        // Get the property
        PropertyInfo propertyInfo = EntityType.GetProperty(PropertyName);

        // Expression: "entity"
        ParameterExpression parameter = Expression.Parameter(EntityType, "entity");

        // Expression: "entity.PropertyName"
        MemberExpression property = Expression.MakeMemberAccess(parameter, propertyInfo);

        // Expression: "value"
        object             convertedValue = Convert.ChangeType(value, propertyInfo.PropertyType);
        ConstantExpression rhs            = Expression.Constant(convertedValue);

        // Expression: "entity.PropertyName == value"
        BinaryExpression equal = Expression.Equal(property, rhs);

        // Expression: "entity => entity.PropertyName == value"
        LambdaExpression lambda = Expression.Lambda(equal, parameter);

        // Instantiate the count method with the right TSource (our entity type)
        MethodInfo countMethod = QueryableCountMethod.MakeGenericMethod(EntityType);

        // Execute Count() and say "you're valid if you have none matching"
        int count = (int)countMethod.Invoke(null, new object[] { table, lambda });

        return(count == 0);
    }
Example #4
0
        int ComputeHashCode()
        {
            unchecked
            {
                var hashCode = 0;
                if (NamespaceImports != null)
                {
                    foreach (var import in NamespaceImports)
                    {
                        hashCode += (hashCode * 47) ^ import.GetHashCode();
                    }
                }

                hashCode = (hashCode * 397) ^ (Parent?.GetHashCode() ?? 0);
                hashCode = (hashCode * 13) ^ (DataContextType?.GetHashCode() ?? 0);
                return(hashCode);
            }
        }
Example #5
0
 public static IScriptCommand AssignDataContext(
     string sourceElementVariable = "{EventArgs.OriginalSource}",
     DataContextType type         = DataContextType.SupportDrag,
     string destVariable          = "{Variable}",
     string destEleVariable       = null,
     bool skipIfExists            = false,
     IScriptCommand nextCommand   = null)
 {
     return(new AssignDataContext()
     {
         SourceElementKey = sourceElementVariable,
         DataContextType = type,
         VariableKey = destVariable,
         DataContextElementKey = destEleVariable,
         SkipIfExists = skipIfExists,
         NextCommand = (ScriptCommandBase)nextCommand
     });
 }
Example #6
0
        public DataContext(DbConnection connection, string name = "", DataContextType type = DataContextType.Meta | DataContextType.Document | DataContextType.Account)
        {
            if (connection != null)
            {
                var workspace = new MetadataWorkspace(EntityDataContextMetadataLocator.GetPath(),
                                                      new[] { Assembly.GetExecutingAssembly() });

                Connection = new EntityConnection(workspace, connection);
            }
            else
            {
                Connection = new EntityConnection("name=cissaEntities");
            }

            _ownConnection       = true;
            Name                 = String.IsNullOrEmpty(name) ? Connection.Database : name;
            DataType             = type;
            Connection.Disposed += OnConnectionDisposed;
            _entities            = new cissaEntities(Connection)
            {
                CommandTimeout = 600
            };
            DbContext = new DbContext(_entities, true);
        }