public static AbstractSource DoCreateNewSource(string name, List <IMetaDataObject> metaData) //URL is in meta { int tmp; //Set defaults IMetaDataObject mdo = MetaDataObject.FindIn(metaData, JobsProvider.META_PAGES); bool hasUrl = false; bool hasPages = false; foreach (var m in metaData) { switch (m.ID) { case JobsProvider.META_URL: hasUrl = true; break; case JobsProvider.META_PAGES: string value = m.GetValueAsString(); if (String.IsNullOrEmpty(value)) { mdo.SetValue(DefaultPages); } else if (int.TryParse(value, out tmp)) { mdo.SetValue(tmp); } else { throw new Exception("Not a valid number"); } hasPages = true; break; } } if (!hasUrl) { throw new Exception("Url must be provided."); } if (!hasPages) { mdo = JobsProvider.MetaPages.Create(); mdo.SetValue(DefaultPages); metaData.Add(mdo); } AbstractSource s = new JobsSource(name); s.SetMetaData(metaData); return(s); }
// parse utility function to ensure that the class of a field matches the // class name specified in a TokenDefinition public bool MatchFieldType(FieldDefinition rule, MetaDataField field) { if (rule.matchClassType != null) { MetaDataObject classobj = field.Signature.FieldType.ClassObject; string classtype = ""; // Since we can pass in different objects as field, we need to be // careful here about how we get the class type if (classobj is MetaDataTypeDefinition) { classtype = ((MetaDataTypeDefinition)classobj).FullName; } else if (classobj is MetaDataTypeReference) { classtype = ((MetaDataTypeReference)classobj).FullName; } else if (classobj == null) { classtype = field.Signature.FieldType.ElementType.ToString(); } if (classtype != rule.matchClassType) { Error("{0} can't be applied to {1}", LastName(rule.attribute), field.FullName); Error("{0}does not match {1}", classtype, rule.matchClassType); return(false); } } return(true); }
public SuiteDesc ProvideSuite(MetaDataObject m, out string child) { string className; child = mktests.Tail(m.FullName, '.', out className); return(ProvideSuite(className)); }
protected override AbstractSource DoCreateNewSource(string name, string url, List <MetaDataObject> templateAndValues) { string value; int tmp; MetaDataObject source = MetaDataObject.FindIn(templateAndValues, SmackProvider.META_SOURCE); value = source.GetValueAsString(); if (String.IsNullOrEmpty(value)) { throw new Exception("No source selected"); } AbstractSource s = new SmackSource(value); MetaDataObject pages = MetaDataObject.FindIn(templateAndValues, SmackProvider.META_PAGES); value = pages.GetValueAsString(); if (String.IsNullOrEmpty(value)) { tmp = DefaultPages; } else { int.TryParse(value, out tmp); } pages.SetValue(tmp); s.SetMetaData(templateAndValues); return(s); }
/** * Creates an object of a given metadataobject and sets the meta data * * Currently is only lat/lon supported * * @param meta - the meta data object. * * */ public static MultimediaObject ConvertFrom(MetaDataObject meta) { MultimediaObject output = new MultimediaObject(); output.id = meta.objectId; output.AddMetaData(meta); return(output); }
/** * Adds the given meta data to this object. * If the meta data has an unkown key or the ID is not matching, FALSE will be returned. * */ public bool AddMetaData(MetaDataObject meta) { if (id.Equals(meta.objectId)) { if (CineastUtils.KNOWN_KEYS.Contains(meta.key)) { var changes = false; switch (meta.key) { case CineastUtils.LATITUDE_KEY: if (double.IsNaN(latitude)) { latitude = double.Parse(meta.value); changes = true; } break; case CineastUtils.LONGITUDE_KEY: if (double.IsNaN(longitude)) { longitude = double.Parse(meta.value); changes = true; } break; case CineastUtils.DATETIME_KEY: if (datetime == null) { datetime = meta.value; changes = true; } break; case CineastUtils.BEARING_KEY: if (double.IsNaN(bearing)) { bearing = double.Parse(meta.value); changes = true; } break; } return(changes); } return(false); } return(false); }
[HttpPost]/*, ValidateAntiForgeryToken]*/ public ActionResult AddSponsor(MetadataModel model) { if (ModelState.IsValid && MainObject.CheckUserHasWriteAccess(model.MainId)) { model.Save(); return(PartialView("Partials/_sponsorOrgList", MetaDataObject.GetMetaDatas(model.MainId, MetaDataTypeEnum.SponsoringOrgs))); } return(null); }
[HttpPost]/*, ValidateAntiForgeryToken]*/ public ActionResult AddCoreCapabilities(MetadataModel model) { if (ModelState.IsValid && MainObject.CheckUserHasWriteAccess(model.MainId)) { model.Save(); return(PartialView("Partials/_coreCapabilitiesList", MetaDataObject.GetMetaDatas(model.MainId, MetaDataTypeEnum.CoreCapabilities))); } return(null); }
string GetBaseClassName(MetaDataObject d) { if (d is MetaDataTypeDefinition) { return(((MetaDataTypeDefinition)d).FullName); } else if (d is MetaDataTypeReference) { return(((MetaDataTypeReference)d).Namespace + "." + ((MetaDataTypeReference)d).Name); } return(null); }
Type ResolveTypeRef(MetaDataObject d, string path) { if (d is MetaDataTypeDefinition) { return((Type)GetSymbol((MetaDataTypeDefinition)d, path)); } else if (d is MetaDataTypeReference) { return((Type)GetSymbol((MetaDataTypeReference)d)); } else { return(null); } }
public ActionResult RemoveKeyword(int?id) { int mid = 0; if (id.HasValue) { var meta = MetaDataObject.GetMetaData(id.Value); if (meta != null) { mid = meta.MainId; if (MainObject.CheckUserHasWriteAccess(mid)) { meta.Delete(); } } } return(PartialView("Partials/_keywordsList", MetaDataObject.GetMetaDatas(mid, MetaDataTypeEnum.Keywords))); }
//TODO: Need to set display name elsewhere and metaData type private Dictionary <string, IMetaDataObject> DeserializeMeta(string meta) { string[] data = meta.Split(MetaDelim); Dictionary <string, IMetaDataObject> kvs = new Dictionary <string, IMetaDataObject>(); foreach (string kv in data) { int split = kv.IndexOf('='); string key = kv.Substring(0, split); string value = kv.Substring(split + 1); MetaDataObject mdo = new MetaDataObject(key, null, MetaDataObjectType.NA); mdo.SetValue(value); kvs.Add(key, mdo); } return(kvs); }
public static SourceAdapter CreateSourceAdapter(V1.AbstractSource src, V1.AbstractProvider provider) { string strDisabled = src.GetMetaDataValue(AbstractSource.DISABLED); bool disabled = strDisabled == null ? false : Convert.ToBoolean(strDisabled); GenericSource gs = new GenericSource(src.SourceName, src.ProviderID, disabled); //Update Meta Dictionary <string, MetaDataObject> newMeta = new Dictionary <string, MetaDataObject>(); List <string> providerMeta = provider.GetMetaFields(); { foreach (string name in providerMeta) { var mdo = new MetaDataObject(name, name); if (src.GetMetaData().ContainsKey(name)) { mdo.SetValue(src.GetMetaDataValue(name)); } newMeta.Add(mdo.ID, mdo); } } gs.SetMetaData(newMeta); if (src.ID.HasValue) { gs.SetID(src.ID.Value); } var sa = new SourceAdapter(gs); return(sa); }
private void ProcessAssembly(MetaData md) { // Look for the annotation that tells us that this assembly is a stand-alone // test app. MetaDataAssembly mda = (MetaDataAssembly)md.Assemblies[0]; foreach (MetaDataCustomAttribute attrib in md.CustomAttributes) { MetaDataObject parent = attrib.Parent; //Console.WriteLine("Found: {0} in {1} {2}", attrib.Name, parent.FullName, parent.FullNameWithContext); if (!attrib.Name.StartsWith(ATTRIBUTE_PREFIX)) { continue; } Console.WriteLine("Found: {0} in {1} {2}", attrib.Name, parent.FullName, parent.FullNameWithContext); string attribName = attrib.Name.Substring(ATTRIBUTE_PREFIX.Length); string className; string item = Tail(attrib.Parent, out className); if (attribName == "TestClassAttribute") { m_suites.Add(attrib.Parent.FullName, attrib); } else if (attribName == "TestMethodAttribute") { m_module.ProvideSuite(className).tests.Add(item); } else if (attribName == "ClassInitializeAttribute") { m_module.ProvideSuite(className).init = item; } else if (attribName == "ClassCleanupAttribute") { m_module.ProvideSuite(className).cleanup = item; } else if (attribName == "TestInitializeAttribute") { m_module.ProvideSuite(className).testInit = item; } else if (attribName == "TestCleanupAttribute") { m_module.ProvideSuite(className).testCleanup = item; } else if (attribName == "AssemblyInitializeAttribute") { m_module.init = item; } else if (attribName == "TestCleanupAttribute") { m_module.cleanup = item; } else { // IGNORE } } StringBuilder suiteStr = new StringBuilder(); StringBuilder jigsStr = new StringBuilder(); foreach (KeyValuePair <string, SuiteDesc> kvp in m_module.suites) { string fullname = kvp.Key; if (!m_suites.ContainsKey(fullname)) { Console.WriteLine("TestMethod declared outside of a TestClass: {0}", fullname); continue; } string pkg; string className = Tail(fullname, '.', out pkg); SuiteDesc desc = kvp.Value; GenTests(className, pkg, desc, suiteStr); jigsStr.AppendFormat(SUITE_CASE_TEMPLATE, className, pkg); } string modulename = "Foo"; StringBuilder otherStr = new StringBuilder(); //AppendOpt(MODULE_INIT_TEMPLATE, m_module.init, otherStr); //AppendOpt(MODULE_INIT_TEMPLATE, m_module.cleanup, otherStr); string content = string.Format(FILE_TEMPLATE, modulename, jigsStr, otherStr, suiteStr); File.WriteAllText(m_outpath, content); }
private static void ProcessAssembly(XmlTextWriter oo, MetaData md) { IDictionary <string, MetaDataObject> tests = new SortedDictionary <string, MetaDataObject>(); IDictionary <string, MetaDataObject> suites = new SortedDictionary <string, MetaDataObject>(); // Look for the annotation that tells us that this assembly is a stand-alone // test app. MetaDataAssembly mda = (MetaDataAssembly)md.Assemblies[0]; foreach (MetaDataCustomAttribute attrib in md.CustomAttributes) { MetaDataObject parent = attrib.Parent; //Console.WriteLine("Found: {0} in {1} {2}", attrib.Name, parent.FullName, parent.FullNameWithContext); if (!attrib.Name.StartsWith(ATTRIBUTE_PREFIX)) { continue; } string attribName = attrib.Name.Substring(ATTRIBUTE_PREFIX.Length); switch (attribName) { case "TestAppAttribute": break; case "TestClassAttribute": suites.Add(attrib.Parent.FullName, attrib); break; case "TestMethodAttribute": MetaDataObject m = attrib.Parent; tests.Add(attrib.Parent.FullName, attrib); break; } } string prevSuite = ""; foreach (KeyValuePair <string, MetaDataObject> kvp in tests) { string k = kvp.Key; string className; string testname = Tail(k, '.', out className); if (!suites.ContainsKey(className)) { Console.WriteLine("TestMethod declared outside of a TestClass: {0}", k); continue; } if (!prevSuite.Equals(className)) { if (!prevSuite.Equals("")) { oo.WriteEndElement(); } oo.WriteStartElement("Suite"); string ignored; oo.WriteAttributeString("Name", Tail(className, '.', out ignored)); prevSuite = className; } oo.WriteStartElement("Test"); oo.WriteAttributeString("Name", testname); #if EXTRACT_TIMEOUT object timeout = psItem.Fields["Test Timeout"].Value; if (timeout != null) { oo.WriteAttributeString("Timeout", timeout.ToString()); } object knownFailure = psItem.Fields["Test Known Failure"].Value; if (knownFailure != null) { oo.WriteAttributeString("KnownFailure", knownFailure.ToString()); } #endif oo.WriteEndElement(); } if (!prevSuite.Equals("")) { oo.WriteEndElement(); } }
public static string Tail(MetaDataObject m, out string before) { return(Tail(m.FullName, '.', out before)); }
public MetaDataObjectViewModel(MetaDataObject data) { this.data = data; }
// Endpoints are special in a lot of ways, and require a special method public XmlNode CreateEndpointNode(MetaDataCustomAttribute data, EndpointDefinition rule, int index) { // assume that the constructor to an endpoint always takes one argument, // and that the argument looks like this: // "<discard*> contractname+Exp*,AssemblyName, Version=foo, // Culture=bar, PublicKeyToken=fbar" // we'll parse this to get all the attributes of the top-level tag, and // then parse field that is being decorated to get the rest of the // information we need. // get the type of the field that is decorated: MetaDataObject t = (MetaDataObject) ((MetaDataField)data.Parent).Signature.FieldType.ClassObject; // split the field to get the parts we need string typeName = t.FullName; typeName = typeName.Replace("<", ","); typeName = typeName.Replace(">", ""); typeName = typeName.Replace("+", ","); string [] nameParts = typeName.Split(','); string contractName = nameParts[1]; string impName = contractName + ".Imp"; string expName = contractName + ".Exp"; string stateName = contractName + "." + nameParts[4]; XmlNode impNode = GetEndpointHierarchy("imp", impName); XmlNode expNode = GetEndpointHierarchy("exp", expName); MetaDataTypeDefinition r1 = resolver.ResolveName(impName); MetaDataTypeDefinition r2 = resolver.ResolveName(expName); MetaDataTypeDefinition r3 = resolver.ResolveName(stateName); string startState = ""; for (int i = 0; i < r3.Fields.Length; i++) { if (r3.Fields[i].Name == "Value") { startState = r3.Fields[0].DefaultValue.ToString(); break; } } XmlNode node = manifest.CreateNode(XmlNodeType.Element, rule.xmlTagName, ""); node.AppendChild(impNode); node.AppendChild(expNode); AddAttribute(node, "id", index.ToString()); if (startState != "") { AddAttribute(node, "startStateId", startState); } // Contract name comes from either the attribute argument // or the TRef type depending on the endpoint kind rule.AddContractNameAttribute(this, node, data, contractName); // add an attribute for each constructor argument if there is one // This should only be true for input/ouput pipes if (rule.constructorFields != null && rule.constructorFields.Length != 0) { if (data.FixedArgs.Length != 0) { for (int i = 0; i < data.FixedArgs.Length; i++) { if (rule.constructorFields[i] != null) { string name = rule.constructorFields[i]; if (data.FixedArgs[i] == null) { AddAttribute(node, name, ""); } else { string value = data.FixedArgs[i].ToString(); AddAttribute(node, name, value); } } else { Console.WriteLine(" fixed=({0}), no matching constructor?", data.FixedArgs[i] == null? null : data.FixedArgs[i].ToString()); } } } } return(node); }