Esempio n. 1
0
        public string Visit(GenericElement genericElement)
        {
            var genericText = genericElement.ToString();

            switch (genericElement.Tag)
            {
            case TagType.Split:
                if (genericText == "<Split(<Highlight>ObjectParameter(1)</Highlight>, ,1)/>")
                {
                    return("<span class=\"highlight\">Forename</span>");
                }
                else if (genericText == "<Split(<Highlight>ObjectParameter(1)</Highlight>, ,2)/>")
                {
                    return("<span class=\"highlight\">Surname</span>");
                }
                else
                {
                    throw new NotImplementedException();
                }

            case TagType.Highlight:
                var content = genericElement.Content.Accept(this);
                return("<span class=\"highlight\">" + content + "</span>");

            case TagType.Sheet:
                if (genericText == "<Sheet(Addon,9,0)/>")
                {
                    return("<img class=\"hq-icon small\" src=\"images/item/hq.png\">");
                }
                else if (genericText.Contains("GCRank"))
                {
                    return("[GC Rank]");
                }
                else if (genericText == "<Sheet(Race,PlayerParameter(71),0)/>")
                {
                    return("[Race]");
                }
                else if (genericText == "<Sheet(ClassJob,PlayerParameter(68),0)/>")
                {
                    return("[Job]");
                }
                else if (genericText == "<Sheet(Town,PlayerParameter(70),0)/>")
                {
                    return("[Starting City]");
                }
                else if (genericText == "<Sheet(ContentFinderCondition,IntegerParameter(1),18)/>")
                {
                    return("[Item Level]");
                }
                else if (genericText == "<Sheet(ContentFinderCondition,IntegerParameter(2),32)/>")
                {
                    return("[Instance]");
                }
                else if (genericText == "<Sheet(ContentFinderCondition,IntegerParameter(2),34)/>")
                {
                    return("[Instance]");
                }
                else if (genericText.StartsWith("<Sheet(") && !genericText.Contains("PlayerParameter("))
                {
                    var genericElementArgs = genericElement.Arguments.ToArray();
                    var sheetName          = genericElementArgs[0].Accept(this);
                    var sheetKeyRaw        = genericElementArgs[1].Accept(this);
                    if (int.TryParse(sheetKeyRaw.Trim(), out var sheetKey))
                    {
                        var sheet    = DatabaseBuilder.Instance.Realm.GameData.GetSheet(sheetName);
                        var row      = sheet[sheetKey];
                        var rowIndex = int.Parse(genericElementArgs[2].Accept(this).Trim());
                        return(row[rowIndex].ToString());
                    }
                    return("[???]");
                }
                else
                {
                    throw new NotImplementedException();
                }

            case TagType.Clickable:
                return(string.Join("", genericElement.Arguments.Select(v => v.Accept(this))));

            case TagType.Gui:
                if (genericText == "<Gui(54)/>")
                {
                    return("{");
                }
                else if (genericText == "<Gui(55)/>")
                {
                    return("}");
                }
                else if (genericText == "<Gui(63)/>")
                {
                    return("*");    // Not sure about this.
                }
                else
                {
                    DatabaseBuilder.PrintLine($"Unknown GUI string flag: {genericText}, defaulting to *.");
                    return("*");
                }

            case TagType.Time:
                return("[Time]");

            case TagType.SheetEn:
            case TagType.SheetDe:
            case TagType.SheetFr:
            case TagType.SheetJa:
            {
                var genericElementArgs = genericElement.Arguments.ToArray();
                var args      = genericElement.Arguments.Select(a => a.Accept(this)).ToArray();
                var sheetName = genericElementArgs[0].Accept(this);
                try
                {
                    var sheet = DatabaseBuilder.Instance.Realm.GameData.GetSheet(sheetName);
                    if (genericElementArgs[2] is Parameter sheetKeyParam)
                    {
                        return("[Error]");
                    }
                    var sheetKey = int.Parse(genericElementArgs[2].Accept(this).Trim());
                    var row      = sheet[sheetKey];
                    return(row.ToString());
                } catch (KeyNotFoundException e)
                {
                    DatabaseBuilder.PrintLine($"Missing sheet for HTML String Formatter: {sheetName}");
                    return("");
                }
            }

            case TagType.Value:
                return(genericElement.Content.Accept(this));

            case TagType.CommandIcon:
                return("[???]");

            default:
                return("");
            }
        }
 public void Clear()
 {
     _first = _last = null;
     Lenght = 0;
 }
Esempio n. 3
0
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();

            of.Filter = "RaspiDevice Files (*.rd) | *.rd";

            if (of.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                RaspiDeviceFile data = importer.DeserializeDeviceFile(File.ReadAllText(of.FileName));

                foreach (var v in designer1.Document.Elements.OfType <Dalssoft.DiagramNet.BaseElement>().ToArray())
                {
                    designer1.Document.DeleteElement(v);
                }

                linkedIOS.Clear();
                elements.Clear();

                Dictionary <string, Dalssoft.DiagramNet.BaseElement> groups = new Dictionary <string, Dalssoft.DiagramNet.BaseElement>();

                foreach (var item in data.Elements)
                {
                    var elem = importer.ElementsByType[item.InternalClassName];
                    var rect = GenericElement.GetGenericElement(elem);
                    elem      = rect.Tag as RaspiImporter.BaseElement;
                    elem.Name = item.Name;
                    groups.Add(elem.Name, rect);
                    elements.Add(rect.Tag as RaspiImporter.BaseElement);
                    designer1.Document.AddElement(rect);

                    var props = item.GetType().GetProperties();

                    foreach (var prop in props)
                    {
                        prop.SetValue(elem, prop.GetValue(item));
                    }
                }

                foreach (var pos in data.Positions)
                {
                    groups[pos.ElementName].Location = new Point(pos.X, pos.Y);
                }

                foreach (var link in data.Links)
                {
                    var inputElement  = groups[link.InputDevice] as RectangleGroup;
                    var outputElement = groups[link.OutputDevice] as RectangleGroup;

                    var input  = (inputElement.Tag as RaspiImporter.BaseElement).Inputs.Where(i => i.InputName == link.InputName).FirstOrDefault();
                    var output = (outputElement.Tag as RaspiImporter.BaseElement).Outputs.Where(o => o.OutputName == link.OutputName).FirstOrDefault();

                    var inputLinkNode  = (inputElement.Children[input.InputName] as NodeElement).Connectors[link.InputLinkOnLeft ?  1 : 0];
                    var outputLinkNode = (outputElement.Children[output.OutputName] as NodeElement).Connectors[link.OutputLinkOnLeft ? 1 : 0];

                    var lnk = designer1.Document.AddLink(inputLinkNode, outputLinkNode);

                    Guid g = Guid.NewGuid();

                    var lnkI = new BaseElementLink {
                        Input = input, Output = output
                    };

                    linkedIOS.Add(g.ToString(), lnkI);

                    lnk.Tag = lnkI;
                }
            }
        }
        public void Test_GenericElement_And_Element_Clear()
        {
            GenericElement<Element> t = new GenericElement<Element>("Test");

            t.Id("myId");
            t.Attributes(new { data_test = true, data_test2 = "true" });

            // Render again to register options above
            t.Render();
            t.Clear();

            Assert.AreEqual("<Test></Test>", t.Render(), "Options not removed");
        }
 public ListGeneric()
 {
     _first = _last = null;
 }
        public void Test_GenericElement_Render_With_Id_And_Css()
        {
            GenericElement<Element> t = new GenericElement<Element>("Test");

            t.Id("myId");
            t.AddCss("myClass");
            Assert.AreEqual("<Test class=\"myClass\" id=\"myId\"></Test>", t.Render(),
                "Class is not the same");
        }
        public void Test_GenericElement_With_Id_Render()
        {
            GenericElement<Element> t = new GenericElement<Element>("Test");

            t.Id("myId");
            Assert.AreEqual("<Test id=\"myId\"></Test>", t.Render(), "Id is not the same");
        }
        protected virtual IExpression EvaluateDefaultGenericElement(EvaluationParameters parameters, GenericElement element)
        {
            List <IExpression> items = new List <IExpression>();
            bool hasArgs             = element.Arguments.Any();

            items.Add(new GenericExpression(StringTokens.TagOpen + element.Tag.ToString()));
            if (hasArgs)
            {
                items.Add(new SurroundedExpression(StringTokens.ArgumentsOpen, new ExpressionCollection(element.Arguments.Select(_ => _.TryEvaluate(parameters)))
                {
                    Separator = StringTokens.ArgumentsSeperator
                }, StringTokens.ArgumentsClose));
            }

            if (element.Content == null)
            {
                items.Add(new GenericExpression(StringTokens.ElementClose + StringTokens.TagClose));
            }
            else
            {
                items.Add(new GenericExpression(StringTokens.TagClose));
                items.Add(element.Content.TryEvaluate(parameters));
                items.Add(new GenericExpression(StringTokens.TagOpen + StringTokens.ElementClose + element.Tag.ToString() + StringTokens.TagClose));
            }

            return(new ExpressionCollection(items));
        }
        public void Test_GenericElement_Render_With_HtmlAttributes()
        {
            GenericElement<Element> t = new GenericElement<Element>("Test");

            t.Attributes(new { data_test = true, data_test2 = "true" });
            Assert.AreEqual("<Test data-test=\"True\" data-test2=\"true\"></Test>", t.Render(),
                "Attributes is not the same");
        }
Esempio n. 10
0
 public void AddElement(GenericElement elementToAdd)
 {
     tlpElementViewer.Controls.Add(elementToAdd);
     elementToAdd.Dock = DockStyle.Fill;
     elementToAdd.ElementDoubleClick += new GenericElement.ElementDoubleClickEventHandler(Element_OnDoubleClick);
 }
Esempio n. 11
0
        public static ObservableCollection <ProcessUnit> ExtractProcessUnits(Batch batch)
        {
            ObservableCollection <ProcessUnit> processUnits = new ObservableCollection <ProcessUnit>();

            try
            {
                ProcessUnit unit = new ProcessUnit();
                ObservableCollection <GenericElement> elements = batch.Target.Elements;
                for (int i = 0; i < elements.Count; i++)
                {
                    GenericElement element     = elements[i];
                    string         elementType = element.GetType().Name;
                    switch (elementType)
                    {
                    case "OpenModel":
                        OpenModel openModel = element as OpenModel;
                        if (openModel.FileExtension == ".smc")
                        {
                            unit.OpenSolibri = openModel;
                        }
                        else if (modelExtensions.Contains(openModel.FileExtension))
                        {
                            InputModel modeltoOpen = new InputModel(openModel);
                            unit.Models.Add(modeltoOpen);
                        }
                        break;

                    case "UpdateModel":
                        UpdateModel updateModel   = element as UpdateModel;
                        InputModel  modeltoUpdate = new InputModel(updateModel);
                        unit.Models.Add(modeltoUpdate);
                        break;

                    case "OpenRuleset":
                        OpenRuleset ruleset = element as OpenRuleset;
                        unit.Rulesets.Add(ruleset);
                        break;

                    case "OpenClassification":
                        OpenClassification classification = element as OpenClassification;
                        unit.Classifications.Add(classification);
                        break;

                    case "Check":
                        Check check = element as Check;
                        check.IsSpecified = true;
                        unit.CheckTask    = check;
                        break;

                    case "AutoComment":
                        AutoComment comment = element as AutoComment;
                        comment.IsSpecified = true;
                        unit.CommentTask    = comment;
                        break;

                    case "WriterReport":
                        unit.CheckingReport = element as WriterReport;
                        break;

                    case "CreatePresentation":
                        CreatePresentation createP = element as CreatePresentation;
                        createP.IsSelected      = true;
                        unit.PresentationCreate = createP;
                        break;

                    case "UpdatePresentation":
                        UpdatePresentation updateP = element as UpdatePresentation;
                        updateP.IsSelected      = true;
                        unit.PresentationUpdate = updateP;
                        break;

                    case "GeneralReport":
                        unit.PresentationReport = element as GeneralReport;
                        break;

                    case "BCFReport":
                        unit.BCFReport = element as BCFReport;
                        break;

                    case "CoordinationReport":
                        unit.CoordReport = element as CoordinationReport;
                        break;

                    case "SaveModel":
                        unit.SaveSolibri = element as SaveModel;
                        unit.TaskName    = System.IO.Path.GetFileNameWithoutExtension(unit.SaveSolibri.File);
                        break;

                    case "CloseModel":
                        processUnits.Add(unit);
                        unit = new ProcessUnit();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to extract process units.\n" + ex.Message, "Extract Process Unit", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(processUnits);
        }
 private void elements_DoubleClick(GenericElement sender)
 {
     sender.ShowElement(variables);
     txtBxDescription.Text = sender.ActionDescription;
 }
        /// <summary>
        /// Creates an extension with every element and attribute and adds it to the container.
        /// </summary>
        /// <param name="extensible">The container to add the extension to.</param>
        private void AddExtension(IExtensible extensible)
        {
            GenericExtension extension;

            extension = new GenericExtension("extension");

            if (extensible.SupportsAttributeExtensions)
            {
                extension.AddAttribute(new GenericExtensionAttribute("ext", "ext:namespace", "attr2", "value"));
            }

            if (extensible.SupportsElementExtensions)
            {
                GenericElement element;

                element = new GenericElement();
                element.SetAttribute("ext", "ext:namespace", "attr1", "value");
                extension.AddChild(new ElementInfo(new XmlNameInfo("ext", "ext:namespace", "extelement"), element));
            }

            extensible.Extensions.Add(extension);
        }
        public void Extensibility_SerializeWithRegisteredExtensions()
        {
            GenericElement child1;
            GenericElement child2;
            XliffDocument document;
            IExtensible extensible;
            IExtension extension;
            Segment segment;
            Source source;
            Unit unit;

            // Document extensions.
            document = new XliffDocument("en-us");
            extensible = document;
            extension = new GenericExtension("extension");
            extensible.Extensions.Add(extension);
            extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute1", "attribute 1"));
            extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 2"));
            extension = new GenericExtension("extension");
            extensible.Extensions.Add(extension);
            extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute1", "attribute 3"));
            extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute2", "attribute 4"));

            // File extensions.
            document.Files.Add(new File("f1"));
            extensible = document.Files[0];
            extension = new GenericExtension("extension");
            extensible.Extensions.Add(extension);
            extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute1", "attribute 5"));
            extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 6"));
            extension = new GenericExtension("extension");
            extensible.Extensions.Add(extension);
            extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute1", "attribute 7"));
            extension.AddAttribute(new GenericExtensionAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute2", "attribute 8"));

            // Child 0.
            child1 = new GenericElement();
            child1.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute1", "attribute 9");
            child1.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 10");
            extension.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element1"), child1));
            child2 = new GenericElement();
            child2.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute3", "attribute 11");
            child1.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element2"), child2));
            source = new Source();
            source.Language = "de-de";
            source.Space = Preservation.Preserve;
            child2.AddChild(new ElementInfo(new XmlNameInfo("source"), source));

            // Child 1.
            child1 = new GenericElement();
            child1.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute1", "attribute 12");
            child1.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 13");
            extension.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element1"), child1));
            child2 = new GenericElement();
            child2.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute3", "attribute 14");
            child1.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Namespace1, "element2"), child2));
            child2.AddChild(new ElementInfo(new XmlNameInfo((string)null), new PlainText("text 1")));

            // Child 2.
            child1 = new GenericElement();
            child1.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute1", "attribute 15");
            child1.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 16");
            child1.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute1", "attribute 17");
            extension.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "element1"), child1));
            child2 = new GenericElement();
            child2.SetAttribute(ExtensibilityTests.Prefix1, ExtensibilityTests.Namespace1, "attribute2", "attribute 18");
            child1.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Namespace2, "element1"), child2));
            child2.AddChild(new ElementInfo(new XmlNameInfo((string)null), new PlainText("text 3")));

            // Child 3.
            child1 = new GenericElement();
            child1.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute1", "attribute 19");
            child1.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute2", "attribute 20");
            extension.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "element1"), child1));
            child2 = new GenericElement();
            child2.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute3", "attribute 21");
            child1.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Namespace2, "element2"), child2));
            child2.AddChild(new ElementInfo(new XmlNameInfo("target"), new Target()));

            // Child 4.
            child1 = new GenericElement();
            child1.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute1", "attribute 22");
            child1.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute2", "attribute 23");
            extension.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "element1"), child1));
            child2 = new GenericElement();
            child2.SetAttribute(ExtensibilityTests.Prefix2, ExtensibilityTests.Namespace2, "attribute3", "attribute 24");
            child1.AddChild(new ElementInfo(new XmlNameInfo(ExtensibilityTests.Namespace2, "element2"), child2));
            child2.AddChild(new ElementInfo(new XmlNameInfo((string)null), new PlainText("text 2")));

            // Unit information.
            unit = new Unit("u1");
            document.Files[0].Containers.Add(unit);
            extensible = unit;

            extension = new GenericExtension("extension");
            extensible.Extensions.Add(extension);

            // Segment information.
            segment = new Segment("s1");
            segment.Source = new Source();
            segment.State = TranslationState.Initial;
            unit.Resources.Add(segment);

            Assert.AreEqual(
                            TestUtilities.GetFileContents(TestData.DocumentWithExtensions),
                            TestUtilities.GetDocumentContents(document, "    "),
                            "Document contents are incorrect.");
        }
Esempio n. 15
0
        public void the_attribute_is_set_to_the_correct_value()
        {
            var element = new GenericElement("fake").ID("fakeid");

            element.ID.ShouldBe("fakeid");
        }
        protected virtual IExpression EvaluateDefaultGenericElement(EvaluationParameters parameters, GenericElement element)
        {
            var items = new List<IExpression>();
            var hasArgs = element.Arguments.Any();
            items.Add(new GenericExpression(StringTokens.TagOpen + element.Tag.ToString()));
            if (hasArgs)
                items.Add(new SurroundedExpression(StringTokens.ArgumentsOpen, new ExpressionCollection(element.Arguments.Select(_ => _.TryEvaluate(parameters))) { Separator = StringTokens.ArgumentsSeperator }, StringTokens.ArgumentsClose));

            if (element.Content == null) {
                items.Add(new GenericExpression(StringTokens.ElementClose + StringTokens.TagClose));
            } else {
                items.Add(new GenericExpression(StringTokens.TagClose));
                items.Add(element.Content.TryEvaluate(parameters));
                items.Add(new GenericExpression(StringTokens.TagOpen + StringTokens.ElementClose + element.Tag.ToString() + StringTokens.TagClose));
            }

            return new ExpressionCollection(items);
        }