Ejemplo n.º 1
0
        public async Task <TCollection> Get <TCollection>()
            where TCollection : DataCollection, new()
        {
            TCollection collection = new TCollection();

            string data = "{}";
            string path = Path.Combine(root, $"{collection.Name}.json");

            await synchronize.WaitAsync();

            try
            {
                if (File.Exists(path))
                {
                    using (FileStream stream = File.OpenRead(path))
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            data = await reader.ReadToEndAsync();
                        }
                }

                IDictionary <string, object> items = Deserialize(data);
                DataStore store = new DataStore(items);

                collection.Get(store);
                return(collection);
            }
            finally
            {
                synchronize.Release();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gibt alle gespeicherten Objekte in der angegebenen <see cref="ICollection{T}"/> aus
        /// </summary>
        /// <typeparam name="TCollection">Die <see cref="ICollection{T}"/></typeparam>
        /// <returns>Die auszugebeneden Objekte</returns>
        public virtual TCollection GetLootObjects <TCollection>() where TCollection : ICollection <ILootable <T> >, new()
        {
            TCollection result = new TCollection();

            Array.ForEach(objects, o => result.Add(o));
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts an IDataReader to a TCollection WITH possible associated children (linked entities).
        /// </summary>
        ///
        /// <param name="source">
        /// IDataReader source.
        ///</param>
        ///
        /// <returns>
        /// A collection.
        /// </returns>
        protected override TCollection <VahapYigit.Test.Models.Role> DeepMap(IDataReader dbReader)
        {
            var collection = new TCollection <VahapYigit.Test.Models.Role>();

            while (dbReader.Read())
            {
                var entity = new VahapYigit.Test.Models.Role();
                entity.DeepMap(dbReader, base.UserContext);

                var currentRole = collection.FirstOrDefault(i => i.Id == entity.Id);
                if (currentRole == null)
                {
                    collection.Add(entity);
                    currentRole = entity;
                }

                // UserRoleCollection (-> Role)...
                foreach (var child in entity.UserRoleCollection)
                {
                    var e = currentRole.UserRoleCollection.FirstOrDefault(i => i.Id == child.Id);
                    if (e == null)
                    {
                        currentRole.UserRoleCollection.Add(child);
                        e = child;
                    }
                }
            }

            return(collection);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts an DataTable to a TCollection WITH possible associated children (linked entities).
        /// </summary>
        ///
        /// <param name="source">
        /// DataTable source.
        /// </param>
        ///
        /// <returns>
        /// A collection.
        /// </returns>
        protected override TCollection <VahapYigit.Test.Models.Role> DeepMap(DataTable source)
        {
            var collection = new TCollection <VahapYigit.Test.Models.Role>();

            foreach (DataRow row in source.Rows)
            {
                var entity = new VahapYigit.Test.Models.Role();
                entity.DeepMap(row, base.UserContext);

                var currentRole = collection.FirstOrDefault(i => i.Id == entity.Id);
                if (currentRole == null)
                {
                    collection.Add(entity);
                    currentRole = entity;
                }

                // UserRoleCollection (-> Role)...
                foreach (var child in entity.UserRoleCollection)
                {
                    var e = currentRole.UserRoleCollection.FirstOrDefault(i => i.Id == child.Id);
                    if (e == null)
                    {
                        currentRole.UserRoleCollection.Add(child);
                        e = child;
                    }
                }
            }

            return(collection);
        }
Ejemplo n.º 5
0
        private static void TestConfigurationElementCollectionRoundtripSerialization <TCollection, TElement>(params TElement[] seedElements)
            where TCollection : ConfigurationElementCollection <TElement>, new()
        {
            var original = new TCollection();

            foreach (var element in seedElements)
            {
                original.Add(element);
            }

            string      xml;
            TCollection deserialized;

            var xmlSerializer = new XmlSerializer(typeof(TCollection));

            using (var stringWriter = new StringWriter())
            {
                xmlSerializer.Serialize(stringWriter, original);
                xml = stringWriter.GetStringBuilder().ToString();
            }

            using (var stringReader = new StringReader(xml))
            {
                deserialized = (TCollection)xmlSerializer.Deserialize(stringReader);
            }

            Assert.AreEqual(original.Count, deserialized.Count, "Collection element counts differ.");
            for (var n = 0; n < original.Count; ++n)
            {
                Assert.AreEqual(original[n], deserialized[n], "Collections differ at index {0}", n);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads the UserRole entities associated to the instances (entity.UserRole collection property).
        /// </summary>
        ///
        /// <param name="entities">
        /// The target entity collection.
        /// </param>
        public void LoadUserRoleCollection(TCollection <VahapYigit.Test.Models.Role> entities)
        {
            if (entities != null)
            {
                var collection = entities.Where(i => i.IsInDb).ToTCollection();
                var idList     = collection.Select(i => i.Id).ToList();

                var options = new SearchOptions();
                options.Filters.Add(VahapYigit.Test.Models.UserRole.ColumnNames.IdRole, FilterOperator.In, idList);

                using (var db = new UserRoleCrud(base.UserContext))
                {
                    var data = db.Search(ref options);
                    foreach (var entity in collection)
                    {
                        entity.UserRoleCollection = data.Where(i => i.IdRole == entity.Id).ToTCollection();
                    }

                    foreach (var item in data)
                    {
                        item.Role = collection.First(i => i.Id == item.IdRole);
                    }
                }
            }
        }
        public static RuleCollectionTester <TCollection, T> Create <TCollection, T>()
            where TCollection : RuleCollection <T>, new()
        {
            var collection = new TCollection();

            return(new RuleCollectionTester <TCollection, T>(collection));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Loads the UserRole entities associated to the instances (entity.UserRole collection property).
 /// </summary>
 ///
 /// <param name="userContext">
 /// User context.
 /// </param>
 ///
 /// <param name="entities">
 /// The target entity collection.
 /// </param>
 public void LoadUserRoleCollection(IUserContext userContext, TCollection <VahapYigit.Test.Models.User> entities)
 {
     using (var et = new ExecutionTracerService())
         using (var db = new UserCrud(userContext))
         {
             db.LoadUserRoleCollection(entities);
         }
 }
Ejemplo n.º 9
0
        public void RegisterCollection <TCollection>()
            where TCollection : IEntityCollection
        {
            Type        type     = typeof(TCollection);
            TCollection instance = (TCollection)Activator.CreateInstance(type);

            this.Context.Add(type, instance);
        }
Ejemplo n.º 10
0
        protected internal override Task PackToAsyncCore(Packer packer, TCollection objectTree, CancellationToken cancellationToken)
        {
            if (this._isAsyncPackable)
            {
                return((( IAsyncPackable )objectTree).PackToMessageAsync(packer, null, cancellationToken));
            }

            return(base.PackToAsyncCore(packer, objectTree, cancellationToken));
        }
Ejemplo n.º 11
0
        public DbContextSeedBuilder WithSeedCollection <TCollection>() where TCollection : ISeederCollection, new()
        {
            TCollection collection = new TCollection();

            foreach (Type seeder in collection.GetSeederTypes())
            {
                this.WithSeedData(seeder);
            }
            return(this);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Returns a collection of all repositories of the underlying user.
        /// </summary>
        /// <typeparam name="TCollection">The type of the collection.</typeparam>
        /// <returns>The collection of repositories.</returns>
        public async Task <TCollection> GetAll <TCollection>()
            where TCollection : global::System.Collections.Generic.ICollection <Repository>, new()
        {
            using (var rest = User.Endpoint.Client.CreateBaseClient())
            {
                var resp = await rest.GetAsync("users/" + HttpUtility.UrlEncode(User.Username) + "/repos");

                Exception exception = null;

                if (resp.StatusCode != HttpStatusCode.OK)
                {
                    switch (resp.StatusCode)
                    {
                    case HttpStatusCode.InternalServerError:
                        exception = new ApiException(JsonConvert.DeserializeObject <ApiError>
                                                     (
                                                         await resp.Content.ReadAsStringAsync()
                                                     ),
                                                     (int)resp.StatusCode, resp.ReasonPhrase);
                        break;

                    default:
                        exception = new UnexpectedResponseException((int)resp.StatusCode,
                                                                    resp.ReasonPhrase);
                        break;
                    }
                }

                if (exception != null)
                {
                    throw exception;
                }

                var json = await resp.Content.ReadAsStringAsync();

                var repoList = JsonConvert.DeserializeObject <IEnumerable <Repository> >
                               (
                    await resp.Content.ReadAsStringAsync()
                               );

                var userRepos = new TCollection();
                using (var e = repoList.GetEnumerator())
                {
                    while (e.MoveNext())
                    {
                        var r = e.Current;
                        r.Owner.Endpoint = User.Endpoint;

                        userRepos.Add(r);
                    }
                }

                return(userRepos);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Searchs entities with search options.
        /// </summary>
        ///
        /// <param name="options">
        /// Optional options, filters, orderby, paging, etc.
        /// </param>
        ///
        /// <returns>
        /// A collection of entities.
        /// </returns>
        public override TCollection <VahapYigit.Test.Models.UserRole> Search(ref SearchOptions options)
        {
            TCollection <VahapYigit.Test.Models.UserRole> collection = null;

            using (var et = new ExecutionTracerService())
            {
                if (options == null)
                {
                    options = new SearchOptions();
                }

                var parameters = new Dictionary <string, object>();

                if (!options.Filters.IsNullOrEmpty())
                {
                    parameters.Add("Filter", options.Filters.ToSql());
                }

                if (!options.Orders.IsNullOrEmpty())
                {
                    parameters.Add("OrderBy", options.Orders.ToSql());
                }

                int maxRecords = int.MaxValue;
                if (options.MaxRecords != 0)
                {
                    maxRecords = (options.MaxRecords < 0) ? 0 : options.MaxRecords;
                }

                parameters.Add("MaxRecords", maxRecords);

                parameters.Add("CtxWithPaging", options.WithPaging);
                parameters.Add("CtxPagingCurrentPage", options.PagingOptions.CurrentPage);
                parameters.Add("CtxPagingRecordsPerPage", options.PagingOptions.RecordsPerPage);

                DbConnection dbConnection;

                using (var dbReader = this.ToDataReader("UserRole_Search", parameters, out dbConnection))
                {
                    collection = this.Map(dbReader);

                    dbReader.NextResult();
                    dbReader.Read();

                    options.PagingOptions.TotalRecords = TypeHelper.To <int>(dbReader[0]);
                }

                if (dbConnection != null)
                {
                    dbConnection.Close();
                }
            }

            return(collection);
        }
        public TCollection To <TCollection>()
            where TCollection : ICollection <TItem>, new()
        {
            var collection = new TCollection();

            foreach (var item in _source)
            {
                collection.Add(item);
            }
            return(collection);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Returns a collection of all followers.
        /// </summary>
        /// <typeparam name="TCollection">The type of the collection.</typeparam>
        /// <returns>The collection of followers.</returns>
        public async Task <TCollection> GetFollowers <TCollection>()
            where TCollection : global::System.Collections.Generic.ICollection <User>, new()
        {
            using (var rest = Endpoint.Client.CreateBaseClient())
            {
                var resp = await rest.GetAsync("users/" + HttpUtility.UrlEncode(Username) + "/followers");

                Exception exception = null;

                if (resp.StatusCode != HttpStatusCode.OK)
                {
                    switch ((int)resp.StatusCode)
                    {
                    case 500:
                        exception = new ApiException(JsonConvert.DeserializeObject <ApiError>
                                                     (
                                                         await resp.Content.ReadAsStringAsync()
                                                     ),
                                                     (int)resp.StatusCode, resp.ReasonPhrase);
                        break;

                    default:
                        exception = new UnexpectedResponseException((int)resp.StatusCode,
                                                                    resp.ReasonPhrase);
                        break;
                    }
                }

                if (exception != null)
                {
                    throw exception;
                }

                var users = JsonConvert.DeserializeObject <IEnumerable <User> >
                            (
                    await resp.Content.ReadAsStringAsync()
                            );

                var followers = new TCollection();
                using (var e = users.GetEnumerator())
                {
                    while (e.MoveNext())
                    {
                        var f = e.Current;
                        Endpoint.SetupUser(f);

                        followers.Add(f);
                    }
                }

                return(followers);
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="KMeansClusterCollection"/> class.
 /// </summary>
 ///
 /// <param name="collection">The collection that contains this instance as a field.</param>
 /// <param name="k">The number of clusters K.</param>
 ///
 public ClusterCollection(TCollection collection, int k)
 {
     // To store centroids of the clusters
     this.proportions = new double[k];
     this.clusters    = new TCluster[k];
     this.collection  = collection;
     for (int i = 0; i < clusters.Length; i++)
     {
         clusters[i]       = new TCluster();
         clusters[i].owner = collection;
         clusters[i].index = i;
     }
 }
Ejemplo n.º 17
0
            public virtual void Reset()
            {
                serializedObject    = null;
                tableReference      = null;
                tableEntryReference = null;
                fallbackState       = null;

                // Clear cached values
                m_FieldLabel              = null;
                m_SelectedEntry           = null;
                m_SelectedTableCollection = null;
                m_SelectedTableIdx        = -1;

                NeedsInitializing = true;
            }
Ejemplo n.º 18
0
        protected TCollection GetCaseObjects <TCase, TCollection>()
            where TCase : CaseObjectBase, new()
            where TCollection : List <TCase>, new()
        {
            var result = new TCollection();

            foreach (var item in Cases)
            {
                var itemObject = new TCase();
                itemObject.Min  = item.Min;
                itemObject.Max  = item.Max;
                itemObject.Item = item.Item;
                result.Add(itemObject);
            }

            return(result);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Executes the query and returns an entity observable collection.
        /// </summary>
        /// <typeparam name="T">Type of the returned entity (derived from EntityBase).</typeparam>
        /// <param name="procedure">Name of the stored procedure.</param>
        /// <param name="parameters">Input parameters for the stored procedure call.</param>
        /// <param name="withDeepMapping">Value indicating whether possible linked entities are mapped.</param>
        /// <returns>A collection.</returns>
        protected TCollection <T> ToEntityCollection(string procedure, IDictionary <string, object> parameters, bool?withDeepMapping = true)
        {
            DbConnection    dbConnection;
            TCollection <T> collection = null;

            using (var et = new ExecutionTracerService(procedure))
                using (var dbReader = this.ToDataReader(procedure, parameters, out dbConnection))
                {
                    collection = (withDeepMapping == true) ? this.DeepMap(dbReader) : this.Map(dbReader);
                }

            if (dbConnection != null)
            {
                dbConnection.Close();
            }

            return(collection);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Converts an IDataReader to a TCollection WITH possible associated children (linked entities).
        /// </summary>
        ///
        /// <param name="source">
        /// IDataReader source.
        ///</param>
        ///
        /// <returns>
        /// A collection.
        /// </returns>
        protected override TCollection <VahapYigit.Test.Models.UserRole> DeepMap(IDataReader dbReader)
        {
            var collection = new TCollection <VahapYigit.Test.Models.UserRole>();

            while (dbReader.Read())
            {
                var entity = new VahapYigit.Test.Models.UserRole();
                entity.DeepMap(dbReader, base.UserContext);

                var currentUserRole = collection.FirstOrDefault(i => i.Id == entity.Id);
                if (currentUserRole == null)
                {
                    collection.Add(entity);
                    currentUserRole = entity;
                }
            }

            return(collection);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Converts an DataTable to a TCollection WITHOUT associated children (linked entities).
        /// </summary>
        ///
        /// <param name="source">
        /// DataTable source.
        /// </param>
        ///
        /// <returns>
        /// A collection.
        /// </returns>
        protected override TCollection <VahapYigit.Test.Models.UserRole> Map(DataTable source)
        {
            var collection = new TCollection <VahapYigit.Test.Models.UserRole>();

            foreach (DataRow row in source.Rows)
            {
                var entity = new VahapYigit.Test.Models.UserRole();
                entity.Map(row, base.UserContext);

                var currentUserRole = collection.FirstOrDefault(i => i.Id == entity.Id);
                if (currentUserRole == null)
                {
                    collection.Add(entity);
                    currentUserRole = entity;
                }
            }

            return(collection);
        }
Ejemplo n.º 22
0
        /// <summary>
        ///
        /// </summary>
        public TreeView() : base()
        {
            DefaultStyleKey = typeof(TreeView);

            Columns       = new TreeViewColumnCollection();
            SelectedIndex = new int[1] {
                -1
            };
            SelectedItems = new TCollection <object>();

            GotFocus += OnGotFocus;

            SelectedItemChanged        += OnSelectedItemChanged;
            SelectedItems.ItemsChanged += OnSelectedItemsChanged;

            this.Bind(TreeViewExtensions.SelectedItemsProperty, new Binding()
            {
                Path   = new PropertyPath(nameof(SelectedItems)),
                Source = this
            });
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Gets data from a binary file.
        /// </summary>
        ///
        /// <param name="filePath">
        /// Path of the binary file to read.
        /// </param>
        ///
        /// <param name="isCompressed">
        /// Value indicating whether the binary file is compressed.
        /// </param>
        ///
        /// <returns>
        /// A collection of entities.
        /// </returns>
        public TCollection <T> GetDataFromBinFile <T>(string filePath, bool isCompressed = false)
            where T : IDataRowMapping, new()
        {
            TCollection <T> collection = new TCollection <T>();

            object data = this.GetDataFromBinFile(filePath, isCompressed);

            return(data as TCollection <T>);



            //DataTable data =null;//= this.GetDataFromBinFile(filePath, isCompressed);
            //TCollection<T> collection = new TCollection<T>();

            //foreach (DataRow row in data.Rows)
            //{
            //	T entity = new T();
            //	entity.DeepMap(row);

            //	collection.Add(entity);
            //}

            //return collection;
        }
Ejemplo n.º 24
0
 /// <summary>
 ///
 /// </summary>
 public FlagCheckView() : base()
 {
     DefaultStyleKey  = typeof(FlagCheckView);
     Items            = new TCollection <CheckableObject <object> >();
     Items.ItemAdded += OnItemAdded;
 }
 protected override void AddItem(TCollection collection, TItem item)
Ejemplo n.º 26
0
 public CollectionWrapperEnumerable(TCollection collection)
 {
     this.collection = collection;
 }
Ejemplo n.º 27
0
 protected internal override void PackToCore(Packer packer, TCollection objectTree)
Ejemplo n.º 28
0
 public IValueEntry <TCollection, TItem> CreateValueEntry(TCollection owner)
 {
     return(new FixedValueEntry <TCollection, TItem>(owner, Item, GetResult));
 }
Ejemplo n.º 29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="source"></param>
 /// <param name="getObservableFunc"></param>
 /// <typeparam name="TCollection"></typeparam>
 /// <typeparam name="TElement"></typeparam>
 /// <typeparam name="TProperty"></typeparam>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static IObservable <(TElement element, TProperty property)> ObserveElementObservable <TCollection, TElement, TProperty>(this TCollection source, Func <TElement, IObservable <TProperty> > getObservableFunc) where TCollection : INotifyCollectionChanged, IEnumerable <TElement> where TElement : class
 protected override void AddItem(TCollection collection, object item)