Exemple #1
0
 private static IconDef FromXml(XElement xml, PackagePart part)
 {
     var icon = xml.Attr<string>("icon");
     if (icon != null)
         icon = part.GetRelationship(icon).TargetUri.OriginalString;
     return new IconDef { Icon = icon, Pattern = xml.Attr<string>("pattern")};
 }
Exemple #2
0
        public static PropertyDef LoadFromXml(XElement xml)
        {
            var name = xml.Attr<string>("name");

            string kindStr = xml.Attr("textKind", "Free");
            PropertyTextKind kind;
            switch (kindStr)
            {
                case "Free":
                    kind = PropertyTextKind.FreeText;
                    break;
                case "Enum":
                    kind = PropertyTextKind.Enumeration;
                    break;
                case "Tokens":
                    kind = PropertyTextKind.Tokens;
                    break;
                default:
                    throw new InvalidFileFormatException(
                        string.Format("Unknown value '{0}' for textKind attribute (Property = {1})",
                                      kindStr, name));
            }

            return new PropertyDef
                       {
                           Name = name,
                           Type = xml.Attr<PropertyType>("type"),
                           IgnoreText = xml.Attr<bool>("ignoreText"),
                           TextKind = kind,
                           Hidden = xml.Attr<bool>("hidden")
                       };
        }
        private LoadPackage ReadPackage(XElement pkge) {
            var result = new LoadPackage {Code = pkge.Attr("code")};
            var level = pkge.Attr("level");
            if (!string.IsNullOrWhiteSpace(level)) {
                result.Level = (LoadLevel) Enum.Parse(typeof (LoadLevel), level, true);
            }

            result.Arm = pkge.Attr("arm","default");
            result.Command = pkge.Attr("command", "");
               

            var deps = pkge.Elements("uses");
            foreach (var dep in deps) {
                result.Dependency.Add(dep.Attr("code"));
            }
            foreach (var item in pkge.Elements("load")) {
                result.Items.Add(ReadItem(item));
            }
            foreach (var item in pkge.Elements("widget")) {
                ReadWidget(result, item);
            }


            return result;
        }
        public void BoolToAttribute() {
            var el = new XElement("data");
            el.Attr("foo", true);
            el.Attr("bar", false);

            Assert.That(el.Attribute("foo").Value, Is.EqualTo("true"));
            Assert.That(el.Attribute("bar").Value, Is.EqualTo("false"));
        }
Exemple #5
0
 internal static DeckSectionDef LoadFromXml(XElement xml)
 {
     return new DeckSectionDef
                {
                    Name = xml.Attr<string>("name"),
                    Group = xml.Attr<string>("group")
                };
 }
 internal static new At LoadFromXml(XElement xml)
 {
     return new At
       {
     group = xml.Attr<string>("group"),
     position = xml.Attr<string>("position")
       };
 }
Exemple #7
0
        internal static CardDef LoadFromXml(XElement xml, PackagePart part)
        {
            var backUri = xml.Attr<string>("back");
            if (backUri != null) backUri = part.GetRelationship(backUri).TargetUri.OriginalString;

            var frontUri = xml.Attr<string>("front");
            if (frontUri != null) frontUri = part.GetRelationship(frontUri).TargetUri.OriginalString;

            var cd = new CardDef
                       {
                           back = backUri,
                           front = frontUri,
                           Width = xml.Attr<int>("width"),
                           Height = xml.Attr<int>("height"),
                           CornerRadius = xml.Attr<int>("cornerRadius"),
                           //Properties = xml.Elements(Defs.XmlnsOctgn + "property")
                           //    //.Select(PropertyDef.LoadFromXml)
                           //    .ToDictionary(x => x.Name)
                       };
            var list = xml.Elements(Defs.XmlnsOctgn + "property");
            var proplist = new Dictionary<string,PropertyDef>();
            foreach (var l in list)
            {
                var name = l.Attr<string>("name");

                string kindStr = l.Attr("textKind", "Free");
                PropertyTextKind kind;
                switch (kindStr)
                {
                    case "Free":
                        kind = PropertyTextKind.FreeText;
                        break;
                    case "Enum":
                        kind = PropertyTextKind.Enumeration;
                        break;
                    case "Tokens":
                        kind = PropertyTextKind.Tokens;
                        break;
                    default:
                        throw new InvalidFileFormatException(
                            string.Format("Unknown value '{0}' for textKind attribute (Property = {1})",
                                          kindStr, name));
                }

                var prop = new PropertyDef
                {
                    Name = name,
                    Type = l.Attr<PropertyType>("type"),
                    IgnoreText = l.Attr<bool>("ignoreText"),
                    TextKind = kind,
                    Hidden = l.Attr<bool>("hidden")
                };
                proplist.Add(name,prop);
            }
            cd.Properties = proplist;
            return cd;
        }
Exemple #8
0
 public XsltTask(IBSharpProject project, XElement definition)
 {
     this.Project = project;
     this.TemplateUri = new Uri(definition.Attr("template"));
     this.ClassSelector = new Uri(definition.Attr("selector"));
     this.Batch = definition.Attr("batch").ToBool();
     this.OutputPath = new Uri(definition.Attr("output"));
     this.NoXml = definition.Attr("noxml").ToBool();
     this._resolver = new ProjectUriResolver(project);
 }
        public void ContextSwitch()
        {
            var el = new XElement("data");
            el.With(new {foo = "bar"})
                .ToAttr(o => o.foo)
                .With(new {bar = "baz"})
                .ToAttr(o => o.bar);

            Assert.That(el.Attr<string>("foo"), Is.EqualTo("bar"));
            Assert.That(el.Attr<string>("bar"), Is.EqualTo("baz"));
        }
 internal static new AddMarker LoadFromXml(XElement xml)
 {
     var res = new AddMarker
       {
     markerId = xml.Attr<Guid?>("id", null),
     markerName = xml.Attr<string>("name"),
     quantity = xml.Attr<string>("qty", "1")
       };
       res.LoadBaseFromXml(xml);
       return res;
 }
		public override void Execute(XElement el){
			string[] codes = Split
				                 ? el.Attr("code").SmartSplit(false, true, ',', '/', ';', ' ').ToArray()
				                 : new[]{el.Attr("code")};
			string value = el.Value;
			foreach (string code in codes){
				lock (_project.Global){
					_project.Global.Set(code, value);
				}
			}
		}
Exemple #12
0
 internal new static ActionDef LoadFromXml(XElement xml)
 {
     return new ActionDef
                {
                    Name = xml.Attr<string>("menu"),
                    DefaultAction = xml.Attr<bool>("default"),
                    Shortcut = xml.Attr<string>("shortcut"),
                    Execute = xml.Attr<string>("execute"),
                    BatchExecute = xml.Attr<string>("batchExecute")
                };
 }
 internal Resource(ResourceSet parent, XElement xe)
 {
     ParentSet = parent;
     Path = xe.Attr<string>(SchemaConstants.Resource.Path);
     Mode = xe.Attr(SchemaConstants.Resource.Mode, Default.Resource.Mode);
     ForwardCookie = xe.Attr(SchemaConstants.Resource.ForwardCookie,
         Default.Resource.ForwardCookie);
     Minifier = ParentSet.Type == ResourceType.JS
         ? ModelUtils.LoadMinifier(xe, SchemaConstants.Resource.MinifierRef, ParentSet.Minifier.Name, ParentSet.Settings.JSMinifierMap)
         : ModelUtils.LoadMinifier(xe, SchemaConstants.Resource.MinifierRef, ParentSet.Minifier.Name, ParentSet.Settings.CssMinifierMap);
     if (Mode == ResourceMode.Static && ForwardCookie)
         throw new XmlSchemaException("ForwardCookie must not be True when Mode is Static");
 }
 private void RenameElement(XElement gj, XElement e, XElement[] selection)
 {
     var targetattr = gj.Attr("targetattr");
     var newname = gj.Attr("newname");
     foreach(var s in selection)
     {
         if (!string.IsNullOrWhiteSpace(targetattr))
         {
             s.SetAttributeValue(targetattr, s.Name.LocalName);
         }
         s.Name = newname;
     }
 }
 private void ReadWidget(LoadPackage result, XElement item) {
     var level = LoadLevel.Guest;
     var levele = item.Attr("level");
     if (!string.IsNullOrWhiteSpace(levele))
     {
         level = (LoadLevel)Enum.Parse(typeof(LoadLevel), levele, true);
     }
     var code = item.Attr("code");
     var command = item.Attr("command");
     result.Items.Add(new LoadItem {Level = level, Command=command, Type = LoadItemType.Script, Value = code + ".js"});
     result.Items.Add(new LoadItem { Level = level, Command=command, Type = LoadItemType.Style, Value = code + ".css" });
     result.Items.Add(new LoadItem { Level = level, Command = command, Type = LoadItemType.Template, Value = code + ".tpl.html" });
 }
Exemple #16
0
 internal static new ActionDef LoadFromXml(XElement xml)
 {
     return new ActionDef
       {
     Name = xml.Attr<string>("menu"),
     DefaultAction = xml.Attr<bool>("default"),
     Shortcut = xml.Attr<string>("shortcut"),
     Execute = xml.Attr<string>("execute"),
     BatchExecute = xml.Attr<string>("batchExecute"),
     Actions = xml.Elements()
              .Select(x => Action.LoadFromXml(x))
              .ToArray()
       };
 }
Exemple #17
0
        internal static CounterDef LoadFromXml(XElement xml, PackagePart part, int index)
        {
            var icon = xml.Attr<string>("icon");
            if (icon != null)
                icon = part.GetRelationship(icon).TargetUri.OriginalString;

            return new CounterDef
                       {
                           Id = (byte) index,
                           Name = xml.Attr<string>("name"),
                           Icon = icon,
                           Start = xml.Attr<int>("default"),
                           Reset = xml.Attr("reset", true)
                       };
        }
        public void DateTimeToAttribute()
        {
            var el = new XElement("data");
            el.Attr("foo", new DateTime(1970, 5, 21, 13, 55, 21, 934, DateTimeKind.Utc));

            Assert.That(el.Attribute("foo").Value, Is.EqualTo("1970-05-21T13:55:21.934Z"));
        }
        public override void InitializeFromXml(XElement e) {
            if (null != e) {
                e = e.Element("messaging");
            }
            if (null != e) {
                foreach (var element in e.Elements("smtp")) {
                    var conf = new SmtpConfig {
                        Code = element.Attr("code"),
                        From = element.Attr("name"),
                        Host = element.Attr("host"),
                        Port = element.Attr("port").ToInt(),
                        SslRequired = element.Attr("ssl").ToBool(),
                        User = element.Attr("user"),
                        Name = element.Attr("title")
                    };

                    var _password = element.Attr("pass");
                    var p = new SecureString();
                    foreach (var c in _password) {
                        p.AppendChar(c);
                    }
                    conf.Password = p;
                    Registry[conf.Code] = conf;
                    Registry[conf.From] = conf;
                    if (e.Attr("default").ToBool()) {
                        Registry["default"] = conf;
                    }
                }
            }
        }
Exemple #20
0
        internal Resource(ResourceSet parent, XElement xe)
        {
            ParentSet = parent;
            Path = xe.Attr<string>(SchemaConstants.Resource.Path);
			if (Path.Contains("${"))
			{
				Path.Split('$').ToList().ForEach(p =>
				{
					if (p.Contains('{'))
					{
						string resourceSetting = p.Split(new char[] {'{', '}'})[1];
						String resourceContent = ConfigurationManager.AppSettings[resourceSetting];
						if (String.IsNullOrEmpty(resourceContent))
						{
							resourceContent = "empty";
						}
						Path = Path.Replace("${" + resourceSetting + "}", resourceContent);
					}
				});
			}
			Mode = xe.Attr(SchemaConstants.Resource.Mode, Default.Resource.Mode);
			if (Mode == ResourceMode.Auto)
			{
				Mode = Path.StartsWith("http") ? ResourceMode.Dynamic : ResourceMode.Static;
			}

            ForwardCookie = xe.Attr(SchemaConstants.Resource.ForwardCookie,
                Default.Resource.ForwardCookie);
            Minifier = ParentSet.Type == ResourceType.JS
                ? ModelUtils.LoadMinifier(xe, SchemaConstants.Resource.MinifierRef, ParentSet.Minifier.Name, ParentSet.Settings.JSMinifierMap)
                : ModelUtils.LoadMinifier(xe, SchemaConstants.Resource.MinifierRef, ParentSet.Minifier.Name, ParentSet.Settings.CssMinifierMap);
            if (Mode == ResourceMode.Static && ForwardCookie)
                throw new XmlSchemaException("ForwardCookie must not be True when Mode is Static");
        }
		public override void Execute(XElement el){
			string code = el.Attr("code");
			Type type = Type.GetType(code, false);
			if (null == type){
				_project.Log.Error("Не могу найти расширение - генератор с именем " + code);
				return;
			}
			var gen = Activator.CreateInstance(type) as ISourceCodeGenerator;
			if (null == gen){
				_project.Log.Error("Указанный класс " + code + " не соответствует интерфейсу ISourceCodeGenerator");
				return;
			}
			IEnumerable<XNode> replaces = null;
			try{
				replaces = gen.Execute(_project, el, null).ToArray();
			}
			catch (Exception ex){
				_project.Log.Error("Ошибка при вызове " + gen.GetType().Name + " на " + el, ex);
				return;
			}
			if (!replaces.Any()){
				el.Remove();
			}
			else{
				el.ReplaceWith(replaces.OfType<object>().ToArray());
			}
		}
Exemple #22
0
		/// <summary>
		/// </summary>
		/// <param name="model"></param>
		/// <param name="cls"></param>
		/// <param name="bscls"></param>
		/// <param name="xml"></param>
		public override SqlObject Setup(PersistentModel model, PersistentClass cls, IBSharpClass bscls, XElement xml){
			base.Setup(model, cls, bscls, xml);
			if (null != xml){
				Start = xml.Attr("start", "10").ToInt();
				Step = xml.Attr("step", "10").ToInt();
			}
			Name = cls.Name + "_SEQ";
			Schema = cls.Schema;
			IsCyclic = cls.CyclicId;
			if (null != cls.PrimaryKey){
				DataType = cls.PrimaryKey.DataType;
			}
			else{
				DataType = cls.DataTypeMap["int"];
			}
			return this;
		}
Exemple #23
0
        public static ScriptDef FromXml(XElement xml, PackagePart part)
        {
            string srcUri = part.GetRelationship(xml.Attr<string>("src")).TargetUri.OriginalString;
            PackagePart scriptPart = part.Package.GetPart(new Uri(srcUri, UriKind.Relative));

            using (Stream stream = scriptPart.GetStream(FileMode.Open, FileAccess.Read))
            using (var textReader = new StreamReader(stream))
                return new ScriptDef {Python = textReader.ReadToEnd(), FileName = srcUri};
        }
        public void AttrWithContext()
        {
            var el = new XElement("data")
                .With(new {foo = 123})
                .ToAttr(o => o.foo);
            var val = el.Attr(o => o.foo);

            Assert.That(val, Is.EqualTo(123));
        }
Exemple #25
0
        public void Enqueue(string executionId, RecipeStep step) {
            Logger.Information("Enqueuing recipe step '{0}'.", step.Name);
            var recipeStepElement = new XElement("RecipeStep");
            recipeStepElement.Attr("Id", step.Id);
            recipeStepElement.Attr("RecipeName", step.RecipeName);
            recipeStepElement.Add(new XElement("Name", step.Name));
            recipeStepElement.Add(step.Step);

            if (_appDataFolder.DirectoryExists(Path.Combine(_recipeQueueFolder, executionId))) {
                int stepIndex = GetLastStepIndex(executionId) + 1;
                _appDataFolder.CreateFile(Path.Combine(_recipeQueueFolder, executionId + Path.DirectorySeparatorChar + stepIndex),
                                          recipeStepElement.ToString());
            }
            else {
                _appDataFolder.CreateFile(
                    Path.Combine(_recipeQueueFolder, executionId + Path.DirectorySeparatorChar + "0"),
                    recipeStepElement.ToString());
            }
        }
Exemple #26
0
 internal static new ActionGroupDef LoadFromXml(XElement xml)
 {
     return new ActionGroupDef
       {
     Name = xml.Attr<string>("menu"),
     Children = xml.Elements()
               .Select(x => BaseActionDef.LoadFromXml(x))
               .ToArray()
       };
 }
Exemple #27
0
 internal static PlayerDef LoadFromXml(XElement xml, PackagePart part)
 {
     var res = new PlayerDef
      {
     IndicatorsFormat = xml.Attr<string>("summary"),
     Hand = GroupDef.LoadFromXml(xml.Child("hand"), part, 0)
      };
      res.LoadBaseXml(xml, part);
      return res;
 }
Exemple #28
0
        internal static CardDef LoadFromXml(XElement xml, PackagePart part)
        {
            var backUri = xml.Attr<string>("back");
            if (backUri != null) backUri = part.GetRelationship(backUri).TargetUri.OriginalString;

            var frontUri = xml.Attr<string>("front");
            if (frontUri != null) frontUri = part.GetRelationship(frontUri).TargetUri.OriginalString;

            return new CardDef
                       {
                           back = backUri,
                           front = frontUri,
                           Width = xml.Attr<int>("width"),
                           Height = xml.Attr<int>("height"),
                           CornerRadius = xml.Attr<int>("cornerRadius"),
                           Properties = xml.Elements(Defs.XmlnsOctgn + "property")
                               .Select(PropertyDef.LoadFromXml)
                               .ToDictionary(x => x.Name)
                       };
        }
 private void Initialize(XElement e) {
     var _ref = e.Attr("ref");
     if (null != _ref) {
         var root = e.toRoot();
         var elastic = root.Element("elastic");
         if(null==elastic)throw new Exception("invalid ref");
         var cfg = elastic.Element(_ref);
         if(null==cfg) throw new Exception("invalid ref");
         InitializeDirect(cfg);
     }
     InitializeDirect(e);
 }
	    private void Execute(ClassFilter filter, XElement e, string rootns) {
		    if (e.Name.LocalName == BSharpSyntax.Namespace) {
			    var ns = e.Attr("code");
				if (!string.IsNullOrWhiteSpace(rootns)) {
					ns = rootns + "." + ns;
				}
				if (!filter.IsAvailableNamespace(ns)) {
					e.Remove();
				}
				foreach (var c in e.Elements().ToArray())
				{
					Execute(filter, c,ns);
				}
		    }
		    else {
			    var clsname = e.Attr("code");
				if (!filter.IsAvailableClassname(clsname)) {
					e.Remove();
				}
		    }
	    }