Esempio n. 1
0
 public VfsEntry(string name, bool isFile, long size, VfsEntry parent, IVfsImpl implementation)
 {
     _name   = name;
     _size   = size;
     _isFile = isFile;
     _parent = parent;
     _impl   = new Lazy <IVfsImpl>(() => implementation);
 }
Esempio n. 2
0
 /// <summary>
 /// Resets the initialized value of the current <see cref="Lazy{T}"/> instance.
 /// </summary>
 public void Reset()
 {
     if (_lazy != null && _lazy.IsValueCreated && _lazy.Value is IDisposable)
     {
         ((IDisposable)_lazy.Value).Dispose();
     }
     _lazy           = CreateLazy();
     _isValueFaulted = false;
 }
Esempio n. 3
0
 public CopaFilmeBase(HttpClient httpClient, UrlApi baseUrl)
 {
     _httpClient = httpClient;
     _baseUrl    = baseUrl.URL;
     _settings   = new System.Lazy <Newtonsoft.Json.JsonSerializerSettings>(() =>
     {
         var settings = new Newtonsoft.Json.JsonSerializerSettings();
         return(settings);
     });
 }
Esempio n. 4
0
 internal EnumerationMemberDescriptor(Type enumerationType, FieldInfo field)
     : base(field.Name, Attribute.GetCustomAttributes(field))
 {
     EnumerationType = enumerationType;
     _field          = field;
     _displayName    = new System.Lazy <string>(GetDisplayName);
     _order          = new System.Lazy <int>(GetOrder);
     _description    = new System.Lazy <string>(GetDescription);
     _category       = new System.Lazy <string>(GetCategory);
     _prompt         = new System.Lazy <string>(GetPrompt);
     _aliasName      = new System.Lazy <string>(GetAliasName);
 }
Esempio n. 5
0
 public BasePaymentServiceApiClient(string baseUrl, HttpClient httpClient, ICorrelationContextAccessor correlationContext)
 {
     BaseUrl                 = baseUrl;
     this.httpClient         = httpClient;
     this.correlationContext = correlationContext;
     settings                = new Lazy <JsonSerializerSettings>(() =>
     {
         var settings = new JsonSerializerSettings();
         UpdateJsonSerializerSettings(settings);
         return(settings);
     });
 }
Esempio n. 6
0
        private CodeContractStatement(ICSharpStatement statement,
                                      IInvocationExpression invocationExpression,
                                      CodeContractStatementType statementType)
            : base(statement)
        {
            Contract.Requires(invocationExpression != null);

            _invocationExpression = invocationExpression;
            _statementType        = statementType;

            // Due to weird bug in CC compiler, I can't use the same variable in Contract.Requires
            // and in lambda expression.
            _codeContractExpression = JetBrains.Util.Lazy.Of(
                () => Assertions.ContractStatementFactory.TryCreateAssertion(_invocationExpression), true);
        }
Esempio n. 7
0
 public ResourceNode(ITypeMapper typeMapper,
     PathNode parent,
     string name,
     Func<object> valueFetcher,
     ResourceType expectedType)
     : base(typeMapper, parent, name)
 {
     this.value = new System.Lazy<object>(valueFetcher);
     this.expectedType = expectedType;
     this.type = new System.Lazy<ResourceType>(() =>
     {
         var localValue = Value;
         if (Value == null)
             return expectedType;
         return (ResourceType)typeMapper.GetClassMapping(localValue.GetType());
     });
 }
        public IdentityMapperAsync(GridClient Client, string GridDomain)
        {
            client = Client;
            gridDomain = GridDomain;

            grid = new MappedIdentity(IdentityCategory.System);
            grid.AvatarID = UUID.Zero;
            grid.IrcDomain = gridDomain;
            grid.SlName = gridDomain;
            grid.IrcNick = gridDomain;

            clientIdentity = new System.Lazy<MappedIdentity>(() =>
            {
                return MakeAgentIdentity(client.Self.AgentID, client.Self.Name);
            });

            client.Avatars.UUIDNameReply += Avatars_UUIDNameReply;
            client.Groups.GroupNamesReply += Groups_GroupNamesReply;
        }
        public IdentityMapperAsync(GridClient Client, string GridDomain)
        {
            client     = Client;
            gridDomain = GridDomain;

            grid           = new MappedIdentity(IdentityCategory.System);
            grid.AvatarID  = UUID.Zero;
            grid.IrcDomain = gridDomain;
            grid.SlName    = gridDomain;
            grid.IrcNick   = gridDomain;

            clientIdentity = new System.Lazy <MappedIdentity>(() =>
            {
                return(MakeAgentIdentity(client.Self.AgentID, client.Self.Name));
            });

            client.Avatars.UUIDNameReply  += Avatars_UUIDNameReply;
            client.Groups.GroupNamesReply += Groups_GroupNamesReply;
        }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Lazy{T}"/> class
 /// that uses the specified initialization function and thread-safety mode.
 /// </summary>
 /// <param name="valueFactory">
 /// The delegate that is invoked to produce the lazily initialized value when it is needed.
 /// </param>
 /// <param name="mode">
 /// One of the enumeration values that specifies the thread safety mode.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="valueFactory"/> is <see langword="null"/>.
 /// </exception>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="mode"/> contains an invalid value.
 /// </exception>
 public Lazy(Func <T> valueFactory, LazyThreadSafetyMode mode)
 {
     _valueFactory = valueFactory;
     Mode          = mode;
     _lazy         = CreateLazy();
 }
Esempio n. 11
0
            public TypeCodeGenInfo(ClientLibGenerator parent, TransformedType transformedType)
            {
                var resourceType = transformedType as ResourceType;
                if (resourceType != null && resourceType.IsUriBaseType)
                {
                    if ((resourceType.IsRootResource && resourceType.IsExposedAsRepository)
                        || (resourceType.ParentToChildProperty != null
                            && resourceType.ParentToChildProperty.ExposedAsRepository))
                    {
                        this.customRepositoryInterface = new TypeDefinition(parent.assemblyName,
                            string.Format("I{0}Repository", transformedType.Name),
                            TypeAttributes.Interface | TypeAttributes.Public |
                            TypeAttributes.Abstract);
                        parent.module.Types.Add(this.customRepositoryInterface);
                    }
                }

                if (parent == null)
                    throw new ArgumentNullException("parent");
                this.parent = parent;
                this.transformedType = transformedType;

                this.postReturnTypeReference = new System.Lazy<TypeReference>(() =>
                {
                    if (resourceType == null || resourceType.PostReturnType == null)
                        return InterfaceType;
                    return parent.clientTypeInfoDict[resourceType.PostReturnType].InterfaceType;
                });

                this.customRepositoryBaseType = new System.Lazy<Type>(() =>
                {
                    if (resourceType != null)
                    {
                        if (resourceType.IsUriBaseType)
                        {
                            if (resourceType.IsRootResource && resourceType.IsExposedAsRepository)
                                return typeof(ClientRepository<,>);
                            if (resourceType.ParentToChildProperty != null
                                && resourceType.ParentToChildProperty.ExposedAsRepository)
                                return typeof(ChildResourceRepository<,>);
                        }
                    }
                    return null;
                });

                this.customRepositoryBaseTypeDefinition = new System.Lazy<TypeDefinition>(() =>
                {
                    if (this.customRepositoryBaseType.Value == null)
                        return null;

                    var typeRef = parent.Import(this.customRepositoryBaseType.Value);
                    return typeRef as TypeDefinition ?? typeRef.Resolve();
                });

                this.customRepositoryBaseTypeReference = new System.Lazy<TypeReference>(() =>
                {
                    if (this.customRepositoryBaseType.Value == null)
                        return null;

                    return
                        parent.Import(this.customRepositoryBaseType.Value).MakeGenericInstanceType(
                            InterfaceType,
                            PostReturnTypeReference);
                });

                this.interfaceType = new TypeDefinition(
                    parent.assemblyName,
                    "I" + transformedType.Name,
                    TypeAttributes.Interface | TypeAttributes.Public |
                    TypeAttributes.Abstract);
            }
            private const int ITEM_FAIL_TRACKING_TIME = 5 * 60; //5 minutes

            /// <summary>
            /// Tracks that there was an error fetching an item
            /// </summary>
            /// <param name="itemId"></param>
            private void AccountItemFetchFailure(UUID itemId)
            {
                lock (m_BlacklistedItems)
                {
                    TimestampedItem<int> entry;
                    if (m_BlacklistedItems.TryGetValue(itemId, out entry))
                    {
                        entry.ResetTimestamp();
                        entry.Item = entry.Item + 1;
                    }
                    else
                    {
                        //add this brand new one
                        m_BlacklistedItems.Add(itemId, new TimestampedItem<int>(1));

                        //also clean out old ones
                        System.Lazy<List<UUID>> deadKeys = new System.Lazy<List<UUID>>();
                        foreach (var kvp in m_BlacklistedItems)
                        {
                            if (kvp.Value.ElapsedSeconds > ITEM_FAIL_TRACKING_TIME)
                            {
                                deadKeys.Value.Add(kvp.Key);
                            }
                        }

                        if (deadKeys.IsValueCreated)
                        {
                            foreach (UUID id in deadKeys.Value)
                            {
                                m_BlacklistedItems.Remove(id);
                            }
                        }
                    }
                }
            }
Esempio n. 13
0
 public ValueFactoryImpl(Func <T> valueFactory)
 {
     this.lazyValue = new Lazy <T>(valueFactory);
 }
Esempio n. 14
0
        /// <summary>
        /// Marks the sitting avatars in transit, and waits for this group to be sent
        /// before sending the avatars over to the neighbor region
        /// </summary>
        /// <param name="newRegionHandle"></param>
        /// <returns></returns>
        public async Task BeginCrossSittingAvatars(ulong newRegionHandle)
        {
            System.Lazy<List<Task>> crossingUsers = new System.Lazy<List<Task>>();

            ForEachSittingAvatar((ScenePresence sp) =>
            {
                PositionInfo posInfo = sp.GetPosInfo();
                if (posInfo != null)
                    crossingUsers.Value.Add(sp.CrossIntoNewRegionWithGroup(this, posInfo.Parent, newRegionHandle));
            });

            if (crossingUsers.IsValueCreated)
            {
                await Task.WhenAll(crossingUsers.Value.ToArray());
            }
        }
Esempio n. 15
0
 public RTreeNode(T data, Envelope envelope)
 {
     Data     = data;
     Envelope = envelope;
     children = new Lazy <List <RTreeNode <T> > >(() => new List <RTreeNode <T> >(), LazyThreadSafetyMode.None);
 }
Esempio n. 16
0
        /// <summary>
        /// Marks the sitting avatars in transit, and waits for this group to be sent
        /// before sending the avatars over to the neighbor region
        /// </summary>
        /// <param name="newRegionHandle"></param>
        /// <returns></returns>
        public async Task BeginCrossSittingAvatars(ulong newRegionHandle)
        {
            SceneObjectPart[] parts = this.GetParts();
            System.Lazy<List<Task>> crossingUsers = new System.Lazy<List<Task>>();

            foreach (SceneObjectPart part in parts)
            {
                if (part.SitTargetAvatar != UUID.Zero)
                {
                    ScenePresence sp = m_scene.GetScenePresence(part.SitTargetAvatar);
                    if (sp == null)
                    {
                        m_log.ErrorFormat("[SCENE OBJECT GROUP]: Crossing failed: Could not find avatar {0} seated on part {1}", part.SitTargetAvatar.ToString(), part.LocalId.ToString());
                    }
                    else
                    {
                        crossingUsers.Value.Add(sp.CrossIntoNewRegionWithGroup(this, part, newRegionHandle));
                    }
                }
            }

            if (crossingUsers.IsValueCreated)
            {
                await Task.WhenAll(crossingUsers.Value.ToArray());
            }
        }
Esempio n. 17
0
 /// <summary>
 /// Resets the initialized value of the current <see cref="Lazy{T}"/> instance.
 /// </summary>
 public void Reset()
 {
     _lazy          = CreateLazy();
     IsValueFaulted = false;
 }
Esempio n. 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Lazy{T}"/> class that uses the default constructor of T
 /// and the specified thread-safety mode.
 /// </summary>
 /// <param name="mode">
 /// One of the enumeration values that specifies the thread safety mode.
 /// </param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="mode"/> contains an invalid value.
 /// </exception>
 public Lazy(LazyThreadSafetyMode mode)
 {
     Mode  = mode;
     _lazy = CreateLazy();
 }
Esempio n. 19
0
 /// <summary>
 /// Creates Lazy based on the specified target.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="target">The target.</param>
 /// <returns></returns>
 public static dynamic Create <T>(System.Lazy <T> target)
 {
     return(new Lazy <T>(target));
 }