BililiveRecorder/BililiveRecorder.WPF/MockData/MockRecorder.cs

165 lines
5.2 KiB
C#
Raw Normal View History

2020-11-27 18:51:02 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using BililiveRecorder.Core;
2021-01-01 14:46:27 +08:00
using BililiveRecorder.Core.Config.V2;
2020-11-27 18:51:02 +08:00
namespace BililiveRecorder.WPF.MockData
{
#if DEBUG
internal class MockRecorder : IRecorder
{
private bool disposedValue;
public MockRecorder()
{
2021-01-01 14:46:27 +08:00
this.Rooms.Add(new MockRecordedRoom
2020-11-27 18:51:02 +08:00
{
IsMonitoring = false,
IsRecording = false
});
2021-01-01 14:46:27 +08:00
this.Rooms.Add(new MockRecordedRoom
2020-11-27 18:51:02 +08:00
{
IsMonitoring = true,
IsRecording = false
});
2021-01-01 14:46:27 +08:00
this.Rooms.Add(new MockRecordedRoom
2020-11-27 18:51:02 +08:00
{
DownloadSpeedPersentage = 100,
DownloadSpeedMegaBitps = 12.45
});
2021-01-01 14:46:27 +08:00
this.Rooms.Add(new MockRecordedRoom
2020-11-27 18:51:02 +08:00
{
DownloadSpeedPersentage = 95,
DownloadSpeedMegaBitps = 789.45
});
2021-01-01 14:46:27 +08:00
this.Rooms.Add(new MockRecordedRoom
2020-11-27 18:51:02 +08:00
{
DownloadSpeedPersentage = 90
});
2021-01-01 14:46:27 +08:00
this.Rooms.Add(new MockRecordedRoom
2020-11-27 18:51:02 +08:00
{
DownloadSpeedPersentage = 85
});
2021-01-01 14:46:27 +08:00
this.Rooms.Add(new MockRecordedRoom
2020-11-27 18:51:02 +08:00
{
DownloadSpeedPersentage = 80
});
2021-01-01 14:46:27 +08:00
this.Rooms.Add(new MockRecordedRoom
2020-11-27 18:51:02 +08:00
{
DownloadSpeedPersentage = 75
});
2021-01-01 14:46:27 +08:00
this.Rooms.Add(new MockRecordedRoom
2020-11-27 18:51:02 +08:00
{
DownloadSpeedPersentage = 70
});
2021-01-01 14:46:27 +08:00
this.Rooms.Add(new MockRecordedRoom
2020-11-27 18:51:02 +08:00
{
DownloadSpeedPersentage = 109
});
}
private ObservableCollection<IRecordedRoom> Rooms { get; } = new ObservableCollection<IRecordedRoom>();
2021-01-01 14:46:27 +08:00
public ConfigV2 Config { get; } = new ConfigV2();
2020-11-27 18:51:02 +08:00
2021-01-01 14:46:27 +08:00
public int Count => this.Rooms.Count;
2020-11-27 18:51:02 +08:00
public bool IsReadOnly => true;
2021-01-01 14:46:27 +08:00
int ICollection<IRecordedRoom>.Count => this.Rooms.Count;
2020-11-27 18:51:02 +08:00
bool ICollection<IRecordedRoom>.IsReadOnly => true;
2021-01-01 14:46:27 +08:00
public IRecordedRoom this[int index] => this.Rooms[index];
2020-11-27 18:51:02 +08:00
public event PropertyChangedEventHandler PropertyChanged
{
2021-01-01 14:46:27 +08:00
add => (this.Rooms as INotifyPropertyChanged).PropertyChanged += value;
remove => (this.Rooms as INotifyPropertyChanged).PropertyChanged -= value;
2020-11-27 18:51:02 +08:00
}
public event NotifyCollectionChangedEventHandler CollectionChanged
{
2021-01-01 14:46:27 +08:00
add => (this.Rooms as INotifyCollectionChanged).CollectionChanged += value;
remove => (this.Rooms as INotifyCollectionChanged).CollectionChanged -= value;
2020-11-27 18:51:02 +08:00
}
void ICollection<IRecordedRoom>.Add(IRecordedRoom item) => throw new NotSupportedException("Collection is readonly");
void ICollection<IRecordedRoom>.Clear() => throw new NotSupportedException("Collection is readonly");
bool ICollection<IRecordedRoom>.Remove(IRecordedRoom item) => throw new NotSupportedException("Collection is readonly");
2021-01-01 14:46:27 +08:00
bool ICollection<IRecordedRoom>.Contains(IRecordedRoom item) => this.Rooms.Contains(item);
2020-11-27 18:51:02 +08:00
2021-01-01 14:46:27 +08:00
void ICollection<IRecordedRoom>.CopyTo(IRecordedRoom[] array, int arrayIndex) => this.Rooms.CopyTo(array, arrayIndex);
2020-11-27 18:51:02 +08:00
2021-01-01 14:46:27 +08:00
public IEnumerator<IRecordedRoom> GetEnumerator() => this.Rooms.GetEnumerator();
2020-11-27 18:51:02 +08:00
2021-01-01 14:46:27 +08:00
IEnumerator<IRecordedRoom> IEnumerable<IRecordedRoom>.GetEnumerator() => this.Rooms.GetEnumerator();
2020-11-27 18:51:02 +08:00
2021-01-01 14:46:27 +08:00
IEnumerator IEnumerable.GetEnumerator() => this.Rooms.GetEnumerator();
2020-11-27 18:51:02 +08:00
public bool Initialize(string workdir)
{
2021-01-01 14:46:27 +08:00
this.Config.Global.WorkDirectory = workdir;
2020-11-27 18:51:02 +08:00
return true;
}
public void AddRoom(int roomid)
{
2021-01-01 14:46:27 +08:00
this.AddRoom(roomid, false);
2020-11-27 18:51:02 +08:00
}
public void AddRoom(int roomid, bool enabled)
{
2021-01-01 14:46:27 +08:00
this.Rooms.Add(new MockRecordedRoom { RoomId = roomid, IsMonitoring = enabled });
2020-11-27 18:51:02 +08:00
}
public void RemoveRoom(IRecordedRoom rr)
{
2021-01-01 14:46:27 +08:00
this.Rooms.Remove(rr);
2020-11-27 18:51:02 +08:00
}
public void SaveConfigToFile()
{
}
protected virtual void Dispose(bool disposing)
{
2021-01-01 14:46:27 +08:00
if (!this.disposedValue)
2020-11-27 18:51:02 +08:00
{
if (disposing)
{
// dispose managed state (managed objects)
2021-01-01 14:46:27 +08:00
this.Rooms.Clear();
2020-11-27 18:51:02 +08:00
}
// free unmanaged resources (unmanaged objects) and override finalizer
// set large fields to null
2021-01-01 14:46:27 +08:00
this.disposedValue = true;
2020-11-27 18:51:02 +08:00
}
}
// override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~MockRecorder()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
2021-01-01 14:46:27 +08:00
this.Dispose(disposing: true);
2020-11-27 18:51:02 +08:00
GC.SuppressFinalize(this);
}
}
#endif
}