예제 #1
0
        public void Add_TheSameEnumType_ThrowException()
        {
            var collection = new ResourceCollection();

            collection.Add <Perm1>(0);
            Assert.Throws <Exception>(() => { collection.Add <Perm1>(1); });
        }
        private ResourceCollection CreateResources()
        {
            var resources = new ResourceCollection();

            resources.Add <Perm1>(1);
            resources.Add <Perm2>(2);
            return(resources);
        }
예제 #3
0
        public static void Initialize(ContentManager content)
        {
            ResourceManager.content = content;
              TileTextureBank = new ResourceCollection<Texture2D>();

              TileTextureBank.Add("Square", content.Load<Texture2D>("Art\\square"));
              TileTextureBank.Add("Grass", content.Load<Texture2D>("Art\\grass32x32"));
        }
예제 #4
0
        public void LastModifiedEqualsLastModifiedOfCollection()
        {
            ResourceCollection resources = new ResourceCollection();
            resources.Add(CreateResource(DateTime.Now));
            resources.Add(CreateResource(DateTime.Now.AddDays(-1)));

            ConsolidatedResource consolidated = new ConsolidatedResource(null, resources, new MemoryStream());
            Assert.That(consolidated.LastModified, Is.EqualTo(resources.LastModified()));
        }
예제 #5
0
        public void LastModifiedReturnsGreatestValueFromItems()
        {
            DateTime mostRecent = DateTime.Now;

            ResourceCollection resources = new ResourceCollection();
            resources.Add(CreateResource(mostRecent.AddDays(-1)));
            resources.Add(CreateResource(mostRecent));
            resources.Add(CreateResource(mostRecent.AddDays(-30)));

            Assert.That(resources.LastModified(), Is.EqualTo(mostRecent));
        }
예제 #6
0
        public void GetAllRersources()
        {
            var resourceCollection = new ResourceCollection();

            resourceCollection.Add <Perm1>(1);
            resourceCollection.Add <Perm2>(2);
            var permissionStoreMock = new Mock <IPermissionStore>();

            var service   = new PermissionManager(resourceCollection, permissionStoreMock.Object, new PermissionCache(), new IResourceInstanceProvider[0]);
            var resources = service.GetAllResources();

            Assert.AreEqual(2, resources.Count);
            Assert.AreNotEqual(0, resources.First().Permissions.First().PermissionId);
        }
예제 #7
0
        public void ConsolidateFiltersContent()
        {
            string contentA = "a a a";
            string contentB = "b b b";
            string separator = Environment.NewLine;

            ResourceCollection resources = new ResourceCollection();
            resources.Add(new StubResource(contentA));
            resources.Add(new StubResource(contentB));

            StringWriter actualWriter = new StringWriter();
            resources.ConsolidateContentTo(actualWriter, r => r.GetContent().Replace(" ", ""), separator);

            Assert.That(actualWriter.ToString(), Is.EqualTo(String.Format("aaa{0}bbb", Environment.NewLine)));
        }
예제 #8
0
        /// <summary>
        /// Find resource by Path
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public ResourceCollection FindResourcesByPath(string path)
        {
            try
            {
                ResourceCollection collection = new ResourceCollection();

                // create sql parameters
                SqlParameter prmResourcePath = new SqlParameter("@Path", SqlDbType.NVarChar, 250);
                prmResourcePath.Direction = ParameterDirection.Input;
                prmResourcePath.Value     = path;

                // execute query
                using (IDataReader dr = Database.ExecuteReader("UspFindResourcesByPath", CommandType.StoredProcedure, prmResourcePath))
                {
                    while (dr.Read())
                    {
                        Resource resource = Populate(dr);

                        collection.Add(resource);
                    }
                }

                return(collection);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #9
0
        /// <summary>
        /// Find Resources by Application ID
        /// </summary>
        /// <param name="application"></param>
        /// <returns></returns>
        public ResourceCollection FindResourcesByApplication(int applicationId)
        {
            try
            {
                ResourceCollection collection = new ResourceCollection();

                // create sql parameters
                SqlParameter prmApplicationID = new SqlParameter("@ApplicationID", SqlDbType.Int, 4);
                prmApplicationID.Direction = ParameterDirection.Input;
                prmApplicationID.Value     = applicationId;

                // execute query
                using (IDataReader dr = Database.ExecuteReader("UspFindResourcesByApplication", CommandType.StoredProcedure, prmApplicationID))
                {
                    while (dr.Read())
                    {
                        Resource resource = Populate(dr);

                        collection.Add(resource);
                    }
                }

                return(collection);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #10
0
        /// <summary>
        /// Get all resources which do not reference to any menuitem
        /// </summary>
        /// <returns></returns>
        public ResourceCollection GetAllOrphanResource(int ApplicationID)
        {
            try
            {
                ResourceCollection collection = new ResourceCollection();

                SqlParameter prmApplicationID = new SqlParameter("@ApplicationID", SqlDbType.Int, 4);
                prmApplicationID.Direction = ParameterDirection.Input;
                prmApplicationID.Value     = ApplicationID;
                // execute query
                using (IDataReader dr = Database.ExecuteReader("UspGetAllOrphanResources", CommandType.StoredProcedure, prmApplicationID))
                {
                    while (dr.Read())
                    {
                        Resource resource = Populate(dr);

                        collection.Add(resource);
                    }
                }

                return(collection);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #11
0
        public async Task GetResourceInstancePermissions()
        {
            var roleId      = "1";
            var resourceId  = 2;
            var permissions = new Dictionary <InstancePermissionKey, bool>()
            {
                {
                    new InstancePermissionKey
                    {
                        ResourceId   = 2,
                        PermissionId = 1,
                        InstanceId   = "1"
                    }, true
                }
            };
            var resourceCollection = new ResourceCollection();

            resourceCollection.Add <Perm1, FakeResourceInstanceProvider>(resourceId);
            var permissionStoreMock = new Mock <IPermissionStore>();

            permissionStoreMock.Setup(s => s.GetRoleInstancePermissionsAsync(roleId, resourceId, CancellationToken.None))
            .Returns(Task.FromResult(permissions));
            var providers = new[] { new FakeResourceInstanceProvider() };
            var service   = new PermissionManager(resourceCollection, permissionStoreMock.Object, new PermissionCache(), providers);
            var resources = await service.GetResourceInstancePermissionsAsync(roleId, resourceId);

            Assert.AreEqual(3, resources.Count);
            var firstResource = resources.First(r => r.InstanceId == "I1");

            Assert.AreNotEqual(0, firstResource.Permissions.First().PermissionId);
        }
        public void OrderedResourceDictionary()
        {
            var random = new Random();

            var input = Enumerable.Repeat<object>(null, 1000).Select(
                x => random.Next()).ToList();

            var resources = new
                ResourceCollection<Entity>.OrderedResourceDictionary();

            foreach (var i in input)
            {
                var entity = new Entity(
                new Service("dummy", 0, HttpService.SchemeHttp),
                    // Encode i in EntityPath
                    i.ToString());

                var list = new List<Entity> { entity };

                resources.Add(i.ToString(), list);
            }

            // Get back what's encoded in Key string.
            CollectionAssert.AreEqual(
                input,
                resources.Keys.Select(x => Convert.ToInt32(x)).ToList());

            var output = resources.Values.Select(x => Convert.ToInt32(
                // Get back what's encoded in Entity.Path.
                x[0].Path.Substring(10))).ToList();

            CollectionAssert.AreEqual(input, output);
        }
        private void LoadData()
        {
            Resources = new ResourceCollection();
            var reservations = _context.Reservation.ToList();

            Events = new List <EventData>();
            var myEvents = new List <EventData>();

            foreach (var reservation in reservations)
            {
                Resources.Add(reservation.Text, reservation.Id.ToString());
                myEvents.Add(new EventData()
                {
                    Id = reservation.Id.ToString(), Resource = reservation.Id.ToString(), Start = reservation.DateDebut, End = reservation.DateFin, Text = reservation.Text
                });
            }

            Events            = myEvents;
            DataIdField       = "Id";
            DataStartField    = "Start";
            DataEndField      = "End";
            DataResourceField = "Resource";
            DataTextField     = "Text";

            Scale = TimeScale.Day;

            TimeHeaders = new TimeHeaderCollection()
            {
                new TimeHeader(GroupBy.Month),
                new TimeHeader(GroupBy.Day)
            };
        }
예제 #14
0
        void LoadResources()
        {
            IList <Entidades.Usuarios.clsUsuario> usuarios = null;

            Entidades.GlobalObject.ResultadoTransaccion res =
                LogicaNegocios.Usuarios.clsUsuarios.ListarUsuarios(Entidades.Enums.Enums.Estado.Habilitado,
                                                                   Entidades.Enums.Enums.CargosUsuarios.Todos);
            if (res.Estado == Entidades.Enums.Enums.EstadoTransaccion.Aceptada)
            {
                usuarios = (IList <Entidades.Usuarios.clsUsuario>)res.ObjetoTransaccion;
            }

            ResourceCollection collection = schedulerStorage.Resources.Items;

            foreach (var usuario in usuarios)
            {
                collection.Add(new Resource(usuario.Id, usuario.NombreCompleto));
            }



            //SchedulerStorage storage = this.schedulerStorage;
            //ResourceCollection resources = storage.Resources.Items;

            //IList<clsUsuario> usuarios = new List<clsUsuario>();

            //ResultadoTransaccion res = LogicaNegocios.Usuarios.clsUsuarios.ListarUsuarios(Enums.Estado.Todos,
            //                                                              Enums.CargosUsuarios.Todos);

            //if (res.Estado == Enums.EstadoTransaccion.Aceptada)
            //    usuarios = (IList<clsUsuario>) res.ObjetoTransaccion;

            //Int16 count = 0;
            //foreach (var user in usuarios)
            //{
            //    Usuarios.SetValue(user.NombreCompleto,count);
            //    count++;
            //}

            //storage.BeginUpdate();
            //try
            //{
            //    int cnt = Math.Min(int.MaxValue, Usuarios.Length);
            //    for (int i = 0; i < cnt; i++)
            //    {
            //        if(Usuarios[i] != null )
            //            resources.Add(new Resource(i, Usuarios[i]));
            //    }
            //}
            //finally
            //{
            //    storage.EndUpdate();
            //}

            foreach (DevExpress.XtraEditors.Controls.CheckedListBoxItem list in resourcesCheckedListBoxControl1.Items)
            {
                list.CheckState = CheckState.Unchecked;
            }
        }
예제 #15
0
        public async Task GetRersourcePermissions()
        {
            var roleId             = "1";
            var resourceCollection = new ResourceCollection();

            resourceCollection.Add <Perm1>(1);
            resourceCollection.Add <Perm2>(2);
            var permissionStoreMock = new Mock <IPermissionStore>();

            permissionStoreMock.Setup(s => s.GetRoleStaticPermissionsAsync(roleId, CancellationToken.None))
            .Returns(Task.FromResult(new Dictionary <ResourcePermissionKey, bool>()));

            var service   = new PermissionManager(resourceCollection, permissionStoreMock.Object, new PermissionCache(), new IResourceInstanceProvider[0]);
            var resources = await service.GetResourcePermissionsAsync(roleId);

            Assert.AreEqual(2, resources.Count);
            Assert.AreNotEqual(0, resources.First().Permissions.First().PermissionId);
        }
예제 #16
0
 public void Dispose()
 {
     ResourceEntity resource = new ResourceEntity();
     resource.Position = _position;
     resource.Source = _page.OutputStack.Pop();
     var resources=new ResourceCollection();
     resources.Name = Guid.NewGuid().ToString("N");
     resources.Add(resource);
     _callBack(resources, _key);
 }
예제 #17
0
        public static void FillResources(SchedulerDataStorage storage, int count)
        {
            ResourceCollection resources = storage.Resources.Items;
            int cnt = Math.Min(count, Users.Length);

            for (int i = 1; i <= cnt; i++)
            {
                resources.Add(storage.CreateResource(i, Users[i - 1]));
            }
        }
예제 #18
0
 public void AtFoot()
 {
     var resources = new ResourceCollection();
     resources.Name = _resource.Name;
     _resource.Each(m =>
     {
         ResourceEntity entity = m.ToNew();
         entity.Position = ResourcePosition.Foot;
         resources.Add(entity);
     });
     _callBack(resources, _key);
 }
 public static void FillResources(ISchedulerStorage storage, int count) {
     ResourceCollection resources = storage.Resources.Items;
     storage.BeginUpdate();
     try {
         int cnt = Math.Min(count, SchedulerHelper.resources.Length);
         for (int i = 1; i <= cnt; i++) {
             Resource resource = storage.CreateResource(i);
             resource.Caption = SchedulerHelper.resources[i - 1];
             resources.Add(resource);
         }
     }
     finally {
         storage.EndUpdate();
     }
 }
예제 #20
0
    public static void FillResources(ASPxSchedulerStorage storage)
    {
        ResourceCollection resources = storage.Resources.Items;

        storage.BeginUpdate();
        try {
            for (int i = 1; i <= Users.Length; i++)
            {
                resources.Add(storage.CreateResource(Usernames[i - 1], Users[i - 1]));
            }
        }
        finally {
            storage.EndUpdate();
        }
    }
예제 #21
0
        private void CargarAsistentes()
        {
            var timer = System.Diagnostics.Stopwatch.StartNew();

            ResourceCollection collection = schedulerStorage1.Resources.Items;
            var myht = new Hashtable();

            foreach (var usuario in Usuarios)
            {
                if (!myht.ContainsKey(usuario.Id.ToString()))
                {
                    collection.Add(new Resource(usuario.Id, usuario.NombreCompleto));
                    myht.Add(usuario.Id.ToString(), usuario);
                }
            }
            ClsLogPerformance.Save(new LogPerformance(Base.Usuario.UsuarioConectado.Usuario, timer.Elapsed.TotalSeconds));
        }
    public static void FillResources(ASPxSchedulerStorage storage, int count)
    {
        ResourceCollection resources = storage.Resources.Items;

        storage.BeginUpdate();
        try {
            int cnt = Math.Min(count, Users.Length);
            for (int i = 1; i <= cnt; i++)
            {
                string resID   = Usernames[i - 1];
                string resName = Users[i - 1];
                resources.Add(storage.CreateResource(resID, resName));
            }
        }
        finally {
            storage.EndUpdate();
        }
    }
예제 #23
0
        public void FillResources(SchedulerStorage storage, int count)
        {
            ResourceCollection resources = storage.Resources.Items;

            storage.BeginUpdate();
            try
            {
                int cnt = Math.Min(count, Usuarios.Length);
                for (int i = 1; i <= cnt; i++)
                {
                    resources.Add(new Resource(i, Usuarios[i - 1]));
                }
            }
            finally
            {
                storage.EndUpdate();
            }
        }
예제 #24
0
        public static void GenerateSampleResources(SchedulerStorage storage)
        {
            ResourceCollection resources = storage.Resources.Items;

            storage.BeginUpdate();
            try {
                for (int i = 0; i < ExampleUtils.Users.Length; i++)
                {
                    Resource resource = storage.CreateResource(i + 1);

                    resource.Caption = ExampleUtils.Users[i];
                    resources.Add(resource);
                }
            }
            finally {
                storage.EndUpdate();
            }
        }
예제 #25
0
        void LoadResources()
        {
            SchedulerStorage   storage   = this.schedulerStorage;
            ResourceCollection resources = storage.Resources.Items;

            storage.BeginUpdate();
            try
            {
                int cnt = Math.Min(int.MaxValue, Users.Length);
                for (int i = 1; i <= cnt; i++)
                {
                    resources.Add(new Resource(i, Users[i - 1]));
                }
            }
            finally
            {
                storage.EndUpdate();
            }
        }
예제 #26
0
        /// <summary>
        /// Get all resources
        /// </summary>
        /// <returns></returns>
        public ResourceCollection GetAllResources()
        {
            try
            {
                ResourceCollection collection = new ResourceCollection();

                // execute query
                using (IDataReader dr = Database.ExecuteReader("UspGetAllResources", CommandType.StoredProcedure))
                {
                    while (dr.Read())
                    {
                        Resource resource = Populate(dr);

                        collection.Add(resource);
                    }
                }

                return(collection);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #27
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            String state = value as String;
            if (state == null)
            {
                return base.ConvertFrom(context, culture, value);
            }

            if (state == String.Empty)
            {
                return new ResourceCollection();
            }

            String[] parts = state.Split('&');

            ResourceCollection collection = new ResourceCollection();
            foreach (string encRes in parts)
            {
                string[] props = Encoder.UrlDecode(encRes).Split('&');

                Resource r = new Resource();
                r.Name = Encoder.UrlDecode(props[0]);
                r.Value = Encoder.UrlDecode(props[1]);

                collection.Add(r);
            }

            return collection;
        }
예제 #28
0
 protected override void Initialize()
 {
     textures = new ResourceCollection<Texture2D>();
       spriteBatch = new SpriteBatch(Game.GraphicsDevice);
       textures.Add("Sun", Game.Content.Load<Texture2D>("sunbg"));
 }
예제 #29
0
 static void FillResourcesStorage(ResourceCollection c)
 {
     Resource r;
     using (DataClasses1DataContext dc = new DataClasses1DataContext())
     {
         foreach (Profecional a in dc.Profecionals)
         {
             r = new Resource(a.IdProfecional, String.Concat(a.Persona.Nombre, ", ", a.Persona.Apellido));
             c.Add(r);
         }
     }
 }
예제 #30
0
        public static ResourceSetCollection ExtractResources(Assembly assembly)
        {
            ResourceSetCollection result = new ResourceSetCollection();

            //search all resource names
            string[] resourceNames = assembly.GetManifestResourceNames()
                .Where(x => x.ToLower().EndsWith(ExtensionPart))
                .ToArray();

            //iterate on resources
            foreach (string resourceName in resourceNames)
            {
                //try gets resource stream by it's name
                Stream stream = assembly.GetManifestResourceStream(resourceName);

                if (ReferenceEquals(stream, null))
                {
                    continue;
                }

                ResourceCollection resource = new ResourceCollection();

                //trying found resource
                try
                {
                    using (ResourceReader rr = new ResourceReader(stream))
                    {
                        foreach (DictionaryEntry entry in rr)
                        {
                            if (entry.Key is string && entry.Value is string)
                            {
                                resource.Add((string)entry.Key, (string)entry.Value);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }

                catch (Exception)
                {
                    continue;
                }

                if (resource.Count > 0)
                {
                    result.Add(resourceName, resource);
                }
            }

            return result;
        }
예제 #31
0
 private static void AddResourceContent(ResourceCollection resources, string content, StringWriter writer)
 {
     resources.Add(new StubResource(content));
     writer.Write(content);
 }