blob: f62093d58faa869b4c5727ab7a71fa60a1e3391f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UVtools.Core.Operations;
namespace UVtools.Core.Managers
{
public class OperationSessionManager : IList<Operation>
{
#region Settings
//public static string FilePath;
#endregion
#region Singleton
private static Lazy<OperationSessionManager> _instanceHolder =
new(() => new OperationSessionManager());
public static OperationSessionManager Instance => _instanceHolder.Value;
#endregion
#region Members
private readonly List<Operation> _operations = new();
#endregion
#region Properties
#endregion
#region Constructor
private OperationSessionManager()
{
}
#endregion
#region Methods
public Operation Find(Type type)
{
return this.FirstOrDefault(operation => operation.GetType() == type);
}
public Operation Find(Operation fromOperation) => Find(fromOperation.GetType());
#endregion
#region List Implementation
public IEnumerator<Operation> GetEnumerator()
{
return _operations.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable) _operations).GetEnumerator();
}
public void Add(Operation item)
{
if (item is null) return;
_operations.RemoveAll(operation => operation.GetType() == item.GetType());
_operations.Add(item.Clone());
}
public void Clear()
{
_operations.Clear();
}
public bool Contains(Operation item)
{
return _operations.Contains(item);
}
public void CopyTo(Operation[] array, int arrayIndex)
{
_operations.CopyTo(array, arrayIndex);
}
public bool Remove(Operation item)
{
return _operations.Remove(item);
}
public int Count => _operations.Count;
public bool IsReadOnly => ((ICollection<Operation>) _operations).IsReadOnly;
public int IndexOf(Operation item)
{
return _operations.IndexOf(item);
}
public void Insert(int index, Operation item)
{
if (item is null) return;
_operations.RemoveAll(operation => operation.GetType() == item.GetType());
_operations.Insert(index, item.Clone());
}
public void RemoveAt(int index)
{
_operations.RemoveAt(index);
}
public Operation this[int index]
{
get => _operations[index];
set => _operations[index] = value;
}
#endregion
}
}
|