public override object VisitParameter(ParameterContext context) { var p = (new Parameter()); var id = (Result)(Visit(context.id())); p.id = id.text; p.permission = id.permission; if (context.annotationSupport() != null) { p.annotation = (string)(Visit(context.annotationSupport())); } if (context.expression() != null) { p.value = (new System.Text.StringBuilder().Append("= ").Append(((Result)(Visit(context.expression()))).text)).to_str(); } p.type = (string)(Visit(context.typeType())); if (context.Comma_Comma_Comma() != null) { p.type = (new System.Text.StringBuilder().Append("params ").Append(p.type).Append("[]")).to_str(); } if (context.Bang() != null) { p.type = (new System.Text.StringBuilder().Append("ref ").Append(p.type)).to_str(); } return(p); }
// Implementation of IProviderExecutor /// <inheritdoc/> DataReader IProviderExecutor.ExecuteTupleReader(QueryRequest request, ParameterContext parameterContext) { Prepare(); using var context = new CommandProcessorContext(parameterContext); return(commandProcessor.ExecuteTasksWithReader(request, context)); }
int WbemNative.IWbemServices.ExecQueryAsync(string queryLanguage, string query, int flags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink) { if (((wbemContext == null) || (wbemSink == null)) || (this.wbemServices == null)) { return(-2147217400); } try { QueryRegex regex = new QueryRegex(query); ParameterContext parms = new ParameterContext(regex.ClassName, this.wbemServices, wbemContext, wbemSink); this.GetProvider(parms.ClassName).EnumInstances(new InstancesContext(parms)); WbemException.ThrowIfFail(wbemSink.SetStatus(0, 0, null, null)); } catch (WbemException exception) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610736), new string[] { exception.ToString() }); wbemSink.SetStatus(0, exception.ErrorCode, null, null); return(exception.ErrorCode); } catch (Exception exception2) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610736), new string[] { exception2.ToString() }); wbemSink.SetStatus(0, -2147217407, null, null); return(-2147217407); } finally { Marshal.ReleaseComObject(wbemSink); } return(0); }
int WbemNative.IWbemServices.DeleteInstanceAsync(string objectPath, int lFlags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink) { if (((wbemContext == null) || (wbemSink == null)) || (this.wbemServices == null)) { return(-2147217400); } try { ObjectPathRegex objPathRegex = new ObjectPathRegex(objectPath); ParameterContext parms = new ParameterContext(objPathRegex.ClassName, this.wbemServices, wbemContext, wbemSink); WbemInstance wbemInstance = new WbemInstance(parms, objPathRegex); if (this.GetProvider(parms.ClassName).DeleteInstance(new InstanceContext(wbemInstance))) { wbemInstance.Indicate(); } WbemException.ThrowIfFail(wbemSink.SetStatus(0, 0, null, null)); } catch (WbemException exception) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610738), new string[] { exception.ToString() }); wbemSink.SetStatus(0, exception.ErrorCode, null, null); return(exception.ErrorCode); } catch (Exception exception2) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId)(-1073610738), new string[] { exception2.ToString() }); wbemSink.SetStatus(0, -2147217407, null, null); return(-2147217407); } finally { Marshal.ReleaseComObject(wbemSink); } return(0); }
public InsertCommandContext(SchemaMetaData schemaMetaData, ParameterContext parameterContext, InsertCommand insertCommand) : base(insertCommand) { _tablesContext = new TablesContext(insertCommand.Table); _columnNames = insertCommand.UseDefaultColumns() ? schemaMetaData.GetAllColumnNames(insertCommand.Table.GetTableName().GetIdentifier().GetValue()) : insertCommand.GetColumnNames(); _insertValueContexts = GetInsertValueContexts(parameterContext); _generatedKeyContext = new GeneratedKeyContextEngine(schemaMetaData).CreateGenerateKeyContext(parameterContext, insertCommand); }
/// <summary> /// Gets <see cref="RecordSetReader"/> bound to the specified <paramref name="session"/>. /// </summary> /// <param name="session">Session to bind.</param> /// <param name="parameterContext"><see cref="ParameterContext"/> instance with /// the values of query parameters.</param> /// <returns>New <see cref="RecordSetReader"/> bound to specified <paramref name="session"/>.</returns> public RecordSetReader GetRecordSetReader(Session session, ParameterContext parameterContext) { ArgumentValidator.EnsureArgumentNotNull(session, nameof(session)); var enumerationContext = session.CreateEnumerationContext(parameterContext); return(RecordSetReader.Create(enumerationContext, this)); }
private void ProcessModels(ApiDeclaration apiDeclaration, GenerationContext dataContext) { foreach (KeyValuePair <string, ModelObject> modelObject in apiDeclaration.Models) { if (!dataContext.DataModels.ContainsKey(modelObject.Key)) { DataModelContext dataModelContext = new DataModelContext { ID = modelObject.Value.ID }; dataModelContext.SubTypes.AddRange(modelObject.Value.SubTypes); foreach (KeyValuePair <string, PropertyObject> propertyObject in modelObject.Value.Properties) { ParameterContext parameter = new ParameterContext { Name = propertyObject.Key }; InitParameterFromDataTypeObject(parameter, propertyObject.Value); dataModelContext.Propeties.Add(propertyObject.Key, parameter); } dataContext.DataModels.Add(modelObject.Key, dataModelContext); } } }
public void CombinedTest() { const string parameterName = "TestParameter"; var parameter = new Parameter <int>(parameterName); Assert.AreEqual(parameterName, parameter.Name); Assert.Throws <NotSupportedException>(() => _ = parameter.Value); var firstContext = new ParameterContext(); firstContext.SetValue(parameter, 10); Assert.AreEqual(10, firstContext.GetValue(parameter)); firstContext.SetValue(parameter, 15); Assert.AreEqual(15, firstContext.GetValue(parameter)); var secondContext = new ParameterContext(firstContext); Assert.AreEqual(15, secondContext.GetValue(parameter)); secondContext.SetValue(parameter, 20); Assert.AreEqual(20, secondContext.GetValue(parameter)); Assert.AreEqual(15, firstContext.GetValue(parameter)); firstContext.SetValue(parameter, 25); Assert.AreEqual(25, firstContext.GetValue(parameter)); Assert.AreEqual(20, secondContext.GetValue(parameter)); }
private void ManualMaterializeTest(int count) { using (var session = Domain.OpenSession()) using (session.Activate()) { int i = 0; using (var ts = session.OpenTransaction()) { var parameterContext = new ParameterContext(); var rs = Domain.Model.Types[typeof(Simplest)].Indexes.PrimaryIndex.GetQuery(); TestHelper.CollectGarbage(); using (warmup ? null : new Measurement("Manual materialize", count)) { while (i < count) { foreach (var tuple in rs.GetRecordSetReader(session, parameterContext).ToEnumerable()) { var o = new SqlClientCrudModel.Simplest { Id = tuple.GetValueOrDefault <long>(0), Value = tuple.GetValueOrDefault <long>(2) }; if (++i >= count) { break; } } } ts.Complete(); } } } }
/// <summary> /// Asynchronously executes the query in specified parameter context. /// </summary> /// <remarks> Multiple active operations are not supported. Use <see langword="await"/> /// to ensure that all asynchronous operations have completed.</remarks> /// <param name="session">The session.</param> /// <param name="parameterContext">The parameter context.</param> /// <param name="token">The token to cancel this operation</param> /// <returns><see cref="Task{TResult}"/> performing this operation.</returns> public async Task <TResult> ExecuteScalarAsync <TResult>( Session session, ParameterContext parameterContext, CancellationToken token) { var sequenceResult = await ExecuteSequenceAsync <TResult>(session, parameterContext, token).ConfigureAwait(false); return(sequenceResult.ToScalar(ResultAccessMethod)); }
public void Start(string dataSourceName, string sql, ParameterContext parameterContext, IDataSourceMetaData dataSourceMetaData, bool isTrunkThread, IDictionary <string, object> shardingExecuteDataMap) { foreach (var sqlExecutionHook in _sqlExecutionHooks) { sqlExecutionHook.Start(dataSourceName, sql, parameterContext, dataSourceMetaData, isTrunkThread, shardingExecuteDataMap); } }
public void Validate(ShardingRule shardingRule, UpdateCommand sqlCommand, ParameterContext parameterContext) { String tableName = sqlCommand.Tables.First().GetTableName().GetIdentifier().GetValue(); foreach (var assignmentSegment in sqlCommand.SetAssignment.GetAssignments()) { String shardingColumn = assignmentSegment.GetColumn().GetIdentifier().GetValue(); if (shardingRule.IsShardingColumn(shardingColumn, tableName)) { var shardingColumnSetAssignmentValue = GetShardingColumnSetAssignmentValue(assignmentSegment, parameterContext); object shardingValue = null; var whereSegmentOptional = sqlCommand.Where; if (whereSegmentOptional != null) { shardingValue = GetShardingValue(whereSegmentOptional, parameterContext, shardingColumn); } if (shardingColumnSetAssignmentValue != null && shardingValue != null && shardingColumnSetAssignmentValue.Equals(shardingValue)) { continue; } throw new ShardingException( $"Can not update sharding key, logic table: [{tableName}], column: [{assignmentSegment}]."); } } }
public static void AddParameterToMainList(Parameter parameter, ParameterContext pContext) { if (FindMatchingParameter(parameter, pContext) == null) { ParametersAlreadyCreated.Add(parameter); } }
internal CommandProcessorContext(ParameterContext parameterContext, bool allowPartialExecution = false) { ParameterContext = parameterContext; AllowPartialExecution = allowPartialExecution; ProcessingTasks = new Queue <SqlTask>(); ActiveTasks = new List <SqlLoadTask>(); }
public static bool IsListValueParameter(ParameterContext pContext) { return(pContext == ParameterContext.AloneValue || pContext == ParameterContext.FirstComaSeparatedValue || pContext == ParameterContext.ComaSeparatedValue || pContext == ParameterContext.LastComaSeparatedValue); }
public ParameterContext parameter() { ParameterContext _localctx = new ParameterContext(Context, State); EnterRule(_localctx, 16, RULE_parameter); int _la; try { EnterOuterAlt(_localctx, 1); { State = 104; _la = TokenStream.LA(1); if (!(_la == SCRIPT || _la == VALUETYPE)) { ErrorHandler.RecoverInline(this); } else { ErrorHandler.ReportMatch(this); Consume(); } State = 105; Match(ID); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
/// <inheritdoc/> void IProviderExecutor.Clear(IPersistDescriptor descriptor, ParameterContext parameterContext) { Prepare(); commandProcessor.RegisterTask(new SqlPersistTask(descriptor.ClearRequest, null)); using (var context = new CommandProcessorContext(parameterContext)) commandProcessor.ExecuteTasks(context); }
/** * Create sharding conditions. * * @param insertCommandContext insert statement context * @param parameters SQL parameters * @return sharding conditions */ public List <ShardingCondition> CreateShardingConditions(InsertCommandContext insertCommandContext, ParameterContext parameterContext) { ICollection <ShardingCondition> result = new LinkedList <ShardingCondition>(); string tableName = insertCommandContext.GetSqlCommand().Table.GetTableName().GetIdentifier().GetValue(); ICollection <string> columnNames = GetColumnNames(insertCommandContext); foreach (var insertValueContext in insertCommandContext.GetInsertValueContexts()) { result.Add(CreateShardingCondition(tableName, columnNames.GetEnumerator(), insertValueContext, parameterContext)); } var generatedKey = insertCommandContext.GetGeneratedKeyContext(); if (generatedKey != null && generatedKey.IsGenerated()) { generatedKey.GetGeneratedValues().AddAll(GetGeneratedKeys(tableName, insertCommandContext.GetSqlCommand().GetValueListCount())); if (_shardingRule.IsShardingColumn(generatedKey.GetColumnName(), tableName)) { AppendGeneratedKeyCondition(generatedKey, tableName, result); } } return(result.ToList()); }
public ParameterContext CloneFrom(ParameterContext previousContext) { if (previousContext == null) { throw new ArgumentNullException(nameof(previousContext)); } var name = previousContext.Name; if (parameterContexts.TryGetValue(name, out ParameterContext existingValue)) { if (existingValue.Equals(previousContext)) { return(existingValue); } throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.ParameterAlreadyAdvertised, name)); } ParameterContext newContext = previousContext.DeepClone(); _ = parameterContexts.TryAdd(name, newContext); return(newContext); }
private IDictionary <Column, ICollection <IRouteValue> > CreateRouteValueMap( ISqlCommandContext <ISqlCommand> sqlCommandContext, AndPredicateSegment andPredicate, ParameterContext parameterContext) { IDictionary <Column, ICollection <IRouteValue> > result = new Dictionary <Column, ICollection <IRouteValue> >(); foreach (var predicate in andPredicate.GetPredicates()) { var tableName = sqlCommandContext.GetTablesContext() .FindTableName(predicate.GetColumn(), schemaMetaData); if (tableName == null || !shardingRule.IsShardingColumn(predicate.GetColumn().GetIdentifier().GetValue(), tableName)) { continue; } Column column = new Column(predicate.GetColumn().GetIdentifier().GetValue(), tableName); var routeValue = ConditionValueGeneratorFactory.Generate(predicate.GetPredicateRightValue(), column, parameterContext); if (routeValue == null) { continue; } if (!result.ContainsKey(column)) { result.Add(column, new LinkedList <IRouteValue>()); } result[column].Add(routeValue); } return(result); }
private ParameterizedQuery GetScalarQuery <TResult>( Func <QueryEndpoint, TResult> query, bool executeAsSideEffect, out TResult result) { AllocateParameterAndReplacer(); var parameterContext = new ParameterContext(outerContext); parameterContext.SetValue(queryParameter, queryTarget); var scope = new CompiledQueryProcessingScope( queryParameter, queryParameterReplacer, parameterContext, executeAsSideEffect); using (scope.Enter()) { result = query.Invoke(endpoint); } var parameterizedQuery = (ParameterizedQuery)scope.ParameterizedQuery; if (parameterizedQuery == null && queryTarget != null) { throw new NotSupportedException(Strings.ExNonLinqCallsAreNotSupportedWithinQueryExecuteDelayed); } PutCachedQuery(parameterizedQuery); return(parameterizedQuery); }
private bool Contains(Key key, Entity item) { // state check var foundInCache = State.Contains(key); if (foundInCache) { return(true); } var ownerState = Owner.PersistenceState; var itemState = item == null ? PersistenceState.Synchronized : item.PersistenceState; if (PersistenceState.New.In(ownerState, itemState) || State.IsFullyLoaded) { return(false); } // association check if (item != null) { var association = Field.GetAssociation(item.TypeInfo); if (association.IsPaired && association.Multiplicity.In(Multiplicity.ManyToOne, Multiplicity.OneToMany)) { var candidate = (IEntity)item.GetFieldValue(association.Reversed.OwnerField); return(candidate == Owner); } } // load from storage EnsureIsLoaded(WellKnown.EntitySetPreloadCount); foundInCache = State.Contains(key); if (foundInCache) { return(true); } if (State.IsFullyLoaded) { return(false); } bool foundInDatabase; var entitySetTypeState = GetEntitySetTypeState(); var parameterContext = new ParameterContext(); parameterContext.SetValue(keyParameter, entitySetTypeState.SeekTransform .Apply(TupleTransformType.TransformedTuple, Owner.Key.Value, key.Value)); using (var recordSetReader = entitySetTypeState.SeekProvider.GetRecordSetReader(Session, parameterContext)) { foundInDatabase = recordSetReader.MoveNext(); } if (foundInDatabase) { State.Register(key); } return(foundInDatabase); }
// Constructors // ReSharper disable MemberCanBeProtected.Global public SubQuery(ProjectionExpression projectionExpression, TranslatedQuery query, Parameter <Tuple> parameter, Tuple tuple, ItemMaterializationContext context) // ReSharper restore MemberCanBeProtected.Global { this.provider = context.Session.Query.Provider; var tupleParameterBindings = new Dictionary <Parameter <Tuple>, Tuple>(projectionExpression.TupleParameterBindings); var currentTranslatedQuery = query; var outerParameterContext = context.ParameterContext; var parameterContext = new ParameterContext(outerParameterContext); // Gather Parameter<Tuple> values from current ParameterScope for future use. outerParameterContext.SetValue(parameter, tuple); foreach (var tupleParameter in currentTranslatedQuery.TupleParameters) { var value = outerParameterContext.GetValue(tupleParameter); tupleParameterBindings[tupleParameter] = value; parameterContext.SetValue(tupleParameter, value); } this.projectionExpression = new ProjectionExpression( projectionExpression.Type, projectionExpression.ItemProjector, tupleParameterBindings, projectionExpression.ResultAccessMethod); var translatedQuery = new TranslatedQuery( query.DataSource, query.Materializer, query.ResultAccessMethod, tupleParameterBindings, EnumerableUtils <Parameter <Tuple> > .Empty); delayedQuery = new DelayedQuery <TElement>(context.Session, translatedQuery, parameterContext); context.Session.RegisterUserDefinedDelayedQuery(delayedQuery.Task); context.MaterializationContext.MaterializationQueue.Enqueue(MaterializeSelf); }
/** * Create sharding conditions. * * @param sqlStatementContext SQL statement context * @param parameters SQL parameters * @return sharding conditions */ public List <ShardingCondition> CreateShardingConditions(ISqlCommandContext <ISqlCommand> sqlCommandContext, ParameterContext parameterContext) { if (sqlCommandContext is IWhereAvailable whereAvailable) { var whereSegment = whereAvailable.GetWhere(); if (whereSegment != null) { var shardingConditions = CreateShardingConditions(sqlCommandContext, whereSegment.GetAndPredicates(), parameterContext); return(new List <ShardingCondition>(shardingConditions)); } } return(new List <ShardingCondition>(0)); // FIXME process subquery // ICollection<SubqueryPredicateSegment> subqueryPredicateSegments = sqlStatementContext.findSQLSegments(SubqueryPredicateSegment.class); // for (SubqueryPredicateSegment each : subqueryPredicateSegments) { // ICollection<ShardingCondition> subqueryShardingConditions = createShardingConditions((WhereSegmentAvailable) sqlStatementContext, each.getAndPredicates(), parameters); // if (!result.containsAll(subqueryShardingConditions)) { // result.addAll(subqueryShardingConditions); // } // } }
// Constructors internal EnumerationContext(Session session, ParameterContext parameterContext, EnumerationContextOptions options = default) { Session = session; this.parameterContext = parameterContext; this.options = options; }
// Constructors /// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="dataSource">The data source.</param> /// <param name="lifetimeToken"><see cref="StateLifetimeToken"/> to be associated with the /// newly created <see cref="QueryTask"/>.</param> /// <param name="parameterContext">The parameter value context.</param> public QueryTask(ExecutableProvider dataSource, StateLifetimeToken lifetimeToken, ParameterContext parameterContext) { ArgumentValidator.EnsureArgumentNotNull(dataSource, "dataSource"); DataSource = dataSource; LifetimeToken = lifetimeToken; ParameterContext = parameterContext; }
/// <summary> /// Returns a parameter that matches some conditions: /// 1- Same values /// 2- If parameter isn't a listValue value, then verify matching in names /// </summary> /// <param name="parameter"></param> /// <param name="pContext"></param> /// <returns></returns> public static Parameter FindMatchingParameter(Parameter parameter, ParameterContext pContext) { var checkNames = !IsListValueParameter(pContext); foreach (var p in ParametersAlreadyCreated) { var sameValues = p.AreValuesTheSame(parameter); if (sameValues) { if (checkNames && p.ExpressionPrefix != null && (p.ExpressionPrefix.Contains(parameter.ExpressionPrefix) || parameter.ExpressionPrefix.Contains(p.ExpressionPrefix))) { return(p); } if (!checkNames) { return(p); } } } return(null); }
private ICollection <ExecutionUnit> ExecuteRewrite(string sql, ParameterContext parameterContext, RouteContext routeContext) { RegisterRewriteDecorator(); SqlRewriteContext sqlRewriteContext = _rewriter.CreateSqlRewriteContext(sql, parameterContext, routeContext.GetSqlCommandContext(), routeContext); return(!routeContext.GetRouteResult().GetRouteUnits().Any() ? Rewrite(sqlRewriteContext) : Rewrite(routeContext, sqlRewriteContext)); }
private void ProcessOperations(ApiDeclaration apiDeclaration, GenerationContext dataContext) { OperationGroupContext operationGroupContext = new OperationGroupContext { Name = apiDeclaration.ResourcePath.NormalizeName() }; foreach (ApiObject apiObject in apiDeclaration.Apis) { string operationPath = apiObject.Path; foreach (OperationObject operation in apiObject.Operations) { OperationContext operationContext = new OperationContext { RelativeUrl = $"{apiDeclaration.BasePath}{operationPath}", Method = operation.Method.ToString(), Name = operation.NickName }; InitParameterFromDataTypeObject(operationContext, operation); foreach (ParameterObject parameterObject in operation.Parameters) { ParameterContext parameter = new ParameterContext { Name = parameterObject.Name }; InitParameterFromDataTypeObject(parameter, parameterObject); switch (parameterObject.ParamType) { case ParamType.Path: operationContext.PathParameters.Add(parameter); break; case ParamType.Query: operationContext.QueryParameters.Add(parameter); break; case ParamType.Body: operationContext.BodyParameter = parameter; break; case ParamType.Header: case ParamType.Form: break; default: throw new ArgumentOutOfRangeException(); } } operationGroupContext.Operations.Add(operationContext); } } dataContext.Groups.Add(operationGroupContext); }
public MainWindowViewModel( StudentContext studentContext, ParameterContext adminContext, ObservableCollection <CollegeLife> collegeLife, ObservableCollection <DegreeProgram> degreePrograms, ObservableCollection <Term> terms) { if (studentContext == null) { throw new ArgumentNullException("studentContext"); } if (adminContext == null) { throw new ArgumentNullException("adminContext"); } if (collegeLife == null) { throw new ArgumentNullException("collegeLife"); } if (degreePrograms == null) { throw new ArgumentNullException("degreePrograms"); } if (terms == null) { throw new ArgumentNullException("terms"); } Students = studentContext; Parameters = adminContext; CollegeLife = collegeLife; DegreePrograms = degreePrograms; Terms = terms; ObservableCollection <StudentViewModel> students = new ObservableCollection <StudentViewModel>(); foreach (Student student in studentContext.Items) { students.Add(new StudentViewModel(student, studentContext)); } ObservableCollection <ParameterViewModel> parameters = new ObservableCollection <ParameterViewModel>(); foreach (Parameter parameter in adminContext.Items) { parameters.Add(new ParameterViewModel(parameter, adminContext)); } InquiryWorkspace = new InquiryWorkspaceViewModel(studentContext, collegeLife, degreePrograms, terms); StudentWorkspace = new StudentWorkspaceViewModel(students, studentContext); AdminWorkspace = new AdminWorkspaceViewModel(parameters, adminContext, terms); ApprovalsWorkspace = new StudentApprovalsViewModel(degreePrograms, students.ToList <StudentViewModel>(), terms); SaveCommand = new DelegateCommand(o => Save()); }
public MainWindowViewModel( StudentContext studentContext, ParameterContext adminContext, ObservableCollection<CollegeLife> collegeLife, ObservableCollection<DegreeProgram> degreePrograms, ObservableCollection<Term> terms) { if(studentContext == null) { throw new ArgumentNullException("studentContext"); } if(adminContext == null) { throw new ArgumentNullException("adminContext"); } if(collegeLife == null) { throw new ArgumentNullException("collegeLife"); } if(degreePrograms == null) { throw new ArgumentNullException("degreePrograms"); } if(terms == null) { throw new ArgumentNullException("terms"); } Students = studentContext; Parameters = adminContext; CollegeLife = collegeLife; DegreePrograms = degreePrograms; Terms = terms; ObservableCollection<StudentViewModel> students = new ObservableCollection<StudentViewModel>(); foreach(Student student in studentContext.Items) { students.Add(new StudentViewModel(student, studentContext)); } ObservableCollection<ParameterViewModel> parameters = new ObservableCollection<ParameterViewModel>(); foreach(Parameter parameter in adminContext.Items) { parameters.Add(new ParameterViewModel(parameter, adminContext)); } InquiryWorkspace = new InquiryWorkspaceViewModel(studentContext, collegeLife, degreePrograms, terms); StudentWorkspace = new StudentWorkspaceViewModel(students, studentContext); AdminWorkspace = new AdminWorkspaceViewModel(parameters, adminContext, terms); ApprovalsWorkspace = new StudentApprovalsViewModel(degreePrograms, students.ToList<StudentViewModel>(), terms); SaveCommand = new DelegateCommand(o => Save()); }
public ParameterViewModel(Parameter parameter, ParameterContext context) { if(parameter == null) { throw new ArgumentNullException("parameter"); } if(context == null) { throw new ArgumentNullException("context"); } this.context = context; this.parameter = parameter; }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); ObservableCollection<CollegeLife> collegeLife; ObservableCollection<DegreeProgram> degreePrograms; ObservableCollection<Term> terms; try { //connect with mysql database Database.ConnectionString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString; Students = new StudentContext( from DataRow row in Database.Query("SELECT * FROM ais.tblstudent").Rows select new Student(row)); Parameters = new ParameterContext( from DataRow row in Database.Query("SELECT * FROM ais.tblparameter").Rows select new Parameter(row)); collegeLife = new ObservableCollection<CollegeLife>( from DataRow row in Database.Proc("getPersonalInterest").Rows select new CollegeLife(row)); degreePrograms = new ObservableCollection<DegreeProgram>( from DataRow row in Database.Proc("getDegreePrograms").Rows select new DegreeProgram(row)); terms = new ObservableCollection<Term>( from DataRow row in Database.Proc("getTerm").Rows select new Term(row)); } catch { Students = ModelGenerator.BuildFakeStudents(); Parameters = ModelGenerator.BuildFakeParameters(); collegeLife = ModelGenerator.BuildFakeCollegeLife(); degreePrograms = ModelGenerator.BuildFakeDegreePrograms(); terms = null; } MainWindowViewModel model = new MainWindowViewModel(Students, Parameters, collegeLife, degreePrograms, terms); MainWindow window = new MainWindow { DataContext = model }; window.Show(); }
public AdminWorkspaceViewModel( ObservableCollection<ParameterViewModel> parameters, ParameterContext context, ObservableCollection<Term> terms) { if(context == null) { throw new ArgumentNullException("context"); } if(parameters == null) { throw new ArgumentNullException("parameters"); } if(terms == null) { throw new ArgumentNullException("terms"); } Terms = terms; this.context = context; this.parameters = parameters; //if(parameters.Count > 0) //{ // CurrentParameter = parameters[0]; //} //else //{ // CurrentParameter = new ParameterViewModel(context.Create(), context); //} UpdateParameter(); SaveCommand = new DelegateCommand(o => Save()); }
int WbemNative.IWbemServices.ExecQueryAsync(string queryLanguage, string query, int flags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink) { if (((wbemContext == null) || (wbemSink == null)) || (this.wbemServices == null)) { return -2147217400; } try { QueryRegex regex = new QueryRegex(query); ParameterContext parms = new ParameterContext(regex.ClassName, this.wbemServices, wbemContext, wbemSink); this.GetProvider(parms.ClassName).EnumInstances(new InstancesContext(parms)); WbemException.ThrowIfFail(wbemSink.SetStatus(0, 0, null, null)); } catch (WbemException exception) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId) (-1073610736), new string[] { exception.ToString() }); wbemSink.SetStatus(0, exception.ErrorCode, null, null); return exception.ErrorCode; } catch (Exception exception2) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId) (-1073610736), new string[] { exception2.ToString() }); wbemSink.SetStatus(0, -2147217407, null, null); return -2147217407; } finally { Marshal.ReleaseComObject(wbemSink); } return 0; }
int WbemNative.IWbemServices.ExecMethodAsync(string objectPath, string methodName, int flags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemClassObject wbemInParams, WbemNative.IWbemObjectSink wbemSink) { if (((wbemContext == null) || (wbemInParams == null)) || ((wbemSink == null) || (this.wbemServices == null))) { return -2147217400; } int hResult = 0; try { ObjectPathRegex objPathRegex = new ObjectPathRegex(objectPath); ParameterContext parms = new ParameterContext(objPathRegex.ClassName, this.wbemServices, wbemContext, wbemSink); WbemInstance wbemInstance = new WbemInstance(parms, objPathRegex); MethodContext method = new MethodContext(parms, methodName, wbemInParams, wbemInstance); if (!this.GetProvider(parms.ClassName).InvokeMethod(method)) { hResult = -2147217406; } WbemException.ThrowIfFail(wbemSink.SetStatus(0, hResult, null, null)); } catch (WbemException exception) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId) (-1073610735), new string[] { exception.ToString() }); hResult = exception.ErrorCode; wbemSink.SetStatus(0, hResult, null, null); } catch (Exception exception2) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId) (-1073610735), new string[] { exception2.ToString() }); hResult = -2147217407; wbemSink.SetStatus(0, hResult, null, null); } finally { Marshal.ReleaseComObject(wbemSink); } return hResult; }
int WbemNative.IWbemServices.DeleteInstanceAsync(string objectPath, int lFlags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink) { if (((wbemContext == null) || (wbemSink == null)) || (this.wbemServices == null)) { return -2147217400; } try { ObjectPathRegex objPathRegex = new ObjectPathRegex(objectPath); ParameterContext parms = new ParameterContext(objPathRegex.ClassName, this.wbemServices, wbemContext, wbemSink); WbemInstance wbemInstance = new WbemInstance(parms, objPathRegex); if (this.GetProvider(parms.ClassName).DeleteInstance(new InstanceContext(wbemInstance))) { wbemInstance.Indicate(); } WbemException.ThrowIfFail(wbemSink.SetStatus(0, 0, null, null)); } catch (WbemException exception) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId) (-1073610738), new string[] { exception.ToString() }); wbemSink.SetStatus(0, exception.ErrorCode, null, null); return exception.ErrorCode; } catch (Exception exception2) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId) (-1073610738), new string[] { exception2.ToString() }); wbemSink.SetStatus(0, -2147217407, null, null); return -2147217407; } finally { Marshal.ReleaseComObject(wbemSink); } return 0; }
internal WbemInstance(ParameterContext parms, WbemNative.IWbemClassObject wbemObject) { this.parms = parms; this.wbemObject = wbemObject; }
internal WbemInstance(ParameterContext parms, string className) { this.parms = parms; if (String.IsNullOrEmpty(className)) { className = parms.ClassName; } this.className = className; WbemNative.IWbemClassObject tempObj = null; WbemException.ThrowIfFail( parms.WbemServices.GetObject(className, 0, parms.WbemContext, ref tempObj, IntPtr.Zero) ); if (null != tempObj) { WbemException.ThrowIfFail(tempObj.SpawnInstance(0, out this.wbemObject)); } }
internal WbemInstance(ParameterContext parms, ObjectPathRegex objPathRegex) : this(parms, objPathRegex.ClassName) { foreach (KeyValuePair<string, object> kv in objPathRegex.Keys) { this.SetProperty(kv.Key, kv.Value); } }
internal InstancesContext(ParameterContext parms) { this.parms = parms; }
int WbemNative.IWbemServices.ExecMethodAsync( string objectPath, string methodName, Int32 flags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemClassObject wbemInParams, WbemNative.IWbemObjectSink wbemSink) { if (wbemContext == null || wbemInParams == null || wbemSink == null || this.wbemServices == null) return (int)WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER; int result = (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR; try { ObjectPathRegex objPathRegex = new ObjectPathRegex(objectPath); ParameterContext parms = new ParameterContext(objPathRegex.ClassName, this.wbemServices, wbemContext, wbemSink); WbemInstance wbemInstance = new WbemInstance(parms, objPathRegex); MethodContext methodContext = new MethodContext(parms, methodName, wbemInParams, wbemInstance); IWmiProvider wmiProvider = this.GetProvider(parms.ClassName); if (!wmiProvider.InvokeMethod(methodContext)) { result = (int)WbemNative.WbemStatus.WBEM_E_NOT_FOUND; } WbemException.ThrowIfFail(wbemSink.SetStatus( (int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, (int)result, null, null)); } catch (WbemException e) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiExecMethodFailed, e.ToString()); result = e.ErrorCode; wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, result, null, null); } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiExecMethodFailed, e.ToString()); result = (int)WbemNative.WbemStatus.WBEM_E_FAILED; wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, (int)result, null, null); } finally { Marshal.ReleaseComObject(wbemSink); } return result; }
int WbemNative.IWbemServices.ExecQueryAsync( string queryLanguage, string query, Int32 flags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink) { if (wbemContext == null || wbemSink == null || this.wbemServices == null) return (int)WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER; try { QueryRegex queryRegex = new QueryRegex(query); ParameterContext parms = new ParameterContext(queryRegex.ClassName, this.wbemServices, wbemContext, wbemSink); IWmiProvider wmiProvider = this.GetProvider(parms.ClassName); //we let WMI to parse WQL to filter results from appropriate provider wmiProvider.EnumInstances(new InstancesContext(parms)); WbemException.ThrowIfFail(wbemSink.SetStatus( (int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR, null, null)); } catch (WbemException e) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiExecQueryFailed, e.ToString()); wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, e.ErrorCode, null, null); return e.ErrorCode; } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiExecQueryFailed, e.ToString()); wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, (int)WbemNative.WbemStatus.WBEM_E_FAILED, null, null); return (int)WbemNative.WbemStatus.WBEM_E_FAILED; } finally { Marshal.ReleaseComObject(wbemSink); } return (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR; }
int WbemNative.IWbemServices.DeleteInstanceAsync( string objectPath, Int32 lFlags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink) { if (wbemContext == null || wbemSink == null || this.wbemServices == null) return (int)WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER; try { ObjectPathRegex objPathRegex = new ObjectPathRegex(objectPath); ParameterContext parms = new ParameterContext(objPathRegex.ClassName, this.wbemServices, wbemContext, wbemSink); WbemInstance wbemInstance = new WbemInstance(parms, objPathRegex); IWmiProvider wmiProvider = this.GetProvider(parms.ClassName); if (wmiProvider.DeleteInstance(new InstanceContext(wbemInstance))) { wbemInstance.Indicate(); } WbemException.ThrowIfFail(wbemSink.SetStatus( (int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR, null, null)); } catch (WbemException e) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiDeleteInstanceFailed, e.ToString()); wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, e.ErrorCode, null, null); return e.ErrorCode; } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiDeleteInstanceFailed, e.ToString()); wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, (int)WbemNative.WbemStatus.WBEM_E_FAILED, null, null); return (int)WbemNative.WbemStatus.WBEM_E_FAILED; } finally { Marshal.ReleaseComObject(wbemSink); } return (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR; }
int WbemNative.IWbemServices.PutInstanceAsync( WbemNative.IWbemClassObject wbemObject, Int32 lFlags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink ) { if (wbemObject == null || wbemContext == null || wbemSink == null || this.wbemServices == null) return (int)WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER; using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null) { try { object val = null; int type = 0; int favor = 0; WbemException.ThrowIfFail(wbemObject.Get("__CLASS", 0, ref val, ref type, ref favor)); string className = (string)val; ServiceModelActivity.Start(activity, SR.GetString(SR.WmiPutInstance, string.IsNullOrEmpty(className) ? string.Empty : className), ActivityType.WmiPutInstance); ParameterContext parms = new ParameterContext(className, this.wbemServices, wbemContext, wbemSink); WbemInstance wbemInstance = new WbemInstance(parms, wbemObject); IWmiProvider wmiProvider = this.GetProvider(parms.ClassName); if (wmiProvider.PutInstance(new InstanceContext(wbemInstance))) { wbemInstance.Indicate(); } WbemException.ThrowIfFail(wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR, null, null)); } catch (WbemException e) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiPutInstanceFailed, TraceUtility.CreateSourceString(this), e.ToString()); wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, e.ErrorCode, null, null); return e.ErrorCode; } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiPutInstanceFailed, TraceUtility.CreateSourceString(this), e.ToString()); wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE, (int)WbemNative.WbemStatus.WBEM_E_FAILED, null, null); return (int)WbemNative.WbemStatus.WBEM_E_FAILED; } finally { Marshal.ReleaseComObject(wbemSink); } } return (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR; }
int WbemNative.IWbemServices.GetObjectAsync(string objectPath, int flags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink) { if (((wbemContext == null) || (wbemSink == null)) || (this.wbemServices == null)) { return -2147217400; } using (DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateActivity(true, System.ServiceModel.SR.GetString("WmiGetObject", new object[] { string.IsNullOrEmpty(objectPath) ? string.Empty : objectPath }), ActivityType.WmiGetObject) : null) { try { ObjectPathRegex objPathRegex = new ObjectPathRegex(objectPath); ParameterContext parms = new ParameterContext(objPathRegex.ClassName, this.wbemServices, wbemContext, wbemSink); WbemInstance wbemInstance = new WbemInstance(parms, objPathRegex); if (this.GetProvider(parms.ClassName).GetInstance(new InstanceContext(wbemInstance))) { wbemInstance.Indicate(); } WbemException.ThrowIfFail(wbemSink.SetStatus(0, 0, null, null)); } catch (WbemException exception) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId) (-1073610740), new string[] { TraceUtility.CreateSourceString(this), exception.ToString() }); wbemSink.SetStatus(0, exception.ErrorCode, null, null); return exception.ErrorCode; } catch (Exception exception2) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId) (-1073610740), new string[] { TraceUtility.CreateSourceString(this), exception2.ToString() }); wbemSink.SetStatus(0, -2147217407, null, null); return -2147217407; } finally { Marshal.ReleaseComObject(wbemSink); } } return 0; }
int WbemNative.IWbemServices.PutInstanceAsync(WbemNative.IWbemClassObject wbemObject, int lFlags, WbemNative.IWbemContext wbemContext, WbemNative.IWbemObjectSink wbemSink) { if (((wbemObject == null) || (wbemContext == null)) || ((wbemSink == null) || (this.wbemServices == null))) { return -2147217400; } using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null) { try { WbemException.ThrowIfFail(wbemObject.Get("__CLASS", 0, null, 0, 0)); string str = (string) pVal; ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("WmiPutInstance", new object[] { string.IsNullOrEmpty(str) ? string.Empty : str }), ActivityType.WmiPutInstance); ParameterContext parms = new ParameterContext(str, this.wbemServices, wbemContext, wbemSink); WbemInstance wbemInstance = new WbemInstance(parms, wbemObject); if (this.GetProvider(parms.ClassName).PutInstance(new InstanceContext(wbemInstance))) { wbemInstance.Indicate(); } WbemException.ThrowIfFail(wbemSink.SetStatus(0, 0, null, null)); } catch (WbemException exception) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId) (-1073610739), new string[] { TraceUtility.CreateSourceString(this), exception.ToString() }); wbemSink.SetStatus(0, exception.ErrorCode, null, null); return exception.ErrorCode; } catch (Exception exception2) { DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, EventLogCategory.Wmi, (EventLogEventId) (-1073610739), new string[] { TraceUtility.CreateSourceString(this), exception2.ToString() }); wbemSink.SetStatus(0, -2147217407, null, null); return -2147217407; } finally { Marshal.ReleaseComObject(wbemSink); } } return 0; }
internal MethodContext(ParameterContext parms, string methodName, WbemNative.IWbemClassObject wbemInParms, WbemInstance wbemInstance) { this.parms = parms; this.methodName = methodName; this.wbemInParms = wbemInParms; this.instance = new InstanceContext(wbemInstance); WbemNative.IWbemClassObject wbemObject = null; WbemException.ThrowIfFail(parms.WbemServices.GetObject(parms.ClassName, 0, parms.WbemContext, ref wbemObject, IntPtr.Zero)); WbemNative.IWbemClassObject wbemMethod = null; WbemException.ThrowIfFail(wbemObject.GetMethod(methodName, 0, IntPtr.Zero, out wbemMethod)); WbemException.ThrowIfFail(wbemMethod.SpawnInstance(0, out this.wbemOutParms)); }