private static ErrorCodes WNetOpenEnum(ResourceScope dwScope, ResourceType dwType,
                                        ResourceUsage dwUsage, NETRESOURCE p, out IntPtr lphEnum)
 {
     Console.WriteLine("Warning--using unimplemented method WNetOpenEnum");             // FIXME Linux
     lphEnum = IntPtr.Zero;
     return(ErrorCodes.NO_ERROR);
 }
Beispiel #2
0
        public static void EmitModuleScopeProperties(ResourceScope targetScope, ScopeData scopeData, ExpressionEmitter expressionEmitter)
        {
            switch (scopeData.RequestedScope)
            {
            case ResourceScope.Tenant:
                expressionEmitter.EmitProperty("scope", new JTokenExpression("/"));
                return;

            case ResourceScope.ManagementGroup:
                if (scopeData.ManagementGroupNameProperty != null)
                {
                    // The template engine expects an unqualified resourceId for the management group scope if deploying at tenant scope
                    var useFullyQualifiedResourceId = targetScope != ResourceScope.Tenant;
                    expressionEmitter.EmitProperty("scope", expressionEmitter.GetManagementGroupResourceId(scopeData.ManagementGroupNameProperty, useFullyQualifiedResourceId));
                }
                return;

            case ResourceScope.Subscription:
            case ResourceScope.ResourceGroup:
                if (scopeData.SubscriptionIdProperty != null)
                {
                    expressionEmitter.EmitProperty("subscriptionId", scopeData.SubscriptionIdProperty);
                }
                if (scopeData.ResourceGroupProperty != null)
                {
                    expressionEmitter.EmitProperty("resourceGroup", scopeData.ResourceGroupProperty);
                }
                return;

            default:
                throw new NotImplementedException($"Cannot format resourceId for scope {scopeData.RequestedScope}");
            }
        }
Beispiel #3
0
 public ModuleDefinition(string moduleName, ResourceScope modulePropertyScopeType, ImmutableArray <StringSyntax?>?modulePropertyScopeValue, StringSyntax modulePropertyNameValue)
 {
     ModuleName = moduleName;
     ModulePropertyScopeType  = modulePropertyScopeType;
     ModulePropertyScopeValue = modulePropertyScopeValue;
     ModulePropertyNameValue  = modulePropertyNameValue;
 }
        public void InvalidResourceScope1()
        {
            ResourceScope             bad = (ResourceScope)Int32.MinValue;
            ResourceExposureAttribute rea = new ResourceExposureAttribute(bad);

            Assert.AreEqual(bad, rea.ResourceExposureLevel, "ResourceScope");
        }
        public TypeSymbol GetDeclaredType(ResourceScope targetScope, IResourceTypeProvider resourceTypeProvider)
        {
            var stringSyntax = this.TypeString;

            if (stringSyntax != null && stringSyntax.IsInterpolated())
            {
                // TODO: in the future, we can relax this check to allow interpolation with compile-time constants.
                // right now, codegen will still generate a format string however, which will cause problems for the type.
                return(ErrorType.Create(DiagnosticBuilder.ForPosition(this.Type).ResourceTypeInterpolationUnsupported()));
            }

            var stringContent = stringSyntax?.TryGetLiteralValue();

            if (stringContent == null)
            {
                return(ErrorType.Create(DiagnosticBuilder.ForPosition(this.Type).InvalidResourceType()));
            }

            var typeReference = ResourceTypeReference.TryParse(stringContent);

            if (typeReference == null)
            {
                return(ErrorType.Create(DiagnosticBuilder.ForPosition(this.Type).InvalidResourceType()));
            }

            return(resourceTypeProvider.GetType(targetScope, typeReference));
        }
Beispiel #6
0
        public static IEnumerable <string> GetResourceScopeDescriptions(ResourceScope resourceScope)
        {
            if (resourceScope == ResourceScope.None)
            {
                yield return("none");
            }

            if (resourceScope.HasFlag(ResourceScope.Resource))
            {
                yield return("resource");
            }
            if (resourceScope.HasFlag(ResourceScope.Module))
            {
                yield return("module");
            }
            if (resourceScope.HasFlag(ResourceScope.Tenant))
            {
                yield return("tenant");
            }
            if (resourceScope.HasFlag(ResourceScope.ManagementGroup))
            {
                yield return("managementGroup");
            }
            if (resourceScope.HasFlag(ResourceScope.Subscription))
            {
                yield return("subscription");
            }
            if (resourceScope.HasFlag(ResourceScope.ResourceGroup))
            {
                yield return("resourceGroup");
            }
        }
Beispiel #7
0
 public ResourceType(ResourceTypeReference typeReference, ResourceScope validParentScopes, ITypeReference body)
     : base(typeReference.FormatName())
 {
     TypeReference     = typeReference;
     ValidParentScopes = validParentScopes;
     Body = body;
 }
        public static string MakeVersionSafeName(string name, ResourceScope from, ResourceScope to, Type type)
        {
            if ((from & ResourceScope.Private) != ResourceScope.None)
            {
                to &= ~(ResourceScope.Private | ResourceScope.Assembly);
            }
            else if ((from & ResourceScope.Assembly) != ResourceScope.None)
            {
                to &= ~ResourceScope.Assembly;
            }
            string name2 = (name != null) ? name : string.Empty;

            switch (from)
            {
            case ResourceScope.Machine:
                break;

            case ResourceScope.Process:
                goto IL_8F;

            default:
                switch (from)
                {
                case ResourceScope.Machine | ResourceScope.Private:
                    break;

                case ResourceScope.Process | ResourceScope.Private:
                    goto IL_8F;

                default:
                    switch (from)
                    {
                    case ResourceScope.Machine | ResourceScope.Assembly:
                        goto IL_86;

                    case ResourceScope.Process | ResourceScope.Assembly:
                        goto IL_8F;

                    case ResourceScope.AppDomain | ResourceScope.Assembly:
                        goto IL_98;
                    }
                    throw new ArgumentException("from");

                case ResourceScope.AppDomain | ResourceScope.Private:
                    goto IL_98;
                }
                break;

            case ResourceScope.AppDomain:
                goto IL_98;
            }
IL_86:
            return(VersioningHelper.ConvertFromMachine(name2, to, type));

IL_8F:
            return(VersioningHelper.ConvertFromProcess(name2, to, type));

IL_98:
            return(VersioningHelper.ConvertFromAppDomain(name2, to, type));
        }
Beispiel #9
0
 public void DestroyAllDeviceObjects(ResourceScope scope)
 {
     foreach (var r in _resourceContainers)
     {
         r.DestroyDeviceObjects(scope);
     }
 }
        // code of this function is based on http://www.codeproject.com/Articles/6235/Enumerating-Network-Resources
        private static void EnumerateServers(ResourceScope scope, ResourceType type, ResourceUsage usage, IList<NetResource> aData)
        {
            uint bufferSize = 16384;
            IntPtr buffer = Marshal.AllocHGlobal((int)bufferSize);
            IntPtr handle;
            uint cEntries = 1;
            var pRsrc = new NetResource();

            int result = WNetOpenEnum(scope, type, usage, pRsrc, out handle);

            if (result == 0)
            {
                while (result == 0)
                {
                    result = WNetEnumResource(handle, ref cEntries, buffer, ref	bufferSize);

                    if (result == 0)
                    {
                        var netResource = new NetResource();
                        Marshal.PtrToStructure(buffer, netResource);

                        aData.Add(netResource);

                        if ((pRsrc.Usage & (int)ResourceUsage.Container) == (int)ResourceUsage.Container)
                        {
                            EnumerateServers(scope, type, usage, aData);
                        }
                    }
                }

                WNetCloseEnum(handle);
            }

            Marshal.FreeHGlobal(buffer);
        }
        public Stream OpenResourceStream(ResourceScope project, string uri)
        {
            string projectPath = "";

              string basePath = BasePathHelper.GetTestBasePathWithBranch();

              switch (project)
              {
            case ResourceScope.Core:
              projectPath = "Core/";
              break;

            case ResourceScope.IdeCommon:
              projectPath = "IDECommon/";
              break;

            case ResourceScope.TestCommon:
              projectPath = "TestsCommon/";
              break;

            default:
              throw new ArgumentOutOfRangeException("project");
              }

              return File.Open(basePath + projectPath + uri, FileMode.Open, FileAccess.Read);
        }
        public Stream OpenResourceStream(ResourceScope project, string uri)
        {
            string projectPath = "";

              switch (project)
              {
            case ResourceScope.Core:
              projectPath = "/Catrobat.Core;component/";
              break;
            case ResourceScope.IdeCommon:
              projectPath = "/Catrobat.IDECommon;component/";
              break;
            case ResourceScope.IdePhone:
              projectPath = "";
              break;
            case ResourceScope.TestsPhone:
              projectPath = "";
              break;
            default:
              throw new ArgumentOutOfRangeException("project");
              }

              var resourceUri = new Uri(projectPath + uri, UriKind.Relative);

              var resource = Application.GetResourceStream(resourceUri);

              return resource != null ? resource.Stream : null;
        }
Beispiel #13
0
        public PortableImage LoadImage(ResourceScope resourceScope, string path)
        {
            var task = LoadImageAsync(resourceScope, path);

            task.Wait();
            return(task.Result);
        }
Beispiel #14
0
 public static extern WinError WNetOpenEnum(
     ResourceScope dwScope,
     ResourceType dwType,
     ResourceUsage dwUsage,
     NETRESOURCE pNetResource,
     out IntPtr phEnum
     );
        private void RemoveScope(PipId pipId)
        {
            lock (m_syncLock)
            {
                ResourceScope scope;
                if (m_pipResourceScopes.TryGetValue(pipId, out scope))
                {
                    m_pipResourceScopes.Remove(pipId);

                    if (scope == m_headScope)
                    {
                        m_headScope = scope.Next;
                    }

                    if (scope.Prior != null)
                    {
                        scope.Prior.Next = scope.Next;
                    }

                    if (scope.Next != null)
                    {
                        scope.Next.Prior = scope.Prior;
                    }

                    scope.Next  = null;
                    scope.Prior = null;
                }
            }
        }
Beispiel #16
0
        public Stream OpenResourceStream(ResourceScope project, string uri)
        {
            var task = OpenResourceStreamAsync(project, uri);

            task.Wait();
            return(task.Result);
        }
        static public string MakeVersionSafeName(string name, ResourceScope from, ResourceScope to, Type type)
        {
            if ((from & ResourceScope.Private) != 0)
            {
                to &= ~(ResourceScope.Private | ResourceScope.Assembly);
            }
            else if ((from & ResourceScope.Assembly) != 0)
            {
                to &= ~ResourceScope.Assembly;
            }

            string result = (name == null) ? String.Empty : name;

            switch (from)
            {
            case ResourceScope.Machine:
            case ResourceScope.Machine | ResourceScope.Private:
            case ResourceScope.Machine | ResourceScope.Assembly:
                return(ConvertFromMachine(result, to, type));

            case ResourceScope.Process:
            case ResourceScope.Process | ResourceScope.Private:
            case ResourceScope.Process | ResourceScope.Assembly:
                return(ConvertFromProcess(result, to, type));

            case ResourceScope.AppDomain:
            case ResourceScope.AppDomain | ResourceScope.Private:
            case ResourceScope.AppDomain | ResourceScope.Assembly:
                return(ConvertFromAppDomain(result, to, type));

            default:
                throw new ArgumentException("from");
            }
        }
 public override void DestroyDeviceObjects(ResourceScope scope)
 {
     if ((scope & ResourceScope.Map) != 0)
     {
         _disposeCollector.DisposeAll();
     }
 }
        private List <NETRESOURCE> GetChildNetResources(
            ResourceScope dwScope,
            ResourceType dwType,
            ResourceUsage dwUsage,
            NETRESOURCE NetResource
            )
        {
            WinError           error  = WinError.NO_ERROR;
            IntPtr             handle = new IntPtr();
            List <NETRESOURCE> nrList = new List <NETRESOURCE>();

            error = FileClient.FileClient.BeginEnumNetResources(dwScope,
                                                                dwType,
                                                                dwUsage,
                                                                NetResource,
                                                                out handle);

            if (error == WinError.NO_ERROR)
            {
                error = FileClient.FileClient.EnumNetResources(handle, out nrList);

                FileClient.FileClient.EndEnumNetResources(handle);
            }

            return(nrList);
        }
Beispiel #20
0
        /*
         * BeginEnumNetResources - Begin search for connections. Options to find connected, connectable, remembered locations.
         */
        public static WinError BeginEnumNetResources(
            ResourceScope dwScope,
            ResourceType dwType,
            ResourceUsage dwUsage,
            NETRESOURCE pNetResource,
            out IntPtr enumHandle
            )
        {
            WinError error = WinError.ERROR_SUCCESS;

            if (useWindowsDlls)
            {
                error = InteropWindows.WNetOpenEnum(dwScope, dwType, dwUsage, pNetResource, out enumHandle);
            }
            else
            {
                error      = WinError.ERROR_INVALID_PARAMETER;
                enumHandle = new IntPtr(0);
            }

            if (error == WinError.ERROR_EXTENDED_ERROR)
            {
                error = (WinError)Marshal.GetLastWin32Error();
            }

            return(error);
        }
Beispiel #21
0
        public TypeSymbol GetDeclaredType(ResourceScope containingScope, SemanticModel moduleSemanticModel)
        {
            var paramTypeProperties = new List <TypeProperty>();

            foreach (var param in moduleSemanticModel.Root.ParameterDeclarations)
            {
                var typePropertyFlags = TypePropertyFlags.WriteOnly;
                if (SyntaxHelper.TryGetDefaultValue(param.DeclaringParameter) == null)
                {
                    // if there's no default value, it must be specified
                    typePropertyFlags |= TypePropertyFlags.Required;
                }

                paramTypeProperties.Add(new TypeProperty(param.Name, param.Type, typePropertyFlags));
            }

            var outputTypeProperties = new List <TypeProperty>();

            foreach (var output in moduleSemanticModel.Root.OutputDeclarations)
            {
                outputTypeProperties.Add(new TypeProperty(output.Name, output.Type, TypePropertyFlags.ReadOnly));
            }

            return(LanguageConstants.CreateModuleType(paramTypeProperties, outputTypeProperties, moduleSemanticModel.TargetScope, containingScope, "module"));
        }
		static private string ConvertFromProcess (string name, ResourceScope to, Type type)
		{
			if ((to < ResourceScope.Process) || (to >= ResourceScope.Private))
				throw new ArgumentException ("to");
			bool ad = ((to & ResourceScope.AppDomain) == ResourceScope.AppDomain);
			return SafeName (name, false, ad);
		}
Beispiel #23
0
        private static ObjectType GetDeploymentReturnType(ResourceScope targetScope)
        {
            // Note: there are other properties which could be included here, but they allow you to break out of the bicep world.
            // We're going to omit them and only include what is truly necessary. If we get feature requests to expose more properties, we should discuss this further.
            // Properties such as 'template', 'templateHash', 'parameters' depend on the codegen, and feel like they could be fragile.
            IEnumerable <TypeProperty> properties = new[]
            {
                new TypeProperty("name", LanguageConstants.String),
                new TypeProperty("properties", new ObjectType("properties", TypeSymbolValidationFlags.Default, new []
                {
                    new TypeProperty("templateLink", new ObjectType("properties", TypeSymbolValidationFlags.Default, new []
                    {
                        new TypeProperty("id", LanguageConstants.String),
                        new TypeProperty("uri", LanguageConstants.String),
                    }, null))
                }, null)),
            };

            if (!targetScope.HasFlag(ResourceScope.ResourceGroup))
            {
                // deployments in the 'resourcegroup' scope do not have the 'location' property. All other scopes do.
                var locationProperty = new TypeProperty("location", LanguageConstants.String);
                properties = properties.Concat(locationProperty.AsEnumerable());
            }

            return(new ObjectType("deployment", TypeSymbolValidationFlags.Default, properties, null));
        }
        public static string MakeVersionSafeName(string name, ResourceScope from, ResourceScope to, Type type)
        {
            ResourceScope resourceScope1 = from & (ResourceScope.Machine | ResourceScope.Process | ResourceScope.AppDomain | ResourceScope.Library);
            ResourceScope resourceScope2 = to & (ResourceScope.Machine | ResourceScope.Process | ResourceScope.AppDomain | ResourceScope.Library);

            if (resourceScope1 > resourceScope2)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_ResourceScopeWrongDirection", (object)resourceScope1, (object)resourceScope2), "from");
            }
            int num1 = (int)VersioningHelper.GetRequirements(to, from);
            int num2 = 24;

            if ((num1 & num2) != 0 && type == (Type)null)
            {
                throw new ArgumentNullException("type", Environment.GetResourceString("ArgumentNull_TypeRequiredByResourceScope"));
            }
            StringBuilder stringBuilder = new StringBuilder(name);
            char          ch            = '_';
            int           num3          = 2;

            if ((num1 & num3) != 0)
            {
                stringBuilder.Append(ch);
                stringBuilder.Append('p');
                stringBuilder.Append(Win32Native.GetCurrentProcessId());
            }
            int num4 = 4;

            if ((num1 & num4) != 0)
            {
                string clrInstanceString = VersioningHelper.GetCLRInstanceString();
                stringBuilder.Append(ch);
                stringBuilder.Append('r');
                stringBuilder.Append(clrInstanceString);
            }
            int num5 = 1;

            if ((num1 & num5) != 0)
            {
                stringBuilder.Append(ch);
                stringBuilder.Append("ad");
                stringBuilder.Append(AppDomain.CurrentDomain.Id);
            }
            int num6 = 16;

            if ((num1 & num6) != 0)
            {
                stringBuilder.Append(ch);
                stringBuilder.Append(type.Name);
            }
            int num7 = 8;

            if ((num1 & num7) != 0)
            {
                stringBuilder.Append(ch);
                stringBuilder.Append(type.Assembly.FullName);
            }
            return(stringBuilder.ToString());
        }
Beispiel #25
0
        private void EnumerateServers(NETRESOURCE pRsrc, ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType, string strDomain)
        {
            uint       bufferSize = 16384;
            IntPtr     buffer     = Marshal.AllocHGlobal((int)bufferSize);
            IntPtr     handle     = IntPtr.Zero;
            ErrorCodes result;
            uint       cEntries = 1;

            result = WNetOpenEnum(scope, type, usage, pRsrc, out handle);

            if (result == ErrorCodes.NO_ERROR)
            {
                do
                {
                    result = WNetEnumResource(handle, ref cEntries, buffer, ref bufferSize);

                    if (result == ErrorCodes.NO_ERROR)
                    {
                        Marshal.PtrToStructure(buffer, pRsrc);

                        // If the discovered item is of the correct type then add a server entry to our array
                        if (pRsrc.dwDisplayType == displayType)
                        {
                            string strName;
                            strName = pRsrc.lpRemoteName;

                            // Remove any "\\" prefix
                            if (strName.StartsWith("\\"))
                            {
                                strName = strName.Remove(0, 2);
                            }
                            Server server = new Server(strName, strDomain);
                            aData.Add(server);
                        }

                        // If this is a domain or NDS container then store the name as the parent
                        if ((pRsrc.dwDisplayType == ResourceDisplayType.RESOURCEDISPLAYTYPE_DOMAIN) ||
                            (pRsrc.dwDisplayType == ResourceDisplayType.RESOURCEDISPLAYTYPE_NDSCONTAINER))
                        {
                            strDomain = pRsrc.lpRemoteName;
                        }

                        // If this is a container then call ourselves recursively to expand it
                        if ((pRsrc.dwUsage & ResourceUsage.RESOURCEUSAGE_CONTAINER) == ResourceUsage.RESOURCEUSAGE_CONTAINER)
                        {
                            EnumerateServers(pRsrc, scope, type, usage, displayType, strDomain);
                        }
                    }
                    else if (result != ErrorCodes.ERROR_NO_MORE_ITEMS)
                    {
                        break;
                    }
                }while   (result != ErrorCodes.ERROR_NO_MORE_ITEMS);

                WNetCloseEnum(handle);
            }

            Marshal.FreeHGlobal((IntPtr)buffer);
        }
        public BrushResourceItem(object resourceKey, ResourceDictionary dictionary, FrameworkElement source, ResourceScope scope)
            : base(resourceKey, dictionary,source, scope)
        {
            _brush = dictionary[resourceKey] as Brush;
            BrushStops = new ListCollectionView(_stops);

            BuildStops();
        }
 static private string ConvertFromAppDomain(string name, ResourceScope to, Type type)
 {
     if ((to < ResourceScope.AppDomain) || (to >= ResourceScope.Private))
     {
         throw new ArgumentException("to");
     }
     return(SafeName(name, false, false));
 }
 private static string ConvertFromAppDomain(string name, ResourceScope to, Type type)
 {
     if (to < ResourceScope.AppDomain || to >= ResourceScope.Private)
     {
         throw new ArgumentException("to");
     }
     return(VersioningHelper.SafeName(name, false, false));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="VersionTransform"/> class.
        /// </summary>
        /// <param name="resourceType">Type of the resource.</param>
        /// <param name="resourceScope">The resource scope.</param>
        /// <param name="versionValue">The version value to append to the end of each web resource.</param>
        /// <exception cref="System.ArgumentNullException">versionValue</exception>
        public VersionTransform(ResourceType resourceType, ResourceScope resourceScope, string versionValue)
            : base(resourceType, resourceScope)
        {
            if (versionValue == null) throw new ArgumentNullException("versionValue");

            VersionValue = versionValue;
            VersionName = "_";
        }
Beispiel #30
0
 public ResourceType(NamespaceType declaringNamespace, ResourceTypeReference typeReference, ResourceScope validParentScopes, ITypeReference body)
     : base(typeReference.FormatName())
 {
     DeclaringNamespace = declaringNamespace;
     TypeReference      = typeReference;
     ValidParentScopes  = validParentScopes;
     Body = body;
 }
        public void InvalidResourceScope2()
        {
            ResourceScope bad = (ResourceScope)Int32.MinValue;
            ResourceConsumptionAttribute rca = new ResourceConsumptionAttribute(ResourceScope.None, bad);

            Assert.AreEqual(ResourceScope.None, rca.ResourceScope, "ResourceScope");
            Assert.AreEqual(bad, rca.ConsumptionScope, "ConsumptionScope");
        }
Beispiel #32
0
        private static ICollection <string> EnumerateResources(NetResource pRsrc, ResourceScope scope, ResourceType type,
                                                               ResourceUsage usage, ResourceDisplayType displayType)
        {
            List <string> result     = new List <string>();
            uint          bufferSize = 16384;
            IntPtr        buffer     = Marshal.AllocHGlobal((int)bufferSize);

            try
            {
                IntPtr handle;
                uint   cEntries = 1;

                ErrorCodes res = WNetOpenEnum(scope, type, usage, pRsrc, out handle);

                if (res == ErrorCodes.NoError)
                {
                    try
                    {
                        do
                        {
                            res = WNetEnumResource(handle, ref cEntries, buffer, ref bufferSize);

                            if (res == ErrorCodes.NoError)
                            {
                                Marshal.PtrToStructure(buffer, pRsrc);

                                if (pRsrc.dwDisplayType == displayType)
                                {
                                    result.Add(pRsrc.lpRemoteName);
                                }

                                // If the current NetworkResource is a container, we call EnumerateResources recursively.
                                // In some situations, the lpRemoteName in the NetworkResource is null or empty. In this case
                                // we do not call EnumerateResources recursively as this leads to an infinite loop of
                                // recursive calls. For details see Jira MP2-356
                                if ((pRsrc.dwUsage & ResourceUsage.Container) == ResourceUsage.Container && !String.IsNullOrEmpty(pRsrc.lpRemoteName))
                                {
                                    result.AddRange(EnumerateResources(pRsrc, scope, type, usage, displayType));
                                }
                            }
                            else if (res != ErrorCodes.ErrorNoMoreItems)
                            {
                                break;
                            }
                        } while (res != ErrorCodes.ErrorNoMoreItems);
                    }
                    finally
                    {
                        WNetCloseEnum(handle);
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
            return(result);
        }
        public static String MakeVersionSafeName(String name, ResourceScope from, ResourceScope to, Type type)
        {
            ResourceScope fromResType = from & ResTypeMask;
            ResourceScope toResType   = to & ResTypeMask;

            if (fromResType > toResType)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_ResourceScopeWrongDirection", fromResType, toResType), "from");
            }

            SxSRequirements requires = GetRequirements(to, from);

            if ((requires & (SxSRequirements.AssemblyName | SxSRequirements.TypeName)) != 0 && type == null)
            {
                throw new ArgumentNullException("type", Environment.GetResourceString("ArgumentNull_TypeRequiredByResourceScope"));
            }

            // Add in process ID, CLR base address, and appdomain ID's.  Also, use a character identifier
            // to ensure that these can never accidentally overlap (ie, you create enough appdomains and your
            // appdomain ID might equal your process ID).
            StringBuilder safeName  = new StringBuilder(name);
            char          separator = '_';

            if ((requires & SxSRequirements.ProcessID) != 0)
            {
                safeName.Append(separator);
                safeName.Append('p');
#if MONO
                safeName.Append(NativeMethods.GetCurrentProcessId());
#else
                safeName.Append(Win32Native.GetCurrentProcessId());
#endif
            }
            if ((requires & SxSRequirements.CLRInstanceID) != 0)
            {
                String clrID = GetCLRInstanceString();
                safeName.Append(separator);
                safeName.Append('r');
                safeName.Append(clrID);
            }
            if ((requires & SxSRequirements.AppDomainID) != 0)
            {
                safeName.Append(separator);
                safeName.Append("ad");
                safeName.Append(AppDomain.CurrentDomain.Id);
            }
            if ((requires & SxSRequirements.TypeName) != 0)
            {
                safeName.Append(separator);
                safeName.Append(type.Name);
            }
            if ((requires & SxSRequirements.AssemblyName) != 0)
            {
                safeName.Append(separator);
                safeName.Append(type.Assembly.FullName);
            }
            return(safeName.ToString());
        }
Beispiel #34
0
        public Resource(ResourceType resourceName, ResourceScope scope, string fullNodeName)
        {
            ResourceName = resourceName;
            Scope        = scope;
            FullNodeName = fullNodeName;

            ResourceId = Guid.NewGuid();
            EndOfData  = false;
        }
        public override void DestroyDeviceObjects(ResourceScope scope)
        {
            if ((scope & ResourceScope.Global) == 0)
            {
                return;
            }

            _imguiRenderer.Dispose();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ExtensionTransform"/> class.
        /// </summary>
        /// <param name="fromExtension">Extension to match on.</param>
        /// <param name="toExtension">Extension to change to.</param>
        /// <param name="resourceType">Type of the resource.</param>
        /// <param name="resourceScope">The resource scope.</param>
        /// <exception cref="System.ArgumentNullException">
        /// fromExtension
        /// or
        /// toExtension
        /// </exception>
        public ExtensionTransform(string fromExtension, string toExtension, ResourceType resourceType, ResourceScope resourceScope)
            : base(resourceType, resourceScope)
        {
            if (fromExtension == null) throw new ArgumentNullException("fromExtension");
            if (toExtension == null) throw new ArgumentNullException("toExtension");

            FromExtension = fromExtension;
            ToExtension = toExtension;
            IgnoreExtensions = new List<string>();
        }
Beispiel #37
0
 public ResourceItem(object resourceKey, ResourceDictionary dictionary, FrameworkElement source, ResourceScope resourceScope)
 {
     _resourceKey = resourceKey;
     _resourceScope = resourceScope;
     _dictionary = dictionary;
     _value = dictionary[resourceKey];
     if( _value == null)
     {
         _value = source.TryFindResource(resourceKey);
     }
 }
        /// <summary>
        /// Creates a best matching resource item for the provided resource
        /// </summary>
        public static ResourceItem CreateResourceItem(object resourceKey, ResourceDictionary dictionary, FrameworkElement source, ResourceScope scope)
        {
            var resource = dictionary[resourceKey] ?? source.TryFindResource(resourceKey);

            if (resource is Style) return new StyleResourceItem(resourceKey, dictionary, source, scope);
            if (resource is Brush) return new BrushResourceItem(resourceKey, dictionary, source, scope);
            if (resource is Drawing) return new DrawingResourceItem(resourceKey, dictionary, source, scope);
            if (resource is Color) return new ColorResourceItem(resourceKey, dictionary, source, scope);
            if (resource is Geometry) return new GeometryResourceItem(resourceKey, dictionary, source, scope);

            return new ResourceItem(resourceKey, dictionary, source, scope);
        }
		static private string ConvertFromMachine (string name, ResourceScope to, Type type)
		{
			switch (to) {
			case ResourceScope.Machine:
				return SafeName (name, false, false);
			case ResourceScope.Process:
				return SafeName (name, true, false);
			case ResourceScope.AppDomain:
				return SafeName (name, true, true);
			default:
				throw new ArgumentException ("to");
			}
		}
Beispiel #40
0
        public static string MakeVersionSafeName(String name, ResourceScope from, ResourceScope to, Type type)
        {
            ResourceScope fromResType = from & ResTypeMask;
            ResourceScope toResType = to & ResTypeMask;
            if (fromResType > toResType)
                throw new ArgumentException(SR.Format(SR.Argument_ResourceScopeWrongDirection, fromResType, toResType), nameof(from));

            SxSRequirements requires = GetRequirements(to, from);

            if ((requires & (SxSRequirements.AssemblyName | SxSRequirements.TypeName)) != 0 && type == null)
                throw new ArgumentNullException(nameof(type), SR.ArgumentNull_TypeRequiredByResourceScope);

            // Add in process ID, CLR base address, and appdomain ID's.  Also, use a character identifier
            // to ensure that these can never accidentally overlap (ie, you create enough appdomains and your
            // appdomain ID might equal your process ID).
            StringBuilder safeName = new StringBuilder(name);
            char separator = '_';
            if ((requires & SxSRequirements.ProcessID) != 0)
            {
                safeName.Append(separator);
                safeName.Append('p');
                safeName.Append(GetCurrentProcessId());
            }
            if ((requires & SxSRequirements.CLRInstanceID) != 0)
            {
                string clrID = GetCLRInstanceString();
                safeName.Append(separator);
                safeName.Append('r');
                safeName.Append(clrID);
            }
            // TODO -- https://github.com/dotnet/corefx/pull/12113
            // if ((requires & SxSRequirements.AppDomainID) != 0) {
            //     safeName.Append(separator);
            //     safeName.Append("ad");
            //     safeName.Append(AppDomain.CurrentDomain.Id);
            // }
            if ((requires & SxSRequirements.TypeName) != 0)
            {
                safeName.Append(separator);
                safeName.Append(type.Name);
            }
            if ((requires & SxSRequirements.AssemblyName) != 0)
            {
                safeName.Append(separator);
                safeName.Append(type.Assembly.FullName);
            }
            return safeName.ToString();
        }
        private static void ReadResourcesRecursive(ResourceDictionary dictionary, ResourceScope scope, FrameworkElement source, List<ResourceItem> resourceItems, List<object> resourceKeyList)
        {
            foreach (var resourceKey in dictionary.Keys)
            {
                if (!resourceKeyList.Contains(resourceKey))
                {
                    resourceKeyList.Add(resourceKey);
                    resourceItems.Add(CreateResourceItem(resourceKey, dictionary, source,scope));
                }
            }

            foreach (ResourceDictionary resourceDictionary in dictionary.MergedDictionaries)
            {
                ReadResourcesRecursive(resourceDictionary, scope, source, resourceItems, resourceKeyList);
            }
        }
        public Stream OpenResourceStream(ResourceScope project, string uri)
        {
            string projectPath = "";

              switch (project)
              {
            case ResourceScope.Core:
              {
            projectPath = "Catrobat.Core.";
            var path = projectPath + uri.Replace("/", ".");
            return Assembly.GetExecutingAssembly().GetManifestResourceStream(path);
              }
            case ResourceScope.IdeCommon:
              {
            projectPath = "Catrobat.IDECommon.";
            var path = projectPath + uri.Replace("/", ".");
            return Assembly.GetExecutingAssembly().GetManifestResourceStream(path);
              }
            case ResourceScope.IdePhone:
              {
            projectPath = "";
            var resourceUri = new Uri(projectPath + uri, UriKind.Relative);
            var resource = Application.GetResourceStream(resourceUri);

            return resource != null ? resource.Stream : null;
              }
            case ResourceScope.TestsPhone:
              {
            projectPath = "";
            var resourceUri = new Uri(projectPath + uri, UriKind.Relative);
            var resource = Application.GetResourceStream(resourceUri);

            return resource != null ? resource.Stream : null;
              }
            case ResourceScope.SampleProjects:
              {
            projectPath = "Content/";
            var resourceUri = new Uri(projectPath + uri, UriKind.Relative);
            var resource = Application.GetResourceStream(resourceUri);

            return resource != null ? resource.Stream : null;
              }
            default:
              throw new ArgumentOutOfRangeException("project");
              }
        }
 /// <summary>
 /// Creates an instance of the Resource class using the XmlReader instance provided.
 /// </summary>
 /// <param name="reader">The XmlReader positioned at the Subject node.</param>
 /// <param name="schemaVersion">The version of the schema that was used to validate.</param>
 public ResourceElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
     : base(reader, Consts.ContextSchema.RequestElement.Resource, schemaVersion)
 {
     // Search for a hierarchical node mark
     foreach (AttributeElementReadWrite attribute in Attributes)
     {
         if (attribute.AttributeId == Consts.ContextSchema.ResourceScope.ResourceScopeAttributeId)
         {
             foreach (AttributeValueElementReadWrite element in attribute.AttributeValues)
             {
                 if (element.Contents == Consts.ContextSchema.ResourceScope.Immediate) continue;
                 _resourceScope = (ResourceScope)Enum.Parse(typeof(ResourceScope), element.Contents, false);
                 return;
             }
         }
     }
 }
        public Stream OpenResourceStream(ResourceScope project, string uri)
        {
            string fullUri = "ms-appx:///";

              switch (project)
              {
            case ResourceScope.Core:
              fullUri += "Core/";
              break;
            case ResourceScope.IdePhone:
              fullUri += "IDEWindowsPhone/";
              break;
            case ResourceScope.IdeStore:
              fullUri += "IDEWindowsStroe/";
              break;
            case ResourceScope.TestsPhone:
              fullUri += "TestsWindowsPhone/";
              break;
            case ResourceScope.TestsStore:
              fullUri += "TestsWindowsStore/";
              break;
            default:
              throw new ArgumentOutOfRangeException("project");
              }

              fullUri += uri;

              // TODO: Find a way to get resources from assembly within Unittest Project
              Func<Task<Stream>> sync = async delegate()
              {
            var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri(fullUri));
            return (await file.OpenAsync(FileAccessMode.Read)).AsStream();
              };

              var stream = sync.Invoke();

              stream.Wait();
              return stream.Result;
        }
		private static extern ErrorCodes WNetOpenEnum(ResourceScope dwScope, ResourceType dwType,
			ResourceUsage dwUsage, NetResource p, out IntPtr lphEnum);
 public ResourceConsumptionAttribute(ResourceScope resourceScope, ResourceScope consumptionScope)
 {
     _resourceScope = resourceScope;
     _consumptionScope = consumptionScope;
 }
 public static string MakeVersionSafeName(string name, ResourceScope from, ResourceScope to, Type type)
 {
 }
    private static ICollection<string> EnumerateResources(NetResource pRsrc, ResourceScope scope, ResourceType type,
        ResourceUsage usage, ResourceDisplayType displayType)
    {
      List<string> result = new List<string>();
      uint bufferSize = 16384;
      IntPtr buffer = Marshal.AllocHGlobal((int) bufferSize);
      try
      {
        IntPtr handle;
        uint cEntries = 1;

        ErrorCodes res = WNetOpenEnum(scope, type, usage, pRsrc, out handle);

        if (res == ErrorCodes.NoError)
          try
          {
            do
            {
              res = WNetEnumResource(handle, ref cEntries, buffer, ref bufferSize);

              if (res == ErrorCodes.NoError)
              {
                Marshal.PtrToStructure(buffer, pRsrc);

                if (pRsrc.dwDisplayType == displayType)
                  result.Add(pRsrc.lpRemoteName);

                // If the current NetworkResource is a container, we call EnumerateResources recursively.
                // In some situations, the lpRemoteName in the NetworkResource is null or empty. In this case
                // we do not call EnumerateResources recursively as this leads to an infinite loop of
                // recursive calls. For details see Jira MP2-356
                if ((pRsrc.dwUsage & ResourceUsage.Container) == ResourceUsage.Container && !String.IsNullOrEmpty(pRsrc.lpRemoteName))
                  result.AddRange(EnumerateResources(pRsrc, scope, type, usage, displayType));
              }
              else if (res != ErrorCodes.ErrorNoMoreItems)
                break;
            } while (res != ErrorCodes.ErrorNoMoreItems);
          }
          finally
          {
            WNetCloseEnum(handle);
          }
      }
      finally
      {
        Marshal.FreeHGlobal(buffer);
      }
      return result;
    }
        public static String MakeVersionSafeName(String name, ResourceScope from, ResourceScope to, Type type)
        {
            ResourceScope fromResType = from & ResTypeMask;
            ResourceScope toResType = to & ResTypeMask;
            if (fromResType > toResType)
                throw new ArgumentException(Environment.GetResourceString("Argument_ResourceScopeWrongDirection", fromResType, toResType), "from");

            SxSRequirements requires = GetRequirements(to, from);

            if ((requires & (SxSRequirements.AssemblyName | SxSRequirements.TypeName)) != 0 && type == null)
                throw new ArgumentNullException("type", Environment.GetResourceString("ArgumentNull_TypeRequiredByResourceScope"));

            // Add in process ID, CLR base address, and appdomain ID's.  Also, use a character identifier
            // to ensure that these can never accidentally overlap (ie, you create enough appdomains and your
            // appdomain ID might equal your process ID).
            StringBuilder safeName = new StringBuilder(name);
            char separator = '_';
            if ((requires & SxSRequirements.ProcessID) != 0) {
                safeName.Append(separator);
                safeName.Append('p');
#if MONO
                safeName.Append (GetCurrentProcessId ());
#else
                safeName.Append(Win32Native.GetCurrentProcessId());
#endif
            }
            if ((requires & SxSRequirements.CLRInstanceID) != 0) {
                String clrID = GetCLRInstanceString();
                safeName.Append(separator);
                safeName.Append('r');
                safeName.Append(clrID);
            }
            if ((requires & SxSRequirements.AppDomainID) != 0) {
                safeName.Append(separator);
                safeName.Append("ad");
                safeName.Append(AppDomain.CurrentDomain.Id);
            }
            if ((requires & SxSRequirements.TypeName) != 0) {
                safeName.Append(separator);
                safeName.Append(type.Name);
            }
            if ((requires & SxSRequirements.AssemblyName) != 0) {
                safeName.Append(separator);
                safeName.Append(type.Assembly.FullName);
            }
            return safeName.ToString();
        }
		public ServerEnum(ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType, string kPath)
		{
			var netRoot = new NetResource();
			EnumerateServers(netRoot, scope, type, usage, displayType, kPath);
		}
        private List<NETRESOURCE> GetChildNetResources(
            ResourceScope dwScope,
            ResourceType dwType,
            ResourceUsage dwUsage,
            NETRESOURCE NetResource
            )
        {
            WinError error = WinError.NO_ERROR;
            IntPtr handle = new IntPtr();
            List<NETRESOURCE> nrList = new List<NETRESOURCE>();

            error = FileClient.FileClient.BeginEnumNetResources(dwScope,
                                                                dwType,
                                                                dwUsage,
                                                                NetResource,
                                                                out handle);

            if (error == WinError.NO_ERROR)
            {
                error = FileClient.FileClient.EnumNetResources(handle, out nrList);

                FileClient.FileClient.EndEnumNetResources(handle);
            }

            return nrList;
        }
        public static String MakeVersionSafeName(String name, ResourceScope from, ResourceScope to, Type type)
        {
            ResourceScope fromResType = from & ResTypeMask;
            ResourceScope toResType = to & ResTypeMask;
            if (fromResType > toResType)
                throw new ArgumentException(Environment.GetResourceString("Argument_ResourceScopeWrongDirection", fromResType, toResType), "from");

            SxSRequirements requires = GetRequirements(to, from);

            if ((requires & (SxSRequirements.AssemblyName | SxSRequirements.TypeName)) != 0 && type == null)
                throw new ArgumentNullException("type", Environment.GetResourceString("ArgumentNull_TypeRequiredByResourceScope"));

            String postfix = "";
            const String separator = "_";
            if ((requires & SxSRequirements.ProcessID) != 0)
                postfix += separator + Win32Native.GetCurrentProcessId();
            if ((requires & SxSRequirements.AppDomainID) != 0)
                postfix += separator + AppDomain.CurrentDomain.GetAppDomainId();
            if ((requires & SxSRequirements.TypeName) != 0)
                postfix += separator + type.Name;
            if ((requires & SxSRequirements.AssemblyName) != 0)
                postfix += separator + type.Assembly.FullName;

            return name + postfix;
        }
        private static IEnumerable<string> EnumerateServers(NETRESOURCE pRsrc, ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType)
        {
            uint bufferSize = 16384;
            IntPtr buffer = Marshal.AllocHGlobal((int)bufferSize);
            IntPtr handle = IntPtr.Zero;
            ErrorCodes result;
            uint cEntries = 1;

            result = WNetOpenEnum(scope, type, usage, pRsrc, out handle);

            if (result == ErrorCodes.NO_ERROR)
            {
                do
                {
                    result = WNetEnumResource(handle, ref cEntries, buffer, ref	bufferSize);

                    if (result == ErrorCodes.NO_ERROR)
                    {
                        Marshal.PtrToStructure(buffer, pRsrc);

                        if (pRsrc.dwDisplayType == displayType)
                            yield return pRsrc.lpRemoteName;

                        if ((pRsrc.dwUsage & ResourceUsage.RESOURCEUSAGE_CONTAINER) == ResourceUsage.RESOURCEUSAGE_CONTAINER)
                        {
                            foreach( string share in EnumerateServers(pRsrc, scope, type, usage, displayType))
                                yield return share;
                        }
                    }
                    else if (result != ErrorCodes.ERROR_NO_MORE_ITEMS)
                        break;
                } while (result != ErrorCodes.ERROR_NO_MORE_ITEMS);

                WNetCloseEnum(handle);
            }

            Marshal.FreeHGlobal((IntPtr)buffer);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ColorResourceItem"/> class.
 /// </summary>
 public ColorResourceItem(object resourceKey, ResourceDictionary dictionary, FrameworkElement source, ResourceScope scope)
     : base(resourceKey, dictionary,source, scope)
 {
 }
 public static String MakeVersionSafeName(String name, ResourceScope from, ResourceScope to)
 {
     return MakeVersionSafeName(name, from, to, null);
 }
		private void EnumerateServers(NetResource pRsrc, ResourceScope scope, ResourceType type,
			ResourceUsage usage, ResourceDisplayType displayType, string kPath)
		{
			uint bufferSize = 16384;
			var buffer = Marshal.AllocHGlobal((int)bufferSize);
			IntPtr handle;
			uint cEntries = 1;
			var serverenum = false;

			var result = WNetOpenEnum(scope, type, usage, pRsrc, out handle);

			if (result == ErrorCodes.NO_ERROR)
			{
				do
				{
					result = WNetEnumResource(handle, ref cEntries, buffer, ref	bufferSize);

					if ((result == ErrorCodes.NO_ERROR))
					{
						Marshal.PtrToStructure(buffer, pRsrc);

						if (kPath == "")
						{
							if ((pRsrc.dwDisplayType == displayType) || (pRsrc.dwDisplayType == ResourceDisplayType.RESOURCEDISPLAYTYPE_DOMAIN))
								_aData.Add(pRsrc.lpRemoteName + "|" + pRsrc.dwDisplayType);

							if ((pRsrc.dwUsage & ResourceUsage.RESOURCEUSAGE_CONTAINER) == ResourceUsage.RESOURCEUSAGE_CONTAINER)
								if ((pRsrc.dwDisplayType == displayType))
									EnumerateServers(pRsrc, scope, type, usage, displayType, kPath);
						}
						else
						{
							if (pRsrc.dwDisplayType == displayType)
							{
								_aData.Add(pRsrc.lpRemoteName);
								EnumerateServers(pRsrc, scope, type, usage, displayType, kPath);
								serverenum = true;
							}
							if (!serverenum)
							{
								if (pRsrc.dwDisplayType == ResourceDisplayType.RESOURCEDISPLAYTYPE_SHARE)
									_aData.Add(pRsrc.lpRemoteName + "-share");
							}
							else
								serverenum = false;

							if ((kPath.IndexOf(pRsrc.lpRemoteName) >= 0) || (String.Compare(pRsrc.lpRemoteName, "Microsoft Windows Network") == 0))
								EnumerateServers(pRsrc, scope, type, usage, displayType, kPath);
						}
					}
					else if (result != ErrorCodes.ERROR_NO_MORE_ITEMS)
						break;
				} while (result != ErrorCodes.ERROR_NO_MORE_ITEMS);

				WNetCloseEnum(handle);
			}
			Marshal.FreeHGlobal(buffer);
		}
        private static SxSRequirements GetRequirements(ResourceScope consumeAsScope, ResourceScope calleeScope)
        {
            SxSRequirements requires = SxSRequirements.None;
        
            switch(calleeScope & ResTypeMask) {
            case ResourceScope.Machine:
                switch(consumeAsScope & ResTypeMask) {
                case ResourceScope.Machine:
                    // No work
                    break;

                case ResourceScope.Process:
                    requires |= SxSRequirements.ProcessID;
                    break;

                case ResourceScope.AppDomain:
                    requires |= SxSRequirements.AppDomainID | SxSRequirements.ProcessID;
                    break;

                default:
                    throw new ArgumentException(Environment.GetResourceString("Argument_BadResourceScopeTypeBits", consumeAsScope), "consumeAsScope");
                }
                break;
            
            case ResourceScope.Process:
                if ((consumeAsScope & ResourceScope.AppDomain) != 0)
                    requires |= SxSRequirements.AppDomainID;
                break;

            case ResourceScope.AppDomain:
                // No work
                break;

            default:
                throw new ArgumentException(Environment.GetResourceString("Argument_BadResourceScopeTypeBits", calleeScope), "calleeScope");
            }

            switch(calleeScope & VisibilityMask) {
            case ResourceScope.None:  // Public - implied
                switch(consumeAsScope & VisibilityMask) {
                case ResourceScope.None:  // Public - implied
                    // No work
                    break;

                case ResourceScope.Assembly:
                    requires |= SxSRequirements.AssemblyName;
                    break;

                case ResourceScope.Private:
                    requires |= SxSRequirements.TypeName | SxSRequirements.AssemblyName;
                    break;

                default:
                    throw new ArgumentException(Environment.GetResourceString("Argument_BadResourceScopeVisibilityBits", consumeAsScope), "consumeAsScope");
                }
                break;

            case ResourceScope.Assembly:
                if ((consumeAsScope & ResourceScope.Private) != 0)
                    requires |= SxSRequirements.TypeName;
                break;

            case ResourceScope.Private:
                // No work
                break;

            default:
                throw new ArgumentException(Environment.GetResourceString("Argument_BadResourceScopeVisibilityBits", calleeScope), "calleeScope");
            }

            if (consumeAsScope == calleeScope) {
                BCLDebug.Assert(requires == SxSRequirements.None, "Computed a strange set of required resource scoping.  It's probably wrong.");
            }

            return requires;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConcatenationTransform"/> class.
 /// </summary>
 /// <param name="resourceType">Type of the resource.</param>
 /// <param name="resourceScope">The resource scope.</param>
 public ConcatenationTransform(ResourceType resourceType, ResourceScope resourceScope)
     : base(resourceType, resourceScope)
 {
     Groups = new Dictionary<string, string>();
 }
 public ResourceExposureAttribute(ResourceScope exposureLevel)
 {
     _resourceExposureLevel = exposureLevel;
 }
 public static ICollection<string> EnumerateResources(ResourceScope scope, ResourceType type, ResourceUsage usage, ResourceDisplayType displayType)
 {
   NetResource pRsrc = new NetResource();
   return EnumerateResources(pRsrc, scope, type, usage, displayType);
 }