NullReferenceException

This commit is contained in:
2022-08-13 11:19:08 -07:00
parent 3aeab88384
commit 0392de1920
33 changed files with 1278 additions and 1030 deletions

View File

@ -284,29 +284,29 @@ public class C_Resize
return results;
}
public byte[] GetResizedBytes(string outputResolution, List<Tuple<string, DateTime>> subFileTuples, PropertyHolder propertyHolder, A_Property property, Dictionary<string, int[]> imageResizes)
public byte[] GetResizedBytes(string outputResolution, List<Tuple<string, DateTime>> subFileTuples, Item item, A_Property property, Dictionary<string, int[]> imageResizes)
{
byte[] results;
if (propertyHolder.ImageFileHolder is null)
throw new Exception($"{propertyHolder.ImageFileHolder} is null!");
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
if (!imageResizes.ContainsKey(outputResolution))
throw new Exception();
int[] resize = imageResizes[outputResolution];
int outputResolutionWidth = resize[_OutputResolutionWidthIndex];
int outputResolutionHeight = resize[_OutputResolutionHeightIndex];
int outputResolutionOrientation = resize[_OutputResolutionOrientationIndex];
results = SaveResizedSubfile(propertyHolder.ImageFileHolder.FullName, property, resize, fileHolder: null);
results = SaveResizedSubfile(item.ImageFileHolder.FullName, property, resize, fileHolder: null);
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
return results;
}
public void SaveResizedSubfile(string outputResolution, List<Tuple<string, DateTime>> subFileTuples, PropertyHolder propertyHolder, string original, A_Property property, Dictionary<string, int[]> imageResizes)
public void SaveResizedSubfile(string outputResolution, List<Tuple<string, DateTime>> subFileTuples, Item item, string original, A_Property property, Dictionary<string, int[]> imageResizes)
{
if (propertyHolder.ImageFileHolder is null)
throw new Exception($"{propertyHolder.ImageFileHolder} is null!");
if (propertyHolder.ResizedFileHolder is null)
throw new Exception($"{propertyHolder.ResizedFileHolder} is null!");
FileHolder fileHolder = propertyHolder.ResizedFileHolder;
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
if (item.ResizedFileHolder is null)
throw new NullReferenceException(nameof(item.ResizedFileHolder));
FileHolder fileHolder = item.ResizedFileHolder;
if (!imageResizes.ContainsKey(outputResolution))
throw new Exception();
if (!fileHolder.Exists)
@ -318,7 +318,7 @@ public class C_Resize
if (File.Exists(parentCheck))
{
File.Move(parentCheck, fileInfo.FullName);
propertyHolder.SetResizedFileHolder(FileHolder.Refresh(fileHolder));
item.SetResizedFileHolder(FileHolder.Refresh(fileHolder));
}
}
int[] resize = imageResizes[outputResolution];
@ -330,7 +330,7 @@ public class C_Resize
{
if (!fileHolder.Exists)
{
File.Copy(propertyHolder.ImageFileHolder.FullName, fileHolder.FullName);
File.Copy(item.ImageFileHolder.FullName, fileHolder.FullName);
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
}
}
@ -347,7 +347,7 @@ public class C_Resize
check = true;
if (check)
{
_ = SaveResizedSubfile(propertyHolder.ImageFileHolder.FullName, property, resize, fileHolder);
_ = SaveResizedSubfile(item.ImageFileHolder.FullName, property, resize, fileHolder);
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
}
}
@ -422,13 +422,15 @@ public class C_Resize
return results;
}
public Dictionary<string, int[]> GetResizeKeyValuePairs(List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, string original, List<KeyValuePair<string, string>> metadataCollection, A_Property property, PropertyHolder propertyHolder)
public Dictionary<string, int[]> GetResizeKeyValuePairs(List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, string original, List<KeyValuePair<string, string>> metadataCollection, A_Property property, Item item)
{
Dictionary<string, int[]> results;
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
string json;
string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata) };
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
FileInfo fileInfo = new(Path.Combine(AngleBracketCollection[0].Replace("<>", "{}"), string.Concat(propertyHolder.ImageFileNameWithoutExtension, ".json")));
FileInfo fileInfo = new(Path.Combine(AngleBracketCollection[0].Replace("<>", "{}"), string.Concat(item.ImageFileHolder.NameWithoutExtension, ".json")));
if (!fileInfo.Exists)
{
if (fileInfo.Directory?.Parent is null)