Пример #1
0
 public static void ResetToNewDesign()
 {
     collectiveBeingDesigned = new Collective();
     assemblyPatterns        = new Queue <CollectiveAssemblyPattern>();
     controllingCharacterAssemblyPatterns = new Queue <ParticipationAssemblyPattern>();
     memberCharacterAssemblyPatterns      = new Queue <ParticipationAssemblyPattern>();
 }
Пример #2
0
 public void ExecuteAdditionalSetup(Collective c)
 {
     if (additionalSetupMethod != null)
     {
         additionalSetupMethod(c);
     }
 }
Пример #3
0
        // gets a set of templates following condition methods that
        // evaluate to true, as well as randomly chosen templates
        public Queue <CollectiveForecastSharedData> PickForecastSharedData(Collective c)
        {
            Queue <CollectiveForecastSharedData> forecastSharedData
                = new Queue <CollectiveForecastSharedData>();

            double randomNumber;

            for (int i = 0; i < forecastsByChance.Count; i++)
            {
                randomNumber = randomizer.NextDouble();
                if (forecastsByChance[i].chance >= randomNumber)
                {
                    forecastSharedData.Enqueue(forecastsByChance[i].template);
                }
            }

            for (int i = 0; i < forecastsByMethod.Count; i++)
            {
                if (forecastsByMethod[i].method(c))
                {
                    forecastSharedData.Enqueue(forecastsByChance[i].template);
                }
            }

            return(forecastSharedData);
        }
Пример #4
0
        public async Task <ActionResult <Collective> > PostCollective(Collective collective)
        {
            _context.Collectives.Add(collective);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCollective", new { id = collective.Id }, collective));
        }
Пример #5
0
    /*
     *  1) get all relevant CareAbouts for each index's
     *  IndexFillSpecification at each index that is not set
     *  2) for all non-set indices, get all targeted complex entities
     *  3) for all non-set indices, assign id of the complex entity with highest score
     */
    public static void SetIndiciesByCareAbout(
        BaseSimpleEntity beingFilled,
        SimpleEntitySharedData beingFilledSharedData,
        Collective c)
    {
        int numOfFillSpecs = beingFilledSharedData.aboutSpecs.Count;

        for (int i = 0; i < numOfFillSpecs; i++)
        {
            // the specification for how to fill the associated
            // index with a complex entity id
            IndexSpecification spec = beingFilledSharedData.aboutSpecs[i];

            // negative value in "about" indicates no set index
            if (spec.fillType <= INDEX_FILL_TYPE.CARE_ABOUT_FIRST &&
                beingFilled.about[i] < 0)
            {
                List <CareAbout> temp = new List <CareAbout>();

                for (int j = 0; j < c.controllingCharacters.Count; j++)
                {
                    var character = c.controllingCharacters[j];

                    // all CareAbouts that have any of the specified IDs
                    temp.AddRange(GetRelevantCareAbouts(character, spec));
                }

                beingFilled.about[i] = GetHighestScoringComplexEntityID(temp);
            }
        }
    }
Пример #6
0
        public async Task <IActionResult> PutCollective(int id, [FromBody] Collective collective)
        {
            if (id != collective.Id)
            {
                return(BadRequest());
            }

            _context.Entry(collective).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CollectiveExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #7
0
        /// <summary>Updates the collective asynchronous.</summary>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        /// <param name="size">The size.</param>
        /// <returns></returns>
        internal async Task <bool> UpdateCollectiveAsync(string name, string description, int size)
        {
            var currentUser = System.Text.Json.JsonSerializer.Deserialize <User>(ReadSetting("CurrentUser"));

#pragma warning disable CA1305 // Specify IFormatProvider
            var collective = new Collective()
            {
                Id = Int32.Parse(ReadSetting("CurrentCollective")), OwnerId = currentUser.Id, Name = name, Description = description, Size = size
            };
#pragma warning restore CA1305 // Specify IFormatProvider
            Uri collectiveUri  = new Uri("http://localhost:4000/Collectives/" + collective.Id);
            var collectiveJson = JsonConvert.SerializeObject(collective);
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task
            Collective currentCollective = await CrudHandler.GetGenericEntityAsync <Collective>(collectiveUri, ReadSetting("AuthInfo"));

#pragma warning restore CA2007 // Consider calling ConfigureAwait on the awaited task
            var collectiveStringContent = new StringContent(collectiveJson, Encoding.UTF8, "application/json");
            if (currentUser.Id == currentCollective.OwnerId)
            {
                await CrudHandler.PutGenericAsync(collectiveStringContent, ReadSetting("AuthInfo"), collectiveUri).ConfigureAwait(false);

                collectiveStringContent.Dispose();
                return(true);
            }
            else
            {
                collectiveStringContent.Dispose();
                await new MessageDialog("You are not allowed to edit this Collective, please pick one from the Manage Collectives Page", "Not allowed").ShowAsync();
                return(false);
            }
        }
Пример #8
0
        // gets a set of templates following condition methods that
        // evaluate to true, as well as randomly chosen templates
        public Queue <CollectiveOptionSharedData> PickOptionSharedData(Collective c)
        {
            Queue <CollectiveOptionSharedData> optionSharedData
                = new Queue <CollectiveOptionSharedData>();

            double randomNumber;

            for (int i = 0; i < optionsByChance.Count; i++)
            {
                randomNumber = randomizer.NextDouble();
                if (optionsByChance[i].chance >= randomNumber)
                {
                    optionSharedData.Enqueue(optionsByChance[i].template);
                }
            }

            for (int i = 0; i < optionsByMethod.Count; i++)
            {
                if (optionsByMethod[i].method(c))
                {
                    optionSharedData.Enqueue(optionsByChance[i].template);
                }
            }

            return(optionSharedData);
        }
Пример #9
0
        public ActionResult Create(CreateCollective collective)
        {
            if (ModelState.IsValid)
            {
                var c = Collective.CreateAndAdd(db, collective.Name, CurrentUser.Id, collective.ShareName, collective.ShareIdentifier, collective.TotalShares, collective.IsTransferable, collective.AssetBacked, collective.UserShares, collective.UserVoteClout);

                db.SaveChanges();

                return(RedirectToAction("Dashboard", "Collective", new { id = c.Id }));
            }

            return(View(collective));
        }
Пример #10
0
        /// <summary>Creates the collective asynchronous.</summary>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        /// <param name="size">The size.</param>
        internal async Task CreateCollectiveAsync(string name, string description, int size)
        {
            var currentUser = System.Text.Json.JsonSerializer.Deserialize <User>(ReadSetting("CurrentUser"));
            var collective  = new Collective()
            {
                Name = name, Description = description, Size = size, OwnerId = currentUser.Id
            };
            var        collectiveJson          = JsonConvert.SerializeObject(collective);
            var        collectiveStringContent = new StringContent(collectiveJson, Encoding.UTF8, "application/json");
            Collective x = await CrudHandler.CreateCollective <Collective>(collectiveStringContent, ReadSetting("AuthInfo")).ConfigureAwait(false);

            collectiveStringContent.Dispose();
            await JoinCollectiveAsync(x.Id).ConfigureAwait(true);
        }
    // personalizes a simple entity of type T, and returns it readily configured
    public static T Personalize <T, U>(
        Collective c,
        World w,
        List <int> forwardedIndices = null)

    // if T = CollectiveSituation, U = CollectiveSituationSharedData,
    // with the same for other simple entities
        where T : BaseSimpleEntity, IShareData <U>, new()
        where U : SimpleEntitySharedData
    {
        // situation/option/forecast to be personalized
        T simpleEntity = new T();

        // the four stages of personalization
        ForwardIndices(simpleEntity, simpleEntity.sharedData, forwardedIndices);
        SetIndiciesByCareAbout(simpleEntity, simpleEntity.sharedData, c);
        SetIndicesByCategoryNumbers(simpleEntity, simpleEntity.sharedData, w);
        SetIndicesByPureRandom(simpleEntity, simpleEntity.sharedData, w);

        return(simpleEntity);
    }
Пример #12
0
    static int Generate(
        World w,
        Collective c,
        Queue <CollectiveAssemblyPattern> collectivePatterns,
        Queue <ParticipationAssemblyPattern> controllingCharacterPatterns,
        Queue <ParticipationAssemblyPattern> memberCharacterPatterns)
    {
        while (collectivePatterns.Count > 0)
        {
            var pattern = collectivePatterns.Dequeue();

            c.categoryNumbers.AddRange(pattern.categoryNumbers);
            pattern.ExecuteAdditionalSetup(c);

            var situationSharedData = pattern.PickSituationSharedData(c);
            while (situationSharedData.Count > 0)
            {
                var temp         = situationSharedData.Dequeue();
                var personalized = Personalizer.Personalize
                                   <Collective.CollectiveSituation,
                                    CollectiveSituationSharedData>
                                       (c, w);

                personalized.stats = personalized.sharedData.stats.GetCopy();
                personalized.stats.InitializeFromSubscription();

                c.situations.Add(personalized);
            }

            var optionSharedData = pattern.PickOptionSharedData(c);
            while (optionSharedData.Count > 0)
            {
                var temp         = optionSharedData.Dequeue();
                var personalized = Personalizer.Personalize
                                   <Collective.CollectiveOption,
                                    CollectiveOptionSharedData>
                                       (c, w);

                c.options.Add(personalized);
            }

            var forecastSharedData = pattern.PickForecastSharedData(c);
            while (forecastSharedData.Count > 0)
            {
                var temp         = forecastSharedData.Dequeue();
                var personalized = Personalizer.Personalize
                                   <Collective.CollectiveForecast,
                                    CollectiveForecastSharedData>
                                       (c, w);

                c.forecasts.Add(personalized);
            }
        }

        /*
         *  Complete all assembly patterns
         */

        w.collectives.Add(c);
        return(w.collectives.Count - 1);
    }
Пример #13
0
 public void UpdateCollective(Collective collective)
 {
     _context.Collectives.Update(collective);
 }
Пример #14
0
        private void Read()
        {
            try
            {

                // Beolvasandó dokumentumok listája
                LinkedList<XDocument> documentList = new LinkedList<XDocument>();

                // Imprortálások bekérése
                XDocument Doc = XDocument.Load(@path + fileName);

                // Rekurzív függvény az importálások kifejtésére
                CheckImports(documentList, Doc, path);

                //--------------------------------------------------------------------

                // Az összes fájl feldolgozása
                foreach (XDocument xd in documentList)
                {
                    XNamespace targetNS = "";
                    XNamespace defNS = "";
                    try
                    {
                        targetNS = (string)xd.Element("definitions").Attribute("targetNamespace");
                        defNS = "";
                    }
                    catch { }
                    try
                    {
                        targetNS = (string)xd.Element("schema").Attribute("targetNamespace");
                        defNS = "";
                    }
                    catch { }
                    try
                    {
                        targetNS = (string)xd.Element(xmlNS + "schema").Attribute("targetNamespace");
                        defNS = xmlNS;
                    }
                    catch { }
                    try
                    {
                        targetNS = (string)xd.Element(wsdlNS + "definitions").Attribute("targetNamespace");
                        defNS = wsdlNS;
                    }
                    catch { }

                    // services
                    var services = from c in xd.Descendants(wsdlNS + "service")
                                   select c;

                    foreach (XElement xe in services)
                    {
                        Collective coll = new Collective()
                        {
                            name = (string)xe.Attribute("name"),
                            definition = xe,
                            objectType = ObjectTypes.service,
                            ownNS = targetNS
                        };

                        readedElements.Add(coll);
                    }

                    // binding
                    var bindings = from c in xd.Descendants(wsdlNS + "binding")
                                   select c;

                    foreach (XElement xe in bindings)
                    {
                        Collective coll = new Collective()
                        {
                            name = (string)xe.Attribute("name"),
                            definition = xe,
                            objectType = ObjectTypes.binding,
                            ownNS = targetNS
                        };

                        readedElements.Add(coll);
                    }

                    // porttype
                    var portTypes = from c in xd.Descendants(wsdlNS + "portType")
                                    select c;

                    foreach (XElement xe in portTypes)
                    {
                        Collective coll = new Collective()
                        {
                            name = (string)xe.Attribute("name"),
                            definition = xe,
                            objectType = ObjectTypes.porttype,
                            ownNS = targetNS
                        };

                        readedElements.Add(coll);
                    }

                    // message
                    var messages = from c in xd.Descendants(wsdlNS + "message")
                                   select c;

                    foreach (XElement xe in messages)
                    {
                        Collective coll = new Collective()
                        {
                            name = (string)xe.Attribute("name"),
                            definition = xe,
                            objectType = ObjectTypes.message,
                            ownNS = targetNS
                        };

                        readedElements.Add(coll);
                    }

                    //TODO: <type> és <schema> ellenőrzése a targetNamespace miatt!!!

                    // simpleTypes
                    var simpleTypes = from c in xd.Descendants(xmlNS + "simpleType")
                                      select c;

                    foreach (XElement xe in simpleTypes)
                    {
                        Collective coll = new Collective()
                        {
                            name = (string)xe.Attribute("name"),
                            definition = xe,
                            objectType = ObjectTypes.enumType,
                            ownNS = targetNS
                        };

                        readedElements.Add(coll);
                    }

                    // complexTypes
                    var complexTypes = from c in xd.Descendants(xmlNS + "complexType")
                                       select c;

                    foreach (XElement xe in complexTypes)
                    {
                        Collective coll = new Collective()
                        {
                            name = (string)xe.Attribute("name"),
                            definition = xe,
                            objectType = ObjectTypes.complexType,
                            ownNS = targetNS

                        };

                        readedElements.Add(coll);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
Пример #15
0
 public void DeleteCollective(Collective collective)
 {
     _context.Collectives.Remove(collective);
 }
Пример #16
0
    private void CreateNavigationLinks(Collective.Offer.SortType sortBy, bool isAsc, int currPage, int numOfRows, int totalPageCount)
    {
        string basicUrl = Request.Url.ToString();
        basicUrl = basicUrl.Substring(0, basicUrl.IndexOf(".aspx") + ".aspx".Count());

        // sort linkovi
        HyperLink hlOfferNameSort = (HyperLink)this.grdOffers.HeaderRow.FindControl("hlOfferNameSort");
        if (sortBy == Collective.Offer.SortType.OfferName)
        {
            hlOfferNameSort.NavigateUrl = basicUrl + "?sortby=" + Collective.Offer.SortType.OfferName.ToString() + "&asc=" + (!isAsc).ToString() + "&page=" + currPage.ToString() + "&rows=" + numOfRows.ToString();
            hlOfferNameSort.Text = isAsc ? "Offer Name ↑" : "Offer Name ↓";
        }
        else
        {
            hlOfferNameSort.NavigateUrl = basicUrl + "?sortby=" + Collective.Offer.SortType.OfferName.ToString() + "&asc=" + true.ToString() + "&page=" + currPage.ToString() + "&rows=" + numOfRows.ToString();
            hlOfferNameSort.Text = "Offer Name ↑";
        }

        HyperLink hlOfferIdSort = (HyperLink)this.grdOffers.HeaderRow.FindControl("hlOfferIdSort");
        if (sortBy == Collective.Offer.SortType.OfferId)
        {
            hlOfferIdSort.NavigateUrl = basicUrl + "?sortby=" + Collective.Offer.SortType.OfferId.ToString() + "&asc=" + (!isAsc).ToString() + "&page=" + currPage.ToString() + "&rows=" + numOfRows.ToString();
            hlOfferIdSort.Text = isAsc ? "ID ↑" : "ID ↓";
        }
        else
        {
            hlOfferIdSort.NavigateUrl = basicUrl + "?sortby=" + Collective.Offer.SortType.OfferId.ToString() + "&asc=" + true.ToString() + "&page=" + currPage.ToString() + "&rows=" + numOfRows.ToString();
            hlOfferIdSort.Text = "ID ↑";
        }

        HyperLink hlCategoryNameSort = (HyperLink)this.grdOffers.HeaderRow.FindControl("hlCategoryNameSort");
        if (sortBy == Collective.Offer.SortType.CategotyName)
        {
            hlCategoryNameSort.NavigateUrl = basicUrl + "?sortby=" + Collective.Offer.SortType.CategotyName.ToString() + "&asc=" + (!isAsc).ToString() + "&page=" + currPage.ToString() + "&rows=" + numOfRows.ToString();
            hlCategoryNameSort.Text = isAsc ? "Category Name ↑" : "Category Name ↓";
        }
        else
        {
            hlCategoryNameSort.NavigateUrl = basicUrl + "?sortby=" + Collective.Offer.SortType.CategotyName.ToString() + "&asc=" + true.ToString() + "&page=" + currPage.ToString() + "&rows=" + numOfRows.ToString();
            hlCategoryNameSort.Text = "Category Name ↑";
        }

        HyperLink hlBoughtCountSort = (HyperLink)this.grdOffers.HeaderRow.FindControl("hlBoughtCountSort");
        if (sortBy == Collective.Offer.SortType.BoughtCount)
        {
            hlBoughtCountSort.NavigateUrl = basicUrl + "?sortby=" + Collective.Offer.SortType.BoughtCount.ToString() + "&asc=" + (!isAsc).ToString() + "&page=" + currPage.ToString() + "&rows=" + numOfRows.ToString();
            hlBoughtCountSort.Text = isAsc ? "Bought Count ↑" : "Bought Count ↓";
        }
        else
        {
            hlBoughtCountSort.NavigateUrl = basicUrl + "?sortby=" + Collective.Offer.SortType.BoughtCount.ToString() + "&asc=" + true.ToString() + "&page=" + currPage.ToString() + "&rows=" + numOfRows.ToString();
            hlBoughtCountSort.Text = "Bought Count ↑";
        }

        HyperLink hlDateStartSort = (HyperLink)this.grdOffers.HeaderRow.FindControl("hlDateStartSort");
        if (sortBy == Collective.Offer.SortType.DateStart)
        {
            hlDateStartSort.NavigateUrl = basicUrl + "?sortby=" + Collective.Offer.SortType.DateStart.ToString() + "&asc=" + (!isAsc).ToString() + "&page=" + currPage.ToString() + "&rows=" + numOfRows.ToString();
            hlDateStartSort.Text = isAsc ? "Date Start ↑" : "Date Start ↓";
        }
        else
        {
            hlDateStartSort.NavigateUrl = basicUrl + "?sortby=" + Collective.Offer.SortType.DateStart.ToString() + "&asc=" + true.ToString() + "&page=" + currPage.ToString() + "&rows=" + numOfRows.ToString();
            hlDateStartSort.Text = "Date Start ↑";
        }

        // paging linovi
        this.hlFirst.NavigateUrl = basicUrl + "?sortby=" + sortBy.ToString() + "&asc=" + isAsc.ToString() + "&page=" + 1.ToString() + "&rows=" + numOfRows.ToString();
        this.hlLast.NavigateUrl = basicUrl + "?sortby=" + sortBy.ToString() + "&asc=" + isAsc.ToString() + "&page=" + totalPageCount.ToString() + "&rows=" + numOfRows.ToString();
        this.hlPrev.NavigateUrl = basicUrl + "?sortby=" + sortBy.ToString() + "&asc=" + isAsc.ToString() + "&page=" + (currPage - 1).ToString() + "&rows=" + numOfRows.ToString();
        this.hlNext.NavigateUrl = basicUrl + "?sortby=" + sortBy.ToString() + "&asc=" + isAsc.ToString() + "&page=" + (currPage + 1).ToString() + "&rows=" + numOfRows.ToString();
        this.hlPrev.Visible = this.hlFirst.Visible = currPage > 1;
        this.hlNext.Visible = this.hlLast.Visible = currPage < totalPageCount;

        SortedList<int, int> pags = new SortedList<int, int>();
        pags.Add(currPage, currPage);
        int pl = currPage;
        int pr = currPage;

        for (int i = 0; i < 3; ++i)
        {
            if (--pl >= 1)
            {
                pags.Add(pl, pl);
            }
            else if (++pr <= totalPageCount)
            {
                pags.Add(pr, pr);
            }

            if (++pr <= totalPageCount)
            {
                pags.Add(pr, pr);
            }
            else if (--pl >= 1)
            {
                pags.Add(pl, pl);
            }
        }

        if (pags.First().Value > 1)
        {
            phPages.Controls.Add(new Literal() { Text = "... " });
        }
        foreach (KeyValuePair<int, int> kwp in pags)
        {
            if (kwp.Value == currPage)
            {
                phPages.Controls.Add(new Literal() { Text = kwp.Value.ToString() });
            }
            else
            {
                phPages.Controls.Add(new HyperLink()
                {
                    Text = kwp.Value.ToString(),
                    NavigateUrl = basicUrl + "?sortby=" + sortBy.ToString() + "&asc=" + isAsc.ToString() + "&page=" + kwp.Value.ToString() + "&rows=" + numOfRows.ToString()
                });
            }
            phPages.Controls.Add(new Literal() { Text = " " });
        }
        if (pags.Last().Value < totalPageCount)
        {
            phPages.Controls.Add(new Literal() { Text = " ..." });
        }
    }
Пример #17
0
 public void AddCollective(Collective collective)
 {
     collective.Id = Guid.NewGuid();
     _context.Collectives.Add(collective);
 }