public bool IsCollectionReadyToCharge(CollectionData collection)
        {
            bool collectablesReady = true;

            RavenhillResourceService resourceService = engine.GetService <IResourceService>().Cast <RavenhillResourceService>();
            PlayerService            playerService   = engine.GetService <IPlayerService>().Cast <PlayerService>();

            foreach (string collectableId in collection.collectableIds)
            {
                CollectableData data        = resourceService.GetCollectable(collectableId);
                int             playerCount = playerService.GetItemCount(data);
                if (playerCount <= 0)
                {
                    collectablesReady = false;
                    break;
                }
            }

            bool chargersReady = true;

            foreach (var info in collection.chargers)
            {
                ChargerData data        = resourceService.GetCharger(info.id);
                int         playerCount = playerService.GetItemCount(data);
                if (playerCount < info.count)
                {
                    chargersReady = false;
                    break;
                }
            }

            return(collectablesReady && chargersReady);
        }
Exemple #2
0
        /// <summary>SubWindow.ViewModel</summary>
        public SubWindow()
        {
            Items = new ObservableCollection <CollectionData>();

            var rnd = RandomValue.GetValue();

            for (var iLoop = 0; iLoop < rnd.Next(10000) + 1; iLoop++)
            {
                Items.Add(new CollectionData(iLoop + 1, rnd.Next()));
            }

            SelectedItem = Items[0];

            Values = new ObservableCollection <CollectionData>();

            rnd = RandomValue.GetValue();
            for (var iLoop = 0; iLoop < RandomValue.GetValue().Next(10000) + 1; iLoop++)
            {
                Values.Add(new CollectionData(iLoop + 1, rnd.Next()));
            }

            SelectedValue = Values[0];

            Close();
        }
            internal CollectionData(CollectionData original, int additionalCapacity)
            {
                this.OrderedList = new List <T>(original.OrderedList.Count + additionalCapacity);
                foreach (T item in original.OrderedList)
                {   // using AddRange results in a temporary memory allocation
                    this.OrderedList.Add(item);
                }

                if (UseSortedListCrossover <= this.OrderedList.Capacity)
                {
                    this.IdentityDictionary = new Dictionary <string, OrderedIndex>(this.OrderedList.Capacity, StringComparer.OrdinalIgnoreCase);

                    if (null != original.IdentityDictionary)
                    {
                        foreach (KeyValuePair <string, OrderedIndex> pair in original.IdentityDictionary)
                        {
                            this.IdentityDictionary.Add(pair.Key, pair.Value);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < this.OrderedList.Count; ++i)
                        {
                            AddToDictionary(this, this.OrderedList[i].Identity, i, false);
                        }
                    }
                }
            }
Exemple #4
0
        private static void AddInitialData()
        {
            DatabaseContext db = new DatabaseContext();

            if (db.Users.Any() == false)
            {
                db.Users.Add(new User {
                    Username = "******", Password = "******"
                });
                db.SaveChanges();
            }

            if (db.Expenses.Any() == false)
            {
                string[] categories = new string[] { "Market", "Elektronik", "Tatil", "Taký" };
                int      userId     = db.Users.FirstOrDefault().Id;

                for (int i = 0; i < 50; i++)
                {
                    db.Expenses.Add(new Expense
                    {
                        Category    = CollectionData.GetElement(categories),
                        Date        = DateTimeData.GetDatetime(),
                        Description = TextData.GetSentence(),
                        Price       = NumberData.GetNumber(100, 500),
                        UserId      = userId
                    });
                }

                db.SaveChanges();
            }
        }
    public bool AddToInventory(GameObject newParent)
    {
        InventoryData[] inventories = newParent.GetComponentsInChildren <InventoryData>();

        for (int i = 0; i < inventories.Length; i++)
        {
            if (inventories[i].inventoryName == this.inventoryName)
            {
                CollectionData collection = inventories[i].GetCollectionByName(collectionName);
                if (collection != null)
                {
                    collection.Insert(this);
                    this.gameObject.SetActive(false);
                    // check for other mixins here?

                    IsEquipable equipable = this.GetComponent <IsEquipable>();
                    if (equipable)
                    {
                        equipable.AttachToSlot(newParent);
                    }

                    return(true);
                }
                else
                {
                    Debug.Log("No collection " + collectionName + " on touched GameObject " + newParent.name + ".");
                    return(false);
                }
            }
        }

        Debug.Log("No inventory " + inventoryName + " on touched GameObject " + newParent.name + ".");
        return(false);
    }
 private void HandleCollectionUnlocked(CollectionData collection)
 {
     if (!button.Shown)
     {
         button.Show();
     }
 }
        public void Setup(CollectionData collectionData)
        {
            this.collectionData = collectionData;

            for (int i = 0; i < chargerViews.Length; i++)
            {
                if (i < collectionData.chargers.Count)
                {
                    var info        = collectionData.chargers[i];
                    var chargerData = resourceService.GetCharger(info.id);
                    chargerViews[i].Setup(collectionData, chargerData);
                }
            }

            if (ravenhillGameModeService.IsCollectionReadyToCharge(collectionData))
            {
                chargeButton.interactable = true;
            }
            else
            {
                chargeButton.interactable = false;
            }

            chargeButton.SetListener(() => {
                ravenhillGameModeService.ChargeCollection(collectionData);
            }, engine.GetService <IAudioService>());
        }
Exemple #8
0
        /// <summary>
        ///     This returns a list of releases, which does not include regular Git tags that have not been associated with a
        ///     release.
        ///     <para />
        ///     Information about published releases are available to everyone. Only users with push access will receive listings
        ///     for draft releases.
        /// </summary>
        /// <param name="api"></param>
        /// <param name="repo"></param>
        /// <returns></returns>
        public static List <Release> GetReleases(this GitHubAPI api, [NotNull] RepoInfo repo)
        {
            string url = api.GetFullEndpointUrl("/repos/:owner/:repo/releases", repo);
            CollectionData <Release> releases = api.DownloadCollectionJson <Release>(url);

            return(releases.HttpStatusCode == HttpStatusCode.OK ? releases.Collection.ToList() : new List <Release>());
        }
        /// <summary>
        ///     Adds a collection of items to the collection
        /// </summary>
        /// <param name="items"> The items to add to the list </param>
        /// <exception cref="System.ArgumentNullException">Thrown if item argument is null</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if the item passed in or the collection itself instance is in ReadOnly state</exception>
        /// <exception cref="System.ArgumentException">Thrown if the item that is being added already belongs to another ItemCollection</exception>
        /// <exception cref="System.ArgumentException">Thrown if the ItemCollection already contains an item with the same identity</exception>
        /// <returns> Whether the add was successful </returns>
        internal bool AtomicAddRange(List <T> items)
        {
            var originalData = _collectionData;
            var newData      = new CollectionData(originalData, items.Count);

            // Add the new items, this will also perform duplication check
            foreach (var item in items)
            {
                if (item == null)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("items"));
                }
                Debug.Assert(!String.IsNullOrEmpty(item.Identity), "Identity of the item must never be null or empty");

                AddInternalHelper(item, newData, false);
            }

            var swappedOutData = Interlocked.CompareExchange(ref _collectionData, newData, originalData);

            // Check if the exchange was done, if not, then someone must have changed the data in the meantime, so
            // return false
            if (swappedOutData != originalData)
            {
                return(false);
            }

            return(true);
        }
        public override void Setup(object objdata = null)
        {
            base.Setup(objdata);
            this.data = objdata as CollectableData;
            if (data == null)
            {
                throw new ArgumentException("objdata");
            }

            collectionData = resourceService.GetCollection(data.collectionId);

            int index = 0;

            foreach (CollectableData collectableData in collectionData.collectableIds.Select(id => resourceService.GetCollectable(id)))
            {
                if (index < collectableViews.Length)
                {
                    collectableViews[index].Setup(collectableData);
                    index++;
                }
            }

            collectionView.Setup(collectionData);

            collectionNameText.text = resourceService.GetString(collectionData.nameId);

            StartCoroutine(CorEffect());
        }
Exemple #11
0
        public void Setup(CollectionData collectionData, ChargerData data)
        {
            this.data                = data;
            this.collectionData      = collectionData;
            iconImage.overrideSprite = resourceService.GetSprite(data);

            var info        = collectionData.GetChargeData(data.id);
            int playerCount = playerService.GetItemCount(data);

            countText.text = string.Format($"{playerCount}/{info.count}");

            if (playerCount >= info.count)
            {
                countText.color = allowColor;
                iconImage.color = nonEmptyIconColor;
            }
            else
            {
                countText.color = notAllowColor;
                iconImage.color = emptyIconColor;
            }

            trigger.SetEventTriggerClick((eventData) => {
                Debug.Log($"Click on charger: {data.id}");
                PointerEventData pointerData = eventData as PointerEventData;
                if (pointerData != null)
                {
                    if (pointerData.GetPointerObjectName() == trigger.name)
                    {
                        viewService.ShowView(RavenhillViewType.collection_buy_charger_view, collectionData);
                    }
                }
            }, engine.GetService <IAudioService>());
        }
 public void LoadCollection(string collectionID, UnityEngine.Events.UnityAction <CollectionData> callback)
 {
     Firebase.Database.FirebaseDatabase.DefaultInstance.RootReference.Child("collections").Child(collectionID).GetValueAsync().ContinueWith(task => {
         if (task.IsFaulted)
         {
             callback(null);
         }
         else if (task.IsCompleted)
         {
             DataSnapshot snapshot = task.Result;
             if (snapshot.Exists)
             {
                 if (snapshot.HasChildren)
                 {
                     Debug.Log("Collection found. Loading collection..");
                     string str = snapshot.GetRawJsonValue();
                     Debug.Log(str);
                     CollectionData collection = JsonUtility.FromJson <CollectionData>(str);
                     callback(collection);
                 }
                 else
                 {
                     Debug.Log("Collection empty");
                     callback(null);
                 }
             }
             else
             {
                 Debug.Log("Collection not exist");
                 callback(null);
             }
         }
     });
 }
Exemple #13
0
        private void GridView_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
        {
            if (CollectionsHolder.SelectedIndex != -1 || e.Row.Index != -1)
            {
                CollectionData cd = data.GetCollectionData(CollectionsHolder.SelectedIndex);

                int  deleteID = -1;
                bool delete   = false;

                for (int i = 0; i < cd.rowData.Count; i++)
                {
                    if (cd.rowData[i].number.ToString() == lastEditedData[0] || cd.rowData[i].name == lastEditedData[1] || cd.rowData[i].url == lastEditedData[2])
                    {
                        deleteID = i;
                        delete   = true;
                        break;
                    }
                }

                if (delete)
                {
                    cd.rowData.RemoveAt(deleteID);

                    SaveData();
                }

                CollectionsHolder_SelectedIndexChanged(null, EventArgs.Empty);
            }
        }
Exemple #14
0
    public void OnEnable()
    {
        // find the collection we need
        if (parent != null)
        {
            CollectionData[] cds = parent.GetComponentsInChildren <CollectionData> ();
            foreach (CollectionData cd in cds)
            {
                if (cd.Name == Name)
                {
                    collection = cd;
                }
            }
        }
        else
        {
            Debug.Log("isInventoryView::OnEnable() ERROR PARENT IS NULL");
        }

        // populate
        isInventorySlot[] sls = this.gameObject.GetComponentsInChildren <isInventorySlot>();
        foreach (isInventorySlot s in sls)
        {
            slots.Add(s);
        }
    }
Exemple #15
0
    public void Insert()
    {
        if (recipient)
        {
            CollectionData[] cdata = recipient.GetComponents <CollectionData>();
            for (int i = 0; i < cdata.Length; i++)
            {
                CollectionData coldat = cdata[i];

                // find the collection we should insert into, by name
                if (coldat.name == collectionName)
                {
                    coldat.Insert(this);

                    // really, only activate passive aspects if we
                    // successfully inserted into inventory
                    IsPassive pas = GetComponent <IsPassive>();
                    if (pas)
                    {
                        pas.Activate();
                        pas.SetRecipient(this.GetRecipient());
                    }

                    Hide();

                    break;
                }
            }
        }
    }
        public ICompositeMemento CreateCollectionMemento <TCollection, TElement>(
            ICollectionAdapter <TCollection, TElement> adapter,
            bool cascade)
        {
            var data = new CollectionData(adapter, cascade, typeof(TElement));

            return(new CollectionMemento(data, this));
        }
        protected override void AddNewData(string undoName, string newName)
        {
            RecordUndo(undoName);
            var newCol = new CollectionData(newName);

            _tableAuthoring.Collections.Add(newCol);
            UpdateTableCollections();
        }
        protected override void CloneData(string undoName, string newName, CollectionListData data)
        {
            RecordUndo(undoName);
            var newCol = new CollectionData(newName, data.CollectionData);

            _tableAuthoring.Collections.Add(newCol);
            UpdateTableCollections();
        }
        public void Setup(CollectionData data)
        {
            this.data = data;

            iconImage.overrideSprite = resourceService.GetSprite(data);
            int playerCount = playerService.GetItemCount(data);

            iconImage.color = (playerCount > 0) ? Color.white : new Color(1, 1, 1, 0.5f);
        }
Exemple #20
0
    public void StartVideo(int iInstanceID, CollectionData oData)
    {
        this.m_bIsVideoRunning = true;
        this.m_iInstanceID     = iInstanceID;

        VideoManager.Instance.SetVideoData(oData);
        UIManager.Instance.CloseAllView();
        UIManager.Instance.ShowViewByName(Constant.UI_Video);
    }
        private void Initialize()
        {
            if (mappedTypes != null)
            {
                return;
            }

            lock (padlock)
            {
                if (mappedTypes != null)
                {
                    return;
                }

                var collectionData = new CollectionData();

                var jsonDoc = store.DatabaseCommands.Get(collectionNamesDocId);
                if (jsonDoc != null)
                {
                    var collectionNames = jsonDoc.DataAsJson["Collections"] as RavenJArray;
                    foreach (RavenJValue value in collectionNames)
                    {
                        collectionData.Collections.Add(value.Value as string);
                    }
                }

                if (timeoutsEnabled)
                {
                    MapTypeToCollectionName(typeof(TimeoutPersisters.RavenDB.TimeoutData), collectionData);
                }
                if (sagasEnabled)
                {
                    foreach (var sagaType in types.Where(IsSagaEntity))
                    {
                        MapTypeToCollectionName(sagaType, collectionData);
                    }
                }

                if (collectionData.Changed)
                {
                    var newDoc = new RavenJObject();
                    var list   = new RavenJArray();
                    foreach (var name in collectionData.Collections)
                    {
                        list.Add(new RavenJValue(name));
                    }
                    newDoc["EndpointName"] = endpointName;
                    newDoc["EndpointName"] = endpointName;
                    newDoc["Collections"]  = list;
                    var metadata = new RavenJObject();
                    store.DatabaseCommands.Put(collectionNamesDocId, null, newDoc, metadata);
                }

                // Completes initialization
                mappedTypes = collectionData.Mappings;
            }
        }
Exemple #22
0
        /// <summary>
        ///     Adds an item to the collection represented by a list and a dictionary
        /// </summary>
        /// <param name="item"> The item to add to the list </param>
        /// <param name="collectionData"> The collection data where the item will be added </param>
        /// <param name="updateIfFound"> Whether the item should be updated if a matching item is found. </param>
        /// <exception cref="System.ArgumentNullException">Thrown if item argument is null</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if the item passed in or the collection itself instance is in ReadOnly state</exception>
        /// <exception cref="System.ArgumentException">Thrown if the MetadataCollection already contains an item with the same identity</exception>
        /// <exception cref="System.ArgumentException">Thrown if the item passed into Setter has null or String.Empty identity</exception>
        /// <remarks>
        ///     If updateIfFound is true, then an update is done in-place instead of
        ///     having an exception thrown. The in-place aspect is required to avoid
        ///     disrupting the indices generated for indexed items, and to enable
        ///     foreach loops to be able to modify the enumerated facets as if it
        ///     were a property update rather than an instance replacement.
        /// </remarks>
        private static void AddInternalHelper(T item, CollectionData collectionData, bool updateIfFound)
        {
            Util.AssertItemHasIdentity(item, "item");

            int index;
            var listCount = collectionData.OrderedList.Count;

            if (null != collectionData.IdentityDictionary)
            {
                index = AddToDictionary(collectionData, item.Identity, listCount, updateIfFound);
            }
            else
            {
                // We only have to take care of the ordered list.
                index = IndexOf(collectionData, item.Identity, false);
                if (0 <= index)
                {
                    // The item is found in the linear ordered list. Unless
                    // we're updating, it's an error.
                    if (!updateIfFound)
                    {
                        throw new ArgumentException(Strings.ItemDuplicateIdentity(item.Identity), "item", null);
                    }
                }
                else
                {
                    // This is a new item to be inserted. Grow if we must before adding to ordered list.
                    if (UseSortedListCrossover <= listCount)
                    {
                        collectionData.IdentityDictionary
                            = new Dictionary <string, OrderedIndex>(
                                  collectionData.OrderedList.Count + 1,
                                  StringComparer.OrdinalIgnoreCase);

                        for (var i = 0; i < collectionData.OrderedList.Count; ++i)
                        {
                            AddToDictionary(collectionData, collectionData.OrderedList[i].Identity, i, false);
                        }

                        AddToDictionary(collectionData, item.Identity, listCount, false);
                    }
                }
            }

            // Index will be listCount when AddToDictionary doesn't find
            // an existing match, and -1 if IndexOf doesn't find in ordered list.
            if (0 <= index &&
                index < listCount)
            {
                collectionData.OrderedList[index] = item;
            }
            else
            {
                Debug.Assert(index == -1 || index == listCount);
                collectionData.OrderedList.Add(item);
            }
        }
 private static void ValidateTableData(CollectionData data)
 {
     data.Name.Should().Be("Flippers");
     data.FireEvents.Should().Be(false);
     data.GroupElements.Should().Be(true);
     data.ItemNames[0].Should().Be("Flipper001");
     data.ItemNames[1].Should().Be("Flipper002");
     data.StopSingleEvents.Should().Be(false);
 }
Exemple #24
0
 private static void ValidateTableData(CollectionData data)
 {
     Assert.Equal("Flippers", data.Name);
     Assert.Equal(false, data.FireEvents);
     Assert.Equal(true, data.GroupElements);
     Assert.Equal("Flipper001", data.ItemNames[0]);
     Assert.Equal("Flipper002", data.ItemNames[1]);
     Assert.Equal(false, data.StopSingleEvents);
 }
        /// <summary>Adds an item to the identityDictionary</summary>
        /// <param name="collectionData">The collection data to add to</param>
        /// <param name="identity">The identity to add</param>
        /// <param name="index">The identity's index in collection</param>
        /// <param name="updateIfFound">Whether the item should be updated if a matching item is found.</param>
        /// <returns>
        /// Index of the added entity, possibly different from the index
        /// parameter if updateIfFound is true.
        /// </returns>
        private static int AddToDictionary(CollectionData collectionData, string identity, int index, bool updateIfFound)
        {
            Debug.Assert(collectionData != null && collectionData.IdentityDictionary != null, "the identity dictionary is null");
            Debug.Assert(!String.IsNullOrEmpty(identity), "empty identity");
            int[]        inexact = null;
            OrderedIndex orderIndex;
            int          exactIndex = index;

            // find the item(s) by OrdinalIgnoreCase
            if (collectionData.IdentityDictionary.TryGetValue(identity, out orderIndex))
            {
                // identity was already tracking an item, verify its not a duplicate by exact name
                if (EqualIdentity(collectionData.OrderedList, orderIndex.ExactIndex, identity))
                {
                    // If the item is already here and we are updating, there is no more work to be done.
                    if (updateIfFound)
                    {
                        return(orderIndex.ExactIndex);
                    }
                    throw EntityUtil.ItemDuplicateIdentity(identity, "item", null);
                }
                else if (null != orderIndex.InexactIndexes)
                {
                    // search against the ExactIndex and all InexactIndexes
                    // identity was already tracking multiple items, verify its not a duplicate by exact name
                    for (int i = 0; i < orderIndex.InexactIndexes.Length; ++i)
                    {
                        if (EqualIdentity(collectionData.OrderedList, orderIndex.InexactIndexes[i], identity))
                        {
                            // If the item is already here and we are updating, there is no more work to be done.
                            if (updateIfFound)
                            {
                                return(orderIndex.InexactIndexes[i]);
                            }
                            throw EntityUtil.ItemDuplicateIdentity(identity, "item", null);
                        }
                    }
                    // add another item for existing identity that already was tracking multiple items
                    inexact = new int[orderIndex.InexactIndexes.Length + 1];
                    orderIndex.InexactIndexes.CopyTo(inexact, 0);
                    inexact[inexact.Length - 1] = index;
                }
                else
                {
                    // turn the previously unique identity by ignore case into a multiple item for identity by ignore case
                    inexact = new int[1] {
                        index
                    };
                }
                // the index of the item whose identity was used to create the initial dictionary entry
                exactIndex = orderIndex.ExactIndex;
            }
            // else this is a new identity

            collectionData.IdentityDictionary[identity] = new OrderedIndex(exactIndex, inexact);
            return(index);
        }
    private void OnCollectionDataChanged(EventData e)
    {
        Debug.Log("Collection data changed! Updating UI...");
        DataSnapshot dataList = (DataSnapshot)e.Data["box_list"];

        Debug.Log(dataList.GetRawJsonValue());
        CollectionData collection = JsonUtility.FromJson <CollectionData>(dataList.GetRawJsonValue());

        BoxList.UpdateList(collection);
    }
 public void SetData(CollectionData data)
 {
     Points          = data.Points;
     StartTier       = data.StartTier;
     NextTier        = data.NextTier;
     DailyDecay      = data.DailyDecay;
     m_Tier          = data.Tier;
     m_DonationTitle = data.DonationTitle;
     m_Tiers         = data.Tiers;
 }
Exemple #28
0
 public CollectionData GetValue(CollectionData item, DependencyObject container)
 {
     switch (item.type)
     {
         case "password":
             return collectionDataFromPasswordFactory.Get(container, item);
         default:
             return collectionDataFromTextBoxFactory.Get(container, item);
     }
 }
        public static IEnumerable <Customer> GetCustomers()
        {
            IEnumerable <Customer> customers = new List <Customer>();

            using (var client = new HttpClient())
            {
                // try {
                client.BaseAddress = new Uri(ECONOMIC_URL);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add(Header_Name_AccessID, AccessID);
                client.DefaultRequestHeaders.Add(Header_Name_AppID, AppID);

                var responseTask = client.GetAsync(string.Format("customers{0}", isDemo ? "?demo=true" : string.Empty));
                responseTask.Wait();

                HttpResponseMessage response = responseTask.Result;

                response.EnsureSuccessStatusCode();
                var formatters = new List <MediaTypeFormatter>()
                {
                    new JsonMediaTypeFormatter(),
                    new XmlMediaTypeFormatter()
                };

                if (response.IsSuccessStatusCode)
                {
                    var resultTask = response.Content.ReadAsAsync <CollectionData <Customer> >(formatters);
                    resultTask.Wait();
                    CollectionData <Customer> collectionResult = resultTask.Result;
                    customers = collectionResult.Collection;

                    if (!traceOff)
                    {
                        Trace.Write("Loop customers");

                        foreach (var customer in collectionResult.Collection)
                        {
                            Trace.Write("Customer number: " + customer.CustomerNumber);
                            Trace.Write("Customer name: " + customer.Name);
                        }
                    }
                }
                else
                {
                    var content = response.Content.ReadAsStringAsync();
                    content.Wait();

                    throw new Exception(string.Format("ErrorCode: {0} - Message: {1}", response.StatusCode, content.Result));
                }
                // } catch (Exception ex) { }
            }

            return(customers);
        }
Exemple #30
0
        public void ShouldHandleNullTargetDifferentTypeCollection()
        {
            var source = new[] { new PersonViewModel {
                                     Name = "Frank"
                                 } };
            var collectionData = CollectionData.Create(source, default(Person[]), pvm => pvm.Id, p => p.Id);

            collectionData.AbsentTargetItems.ShouldBeEmpty();
            collectionData.Intersection.ShouldBeEmpty();
            collectionData.NewSourceItems.SequenceEqual(source).ShouldBeTrue();
        }
        public CollectionData[] Load(CollectionConfig[] configs)
        {
            var result = new CollectionData[configs.Length];

            for (int i = 0; i < configs.Length; i++)
            {
                result[i] = Load(configs[i]);
            }

            return(result);
        }
        public static void CreateCollectionData(int locationId, int userId)
        {
            CheckoutDataContextProvider dcp = CheckoutDataContextProvider.Instance;

            Repository<CollectionData> rep = new Repository<CollectionData>(dcp);

            CollectionData collectionData = new CollectionData();
            collectionData.LocationID = locationId;

            rep.InsertOnSubmit(collectionData);
            dcp.CommitChanges(userId);
        }
        private void Initialize()
        {
            if (mappedTypes != null)
                return;

            lock (padlock)
            {
                if (mappedTypes != null)
                    return;

                var collectionData = new CollectionData();

                var jsonDoc = store.DatabaseCommands.Get(collectionNamesDocId);
                if (jsonDoc != null)
                {
                    var collectionNames = jsonDoc.DataAsJson["Collections"] as RavenJArray;
                    foreach (RavenJValue value in collectionNames)
                    {
                        collectionData.Collections.Add(value.Value as string);
                    }
                }

                if (timeoutsEnabled)
                {
                    MapTypeToCollectionName(typeof(TimeoutPersisters.RavenDB.TimeoutData), collectionData);
                }
                if (sagasEnabled)
                {
                    foreach (var sagaType in types.Where(IsSagaEntity))
                    {
                        MapTypeToCollectionName(sagaType, collectionData);
                    }
                }

                if (collectionData.Changed)
                {
                    var newDoc = new RavenJObject();
                    var list = new RavenJArray();
                    foreach (var name in collectionData.Collections)
                    {
                        list.Add(new RavenJValue(name));
                    }
                    newDoc["EndpointName"] = this.endpointName;
                    newDoc["EndpointName"] = this.endpointName;
                    newDoc["Collections"] = list;
                    var metadata = new RavenJObject();
                    store.DatabaseCommands.Put(collectionNamesDocId, null, newDoc, metadata);
                }

                // Completes initialization
                this.mappedTypes = collectionData.Mappings;
            }
        }
        private void MapTypeToCollectionName(Type type, CollectionData collectionData)
        {
            var byUserConvention = userSuppliedConventions(type);
            var ravenDefault = Raven.Client.Document.DocumentConvention.DefaultTypeTagName(type);
            var byLegacy = LegacyFindTypeTagName(type);

            var mappingsInPriorityOrder = new[]
            {
                byUserConvention,
                ravenDefault,
                byLegacy
            };

            var configuredName = mappingsInPriorityOrder
                .Distinct()
                .SingleOrDefault(name => collectionData.Collections.Contains(name));

            if (configuredName == null)
            {
                if (collectionData.IndexResults == null)
                {
                    collectionData.IndexResults = GetTerms();
                }

                var collectionsThatExist = mappingsInPriorityOrder
                    .Distinct()
                    .Where(name => collectionData.IndexResults.Contains(name))
                    .ToArray();


                if (collectionsThatExist.Length > 1)
                {
                    var options = string.Join(", ", collectionsThatExist);
                    throw new InvalidOperationException($"Multiple RavenDB collection names ({options}) found for type `{type.FullName}`. Unable to determine DocumentId naming strategy for this type. Remove or modify the documents that were mapped incorrectly.");
                }

                configuredName = collectionsThatExist.FirstOrDefault() ?? ravenDefault;
                collectionData.Collections.Add(configuredName);
                collectionData.Changed = true;
            }

            collectionData.Mappings.Add(type, configuredName);
        }