예제 #1
0
 public void InvokeCommand()
 {
     if (PSCommandManager.IsReferenceCmdlet(this.commandType))
     {
         IReferenceSetCommand referenceSetCommand = DataServiceController.Current.GetReferenceSetCommand(this.commandType, this.userContext, this.referringProperty, this.metadata, this.membershipId, null);
         using (referenceSetCommand)
         {
             UriParametersHelper.AddParametersToCommand(referenceSetCommand, DataServiceController.Current.GetCurrentResourceUri());
             this.AddPropertyUpdates(referenceSetCommand);
             referenceSetCommand.AddReferredObject(this.referredInstance.GetKeyValues());
             referenceSetCommand.AddReferringObject(this.GetKeyValues());
             List <DSResource> dSResources = new List <DSResource>();
             DataServiceController.Current.QuotaSystem.CheckCmdletExecutionQuota(this.userContext);
             IEnumerator <DSResource> enumerator = referenceSetCommand.InvokeAsync(dSResources.AsQueryable <DSResource>().Expression, true);
             while (enumerator.MoveNext())
             {
             }
         }
     }
     else
     {
         ICommand command = DataServiceController.Current.GetCommand(this.commandType, this.userContext, this.resourceType, this.metadata, this.membershipId);
         using (command)
         {
             UriParametersHelper.AddParametersToCommand(command, DataServiceController.Current.GetCurrentResourceUri());
             this.AddPropertyUpdates(command);
             List <DSResource>        dSResources1 = new List <DSResource>();
             IEnumerator <DSResource> enumerator1  = command.InvokeAsync(dSResources1.AsQueryable <DSResource>().Expression, true);
             while (enumerator1.MoveNext())
             {
                 dSResources1.Add(enumerator1.Current);
             }
             if (this.commandType == CommandType.Delete || dSResources1.Count < 1)
             {
                 if (this.commandType != CommandType.Create || dSResources1.Count > 0)
                 {
                     this.updatedResource = null;
                 }
                 else
                 {
                     throw new DataServiceException(string.Format(Resources.CreateCommandNotReturnedInstance, this.resourceType.Name));
                 }
             }
             else
             {
                 this.updatedResource = dSResources1.First <DSResource>();
             }
         }
     }
 }
예제 #2
0
 private DataServiceController(DSConfiguration settings, CustomAuthorizationHandler.ICustomContextStore customContextStore, ISchemaBuilder testSchemaBuilder)
 {
     TraceHelper.Current.CorrelateWithActivity(EtwActivity.GetActivityId());
     try
     {
         this.Configuration = settings;
         this.cmdManagers   = new Dictionary <ManagementSystemType, ICommandManager>();
         this.PerfCounters  = new PerfCounters(CurrentRequestHelper.EndPointAddress);
         this.UserDataCache = new UserDataCache(this.Configuration.Invocation.Lifetime);
         this.QuotaSystem   = new QuotaSystem();
         InitialSessionStateManager initialSessionStateManager = new InitialSessionStateManager(this.Configuration.PowerShell.SessionConfig.Assembly, this.Configuration.PowerShell.SessionConfig.Type);
         this.intialSessionStateStore = new SharedItemStore <InitialSessionState, UserContext>(initialSessionStateManager, this.Configuration.Quotas.UserSchemaTimeout, this.Configuration.Quotas.MaxUserSchemas);
         PSRunspaceFactory pSRunspaceFactory = new PSRunspaceFactory(this.intialSessionStateStore, true);
         int runspaceTimeout = this.Configuration.PowerShell.Quotas.RunspaceTimeout;
         ExclusiveItemStore <PSRunspace, UserContext> exclusiveItemStore = new ExclusiveItemStore <PSRunspace, UserContext>(pSRunspaceFactory, runspaceTimeout, this.Configuration.PowerShell.Quotas.MaxRunspaces);
         PSCommandManager pSCommandManager = new PSCommandManager(exclusiveItemStore);
         this.cmdManagers.Add(ManagementSystemType.PowerShell, pSCommandManager);
         PSRunspaceFactory pSRunspaceFactory1 = new PSRunspaceFactory(this.intialSessionStateStore, false);
         ExclusiveItemStore <PSRunspace, UserContext> exclusiveItemStore1 = new ExclusiveItemStore <PSRunspace, UserContext>(pSRunspaceFactory1, runspaceTimeout, this.Configuration.PowerShell.Quotas.MaxRunspaces);
         this.cmdManagers.Add(ManagementSystemType.GenericInvoke, new GICommandManager(exclusiveItemStore1));
         List <ISchemaBuilder> schemaBuilders = new List <ISchemaBuilder>();
         if (testSchemaBuilder != null)
         {
             schemaBuilders.Add(testSchemaBuilder);
         }
         schemaBuilders.Add(new PSSchemaBuilder(exclusiveItemStore));
         schemaBuilders.Add(new GISchemaBuilder());
         SchemaFactory schemaFactory = new SchemaFactory(this.Configuration.SchemaFileName, this.Configuration.ResourceMappingFileName, schemaBuilders, settings);
         this.schemaStore = new SharedItemStore <Microsoft.Management.Odata.Schema.Schema, UserContext>(schemaFactory, this.Configuration.Quotas.UserSchemaTimeout, this.Configuration.Quotas.MaxUserSchemas);
         this.customAuthorizationHandler = new CustomAuthorizationHandler(this.Configuration.CustomAuthorization.Assembly, this.Configuration.CustomAuthorization.Type, customContextStore);
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         TraceHelper.Current.DataServiceControllerCreationFailedOperational(exception.Message);
         if (TraceHelper.IsEnabled(5))
         {
             TraceHelper.Current.DebugMessage(exception.ToTraceMessage("DataServiceController failed to create"));
         }
         if (this.PerfCounters != null)
         {
             this.PerfCounters.Dispose();
         }
         throw;
     }
     TraceHelper.Current.DataServiceControllerCreationSucceeded();
 }