public override bool RunTask() { var intermediateFiles = new List <ITaskItem> (); var resolvedFiles = new List <ITaskItem> (); string[] prefixes = Prefixes != null?Prefixes.Split(';') : null; if (prefixes != null) { for (int i = 0; i < prefixes.Length; i++) { string p = prefixes [i]; char c = p [p.Length - 1]; if (c != '\\' && c != '/') { prefixes [i] = p + Path.DirectorySeparatorChar; } } } var nameCaseMap = new StringWriter(); for (int i = 0; i < ResourceFiles.Length; i++) { var item = ResourceFiles [i]; if (Directory.Exists(item.ItemSpec)) { continue; } //compute the target path string rel; var logicalName = item.GetMetadata("LogicalName").Replace('\\', Path.DirectorySeparatorChar); if (item.GetMetadata("IsWearApplicationResource") == "True") { rel = item.ItemSpec.Substring(IntermediateDir.Length); } else if (!string.IsNullOrEmpty(logicalName)) { rel = logicalName; } else { rel = item.GetMetadata("Link").Replace('\\', Path.DirectorySeparatorChar); if (string.IsNullOrEmpty(rel)) { rel = item.GetMetadata("Identity"); if (!string.IsNullOrEmpty(ProjectDir)) { var fullRelPath = Path.GetFullPath(rel).Normalize(NormalizationForm.FormC); var fullProjectPath = Path.GetFullPath(ProjectDir).Normalize(NormalizationForm.FormC); if (fullRelPath.StartsWith(fullProjectPath)) { rel = fullRelPath.Replace(fullProjectPath, string.Empty); } } } } if (Path.IsPathRooted(rel)) { var root = Path.GetPathRoot(rel); rel = rel.Substring(root.Length); } if (prefixes != null) { foreach (var p in prefixes) { if (rel.StartsWith(p)) { rel = rel.Substring(p.Length); } } } string baseFileName = LowercaseFilenames ? rel.ToLowerInvariant() : rel; if (Path.GetExtension(baseFileName) == ".axml") { baseFileName = Path.ChangeExtension(baseFileName, ".xml"); } if (baseFileName != rel) { nameCaseMap.WriteLine("{0}|{1}", rel, baseFileName); } string dest = Path.GetFullPath(Path.Combine(IntermediateDir, baseFileName)); string intermediateDirFullPath = Path.GetFullPath(IntermediateDir); // if the path ends up "outside" of our target intermediate directory, just use the filename if (String.Compare(intermediateDirFullPath, 0, dest, 0, intermediateDirFullPath.Length, StringComparison.OrdinalIgnoreCase) != 0) { dest = Path.GetFullPath(Path.Combine(IntermediateDir, Path.GetFileName(baseFileName))); } var newItem = new TaskItem(dest); newItem.SetMetadata("LogicalName", rel); item.CopyMetadataTo(newItem); intermediateFiles.Add(newItem); resolvedFiles.Add(item); } IntermediateFiles = intermediateFiles.ToArray(); ResolvedResourceFiles = resolvedFiles.ToArray(); ResourceNameCaseMap = nameCaseMap.ToString().Replace(nameCaseMap.NewLine, ";"); Log.LogDebugTaskItems(" IntermediateFiles:", IntermediateFiles); Log.LogDebugTaskItems(" ResolvedResourceFiles:", ResolvedResourceFiles); Log.LogDebugTaskItems(" ResourceNameCaseMap:", ResourceNameCaseMap); return(true); }
public override bool RunTask() { var intermediateFiles = new List <ITaskItem> (ResourceFiles.Length); var resolvedFiles = new List <ITaskItem> (ResourceFiles.Length); string[] prefixes = Prefixes != null?Prefixes.Split(';') : null; if (prefixes != null) { for (int i = 0; i < prefixes.Length; i++) { string p = prefixes [i]; char c = p [p.Length - 1]; if (c != '\\' && c != '/') { prefixes [i] = p + Path.DirectorySeparatorChar; } } } var nameCaseMap = new Dictionary <string, string> (ResourceFiles.Length, StringComparer.Ordinal); for (int i = 0; i < ResourceFiles.Length; i++) { var item = ResourceFiles [i]; if (Directory.Exists(item.ItemSpec)) { continue; } //compute the target path string rel; var logicalName = item.GetMetadata("LogicalName").Replace('\\', Path.DirectorySeparatorChar); if (item.GetMetadata("IsWearApplicationResource") == "True") { rel = item.ItemSpec.Substring(IntermediateDir.Length); } else if (!string.IsNullOrEmpty(logicalName)) { rel = logicalName; } else { rel = item.GetMetadata("Link").Replace('\\', Path.DirectorySeparatorChar); if (string.IsNullOrEmpty(rel)) { rel = item.GetMetadata("Identity"); if (!string.IsNullOrEmpty(ProjectDir)) { var fullRelPath = Path.GetFullPath(rel).Normalize(NormalizationForm.FormC); var fullProjectPath = Path.GetFullPath(ProjectDir).Normalize(NormalizationForm.FormC); if (fullRelPath.StartsWith(fullProjectPath)) { rel = fullRelPath.Replace(fullProjectPath, string.Empty); } } } } if (Path.IsPathRooted(rel)) { var root = Path.GetPathRoot(rel); rel = rel.Substring(root.Length); } if (prefixes != null) { foreach (var p in prefixes) { if (rel.StartsWith(p)) { rel = rel.Substring(p.Length); } } } string baseFileName = LowercaseFilenames ? rel.ToLowerInvariant() : rel; if (Aapt2.IsInvalidFilename(baseFileName)) { Log.LogDebugMessage($"Invalid filename, ignoring: {baseFileName}"); continue; } if (Path.GetExtension(baseFileName) == ".axml") { baseFileName = Path.ChangeExtension(baseFileName, ".xml"); } if (baseFileName != rel) { nameCaseMap [baseFileName] = rel; } string dest = Path.GetFullPath(Path.Combine(IntermediateDir, baseFileName)); string intermediateDirFullPath = Path.GetFullPath(IntermediateDir); // if the path ends up "outside" of our target intermediate directory, just use the filename if (String.Compare(intermediateDirFullPath, 0, dest, 0, intermediateDirFullPath.Length, StringComparison.OrdinalIgnoreCase) != 0) { dest = Path.GetFullPath(Path.Combine(IntermediateDir, Path.GetFileName(baseFileName))); } if (!File.Exists(item.ItemSpec)) { Log.LogCodedError("XA2001", file: item.ItemSpec, lineNumber: 0, message: Properties.Resources.XA2001, item.ItemSpec); continue; } var newItem = new TaskItem(dest); newItem.SetMetadata("LogicalName", rel); newItem.SetMetadata("_FlatFile", Monodroid.AndroidResource.CalculateAapt2FlatArchiveFileName(dest)); newItem.SetMetadata("_ArchiveDirectory", AndroidLibraryFlatFilesDirectory); item.CopyMetadataTo(newItem); intermediateFiles.Add(newItem); resolvedFiles.Add(item); } IntermediateFiles = intermediateFiles.ToArray(); ResolvedResourceFiles = resolvedFiles.ToArray(); MonoAndroidHelper.SaveResourceCaseMap(BuildEngine4, nameCaseMap); return(!Log.HasLoggedErrors); }
public override bool Execute() { Log.LogDebugMessage(" IntermediateDir: {0}", IntermediateDir); Log.LogDebugMessage(" Prefixes: {0}", Prefixes); Log.LogDebugMessage(" ProjectDir: {0}", ProjectDir); Log.LogDebugMessage(" LowercaseFilenames: {0}", LowercaseFilenames); Log.LogDebugTaskItems(" ResourceFiles:", ResourceFiles); IntermediateFiles = new ITaskItem[ResourceFiles.Length]; string[] prefixes = Prefixes != null?Prefixes.Split(';') : null; if (prefixes != null) { for (int i = 0; i < prefixes.Length; i++) { string p = prefixes [i]; char c = p [p.Length - 1]; if (c != '\\' && c != '/') { prefixes [i] = p + Path.DirectorySeparatorChar; } } } var nameCaseMap = new StringWriter(); for (int i = 0; i < ResourceFiles.Length; i++) { var item = ResourceFiles [i]; //compute the target path string rel; var logicalName = item.GetMetadata("LogicalName"); if (item.GetMetadata("IsWearApplicationResource") == "True") { rel = item.ItemSpec.Substring(IntermediateDir.Length); } else if (!string.IsNullOrEmpty(logicalName)) { rel = logicalName; } else { rel = item.GetMetadata("Link"); if (string.IsNullOrEmpty(rel)) { rel = item.GetMetadata("Identity"); if (!string.IsNullOrEmpty(ProjectDir)) { var fullRelPath = Path.GetFullPath(rel); var fullProjectPath = Path.GetFullPath(ProjectDir); if (fullRelPath.StartsWith(fullProjectPath)) { rel = fullRelPath.Replace(fullProjectPath, string.Empty); } } } if (prefixes != null) { foreach (var p in prefixes) { if (rel.StartsWith(p)) { rel = rel.Substring(p.Length); } } } } string baseFileName = LowercaseFilenames ? rel.ToLowerInvariant() : rel; if (Path.GetExtension(baseFileName) == ".axml") { baseFileName = Path.ChangeExtension(baseFileName, ".xml"); } if (baseFileName != rel) { nameCaseMap.WriteLine("{0}|{1}", rel, baseFileName); } string dest = Path.GetFullPath(Path.Combine(IntermediateDir, baseFileName)); var newItem = new TaskItem(dest); newItem.SetMetadata("LogicalName", rel); item.CopyMetadataTo(newItem); IntermediateFiles [i] = newItem; } ResourceNameCaseMap = nameCaseMap.ToString().Replace(nameCaseMap.NewLine, ";"); Log.LogDebugTaskItems(" IntermediateFiles:", IntermediateFiles); Log.LogDebugTaskItems(" ResourceNameCaseMap:", ResourceNameCaseMap); return(true); }
/// <summary> /// Unbinds form variables into the specified target object /// </summary> /// <returns></returns> public bool Unbind() { this.BindingErrors.Clear(); var props = Model.GetType().GetProperties( BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); HttpRequest Request = HttpContext.Current.Request; var prefixes = Prefixes.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); var activePrefix = string.Empty; foreach (string reqKey in Request.Form.Keys) { // skip over 'system' form vars if (reqKey.StartsWith("__")) { continue; } // if a prefix is specified but not provided skip over key if (!string.IsNullOrEmpty(Prefixes)) { if (prefixes.Length == 1) { if (!reqKey.StartsWith(Prefixes)) { continue; } activePrefix = Prefixes; } else { // check each of the prefixes foreach (string prefix in prefixes) { if (reqKey.StartsWith(prefix)) { activePrefix = prefix; break; } } if (string.IsNullOrEmpty(activePrefix)) { continue; } } string key = reqKey.Replace(this.FormVarPropertySeparator, "."); if (!string.IsNullOrEmpty(activePrefix)) { key = key.Replace(activePrefix, ""); } // Check for invalid property names or excluded keys if (key.StartsWith(".") || PropertyExceptionList.Where(s => s.ToLower() == reqKey.ToLower()).Count() > 0) { continue; } // We'll check the the first 'property' in chain against our property list // to see whether it's a property we need to look up string propertyKey = key; if (key.IndexOf(".") > 1) { propertyKey = key.Substring(0, key.IndexOf(".")); } PropertyInfo prop = props.Where(p => p.Name.ToLower() == propertyKey.ToLower()).FirstOrDefault(); // If we found a match try to bind it - otherwise skip over if (prop != null) { string val = Request.Form[reqKey]; object objVal = null; try { if (key == propertyKey) { objVal = ReflectionUtils.StringToTypedValue(val, prop.PropertyType); prop.SetValue(Model, objVal, null); } else { // Retrieve the type and convert from string to type prop = ReflectionUtils.GetPropertyInfoEx(Model, key); // No match just continue looping thru form vars if (prop == null) { continue; } // Conversion objVal = ReflectionUtils.StringToTypedValue(val, prop.PropertyType); // Assign value to complex type ReflectionUtils.SetPropertyEx(Model, key, objVal); } } catch (Exception ex) { if (ex.InnerException != null) { ex = ex.InnerException; } BindingErrors.Add(new BindingError() { ClientID = key, Message = ex.Message, ErrorMessage = ex.Message }); } } } } if (BindingErrors.Count > 0) { return(false); } return(true); }