/// <summary>
        /// Updates the existing database WorkArtist on the column name using the 
        /// XML document parsed using the tagName.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="columnName"></param>
        /// <param name="tagName"></param>
        public void UpdateData(System.Xml.Linq.XDocument doc, string columnName, string tagName)
        {
            IEnumerable<System.Xml.Linq.XElement> eventElements = doc.Descendants(Constants.Event.eventElement);
            foreach (System.Xml.Linq.XElement eventElement in eventElements)
            {
                var workElements = eventElement.Descendants(Constants.Work.workElement);
                foreach (var workElement in workElements)
                {
                    Work workItem = Work.GetWorkFromNode(workElement);

                    IEnumerable<System.Xml.Linq.XElement> workArtistElements = workElement.Descendants(Constants.WorkArtist.workArtistElement);
                    foreach (var workArtistElement in workArtistElements)
                    {
                        int artistID = 0;
                        int.TryParse((string)workArtistElement.GetXElement(Constants.WorkArtist.workArtistIDElement), out artistID);

                        WorkArtist updateWorkArtist = WorkArtist.GetWorkArtistByID(artistID, workItem.WorkID);

                        updateWorkArtist = WorkArtist.BuildWorkArtist(workArtistElement, artistID, updateWorkArtist);

                        if (updateWorkArtist == null) continue;

                        object newValue = (string)workArtistElement.GetXElement(tagName);

                        BsoArchiveEntities.UpdateObject(updateWorkArtist, newValue, columnName);

                        BsoArchiveEntities.UpdateObject(updateWorkArtist.Artist, newValue, columnName);

                        BsoArchiveEntities.UpdateObject(updateWorkArtist.Instrument, newValue, columnName);

                        BsoArchiveEntities.Current.Save();
                    }
                }
            }
        }
Example #2
0
 public void WriteFixedWidth(System.Xml.Linq.XElement CommandNode, DataTable Table, Stream outputStream)
 {
     StreamWriter Output = new StreamWriter(outputStream);
     int StartAt = CommandNode.Attribute("StartAt") != null ? int.Parse(CommandNode.Attribute("StartAt").Value) : 0;
     var positions = from c in CommandNode.Descendants("Position")
                     orderby int.Parse(c.Attribute("Start").Value) ascending
                     select new
                     {
                         Name = c.Attribute("Name").Value,
                         Start = int.Parse(c.Attribute("Start").Value) - StartAt,
                         Length = int.Parse(c.Attribute("Length").Value),
                         Justification = c.Attribute("Justification") != null ? c.Attribute("Justification").Value.ToLower() : "left"
                     };
     int lineLength = positions.Last().Start + positions.Last().Length;
     foreach (DataRow row in Table.Rows)
     {
         StringBuilder line = new StringBuilder(lineLength);
         foreach (var p in positions)
             line.Insert(p.Start,
               p.Justification == "left" ? (row.Field<string>(p.Name) ?? "").PadRight(p.Length, ' ')
                            : (row.Field<string>(p.Name) ?? "").PadLeft(p.Length, ' ')
               );
         Output.WriteLine(line.ToString());
     }
     Output.Flush();
 }
Example #3
0
    static void Compiler_WixSourceGenerated(System.Xml.Linq.XDocument document)
    {
        XElement aspxFileComponent = (from e in document.Descendants("File")
                                      where e.Attribute("Source").Value.EndsWith("Default.aspx")
                                      select e)
                                     .First()
                                     .Parent;

        string dirID = aspxFileComponent.Parent.Attribute("Id").Value;

        XNamespace ns = "http://schemas.microsoft.com/wix/IIsExtension";

        aspxFileComponent.Add(new XElement(ns + "WebVirtualDir",
                                  new XAttribute("Id", "MyWebApp"),
                                  new XAttribute("Alias", "MyWebApp"),
                                  new XAttribute("Directory", dirID),
                                  new XAttribute("WebSite", "DefaultWebSite"),
                                  new XElement(ns + "WebApplication",
                                      new XAttribute("Id", "TestWebApplication"),
                                      new XAttribute("Name", "Test"))));

        document.Root.Select("Product")
                     .Add(new XElement(ns + "WebSite",
                              new XAttribute("Id", "DefaultWebSite"),
                              new XAttribute("Description", "Default Web Site"),
                              new XAttribute("Directory", dirID),
                              new XElement(ns + "WebAddress",
                                   new XAttribute("Id", "AllUnassigned"),
                                    new XAttribute("Port", "80"))));
    }
Example #4
0
    public void RemoveFromXml(System.Xml.Linq.XElement option)
    {
      var result = option.Descendants(key).ToArray();

      if (result.Count() > 0)
      {
        foreach (var item in result)
        {
          item.Remove();
        }
      }
    }
Example #5
0
        /// <summary>
        /// Add workArtists from XElement workItem and add to Work object
        /// </summary>
        /// <param name="node"></param>
        /// <param name="work"></param>
        /// <remarks>
        /// Gets the WorkArtist objects information from the XElement node and 
        /// gets the WorkArtist object. Then adds it to Work's WorkArtists collection.
        /// </remarks>
        /// <returns></returns>
        public static Work GetWorkArtists(System.Xml.Linq.XElement node, Work work)
        {
            IEnumerable<System.Xml.Linq.XElement> workArtistElements = node.Descendants("workArtist");
            foreach (System.Xml.Linq.XElement workArtist in workArtistElements)
            {
                WorkArtist artist = WorkArtist.GetWorkArtistFromNode(workArtist);

                if (artist == null) continue;

                Work.AddWorkArtist(work, artist);
            }
            return work;
        }
        public void UpdateData(System.Xml.Linq.XDocument doc, string columnName, string tagName)
        {
            IEnumerable<System.Xml.Linq.XElement> eventElements = doc.Descendants(Constants.Event.eventElement);
            foreach (System.Xml.Linq.XElement element in eventElements)
            {
                Conductor updateConductor = Conductor.GetConductorFromNode(element);
                System.Xml.Linq.XElement conductorNode = element.Element(Constants.Conductor.conductorElement);
                if (conductorNode == null) continue;

                object newValue = conductorNode.GetXElement(tagName);
                BsoArchiveEntities.UpdateObject(updateConductor, newValue, columnName);
            }
        }
        /// <summary>
        /// Updates the existing database Instrument on the column name using the 
        /// XML document parsed using the tagName.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="columnName"></param>
        /// <param name="tagName"></param>
        public void UpdateData(System.Xml.Linq.XDocument doc, string columnName, string tagName)
        {
            IEnumerable<System.Xml.Linq.XElement> eventElements = doc.Descendants(Constants.Artist.artistElement);
            foreach (System.Xml.Linq.XElement element in eventElements)
            {
                Instrument updateInstrument = Instrument.GetInstrumentFromNode(element);

                if (updateInstrument == null) continue;

                object newValue = element.GetXElement(tagName);

                BsoArchiveEntities.UpdateObject(updateInstrument, newValue, columnName);
            }
        }
        public static UserLogonReq ParseToEntity(System.Xml.Linq.XElement requestElement)
        {
            UserLogonReq req = new UserLogonReq();

            IEnumerable<XElement> elements = requestElement.Descendants("parameter");

            /*
             <req>
  <head>
<msgType>UserLogon</msgType>
<msgPlace>100</msgPlace>
  </head>
  <body>
<parameter>
      <name>loginName</name>
      <value>13500000000</value>
</parameter>
<parameter>
      <name>userType</name>
      <value>1</value>
</parameter>
  </body>
</req>
             */

            foreach (XElement e in elements)
            {
                try
                {
                    string name = e.Element("name").Value;
                    string value = e.Element("value").Value;
                    MapToEntity(req, name, value);
                }
                catch
                {
                    continue;
                }
            }

            return req;

            //XmlSerializer ser = new XmlSerializer(typeof(UserLogonReq));
            //StringReader reader = new StringReader(requestElement.ToString());
            //object obj = ser.Deserialize(reader);
            //if (obj != null && obj is UserLogonReq)
            //    return obj as UserLogonReq;

            //return null;
        }
        /// <summary>
        /// Updates the existing database Type on the column name using the 
        /// XML document parsed using the tagName.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="columnName"></param>
        /// <param name="tagName"></param>
        public void UpdateData(System.Xml.Linq.XDocument doc, string columnName, string tagName)
        {
            IEnumerable<System.Xml.Linq.XElement> eventElements = doc.Descendants(Constants.Event.eventElement);
            foreach (System.Xml.Linq.XElement element in eventElements)
            {
                EventType updateType = EventType.GetEventTypeFromNode(element);

                if (updateType == null) continue;

                System.Xml.Linq.XElement typeNode = element.Element(Constants.EventType.typeElement);

                object newValue = typeNode.GetXElement(tagName);

                BsoArchiveEntities.UpdateObject(updateType, newValue, columnName);
            }
        }
        /// <summary>
        /// Updates the existing database Orchestra on the column name using the 
        /// XML document parsed using the tagName.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="columnName"></param>
        /// <param name="tagName"></param>
        public void UpdateData(System.Xml.Linq.XDocument doc, string columnName, string tagName)
        {
            IEnumerable<System.Xml.Linq.XElement> eventElements = doc.Descendants(Constants.Event.eventElement);
            foreach (System.Xml.Linq.XElement element in eventElements)
            {
                Orchestra updateOrchestra = Orchestra.GetOrchestraFromNode(element);

                if (updateOrchestra == null) continue;

                System.Xml.Linq.XElement orchestraNode = element.Element(Constants.Orchestra.orchestraElement);

                object newValue = orchestraNode.GetXElement(tagName);

                BsoArchiveEntities.UpdateObject(updateOrchestra, newValue, columnName);
            }
        }
Example #11
0
        /// <summary>
        /// Updates the existing database Project on the column name using the 
        /// XML document parsed using the tagName.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="columnName"></param>
        /// <param name="tagName"></param>
        public void UpdateData(System.Xml.Linq.XDocument doc, string columnName, string tagName)
        {
            IEnumerable<System.Xml.Linq.XElement> eventElements = doc.Descendants(Constants.Event.eventElement);
            foreach (System.Xml.Linq.XElement element in eventElements)
            {
                Project updateProject = Project.GetProjectFromNode(element);

                if (updateProject == null) continue;

                System.Xml.Linq.XElement projectNode = element.Element(Constants.Project.projectElement);

                object newValue = projectNode.GetXElement(tagName);

                BsoArchiveEntities.UpdateObject(updateProject, newValue, columnName);
            }
        }
Example #12
0
        /// <summary>
        /// Updates the existing database Season on the column name using the 
        /// XML document parsed using the tagName.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="columnName"></param>
        /// <param name="tagName"></param>
        public void UpdateData(System.Xml.Linq.XDocument doc, string columnName, string tagName)
        {
            IEnumerable<System.Xml.Linq.XElement> eventElements = doc.Descendants(Constants.Event.eventElement);
            foreach (System.Xml.Linq.XElement element in eventElements)
            {
                Season updateSeason = Season.GetSeasonFromNode(element);

                if (updateSeason == null) continue;

                System.Xml.Linq.XElement seasonNode = element.Element(Constants.Season.seasonElement);

                object newValue = seasonNode.GetXElement(tagName);

                BsoArchiveEntities.UpdateObject(updateSeason, newValue, columnName);
            }
        }
        private ICollection<Command> LoadCommandsFromUserNode(System.Xml.Linq.XElement userXmlNode)
        {
            LinkedList<Command> commands = new LinkedList<Command>();
            var commandsNodes = userXmlNode.Descendants("commands");

            foreach (var commandsNode in commandsNodes)
            {
                foreach (var commandNode in commandsNode.Descendants("command"))
                {
                    string name = (string)commandNode.Attribute("name");
                    string right = (string)commandNode.Attribute("right");
                    Command command = new Command(name, right);
                    commands.AddLast(command);
                }
            }

            return commands;
        }
        /// <summary>
        /// Update given column from xml given the tag name
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="columnName"></param>
        /// <param name="tagName"></param>
        /// <remarks>
        /// Read Composer information from OPAS XML and update the Composer Column based upon appropriate tagName
        /// </remarks>
        public void UpdateData(System.Xml.Linq.XDocument doc, string columnName, string tagName)
        {
            IEnumerable<System.Xml.Linq.XElement> eventElements = doc.Descendants(Constants.Event.eventElement);
            foreach (System.Xml.Linq.XElement element in eventElements)
            {
                IEnumerable<System.Xml.Linq.XElement> composerElements = element.Descendants(Constants.Work.workComposerElement);
                foreach (System.Xml.Linq.XElement composer in composerElements)
                {
                    Composer updateComposer = Composer.GetComposerFromNode(composer);

                    if (updateComposer == null) continue;

                    object newValue = composer.GetXElement(tagName);

                    BsoArchiveEntities.UpdateObject(updateComposer, newValue, columnName);
                }
            }
        }
        public override bool ParseDefinition(System.Xml.Linq.XElement element)
        {
            bool result =   base.ParseDefinition(element);

            // parsing of the namedValue
            var ListOfNamedValues = element.Descendants("NamedValue");
            foreach (var namedValueDefinition in ListOfNamedValues)
            {
                //create the NamedValue container
                int namedValuePosition = int.Parse(namedValueDefinition.Attribute("Position").Value);
                OptionContainer opsContainer = new OptionContainer();
                opsContainer.Name = namedValueDefinition.Attribute("Name").Value;
                opsContainer.Position = namedValuePosition;
                // check for the length, if its '*' then set the max int else parse it
                if (namedValueDefinition.Attribute("Length").Value == "*")
                {
                    opsContainer.Length = int.MaxValue;
                }
                else
                {
                    opsContainer.Length = int.Parse(namedValueDefinition.Attribute("Length").Value);

                }
                //fill up the created container
                var listOfOptions = namedValueDefinition.Descendants("Options");
                foreach (var option in listOfOptions)
                {
                    opsContainer.insertOption(option.Value, option.Attribute("Name").Value);
                }

                // add the container to array of options
                ArrayOfOptions.Add(opsContainer.Position, opsContainer);

            }

            return result;
        }
Example #16
0
        private void SetupPluginOptions(Plugins.INotifier plugin, System.Xml.Linq.XElement settingElement)
        {
            var options = plugin.GetAllAvailableOptions();

            if (settingElement != null)
            {
                foreach (var optionElement in (from configuredOption in settingElement.Descendants("Options") select configuredOption))
                {
                    var numericsElement = optionElement.Element("Numerics");
                    var numerics = new List<int>();
                    // TODO: loop through and set up all numerics

                    var gesturesElement = optionElement.Element("Gestures");
                    var gestures = new List<int>();
                    // TODO: loop through and set up all gestures

                    var active = Convert.ToBoolean(optionElement.Attribute("Active").Value);

                    int index = options.FindIndex(x => x.OptionId == Convert.ToInt32(optionElement.Attribute("Id").Value));

                    var newOption = new Objects.Option(Convert.ToInt32(optionElement.Attribute("Id").Value), gestures, numerics, active);
                    if (index == -1)
                    {
                        options.Add(newOption);
                    }
                    else
                    {
                        options[index] = newOption;
                    }
                }
            }

            pluginOptions[plugin.NotificationApplication] = options;
        }
Example #17
0
        public static string GetSeriesFromNode(System.Xml.Linq.XElement node)
        {
            var seriesNodes = node.Descendants(Constants.Series.seriesElement);

            StringBuilder seriesNames = new StringBuilder();
            foreach (var seriesNode in seriesNodes)
            {
                string seriesName = (string)seriesNode.Element(Constants.Series.seriesName);
                if (!string.IsNullOrEmpty(seriesName))
                    seriesNames.Append(string.Format("{0}; ", seriesName));
            }

            if(seriesNames.Length > 2)
                seriesNames = seriesNames.Remove(seriesNames.Length-2, 2);

            return seriesNames.ToString();
        }
        private void SetupPluginOptions(Plugins.INotifier plugin, System.Xml.Linq.XElement settingElement)
        {
            var options = plugin.GetAllAvailableOptions();

            if (settingElement != null)
            {
                foreach (var optionElement in (from configuredOption in settingElement.Descendants("Option") select configuredOption))
                {
                    var numericsElement = optionElement.Element("Numerics");
                    var numerics = new List<int>();

                    if (numericsElement != null)
                    {
                        foreach (var numericElement in (from numeric in numericsElement.Descendants("Numeric") select numeric))
                        {
                            numerics.Add(Convert.ToInt32(numericElement.Value));
                        }
                    }

                    var gesturesElement = optionElement.Element("Gestures");
                    var gestures = new List<int>();

                    if (gesturesElement != null)
                    {
                        foreach (var gestureElement in (from gesture in gesturesElement.Descendants("Gesture") select gesture))
                        {
                            gestures.Add(Convert.ToInt32(gestureElement.Value));
                        }
                    }

                    var active = Convert.ToBoolean(optionElement.Attribute("Active").Value);

                    int index = options.FindIndex(x => x.OptionId == Convert.ToInt32(optionElement.Attribute("Id").Value));

                    var newOption = new Objects.Option(Convert.ToInt32(optionElement.Attribute("Id").Value), gestures, numerics, active);

                    if (index == -1)
                    {
                        options.Add(newOption);
                    }
                    else
                    {
                        options[index] = newOption;
                    }
                }
            }

            plugin.ResetLastAccessed(options, PollingInterval);
            pluginOptions[plugin.NotificationApplication] = options;
        }
		public void Descendants_NestedObjects_ReturnsAllSubsequences()
		{
			var input = new[]
		    {
		        ModelGrammar.TokenObjectBeginUnnamed,
					ModelGrammar.TokenProperty("One"),
					ModelGrammar.TokenNull,

					ModelGrammar.TokenProperty("Two"),
					ModelGrammar.TokenArrayBeginUnnamed,
						ModelGrammar.TokenTrue,
						ModelGrammar.TokenPrimitive("2-B"),
						ModelGrammar.TokenPrimitive(23),
					ModelGrammar.TokenArrayEnd,

					ModelGrammar.TokenProperty("Three"),
					ModelGrammar.TokenObjectBeginUnnamed,
						ModelGrammar.TokenProperty("A"),
						ModelGrammar.TokenPrimitive("3-A"),
						ModelGrammar.TokenProperty("B"),
						ModelGrammar.TokenPrimitive(32),
						ModelGrammar.TokenProperty("C"),
						ModelGrammar.TokenPrimitive("3-C"),
					ModelGrammar.TokenObjectEnd,

					ModelGrammar.TokenProperty("Four"),
					ModelGrammar.TokenPrimitive(4),
		        ModelGrammar.TokenObjectEnd
		    };

			var expected = new[]
			{
				new[]
				{
					ModelGrammar.TokenNull
				},
				new[]
				{
					ModelGrammar.TokenArrayBeginUnnamed,
						ModelGrammar.TokenTrue,
						ModelGrammar.TokenPrimitive("2-B"),
						ModelGrammar.TokenPrimitive(23),
					ModelGrammar.TokenArrayEnd
				},
				new[]
				{
					ModelGrammar.TokenTrue
				},
				new[]
				{
					ModelGrammar.TokenPrimitive("2-B")
				},
				new[]
				{
					ModelGrammar.TokenPrimitive(23)
				},
				new[]
				{
					ModelGrammar.TokenObjectBeginUnnamed,
						ModelGrammar.TokenProperty("A"),
						ModelGrammar.TokenPrimitive("3-A"),
						ModelGrammar.TokenProperty("B"),
						ModelGrammar.TokenPrimitive(32),
						ModelGrammar.TokenProperty("C"),
						ModelGrammar.TokenPrimitive("3-C"),
					ModelGrammar.TokenObjectEnd
				},
				new[]
				{
					ModelGrammar.TokenPrimitive("3-A")
				},
				new[]
				{
					ModelGrammar.TokenPrimitive(32)
				},
				new[]
				{
					ModelGrammar.TokenPrimitive("3-C")
				},
				new[]
				{
					ModelGrammar.TokenPrimitive(4),
				}
			};

			// select all descendants
			var actual = input.Descendants().ToArray();

			Assert.Equal(expected, actual, false);
		}
		public void Descendants_NestedObjectsFindDescendantsWithProperty_ReturnsMatchingSubsequences()
		{
			var input = new[]
		    {
		        ModelGrammar.TokenObjectBeginUnnamed,
					ModelGrammar.TokenProperty("One"),
					ModelGrammar.TokenNull,

					ModelGrammar.TokenProperty("Two"),
					ModelGrammar.TokenArrayBeginUnnamed,
						ModelGrammar.TokenTrue,
						ModelGrammar.TokenPrimitive("2-B"),
						ModelGrammar.TokenPrimitive(23),
					ModelGrammar.TokenArrayEnd,

					ModelGrammar.TokenProperty("Three"),
					ModelGrammar.TokenObjectBeginUnnamed,
						ModelGrammar.TokenProperty("A"),
						ModelGrammar.TokenPrimitive("3-A"),
						ModelGrammar.TokenProperty("B"),
						ModelGrammar.TokenPrimitive(32),
						ModelGrammar.TokenProperty("C"),
						ModelGrammar.TokenPrimitive("3-C"),
					ModelGrammar.TokenObjectEnd,

					ModelGrammar.TokenProperty("Four"),
					ModelGrammar.TokenPrimitive(4),
		        ModelGrammar.TokenObjectEnd
		    };

			var expected = new[]
			{
				new[]
				{
					ModelGrammar.TokenObjectBeginUnnamed,
						ModelGrammar.TokenProperty("A"),
						ModelGrammar.TokenPrimitive("3-A"),
						ModelGrammar.TokenProperty("B"),
						ModelGrammar.TokenPrimitive(32),
						ModelGrammar.TokenProperty("C"),
						ModelGrammar.TokenPrimitive("3-C"),
					ModelGrammar.TokenObjectEnd
				}
			};

			// select all descendants with property named "B"
			var actual = input.Descendants().Where(child => child.HasProperty(name => name.LocalName == "B")).ToArray();

			Assert.Equal(expected, actual, false);
		}
Example #21
0
        public Event(DateTime ClockStart, DateTime ClockEnd, int ClockRunTime, System.Xml.Linq.XDocument XMLEvents, ref CrashHandler Crash)
        {
            ch = Crash;
            events = new Dictionary<string, List<EventItem>>();
            clock = new PartyClock(ClockStart, ClockEnd, ClockRunTime);
            Util.ShowClock = true;
            sound = new Sound(true);
            text = new Text2D();
            chess = new Chess();
            sf = new Starfield(150);

            intro = new Intro(ref sound, ref text);
            outro = new Outro(ref sound);

            advent = new Advent(ref sound);
            birthday = new Birthday(ref sound, ref text, ref chess);
            xmas = new Christmas(ref sound);
            smurf = new Datasmurf(ref sound, ref text); // random
            dif = new Dif(ref chess, ref sound); // random
            fbk = new Fbk(ref sound); // random
            hw = new Halloween(ref chess, ref sound, 25);
            lucia = new Lucia(ref chess, ref sound);
            newyear = new NewYear();
            richard = new RMS(ref sound, ref text); // random
            scroller = new Scroller(ref chess, ref sf, ref text); // random
            semla = new Semla();
            sune = new SuneAnimation(ref sound, ref text);
            tl = new TurboLogo(ref sound, ref chess, (OpenGL.Util.SpringOrFall.Equals("Spring")? true:false)/*((ClockStart.Month >= 1 && ClockStart.Month <= 8)? false:true)*/ ); // vilken termin är det? jan till början av augusti VT, resten HT... random
            valentine = new Valentine(ref sound);
            wl = new WinLinux(ref chess); //random
            creators = new Self(ref sound); // random
            bb = new BB(ref sound); // random
            GM = new GummiBears(ref sound);
            NDay = new National(ref chess, ref sound);
            easter = new Easter(ref sound);
            hajk = new Hajk(ref sound);
            mid = new Midsummer(ref sound);
            vaf = new Vaffla();
            wp = new Walpurgis();
            crayfish = new CrayFish();

            ts = new TeknatStyle(ref chess, ref sound, ref text);
            m = new Matrix(ref text);
            q = new Quiz(ref text, false, ref sound);
            talepsin = new Talespin(ref sound);
            cd = new ChipAndDale(ref sound, ref chess);
            nerd = new Nerdy(ref chess, ref sound);
            trex = new Trex(ref sound);
            sailormoon = new Sailormoon(ref sound,ref chess);
            gb = new GhostBusters(ref sound);
            zelda = new Zelda(ref sound, ref chess);
            tardis = new Tardis(ref sound);
            fuck = new Fuck(ref sound, ref chess);

            silverFang = new SilverFang(ref sound);
            mt = new MoraT(ref sound);

            swine = new Swine(ref chess, ref text);
            tjall = new Tjall(ref chess, ref text);

            ronja = new Ronja(ref sound);
            emil = new Emil(ref sound);
            djungelboken = new Djungelboken(ref sound);
            fabbe = new Fabbe(ref sound);
            drink = new Drink(ref sound);
            frozen = new Frozen(ref sound);

            eventCurrent = null; // event item for events to be triggerd in clock_NewDate
            //randomEvent = new List<string>(new string[] { "starfield", "SuneAnimation", "TurboLogo", "Datasmurf", "WinLinux", "Scroller", "BB", "GummiBears", "TeknatStyle", "Matrix"});
            randomEvent = new List<string>(new string[] { "starfield", "Nerdy", "Talespin", "Sailormoon", "GhostBusters", "Zelda", "Tardis", "Fuck", "SilverFang", "MoraT" });
            //new stuff
             List<UtilXML.EventData> ed = UtilXML.Loadeffectdata();

            // TODO: Make a clean list with all events allowed to be used implement so that it is actaully usable instead of a switch at the bottom of this file.
            Dictionary<string, Effect> effects = new Dictionary<string, Effect>()
            {
                {"SuneAnimation", new Effect(sune, ed.Find(e => e.Name == "SuneAnimation"))},
                {"Dif",new Effect(dif, ed.Find(e => e.Name == "Dif"))},
                {"Fbk",new Effect(fbk, ed.Find(e => e.Name == "Fbk"))},
                {"TurboLogo",new Effect(tl, ed.Find(e => e.Name == "TurboLogo"))},
                {"Datasmurf", new Effect(smurf, ed.Find(e => e.Name == "Datasmurf"))},
                {"RMS",new Effect(richard, ed.Find(e => e.Name == "RMS"))},
                {"WinLinux",new Effect(wl, ed.Find(e => e.Name == "WinLinux"))},
                {"Scroller",new Effect(scroller, ed.Find(e => e.Name == "Scroller"))},
                {"Self",new Effect(creators, ed.Find(e => e.Name == "Self"))},
                {"BB",new Effect(bb, ed.Find(e => e.Name == "BB"))},
                {"GummiBears",new Effect(GM, ed.Find(e => e.Name == "GummiBears"))},
                {"Hajk",new Effect(hajk, ed.Find(e => e.Name == "Hajk"))},
                {"TeknatStyle",new Effect(ts, ed.Find(e => e.Name == "TeknatStyle"))},
                {"Matrix",new Effect(m, ed.Find(e => e.Name == "Matrix"))},
                {"Quiz",new Effect(q, ed.Find(e => e.Name == "Quiz"))},
                {"Talespin",new Effect(talepsin, ed.Find(e => e.Name == "Talespin"))},
                {"ChipDale",new Effect(cd, ed.Find(e => e.Name == "ChipDale"))},
                {"Nerdy",new Effect(nerd, ed.Find(e => e.Name == "Nerdy"))},
              /*  {"Trex",new Effect(trex, ed.Find(e => e.Name == "Trex"))},*/
                {"Sailormoon",new Effect(sailormoon, ed.Find(e => e.Name == "Sailormoon"))},
                {"GhostBusters",new Effect(gb, ed.Find(e => e.Name == "GhostBusters"))},
                {"Zelda",new Effect(zelda, ed.Find(e => e.Name == "Zelda"))},
                {"Tardis",new Effect(tardis, ed.Find(e => e.Name == "Tardis"))},
                {"Fuck",new Effect(fuck, ed.Find(e => e.Name == "Fuck"))},
                {"SilverFang",new Effect(silverFang, ed.Find(e => e.Name == "SilverFang"))},
                {"MoraT",new Effect(mt, ed.Find(e => e.Name == "MoraT"))},
                {"Ronja",new Effect(ronja, ed.Find(e => e.Name == "Ronja"))},
                {"Emil",new Effect(emil, ed.Find(e => e.Name == "Emil"))},
                {"Djungelboken",new Effect(djungelboken, ed.Find(e => e.Name == "Djungelboken"))},
                {"Fabbe",new Effect(fabbe, ed.Find(e => e.Name == "Fabbe"))},
                {"Drink",new Effect(drink, ed.Find(e => e.Name == "Drink"))},
                {"Frozen",new Effect(drink, ed.Find(e => e.Name == "Frozen"))}
            };

            runEffectInMonth = new Dictionary<string, List<objdata>>();

            string[] months = Util.monthlist();
            int counter;
            foreach (KeyValuePair<string, Effect> pair in effects)
            {
                counter = 0;
                foreach (bool b in pair.Value.RunAllowedlist)
                {
                    if (b == true)
                    {
                        if (!runEffectInMonth.ContainsKey(months[counter]))
                        {
                            runEffectInMonth.Add(months[counter], new List<objdata>());
                        }

                        runEffectInMonth[months[counter]].Add(new objdata(pair.Key, pair.Value.Vetolist[counter], pair.Value.Priolist[counter], pair.Value.Runslist[counter]));
                    }
                    counter++;
                }
            }

            clock.NewDate += clock_NewDate; // Event listener

            if (ch.CrashDialogResult == System.Windows.Forms.DialogResult.Yes)
            {
                clock.clock = ch.CrashClock;
            }

            string name, date, type;
            // Event dates setup
            foreach (var item in XMLEvents.Descendants("event"))
            {
                name = item.Element("name").Value;
                date = item.Element("date").Value;
                type = item.Element("type").Value.ToLower();
                EventItem ei = new EventItem(name, type, date);
                if (!events.ContainsKey(date))
                {
                    List<EventItem> list = new List<EventItem>(); // seems most bad in my eyes...
                    events.Add(date, list);
                }

                for (int i = 0; i < events[date].Count; i++)
                {
                    EventItem e = events[date][i];
                    if ("birthday".Equals(e.Type) && "birthday".Equals(ei.Type))
                    {
                        e.Name += "\n\n" + ei.Name;
                        events[date][i] = e;
                    }
                }
                events[date].Add(ei);
                name = date = type = string.Empty;
            }

            // this needs to be fixed nicer...
            if (events.ContainsKey(ClockEnd.ToShortDateString()))
            {
                events[ClockEnd.ToShortDateString()].Clear(); // force this to be top..
                events[ClockEnd.ToShortDateString()].Add( new EventItem("outro", "outro", ClockEnd.ToShortDateString()) );
            }
            else
            {
                events.Add(ClockEnd.ToShortDateString(), new List<EventItem>() { new EventItem("outro", "outro", ClockEnd.ToShortDateString()) });
            }

            // Random effects on dates with no effects and check against new list of allowed things for them...
            DateTime dt = ClockStart;
            bool star = (Util.Rnd.Next(0, 1000) < 500 ? true:false); // make this random at the start too?
            int num = 0;

            while (dt <= ClockEnd)
            {
                date = dt.ToShortDateString();
                if (!events.ContainsKey(date))
                {
                    EventItem ei;

                    if (num == 0 || num == 1)
                    {
                        ei = new EventItem("starfield", "random", date);
                    }
                    else
                    {
                        //ei = new EventItem(randomEvent[Util.Rnd.Next(1, randomEvent.Count)], "random", date);

                        string month = "";
                        if (dt != null)
                            month = dt.Month.ToString();

                        switch (month)
                        {
                            case "1": month = "jan"; break;
                            case "2": month = "feb"; break;
                            case "3": month = "mar"; break;
                            case "4": month = "apr"; break;
                            case "5": month = "maj"; break;
                            case "6": month = "jun"; break;
                            case "7": month = "jul"; break;
                            case "8": month = "aug"; break;
                            case "9": month = "sep"; break;
                            case "10": month = "okt"; break;
                            case "11": month = "nov"; break;
                            case "12": month = "dec"; break;
                        }//switch

                        if (runEffectInMonth.ContainsKey(month))
                        {
                            List<objdata> mobj = runEffectInMonth[month];

                            List<objdata> vetolist = new List<objdata>();
                            List<objdata> novetolist = new List<objdata>();

                            foreach (objdata n in mobj)
                            {

                                if ("Quiz".Equals(n.Name) && eventnum == 4)
                                {
                                    n.vetoAgain();
                                    eventnum = 0;
                                }

                                if (n.Veto == true)
                                {
                                    if (n.Runs > 0)
                                        vetolist.Add(n);
                                }
                                else
                                {
                                    if (n.Runs > 0)
                                        novetolist.Add(n);
                                }
                            }

                            vetolist.Sort();
                            novetolist.Sort();

                            if (vetolist.Count > 0)
                            {
                                ei = new EventItem(vetolist[0].Name, "random", date);
                                vetolist[0].noMoreVeto();
                            }
                            else if (novetolist.Count > 0)
                            {
                                ei = new EventItem(novetolist[0].Name, "random", date);
                                novetolist[0].decRuns();
                                if (eventnum < 4)
                                    eventnum++;
                            }
                            else
                            {
                                ei = new EventItem(randomEvent[Util.Rnd.Next(1, randomEvent.Count)], "random", date);
                            }
                        }
                        else
                        {
                            ei = new EventItem(randomEvent[Util.Rnd.Next(1, randomEvent.Count)], "random", date);
                        }
                    }

                    num++;
                    if (num == 3)
                    {
                        num = 0;
                    }
                    ei = new EventItem("Self", "random", date); // this is for debuging new events
                    events.Add(date, new List<EventItem>());
                    events[date].Add(ei);
                }

                dt = dt.AddDays(1);
                date = string.Empty;
            }
        }
Example #22
0
        /// <summary>
        /// Updates the existing database Work on the column name using the 
        /// XML document parsed using the tagName.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="columnName"></param>
        /// <param name="tagName"></param>
        public void UpdateData(System.Xml.Linq.XDocument doc, string columnName, string tagName)
        {
            IEnumerable<System.Xml.Linq.XElement> eventElements = doc.Descendants(Constants.Event.eventElement);
            foreach (System.Xml.Linq.XElement element in eventElements)
            {
                //System.Xml.Linq.XElement workNode = element.Element(Constants.Work.workElement);
                var workNodes = element.Descendants(Constants.Work.workElement);
                foreach (var workNode in workNodes)
                {
                    Work updateWork = Work.GetWorkFromNode(workNode);

                    if (updateWork == null) continue;

                    object newValue = (string)workNode.GetXElement(tagName);

                    BsoArchiveEntities.UpdateObject(updateWork, newValue, columnName);
                }
            }
        }