Esempio n. 1
0
 public TestHookCommandInvocationData TestHookGetInvocationData()
 {
     object[] objArray = new object[2];
     objArray[0] = "GetInvocationData";
     objArray[1] = "EntityUpdate";
     throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.NotImplementedExceptionMessage, objArray));
 }
Esempio n. 2
0
 public bool AddArrayFieldParameter(string parameter, IEnumerable <object> values)
 {
     object[] objArray = new object[2];
     objArray[0] = "AddArrayFieldParameter";
     objArray[1] = "PipelineInvocation";
     throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.NotImplementedExceptionMessage, objArray));
 }
Esempio n. 3
0
 public void VerifyConcurrencyValues(IEnumerable <KeyValuePair <string, object> > values)
 {
     object[] objArray = new object[2];
     objArray[0] = "VerifyConcurrencyValues";
     objArray[1] = "EntityUpdate";
     throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.NotImplementedExceptionMessage, objArray));
 }
Esempio n. 4
0
 public static void AddParametersToCommand(ICommand command, Uri uri)
 {
     try
     {
         NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(uri.Query);
         foreach (string key in nameValueCollection.Keys)
         {
             if (key == null || string.IsNullOrWhiteSpace(key))
             {
                 object[] str = new object[1];
                 str[0] = uri.ToString();
                 throw new DataServiceException(0x190, ExceptionHelpers.GetDataServiceExceptionMessage(HttpStatusCode.BadRequest, Resources.InvalidQueryParameterMessage, str));
             }
             else
             {
                 string[] values = nameValueCollection.GetValues(key);
                 if ((int)values.Length == 1)
                 {
                     string str1 = values[0];
                     if (!string.IsNullOrWhiteSpace(str1))
                     {
                         string str2 = key.Trim();
                         if (str2.StartsWith("$", StringComparison.OrdinalIgnoreCase))
                         {
                             continue;
                         }
                         try
                         {
                             command.AddParameter(str2, str1.Trim(), true);
                         }
                         catch (ArgumentException argumentException1)
                         {
                             ArgumentException argumentException = argumentException1;
                             object[]          objArray          = new object[1];
                             objArray[0] = uri.ToString();
                             throw new DataServiceException(0x190, string.Empty, ExceptionHelpers.GetDataServiceExceptionMessage(HttpStatusCode.BadRequest, Resources.InvalidQueryParameterMessage, objArray), string.Empty, argumentException);
                         }
                     }
                     else
                     {
                         object[] objArray1 = new object[1];
                         objArray1[0] = uri.ToString();
                         throw new DataServiceException(0x190, ExceptionHelpers.GetExceptionMessage(Resources.InvalidQueryParameterMessage, objArray1));
                     }
                 }
                 else
                 {
                     object[] objArray2 = new object[1];
                     objArray2[0] = uri.ToString();
                     throw new DataServiceException(0x190, ExceptionHelpers.GetDataServiceExceptionMessage(HttpStatusCode.BadRequest, Resources.InvalidQueryParameterMessage, objArray2));
                 }
             }
         }
     }
     catch (Exception exception)
     {
         TraceHelper.Current.UriParsingFailed(uri.ToString());
         throw;
     }
 }
Esempio n. 5
0
 internal ResourceSet AddResourceSet(string name, ResourceType entityType)
 {
     name.ThrowIfNullOrEmpty("name", Resources.NullIsPassedAsResourceSetName, new object[0]);
     object[] objArray = new object[1];
     objArray[0] = name;
     entityType.ThrowIfNull("entityType", Resources.ParameterSetNull, objArray);
     if (entityType.ResourceTypeKind == ResourceTypeKind.EntityType)
     {
         ResourceSet resourceSet = new ResourceSet(name, entityType);
         if (!this.ResourceSets.Keys.Contains <string>(name))
         {
             this.ResourceSets.Add(name, resourceSet);
             return(resourceSet);
         }
         else
         {
             object[] item = new object[3];
             item[0] = name;
             item[1] = entityType.Name;
             item[2] = this.ResourceSets[name];
             throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.ResourceSetNameDuplicated, item));
         }
     }
     else
     {
         throw new InvalidResourceTypeException(entityType.Name, entityType.ResourceTypeKind.ToString(), ResourceTypeKind.EntityType.ToString());
     }
 }
Esempio n. 6
0
        private ulong GetCommonParameterSets(string parameter)
        {
            ulong num = this.cmdletInfo.FindParameterSets(parameter);

            object[] cmdletName = new object[2];
            cmdletName[0] = parameter;
            cmdletName[1] = this.cmdletInfo.CmdletName;
            ExceptionHelpers.ThrowArgumentExceptionIf("parameter", num == (long)0, Resources.ParameterNotFoundInCommand, cmdletName);
            if (this.parameters.Count > 0)
            {
                ulong num1 = this.commonParameterFlag & num;
                if (num1 != (long)0)
                {
                    num = num1;
                }
                else
                {
                    object[] objArray = new object[2];
                    objArray[0] = parameter;
                    objArray[1] = this.cmdletInfo.CmdletName;
                    throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.ParametersAddedFromExclusiveSets, objArray));
                }
            }
            return(num);
        }
        public override object Serialize(object clrObject, int depth)
        {
            CollectionResourceType resourceType = base.ResourceType as CollectionResourceType;

            if (clrObject as PSObject != null)
            {
                clrObject = (clrObject as PSObject).BaseObject;
            }
            if (clrObject != null)
            {
                Type type = clrObject.GetType();
                if (!TypeSystem.ContainsDictionaryInterface(type))
                {
                    if (!TypeSystem.ContainsEnumerableInterface(type))
                    {
                        object[] assemblyQualifiedName = new object[1];
                        assemblyQualifiedName[0] = type.AssemblyQualifiedName;
                        throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.CollectionSeralizationFailedNotValidCollectionType, assemblyQualifiedName));
                    }
                    else
                    {
                        return(this.SerializeEnumerable(clrObject as IEnumerable, resourceType, depth));
                    }
                }
                else
                {
                    return(this.SerializeDictionary(clrObject as IDictionary, resourceType, depth));
                }
            }
            else
            {
                return(this.SerializeEnumerable(null, resourceType, depth));
            }
        }
Esempio n. 8
0
        public static object Build(Type type, Dictionary <string, object> properties)
        {
            object obj = TypeSystem.CreateInstance(type);

            foreach (string key in properties.Keys)
            {
                object       item = properties[key];
                PropertyInfo settablePropertyInfo = TypeSystem.GetSettablePropertyInfo(type, key);
                if (settablePropertyInfo == null)
                {
                    FieldInfo fieldInfoFromPropertyName = TypeSystem.GetFieldInfoFromPropertyName(type, key);
                    if (fieldInfoFromPropertyName != null)
                    {
                        item = TypeSystem.ConvertEnumerableToCollection(item, fieldInfoFromPropertyName.FieldType);
                        fieldInfoFromPropertyName.SetValue(obj, item);
                    }
                    else
                    {
                        object[] assemblyQualifiedName = new object[2];
                        assemblyQualifiedName[0] = key;
                        assemblyQualifiedName[1] = type.AssemblyQualifiedName;
                        throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.SettablePropertyNotFound, assemblyQualifiedName), "instance");
                    }
                }
                else
                {
                    item = TypeSystem.ConvertEnumerableToCollection(item, settablePropertyInfo.PropertyType);
                    settablePropertyInfo.SetValue(obj, item, null);
                }
            }
            return(obj);
        }
        public static SchemaLoader.ClassCategory GetCategory(this ClassDeclaration classDecl)
        {
            bool qualifier = classDecl.GetQualifier("ComplexType") != null;
            bool flag      = classDecl.GetQualifier("Association") != null;

            if (!qualifier || !flag)
            {
                if (!qualifier)
                {
                    if (!flag)
                    {
                        return(SchemaLoader.ClassCategory.Entity);
                    }
                    else
                    {
                        return(SchemaLoader.ClassCategory.Association);
                    }
                }
                else
                {
                    return(SchemaLoader.ClassCategory.Complex);
                }
            }
            else
            {
                object[] fullName = new object[1];
                fullName[0] = classDecl.Name.FullName;
                throw new MetadataException(ExceptionHelpers.GetExceptionMessage(Resources.ComplexTypeWithAssociation, fullName));
            }
        }
Esempio n. 10
0
 public object Resolve()
 {
     if (this.factory == null)
     {
         ResourceCustomState customState = this.resourceType.CustomState as ResourceCustomState;
         if (customState != null)
         {
             foreach (string list in this.properties.Keys.ToList <string>())
             {
                 object item = this.properties[list];
                 item = EntityUpdate.ResolveUpdatableObject(item);
                 item = EntityUpdate.ResolveUpdatableObjectList(item);
                 this.properties[list] = item;
             }
             return(ComplexTypeInstance.ClrInstanceForComplexTypeBuilder.Build(customState.ClrType, this.properties));
         }
         else
         {
             throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(Resources.ResourceCustomStateNull, new object[0]));
         }
     }
     else
     {
         return(this.factory(this.properties));
     }
 }
Esempio n. 11
0
 public IEnumerator <DSResource> InvokeAsync(Expression expression, bool noStreamingResponse)
 {
     object[] objArray = new object[2];
     objArray[0] = "Invoke";
     objArray[1] = "EntityUpdate";
     throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.NotImplementedExceptionMessage, objArray));
 }
        public bool IsAuthorized(UserContext userContext, Uri resourceUri)
        {
            SenderInfo senderInfo = new SenderInfo(userContext.GetIdentity(), userContext.ClientCertificate, resourceUri);

            CustomAuthorizationHandler.CustomContext customContext = null;
            TraceHelper.Current.MethodCall0("CustomAuthorizationHandler", "IsAuthorized");
            try
            {
                using (OperationTracerWithTimeout operationTracerWithTimeout = new OperationTracerWithTimeout(new Action <string>(TraceHelper.Current.CustomAuthzCallStart), new Action <string>(TraceHelper.Current.CustomAuthzCallEnd), "AuthorizeUser", new Action <string>(TraceHelper.Current.CustomAuthzExceedTimeLimit), 30))
                {
                    UserQuota       userQuotum      = null;
                    WindowsIdentity windowsIdentity = this.customAuthorization.AuthorizeUser(senderInfo, out userQuotum);
                    if (windowsIdentity != null)
                    {
                        if (userQuotum != null)
                        {
                            TraceHelper.Current.UserQuotaInformation(userContext.Name, userQuotum.MaxConcurrentRequests, userQuotum.MaxRequestsPerTimeSlot, userQuotum.TimeSlotSize);
                            customContext = new CustomAuthorizationHandler.CustomContext(windowsIdentity, userQuotum);
                        }
                        else
                        {
                            object[] nullQuota = new object[2];
                            nullQuota[0] = "CustomAuthorization.AuthorizeUser";
                            nullQuota[1] = Resources.NullQuota;
                            throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(Resources.MethodReturnedInvalidOutput, nullQuota));
                        }
                    }
                    else
                    {
                        object[] nullWindowsIdentity = new object[2];
                        nullWindowsIdentity[0] = "CustomAuthorization.AuthorizeUser";
                        nullWindowsIdentity[1] = Resources.NullWindowsIdentity;
                        throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(Resources.MethodReturnedInvalidOutput, nullWindowsIdentity));
                    }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                if (!exception.IsSevereException())
                {
                    exception.Trace(null);
                }
                else
                {
                    throw;
                }
            }
            this.customContextStore.StoreContext(customContext);
            if (customContext == null || customContext.Identity == null)
            {
                TraceHelper.Current.AuthorizeUserRequestFailed(userContext.Name, userContext.AuthenticationType);
                return(false);
            }
            else
            {
                TraceHelper.Current.AuthorizeUserRequestSucceeded(userContext.Name);
                return(true);
            }
        }
Esempio n. 13
0
        public void VerifyConcurrencyValues(IEnumerable <KeyValuePair <string, object> > values)
        {
            DSResource originalResource = this.GetOriginalResource();

            if (originalResource != null)
            {
                foreach (KeyValuePair <string, object> value in values)
                {
                    object obj = originalResource.GetValue(value.Key, null);
                    if (obj.Equals(value.Value))
                    {
                        continue;
                    }
                    object[] key = new object[2];
                    key[0] = value.Key;
                    key[1] = value.Value;
                    throw new DataServiceException(0x19c, ExceptionHelpers.GetDataServiceExceptionMessage(HttpStatusCode.PreconditionFailed, Resources.PropertyKey, key));
                }
                return;
            }
            else
            {
                throw new OptimisticConcurrencyException(ExceptionHelpers.GetExceptionMessage(Resources.GetCmdletNotReturningAnObject, new object[0]));
            }
        }
Esempio n. 14
0
 public void AddParameter(string parameter, object value, bool isOption)
 {
     object[] objArray = new object[2];
     objArray[0] = "AddParameter";
     objArray[1] = "EntityUpdate";
     throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.NotImplementedExceptionMessage, objArray));
 }
 public override object Serialize(object clrObject, int depth)
 {
     if (clrObject == null)
     {
         clrObject = this.defaultValue;
     }
     else
     {
         if (clrObject.GetType() != base.ResourceType.InstanceType)
         {
             try
             {
                 clrObject = TypeConverter.ConvertTo(clrObject, base.ResourceType.InstanceType);
             }
             catch (InvalidCastException invalidCastException1)
             {
                 InvalidCastException invalidCastException = invalidCastException1;
                 object[]             message = new object[2];
                 message[0] = this.name;
                 message[1] = invalidCastException.Message;
                 throw new DataServiceException(ExceptionHelpers.GetExceptionMessage(invalidCastException, Resources.PropertyNotSerialized, message), invalidCastException);
             }
         }
     }
     return(clrObject);
 }
        public static PropertyDeclaration GetProperty(this ClassDeclaration classDecl, string propertyName, HashSet <MofProduction> mof)
        {
            Func <PropertyDeclaration, bool> func  = null;
            Func <MofProduction, bool>       func1 = null;

            while (true)
            {
                NodeList <PropertyDeclaration> properties = classDecl.Properties;
                if (func == null)
                {
                    func = (PropertyDeclaration it) => string.Equals(it.Name, propertyName, StringComparison.Ordinal);
                }
                PropertyDeclaration propertyDeclaration = properties.FirstOrDefault <PropertyDeclaration>(func);
                if (propertyDeclaration != null)
                {
                    return(propertyDeclaration);
                }
                if (classDecl.SuperclassName == null)
                {
                    break;
                }
                HashSet <MofProduction> mofProductions = mof;
                if (func1 == null)
                {
                    func1 = (MofProduction item) => item.GetFullClassName() == classDecl.SuperclassName.FullName;
                }
                classDecl = mofProductions.First <MofProduction>(func1) as ClassDeclaration;
            }
            object[] fullClassName = new object[2];
            fullClassName[0] = propertyName;
            fullClassName[1] = classDecl.GetFullClassName();
            throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.PropertyNotFoundInODataResource, fullClassName));
        }
Esempio n. 17
0
 private bool ValidateParameterForSwitch(string parameter, object value)
 {
     if (!this.cmdletInfo.IsSwitch(parameter))
     {
         return(true);
     }
     else
     {
         bool flag = false;
         try
         {
             flag = (bool)TypeConverter.ConvertTo(value, typeof(bool));
         }
         catch (InvalidCastException invalidCastException1)
         {
             InvalidCastException invalidCastException = invalidCastException1;
             object[]             cmdletName           = new object[2];
             cmdletName[0] = parameter;
             cmdletName[1] = this.cmdletInfo.CmdletName;
             throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(invalidCastException, Resources.NotValidUrlOption, cmdletName), invalidCastException);
         }
         if (!flag)
         {
             TraceHelper.Current.DebugMessage(string.Concat("Switch parameter ", parameter, " with false value is passed. So not adding that in the PowerShell pipeline"));
         }
         return(flag);
     }
 }
Esempio n. 18
0
 public void Reset()
 {
     object[] objArray = new object[2];
     objArray[0] = "Reset";
     objArray[1] = "EntityUpdate";
     throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.NotImplementedExceptionMessage, objArray));
 }
Esempio n. 19
0
        public IEnumerator <DSResource> InvokeAsync(Expression expression, bool noStreamingResponse)
        {
            IEnumerator <DSResource> enumerator;

            using (OperationTracer operationTracer = new OperationTracer("Entering Pipeline.InvokeAsync"))
            {
                MonitorLock monitorLock  = new MonitorLock(this);
                MonitorLock monitorLock1 = monitorLock;
                using (monitorLock)
                {
                    if (this.Command == null || this.OutputFormat == null)
                    {
                        throw new DataServiceException(ExceptionHelpers.GetExceptionMessage(Resources.InvalidInvocationData, new object[0]));
                    }
                    else
                    {
                        this.ExpirationTime = DateTimeHelper.UtcNow;
                        DateTime expirationTime = this.ExpirationTime;
                        this.ExpirationTime = expirationTime.AddMilliseconds((double)this.WaitMsec);
                        DateTime dateTime = this.ExpirationTime;
                        this.ExpirationTime = dateTime.AddSeconds((double)DataServiceController.Current.Configuration.Invocation.Lifetime);
                        WindowsImpersonationContext windowsImpersonationContext = this.executionToken.Instance.Impersonate();
                        using (windowsImpersonationContext)
                        {
                            using (OperationTracer operationTracer1 = new OperationTracer("PowerShell.Create"))
                            {
                                ScriptBlockAst scriptBlockAst = this.ValidateAndBuildPipeline(string.Concat(this.Command, "| ConvertTo-", this.OutputFormat));
                                Runspace.DefaultRunspace = this.runspace.Item.Runspace;
                                this.powerShell          = scriptBlockAst.GetScriptBlock().GetPowerShell(new object[0]);
                                this.powerShell.Runspace = this.runspace.Item.Runspace;
                                Runspace.DefaultRunspace = null;
                            }
                            TraceHelper.Current.BeginOperation0("RunspaceContext.Create");
                            DefaultRunspaceContext defaultRunspaceContext = DefaultRunspaceContext.Create(this.runspace.Item.Runspace);
                            using (defaultRunspaceContext)
                            {
                                TraceHelper.Current.EndOperation("RunspaceContext.Create");
                                TraceHelper.Current.PipelineStart(this.ID, this.Command, this.OutputFormat);
                                this.outputObjects.DataAdded += new EventHandler <DataAddedEventArgs>(this.DataAddedEventHandler);
                                this.powerShell.BeginInvoke <PSObject, PSObject>(null, this.outputObjects, Utils.GetPSInvocationSettings(), this.TestHookCompletionCallback, null);
                                monitorLock1.Exit();
                                this.finished.WaitOne(this.WaitMsec);
                                this.timer.Start();
                                monitorLock1.Enter();
                                List <DSResource> dSResources = new List <DSResource>();
                                dSResources.Add(this.MakeDsResource());
                                TraceHelper.Current.DebugMessage("Exiting Pipeline.InvokeAsync");
                                enumerator = dSResources.AsEnumerable <DSResource>().GetEnumerator();
                            }
                        }
                    }
                }
            }
            return(enumerator);
        }
Esempio n. 20
0
 public void AddEnds(Schema.AssociationEnd end1, Schema.AssociationEnd end2)
 {
     if (this.Ends.Count == 0)
     {
         this.Ends.Add(end1);
         this.Ends.Add(end2);
         return;
     }
     else
     {
         throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.AssociationMoreThanTwoEndNotSupported, new object[0]));
     }
 }
Esempio n. 21
0
 public void ValidateResourceLimits(DSConfiguration configuration)
 {
     foreach (DSConfiguration.WcfConfigElement entitySet in configuration.DataServicesConfig.EntitySets)
     {
         if (!(entitySet.Name != "*") || this.ResourceSets.ContainsKey(entitySet.Name))
         {
             continue;
         }
         object[] name = new object[1];
         name[0] = entitySet.Name;
         throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.ConfigurationHasInvalidEntitySet, name));
     }
 }
Esempio n. 22
0
        public IIdentity GetIdentity()
        {
            IIdentity identity = CurrentRequestHelper.Identity;

            if (!string.Equals(this.Name, identity.Name, StringComparison.OrdinalIgnoreCase) || !string.Equals(this.AuthenticationType, identity.AuthenticationType, StringComparison.OrdinalIgnoreCase))
            {
                object[] traceMessage = new object[2];
                traceMessage[0] = this.ToTraceMessage("User Context");
                traceMessage[1] = identity.ToTraceMessage();
                throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(Resources.UserNameContextIdentityMismatch, traceMessage));
            }
            else
            {
                return(CurrentRequestHelper.Identity);
            }
        }
Esempio n. 23
0
 public void RequestProcessed()
 {
     TraceHelper.Current.DebugMessage(string.Concat("Usage.RequestProcessed called. Concurrent requests = ", this.concurrentRequests));
     lock (this.syncObject)
     {
         if (this.concurrentRequests != 0)
         {
             Usage usage = this;
             usage.concurrentRequests = usage.concurrentRequests - 1;
         }
         else
         {
             throw new OverflowException(ExceptionHelpers.GetExceptionMessage(Resources.ConcurrentRequestZero, new object[0]));
         }
     }
 }
Esempio n. 24
0
        public static WellKnownTypeFactory GetFactory(string typeName)
        {
            WellKnownTypeFactory wellKnownTypeFactory = null;

            WellKnownTypes.typeFactoryMap.TryGetValue(typeName, out wellKnownTypeFactory);
            if (wellKnownTypeFactory == null)
            {
                object[] objArray = new object[1];
                objArray[0] = typeName;
                throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.ComplexTypeNotSupported, objArray));
            }
            else
            {
                return(wellKnownTypeFactory);
            }
        }
Esempio n. 25
0
        public InitialSessionState Create(UserContext userContext, string membershipId)
        {
            InitialSessionState initialSessionState;

            using (OperationTracerWithTimeout operationTracerWithTimeout = new OperationTracerWithTimeout(new Action <string>(TraceHelper.Current.PSSessionCallStart), new Action <string>(TraceHelper.Current.PSSessionCallEnd), "InitialSessionState", new Action <string>(TraceHelper.Current.PSSessionMethodExceededTimeLimit), 30))
            {
                PSCertificateDetails pSCertificateDetail = null;
                if (userContext.ClientCertificate != null)
                {
                    pSCertificateDetail = new PSCertificateDetails(userContext.ClientCertificate.Subject, userContext.ClientCertificate.Issuer, userContext.ClientCertificate.Thumbprint);
                }
                PSIdentity   pSIdentity   = new PSIdentity(userContext.AuthenticationType, userContext.IsAuthenticated, userContext.Name, pSCertificateDetail);
                PSPrincipal  pSPrincipal  = new PSPrincipal(pSIdentity, userContext.GetIdentity() as WindowsIdentity);
                PSSenderInfo pSSenderInfo = new PSSenderInfo(pSPrincipal, DataServiceController.Current.GetCurrentResourceUri().ToString());
                try
                {
                    InitialSessionState initialSessionState1 = this.sessionConfiguration.GetInitialSessionState(pSSenderInfo);
                    if (initialSessionState1 != null)
                    {
                        TraceHelper.Current.GetInitialSessionStateRequestSucceeded(userContext.Name);
                        initialSessionState1.Trace();
                        initialSessionState = initialSessionState1;
                    }
                    else
                    {
                        object[] objArray = new object[2];
                        objArray[0] = "PSSessionState.GetInitialSessionState";
                        objArray[1] = "null";
                        throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(Resources.MethodReturnedInvalidOutput, objArray));
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    TraceHelper.Current.GetInitialSessionStateRequestFailed(userContext.Name, exception.Message);
                    if (!exception.IsSevereException())
                    {
                        throw new CustomModuleInvocationFailedException(this.sessionConfiguration.GetType().AssemblyQualifiedName, "GetInitialState", exception);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(initialSessionState);
        }
Esempio n. 26
0
        public object CreateResource(string containerName, string fullTypeName)
        {
            TraceHelper.Current.MethodCall2("DataServiceUpdateProvider", "AddReferenceToCollection", containerName, fullTypeName);
            ResourceType resourceType = null;

            if (containerName != null)
            {
                ResourceSet resourceSet = null;
                this.dataContext.UserSchema.ResourceSets.TryGetValue(containerName, out resourceSet);
                object[] objArray = new object[1];
                objArray[0] = containerName;
                ExceptionHelpers.ThrowArgumentExceptionIf("set", resourceSet == null, Resources.MissingResourceSet, objArray);
                if (this.entityInstance == null)
                {
                    resourceType = resourceSet.ResourceType;
                    EntityMetadata item = this.dataContext.UserSchema.EntityMetadataDictionary[resourceSet.ResourceType.FullName];
                    this.entityInstance = new EntityUpdate(this.dataContext.UserContext, resourceType, item, this.dataContext.MembershipId);
                    this.instances.Add(this.entityInstance);
                    return(this.entityInstance);
                }
                else
                {
                    throw new NotImplementedException(ExceptionHelpers.GetExceptionMessage(Resources.BatchUpdatesNotSupported, new object[0]));
                }
            }
            else
            {
                this.dataContext.UserSchema.ResourceTypes.TryGetValue(fullTypeName, out resourceType);
                if (resourceType != null)
                {
                    object[] objArray1 = new object[1];
                    objArray1[0] = fullTypeName;
                    ExceptionHelpers.ThrowArgumentExceptionIf("fullTypeName", resourceType.ResourceTypeKind != ResourceTypeKind.ComplexType, Resources.NotAComplexType, objArray1);
                    IUpdateInstance complexTypeInstance = new ComplexTypeInstance(resourceType);
                    this.instances.Add(complexTypeInstance);
                    return(complexTypeInstance);
                }
                else
                {
                    TraceHelper.Current.ResourceTypeNotFound(fullTypeName);
                    object[] objArray2 = new object[1];
                    objArray2[0] = fullTypeName;
                    throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.MissingResourceType, objArray2));
                }
            }
        }
Esempio n. 27
0
 public PSRunspace(InitialSessionState initialSessionState, bool executeCmdletInSameThread = false)
 {
     try
     {
         this.Runspace = RunspaceFactory.CreateRunspace(initialSessionState);
         if (executeCmdletInSameThread)
         {
             this.Runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;
         }
         this.Runspace.Open();
         DataServiceController.Current.PerfCounters.ActiveRunspaces.Increment();
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         TraceHelper.Current.FailedToCreateRunspace(exception.ToTraceMessage("Exception"));
         throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(exception, Resources.PowerShellConstrainedRunspaceCreationFailed, new object[0]), exception);
     }
 }
Esempio n. 28
0
        public static object GetFieldValue(object instance, string propertyName)
        {
            object    value;
            Type      type = instance.GetType();
            FieldInfo fieldInfoFromPropertyName = TypeSystem.GetFieldInfoFromPropertyName(type, propertyName);

            if (fieldInfoFromPropertyName != null)
            {
                try
                {
                    value = fieldInfoFromPropertyName.GetValue(instance);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    TraceHelper.Current.DebugMessage(exception.ToTraceMessage(string.Concat("GetFieldValue failed to parse property: ", propertyName)));
                    if (!exception.IsIgnorablePropertyException())
                    {
                        if (!exception.IsSevereException())
                        {
                            object[] message = new object[2];
                            message[0] = propertyName;
                            message[1] = exception.Message;
                            throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.PropertyRetrievalFailed, message), exception);
                        }
                        else
                        {
                            throw;
                        }
                    }
                    else
                    {
                        value = null;
                    }
                }
                return(value);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 29
0
 internal void AddPrimitiveProperty(ResourceType resourceType, string name, Type propertyType, ResourcePropertyKind flags, object defaultValue)
 {
     if (flags == ResourcePropertyKind.Primitive || flags == (ResourcePropertyKind.Primitive | ResourcePropertyKind.ETag) || flags == (ResourcePropertyKind.Primitive | ResourcePropertyKind.Key))
     {
         ResourceType         primitiveResourceType = ResourceType.GetPrimitiveResourceType(propertyType);
         ResourcePropertyKind resourcePropertyKind  = ResourcePropertyKind.Primitive;
         resourcePropertyKind = resourcePropertyKind | flags;
         ResourceProperty resourcePropertyWithDescription = new ResourcePropertyWithDescription(name, resourcePropertyKind, primitiveResourceType);
         resourcePropertyWithDescription.CanReflectOnInstanceTypeProperty = false;
         PropertyCustomState propertyCustomState = new PropertyCustomState();
         propertyCustomState.DefaultValue            = defaultValue;
         resourcePropertyWithDescription.CustomState = propertyCustomState;
         resourceType.AddProperty(resourcePropertyWithDescription);
         return;
     }
     else
     {
         throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.SchemaInvalidKeyOrEtagDiscrepancy, new object[0]), "flags");
     }
 }
Esempio n. 30
0
        private IEnumerable <DSResource> GetUniqueKeys(IQueryable <DSResource> source, ResourceProperty property)
        {
            DSResource.KeyEqualityComparer keyEqualityComparer = new DSResource.KeyEqualityComparer();
            List <DSResource> dSResources = new List <DSResource>();

            foreach (DSResource dSResource in source)
            {
                if (property.Kind != ResourcePropertyKind.ResourceReference)
                {
                    if (property.Kind != ResourcePropertyKind.ResourceSetReference)
                    {
                        throw new ArgumentException("the property is not a reference property", property.Name);
                    }
                    else
                    {
                        object value = dSResource.GetValue(property.Name, this.resultSets);
                        IEnumerable <DSResource> dSResources1 = value as IEnumerable <DSResource>;
                        if (dSResources1 == null)
                        {
                            object[] name = new object[1];
                            name[0] = property.Name;
                            throw new UnauthorizedAccessException(ExceptionHelpers.GetExceptionMessage(Resources.NoAccessToNavProperty, name));
                        }
                        else
                        {
                            dSResources.AddRange(dSResources1);
                        }
                    }
                }
                else
                {
                    DSResource value1 = dSResource.GetValue(property.Name, this.resultSets) as DSResource;
                    if (value1 == null)
                    {
                        continue;
                    }
                    dSResources.Add(value1);
                }
            }
            return(dSResources.Distinct <DSResource>(keyEqualityComparer));
        }