Ejemplo n.º 1
0
        /// <summary>
        /// Converts the net more or less reliable to a string which can be read as a *.dot-File by Graphviz (http://www.graphviz.org/)
        /// </summary>
        /// <returns>Returns said string, which you have to put into a file.</returns>
        public String ConvertToDot()
        {
            StringBuilder content = new StringBuilder();

            content.Append("digraph TC {\n");
            content.Append("node[shape=circle];\nrankdir=LR\n");
            // draw all places with their respective labels and amount of tokens (p0 [label="A (1)"])
            for (int index = 0; index <= Places.Count() - 1; index++)
            {
                content.Append("p" + index + " [label=\"" + Places[index].Name + " (" + Places[index].Token + ")\"]\n");
            }
            content.Append("node[shape=rect];\n");
            // draw all transitions with their respective labels (t0 [label="AtoB"])
            for (int index = 0; index <= Transitions.Count() - 1; index++)
            {
                content.Append("t" + index + " [label=\"" + Transitions[index].Name + "\"]\n");
                // and for each transition draw the incoming (p0 -> t0)...
                foreach (Place incomingPlace in Transitions[index].IncomingPlaces)
                {
                    content.Append("p" + Places.IndexOf(incomingPlace) + " -> " + "t" + index + "\n");
                }
                // ... and outgoing (t0 -> p1) connections
                foreach (Place outgoingPlace in Transitions[index].OutgoingPlaces)
                {
                    content.Append("t" + index + " -> " + "p" + Places.IndexOf(outgoingPlace) + "\n");
                }
            }
            content.Append("}");

            return(content.ToString());
        }
Ejemplo n.º 2
0
        private Contact CreateContact(int number)
        {
            var female          = _rnd.Next(2) == 1;
            int middleNameCount = _rnd.Next(5);

            if (middleNameCount > 2)
            {
                middleNameCount = 0;
            }

            var contact = new Contact(Guid.NewGuid());

            contact.Language.Value = SelectLanguage();
            contact.LastName.Value = LastNames.Skip(_rnd.Next(LastNames.Count())).First();

            if (female)
            {
                contact.FirstName.Value = FemaleFirstNames.Skip(_rnd.Next(FemaleFirstNames.Count())).First();
                var middleNames = new List <string>();
                for (int i = 0; i < middleNameCount; i++)
                {
                    middleNames.Add(FemaleFirstNames.Skip(_rnd.Next(FemaleFirstNames.Count())).First());
                }
                contact.MiddleNames.Value = string.Join(" ", middleNames);
            }
            else
            {
                contact.FirstName.Value = MaleFirstNames.Skip(_rnd.Next(MaleFirstNames.Count())).First();
                var middleNames = new List <string>();
                for (int i = 0; i < middleNameCount; i++)
                {
                    middleNames.Add(MaleFirstNames.Skip(_rnd.Next(MaleFirstNames.Count())).First());
                }
                contact.MiddleNames.Value = string.Join(" ", middleNames);
            }

            contact.BirthDate.Value    = new DateTime(1960, 1, 1).AddDays(_rnd.NextDouble() * 40d * 365d);
            contact.Organization.Value = "New Organization";

            var homeMail = new ServiceAddress(Guid.NewGuid());

            homeMail.Service.Value    = ServiceType.EMail;
            homeMail.Category.Value   = AddressCategory.Home;
            homeMail.Precedence.Value = contact.ServiceAddresses.MaxOrDefault(a => a.Precedence.Value, 0) + 1;
            homeMail.Address.Value    =
                "stefan+" +
                contact.FirstName.Value.ToLowerInvariant() + "." +
                contact.LastName.Value.ToLowerInvariant() + "@savvy.ch";
            homeMail.Contact.Value = contact;

            if (_rnd.Next(3) != 0)
            {
                var mobile = new ServiceAddress(Guid.NewGuid());
                mobile.Service.Value    = ServiceType.Phone;
                mobile.Category.Value   = AddressCategory.Mobile;
                mobile.Precedence.Value = contact.ServiceAddresses.MaxOrDefault(a => a.Precedence.Value, 0) + 1;
                mobile.Address.Value    =
                    MobilePrefix.Skip(_rnd.Next(MobilePrefix.Count())).First() +
                    ComposeNumber();
                mobile.Contact.Value = contact;
            }

            if (_rnd.Next(3) == 0)
            {
                var phone = new ServiceAddress(Guid.NewGuid());
                phone.Service.Value    = ServiceType.Phone;
                phone.Category.Value   = AddressCategory.Mobile;
                phone.Precedence.Value = contact.ServiceAddresses.MaxOrDefault(a => a.Precedence.Value, 0) + 1;
                phone.Address.Value    =
                    PhonePrefix.Skip(_rnd.Next(PhonePrefix.Count())).First() +
                    ComposeNumber();
                phone.Contact.Value = contact;
            }

            var place         = Places.Skip(_rnd.Next(Places.Count())).First();
            var postalAddress = new PostalAddress(Guid.NewGuid());

            postalAddress.Country.Value    = GetCountry("Schweiz");
            postalAddress.State.Value      = GetState(place.Item3);
            postalAddress.PostalCode.Value = place.Item1.ToString();
            postalAddress.Place.Value      = place.Item2;
            postalAddress.Street.Value     =
                Streets.Skip(_rnd.Next(Streets.Count())).First() +
                " " + (_rnd.Next(23) + 1).ToString();
            postalAddress.Precedence.Value = contact.PostalAddresses.MaxOrDefault(a => a.Precedence.Value, 0) + 1;
            postalAddress.Contact.Value    = contact;

            var subscription = new Subscription(Guid.NewGuid());

            subscription.Contact.Value   = contact;
            subscription.Feed.Value      = GetFeed("Piratenpartei Zentralschweiz", null);
            subscription.StartDate.Value = new DateTime(2018, 12, 18);

            switch (_rnd.Next(4))
            {
            case 0:
                var subscription2 = new Subscription(Guid.NewGuid());
                subscription2.Contact.Value   = contact;
                subscription2.Feed.Value      = GetFeed("Piratenpartei Zug", "Piratenpartei Zentralschweiz");
                subscription2.StartDate.Value = new DateTime(2018, 12, 18);
                break;

            case 1:
                var subscription3 = new Subscription(Guid.NewGuid());
                subscription3.Contact.Value   = contact;
                subscription3.Feed.Value      = GetFeed("Piratenpartei Luzern", "Piratenpartei Zentralschweiz");
                subscription3.StartDate.Value = new DateTime(2018, 12, 18);
                break;
            }

            var tagAssignment1 = new TagAssignment(Guid.NewGuid());

            tagAssignment1.Tag.Value     = GetTag("Partizipationsmails", TagUsage.Mailing, TagMode.Default | TagMode.Manual);
            tagAssignment1.Contact.Value = contact;

            if (_rnd.Next(5) < 4)
            {
                var tagAssignment2 = new TagAssignment(Guid.NewGuid());
                tagAssignment2.Tag.Value     = GetTag("Verantstaltungsmails", TagUsage.Mailing, TagMode.Default | TagMode.Manual | TagMode.Self);
                tagAssignment2.Contact.Value = contact;
            }

            if (_rnd.Next(5) < 4)
            {
                var tagAssignment3 = new TagAssignment(Guid.NewGuid());
                tagAssignment3.Tag.Value     = GetTag("Aktionsmails", TagUsage.Mailing, TagMode.Default | TagMode.Manual | TagMode.Self);
                tagAssignment3.Contact.Value = contact;
            }

            if (_rnd.Next(5) < 3)
            {
                var tagAssignment4 = new TagAssignment(Guid.NewGuid());
                tagAssignment4.Tag.Value     = GetTag("Aktivist", TagUsage.None, TagMode.Manual);
                tagAssignment4.Contact.Value = contact;
            }

            _db.Save(contact);

            return(contact);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts the net more or less reliable to a string which can be read as a *.pnml by (http://woped.dhbw-karlsruhe.de/woped/)
        /// </summary>
        /// /// <autor>Naby M. Sow</autor>
        /// <returns>Returns said string, which you have to put into a file.</returns>
        public String ConvertToPNML()
        {
            const string cID = "cId-0";

            StringBuilder content = new StringBuilder();

            content.Append("<pnml xmlns=\"http://www.pnml.org/version-2009/grammar/pnml\">\n");
            content.Append("  <net id=\"" + cID + "\" type=\"http://www.pnml.org/version-2009/grammar/ptnet\">\n");
            content.Append("    <page id=\"page0\">\n");

            for (int index = 0; index < Places.Count(); index++)
            {
                string placeId   = "p" + index;
                string placeName = Places[index].Name;
                int    positionX = Places[index].PositionX;
                int    positionY = Places[index].PositionY;

                content.Append("  <place id=\"" + placeId + "\">\n");
                content.Append("    <name>\n");
                content.Append("      <text>" + placeName + "</text>\n");
                content.Append("      <graphics>\n");
                content.Append("         <offset x=\"" + (positionX + 6) + "\" y=\"" + (positionY + 6) + " \"/>\n");
                content.Append("      </graphics>\n");
                content.Append("    </name>\n");
                content.Append("    <graphics>\n");
                content.Append("      <position x=\"" + positionX + "\" y=\"" + positionY + "\"/>\n");
                content.Append("    </graphics>\n");
                content.Append("   </place>\n");
            }

            for (int index = 0; index < Transitions.Count(); index++)
            {
                string transitionId   = "t" + index;
                string transitionName = Transitions[index].Name;
                int    positionX      = Transitions[index].PositionX;
                int    positionY      = Transitions[index].PositionY;

                content.Append("  <transition id=\"" + transitionId + "\">\n");
                content.Append("    <name>\n");
                content.Append("      <text>" + transitionName + "</text>\n");
                content.Append("      <graphics>\n");
                content.Append("         <offset x=\"" + (positionX + 9) + "\" y=\"" + (positionY + 9) + "\"/>\n");
                content.Append("      </graphics>\n");
                content.Append("    </name>\n");
                content.Append("    <graphics>\n");
                content.Append("      <position x=\"" + positionX + "\" y=\"" + positionY + "\"/>\n");
                content.Append("    </graphics>\n");
                content.Append("  </transition>\n");
            }

            int sourcePlaceId = 0;

            foreach (Place sourcePlace in Places)
            {
                int targetTransitionId = 0;
                foreach (Transition targetTransition in sourcePlace.OutgoingTransitions)
                {
                    string arcId     = "p2t" + ((sourcePlaceId + 1) + (sourcePlaceId + 1) * (targetTransitionId + 1)); //calculation for unique id
                    string arcSource = GetPlaceID(sourcePlace);
                    string arcTarget = GetTransitionID(targetTransition);
                    content.Append("  <arc id=\"" + arcId + "\" " + "source=\"" + arcSource + "\" " + "target=\"" + arcTarget + "\">\n");
                    content.Append("    <graphics/>\n");
                    content.Append("  </arc>\n");

                    targetTransitionId++;
                }
                sourcePlaceId++;
            }

            int sourceTransitionId = 0;

            foreach (Transition sourceTransition in Transitions)
            {
                int targetPlaceId = 0;
                foreach (Place targetPlace in sourceTransition.OutgoingPlaces)
                {
                    string arcId     = "t2p" + ((sourceTransitionId + 1) + (sourceTransitionId + 1) * (targetPlaceId + 1)); //calculation for unique id
                    string arcSource = GetTransitionID(sourceTransition);
                    string arcTarget = GetPlaceID(targetPlace);
                    content.Append("  <arc id=\"" + arcId + "\" " + "source=\"" + arcSource + "\" " + "target=\"" + arcTarget + "\">\n");
                    content.Append("    <graphics/>\n");
                    content.Append("  </arc>\n");

                    targetPlaceId++;
                }

                sourceTransitionId++;
            }

            content.Append("    </page>\n");
            content.Append("    <name>\n");
            content.Append("      <text></text>\n");
            content.Append("    </name>\n");
            content.Append("  </net>\n");
            content.Append("</pnml>\n");

            return(content.ToString());
        }