Ejemplo n.º 1
0
        protected void AddParameterInternal(string parameter, object value, bool isOptionParam)
        {
            bool flag;

            object[] cmdletName = new object[2];
            cmdletName[0] = parameter;
            cmdletName[1] = this.cmdletInfo.CmdletName;
            ExceptionHelpers.ThrowArgumentExceptionIf("parameter", this.parameters.ContainsKey(parameter), Resources.ParameterAlreadyAddedToCommand, cmdletName);
            string str = "parameter";

            if (!isOptionParam)
            {
                flag = false;
            }
            else
            {
                flag = !this.cmdletInfo.IsValidOption(parameter);
            }
            object[] objArray = new object[2];
            objArray[0] = parameter;
            objArray[1] = this.cmdletInfo.CmdletName;
            ExceptionHelpers.ThrowArgumentExceptionIf(str, flag, Resources.NotValidUrlOption, objArray);
            if (this.ValidateParameterForSwitch(parameter, value))
            {
                this.commonParameterFlag = this.GetCommonParameterSets(parameter);
                this.parameters.Add(parameter, value);
                return;
            }
            else
            {
                return;
            }
        }
 public CollectionResourceTypeSerializer(ResourceType resourceType) : base(resourceType)
 {
     object[] resourceTypeKind = new object[2];
     resourceTypeKind[0] = resourceType.ResourceTypeKind;
     resourceTypeKind[1] = ResourceTypeKind.Collection;
     ExceptionHelpers.ThrowArgumentExceptionIf("resourceType", resourceType.ResourceTypeKind != ResourceTypeKind.Collection, new ExceptionHelpers.MessageLoader(SerializerBase.GetInvalidArgMessage), resourceTypeKind);
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        internal IUpdateInstance GetInstanceFromHandle(object resource)
        {
            object          str;
            IUpdateInstance updateInstance      = resource as IUpdateInstance;
            string          str1                = "resource";
            bool            flag                = updateInstance == null;
            string          invalidUpdateHandle = Resources.InvalidUpdateHandle;

            object[] objArray  = new object[1];
            object[] objArray1 = objArray;
            int      num       = 0;

            if (resource != null)
            {
                str = resource.ToString();
            }
            else
            {
                str = string.Empty;
            }
            objArray1[num] = str;
            ExceptionHelpers.ThrowArgumentExceptionIf(str1, flag, invalidUpdateHandle, objArray);
            ExceptionHelpers.ThrowArgumentExceptionIf("resource", !this.instances.Contains(updateInstance), Resources.NoLongerValidUpdateHandle, new object[0]);
            return(updateInstance);
        }
Ejemplo n.º 5
0
        internal PSParameterInfo FindParameterInfo(string parameter)
        {
            IEnumerable <PSParameterSet> pSParameterSets = this.ParameterSets.FindAll((PSParameterSet item) => item.Parameters.ContainsKey(parameter));

            object[] cmdletName = new object[2];
            cmdletName[0] = parameter;
            cmdletName[1] = this.CmdletName;
            ExceptionHelpers.ThrowArgumentExceptionIf("parameter", pSParameterSets.Count <PSParameterSet>() == 0, Resources.ParameterNotFoundInCommand, cmdletName);
            PSParameterInfo pSParameterInfo = null;

            foreach (PSParameterSet pSParameterSet in pSParameterSets)
            {
                PSParameterInfo pSParameterInfo1 = pSParameterSet.Parameters[parameter];
                if (pSParameterInfo != null)
                {
                    if (!(pSParameterInfo.Type != pSParameterInfo1.Type) && pSParameterInfo.IsSwitch == pSParameterInfo1.IsSwitch)
                    {
                        continue;
                    }
                    TraceHelper.Current.DebugMessage(string.Concat("Parameter ", parameter, " is found in multiple parameter set and has either different Type or IsSwitch value. So FindParametersInfo returns null"));
                    pSParameterInfo = null;
                    break;
                }
                else
                {
                    pSParameterInfo = pSParameterInfo1;
                }
            }
            return(pSParameterInfo);
        }
Ejemplo n.º 6
0
        public PrimitiveTypeSerializer(ResourceType resourceType, ResourceProperty resourceProperty) : base(resourceType)
        {
            object defaultValue;

            object[] resourceTypeKind = new object[2];
            resourceTypeKind[0] = resourceType.ResourceTypeKind;
            resourceTypeKind[1] = ResourceTypeKind.Primitive;
            ExceptionHelpers.ThrowArgumentExceptionIf("resourceType", resourceType.ResourceTypeKind != ResourceTypeKind.Primitive, new ExceptionHelpers.MessageLoader(SerializerBase.GetInvalidArgMessage), resourceTypeKind);
            this.defaultValue = null;
            if (resourceProperty != null)
            {
                if ((resourceProperty.Kind & ResourcePropertyKind.Primitive) != ResourcePropertyKind.Primitive || resourceProperty.ResourceType.InstanceType != resourceType.InstanceType)
                {
                    throw new ArgumentException("resourceProperty");
                }
                else
                {
                    PropertyCustomState     customState             = resourceProperty.GetCustomState();
                    PrimitiveTypeSerializer primitiveTypeSerializer = this;
                    if (customState != null)
                    {
                        defaultValue = customState.DefaultValue;
                    }
                    else
                    {
                        defaultValue = null;
                    }
                    primitiveTypeSerializer.defaultValue = defaultValue;
                    this.name = resourceProperty.Name;
                }
            }
        }
Ejemplo n.º 7
0
 public EntityTypeSerializer(ResourceType resourceType, bool serializeKeyOnly = false) : base(resourceType)
 {
     object[] resourceTypeKind = new object[2];
     resourceTypeKind[0] = resourceType.ResourceTypeKind;
     resourceTypeKind[1] = ResourceTypeKind.EntityType;
     ExceptionHelpers.ThrowArgumentExceptionIf("resourceType", resourceType.ResourceTypeKind != ResourceTypeKind.EntityType, new ExceptionHelpers.MessageLoader(SerializerBase.GetInvalidArgMessage), resourceTypeKind);
     this.serializeKeyOnly       = serializeKeyOnly;
     this.TestHookEntityMetadata = null;
 }
Ejemplo n.º 8
0
 public EntityMetadata GetEntityMetadata(ResourceType resourceType)
 {
     object[] name = new object[3];
     name[0] = resourceType.Name;
     name[1] = ResourceTypeKind.EntityType;
     name[2] = resourceType.ResourceTypeKind;
     ExceptionHelpers.ThrowArgumentExceptionIf("resourceType", resourceType.ResourceTypeKind != ResourceTypeKind.EntityType, Resources.ResourceTypeIsInvalid, name);
     return(this.EntityMetadataDictionary[resourceType.FullName]);
 }
Ejemplo n.º 9
0
        public object GetResource(IQueryable query, string fullTypeName)
        {
            object obj;

            TraceHelper.Current.MethodCall2("DataServiceUpdateProvider", "GetResource", query.ToString(), fullTypeName);
            try
            {
                DSLinqQueryProvider provider = query.Provider as DSLinqQueryProvider;
                ExceptionHelpers.ThrowArgumentExceptionIf("query", provider == null, Resources.QueryDoesNotIncludePswsProvider, new object[0]);
                if (!provider.IsFilterOverResourceRoot(query.Expression))
                {
                    ReferredResourceExtractor referredResourceExtractor = new ReferredResourceExtractor();
                    DSResource current = null;
                    if (!referredResourceExtractor.Extract(query.Expression, provider.GetInitialQueryable(), provider.GetInitialResourceType(), provider.GetEntityMetadata(provider.GetInitialResourceType())))
                    {
                        IEnumerator <DSResource> enumerator = (query.GetEnumerator() as IEnumerable <DSResource>).GetEnumerator();
                        if (enumerator.MoveNext())
                        {
                            current = enumerator.Current;
                            if (enumerator.MoveNext())
                            {
                                throw new ArgumentException("multiple instances");
                            }
                        }
                        else
                        {
                            throw new ArgumentException("no instances");
                        }
                    }
                    else
                    {
                        current = referredResourceExtractor.ReferredResource;
                    }
                    ResourceType    resourceType           = current.ResourceType;
                    EntityMetadata  entityMetadata         = provider.GetEntityMetadata(resourceType);
                    IUpdateInstance referredEntityInstance = new ReferredEntityInstance(current, this.dataContext.UserContext, resourceType, entityMetadata, this.dataContext.MembershipId);
                    this.instances.Add(referredEntityInstance);
                    obj = referredEntityInstance;
                }
                else
                {
                    ResourceType   initialResourceType = provider.GetInitialResourceType();
                    EntityMetadata entityMetadatum     = provider.GetEntityMetadata(initialResourceType);
                    this.entityInstance = new EntityUpdate(CommandType.Update, this.dataContext.UserContext, initialResourceType, entityMetadatum, query, this.dataContext.MembershipId);
                    this.instances.Add(this.entityInstance);
                    obj = this.entityInstance;
                }
            }
            catch (ArgumentException argumentException1)
            {
                ArgumentException argumentException = argumentException1;
                TraceHelper.Current.InvalidUpdateQuery(fullTypeName, query.ToString(), argumentException.GetType().ToString(), argumentException.Message);
                obj = null;
            }
            return(obj);
        }
Ejemplo n.º 10
0
        public bool AddFieldParameter(string parameter, object value)
        {
            ResourceProperty resourceProperty = this.resourceType.KeyProperties.SingleOrDefault <ResourceProperty>((ResourceProperty p) => p.Name == parameter);

            object[] objArray = new object[1];
            objArray[0] = parameter;
            ExceptionHelpers.ThrowArgumentExceptionIf("parameter", resourceProperty == null, Resources.FieldIsNotAKey, objArray);
            this.propertyUpdates.Add(parameter, value);
            return(true);
        }
Ejemplo n.º 11
0
 public static void AddDerivedType(this ResourceType resourceType, ResourceType derivedType)
 {
     object[] name = new object[1];
     name[0] = resourceType.Name;
     derivedType.ThrowIfNull("derivedType", Resources.NullPassedAsDerivedType, name);
     object[] fullName = new object[2];
     fullName[0] = resourceType.FullName;
     fullName[1] = derivedType.FullName;
     ExceptionHelpers.ThrowArgumentExceptionIf("derivedType", derivedType.BaseType != resourceType, Resources.NotBaseResourceType, fullName);
     (resourceType.CustomState as ResourceCustomState).DerivedTypes.Add(derivedType);
 }
Ejemplo n.º 12
0
        public ICommand GetCommand(CommandType commandType, UserContext userContext, ResourceType entityType, EntityMetadata entityMetadata, string membershipId)
        {
            Envelope <PSRunspace, UserContext> envelope = this.runspaceStore.Borrow(userContext, membershipId);
            PSEntityMetadata pSEntityMetadatum          = entityMetadata as PSEntityMetadata;

            object[] assemblyQualifiedName = new object[3];
            assemblyQualifiedName[0] = "entityMetadata";
            assemblyQualifiedName[1] = entityMetadata.GetType().AssemblyQualifiedName;
            assemblyQualifiedName[2] = typeof(PSEntityMetadata).AssemblyQualifiedName;
            ExceptionHelpers.ThrowArgumentExceptionIf("entityMetadata", pSEntityMetadatum == null, Resources.InvalidArgClrType, assemblyQualifiedName);
            object[] name = new object[2];
            name[0] = entityType.Name;
            name[1] = commandType.ToString();
            ExceptionHelpers.ThrowArgumentExceptionIf("entityMetadata", !pSEntityMetadatum.Cmdlets.ContainsKey(commandType), Resources.EntityDoesNotHaveCommand, name);
            return(new PSCommand(envelope, entityType, pSEntityMetadatum.Cmdlets[commandType], commandType));
        }
Ejemplo n.º 13
0
        public static DSResource SerializeEntity(object instance, ResourceType resourceType)
        {
            object[] resourceTypeKind = new object[2];
            resourceTypeKind[0] = resourceType.ResourceTypeKind;
            resourceTypeKind[1] = ResourceTypeKind.EntityType;
            ExceptionHelpers.ThrowArgumentExceptionIf("resourceType", resourceType.ResourceTypeKind != ResourceTypeKind.EntityType, new ExceptionHelpers.MessageLoader(SerializerBase.GetInvalidArgMessage), resourceTypeKind);
            DSResource dSResource = SerializerBase.SerializeResourceType(instance, resourceType, 1) as DSResource;

            if (dSResource != null)
            {
                return(dSResource);
            }
            else
            {
                throw new InvalidOperationException(Resources.SerializeEntityReturnedNull);
            }
        }
Ejemplo n.º 14
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));
                }
            }
        }
 public CustomAuthorizationHandler(string customAuthzAssembly, string customAuthzTypeName, CustomAuthorizationHandler.ICustomContextStore customContextStore)
 {
     try
     {
         if (customContextStore != null)
         {
             this.customContextStore = customContextStore;
         }
         else
         {
             this.customContextStore = new CustomAuthorizationHandler.OperationContextBasedContextStore();
         }
         Type type = TypeLoader.LoadType(customAuthzAssembly, customAuthzTypeName);
         if (type != null)
         {
             this.customAuthorization = type.Assembly.CreateInstance(type.FullName) as CustomAuthorization;
             ExceptionHelpers.ThrowArgumentExceptionIf("customAuthzTypeName", this.customAuthorization == null, Resources.CustomAuthorizationPluginCreationFailed, new object[0]);
         }
         else
         {
             object[] objArray = new object[2];
             objArray[0] = customAuthzTypeName;
             objArray[1] = customAuthzAssembly;
             throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.TypeLoadFromAssebmlyFailed, objArray), "customAuthzTypeName");
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         TraceHelper.Current.CustomAuthorizationLoadingFailed(customAuthzAssembly, exception.ToTraceMessage("Exception"));
         if (!exception.IsSevereException())
         {
             throw new TypeLoadException(customAuthzTypeName, customAuthzAssembly, Utils.GetBaseBinDirectory(customAuthzAssembly), exception);
         }
         else
         {
             throw;
         }
     }
     TraceHelper.Current.CustomAuthorizationLoadedSuccessfully(customAuthzTypeName);
 }
Ejemplo n.º 16
0
        internal ScriptBlockAst ValidateAndBuildPipeline(string rawString)
        {
            Token[]        tokenArray      = null;
            ParseError[]   parseErrorArray = null;
            bool           length;
            ScriptBlockAst scriptBlockAst = Parser.ParseInput(rawString, out tokenArray, out parseErrorArray);
            string         str            = "rawString";

            if (parseErrorArray == null)
            {
                length = false;
            }
            else
            {
                length = (int)parseErrorArray.Length != 0;
            }
            object[] objArray = new object[1];
            objArray[0] = rawString;
            ExceptionHelpers.ThrowArgumentExceptionIf(str, length, Resources.InvalidPipeline, objArray);
            return(scriptBlockAst);
        }
Ejemplo n.º 17
0
        public EntityUpdate(CommandType commandType, UserContext userContext, ResourceType type, EntityMetadata metadata, IQueryable query, string membershipId)
        {
            ExceptionHelpers.ThrowArgumentExceptionIf("commandType", commandType != CommandType.Update, Resources.InternalErrorOccurred, new object[0]);
            this.query           = query;
            this.userContext     = userContext;
            this.membershipId    = membershipId;
            this.resourceType    = type;
            this.metadata        = metadata;
            this.commandType     = commandType;
            this.propertyUpdates = new SortedDictionary <string, object>();
            this.updatedResource = null;
            this.resolveResource = null;
            CommandArgumentVisitor commandArgumentVisitor = new CommandArgumentVisitor(this);

            commandArgumentVisitor.Visit(query.Expression);
            if (this.AreAllKeyFieldsSpecified())
            {
                return;
            }
            else
            {
                throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.KeysMissingInQuery, new object[0]));
            }
        }