diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2023-07-24 17:18:46 +0300 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2023-07-24 17:18:46 +0300 |
| commit | 13012a106aac961eaba844b2f525287a0e021b2d (patch) | |
| tree | a51d1c93e72c3ddd18e918f8b2127055236bf3f0 /Software/Visual_Studio/PPC/Modules | |
| parent | 888321b9a6c284a02dafcc86b7332d2872c95cf4 (diff) | |
| parent | 95c5bd35287dd59f98550cfbb67c7c4d6ffbbb14 (diff) | |
| download | Tango-13012a106aac961eaba844b2f525287a0e021b2d.tar.gz Tango-13012a106aac961eaba844b2f525287a0e021b2d.zip | |
Merge Roy & Vica Resume Job.
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules')
6 files changed, 263 insertions, 43 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeDB.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeDB.cs new file mode 100644 index 000000000..b2dcffcdd --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeDB.cs @@ -0,0 +1,83 @@ +using LiteDB; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Jobs.Resume +{ + public class JobResumeDB : IDisposable + { + private LiteDatabase _db; + private ILiteCollection<JobResumeModel> _collection; + + private static Lazy<JobResumeDB> _default = new Lazy<JobResumeDB>(() => new JobResumeDB()); + + public static JobResumeDB Default + { + get + { + return _default.Value; + } + } + + private JobResumeDB() + { + Init(); + } + + private void Init() + { + String dbFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Job Resume v2"); + Directory.CreateDirectory(dbFolder); + _db = new LiteDatabase($"Filename={Path.Combine(dbFolder, "job_resume.db")}"); + _collection = _db.GetCollection<JobResumeModel>("JobResume"); + } + + public void Update(JobResumeModel model) + { + _collection.Update(model); + } + + public void Add(JobResumeModel model) + { + _collection.Insert(model); + } + + public List<JobResumeModel> GetAll() + { + return _collection.FindAll().ToList(); + } + + public JobResumeModel Get(String jobGuild) + { + return _collection.FindOne(x => x.JobGuid == jobGuild); + } + + public void Delete(JobResumeModel model) + { + _collection.Delete(model.JobGuid); + } + + public void Delete(String jobGuid) + { + _collection.Delete(jobGuid); + } + + ~JobResumeDB() + { + Dispose(); + } + + public void Dispose() + { + try + { + _db?.Dispose(); + } + catch { } + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeModel.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeModel.cs new file mode 100644 index 000000000..4ded7e313 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeModel.cs @@ -0,0 +1,21 @@ +using LiteDB; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Jobs.Resume +{ + public class JobResumeModel + { + [BsonId] + public String JobGuid { get; set; } + + public int RemainingUnits { get; set; } + + public double GlobalStartPosition { get; set; } + + public double FirstUnitStartPosition { get; set; } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj index 3aefa29a1..a55f1c91e 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj @@ -351,6 +351,8 @@ <DependentUpon>ColorCorrectionReport.xaml</DependentUpon> </Compile> <Compile Include="Reports\ColorCorrectionRepotVM.cs" /> + <Compile Include="Resume\JobResumeDB.cs" /> + <Compile Include="Resume\JobResumeModel.cs" /> <Compile Include="UndoRedoCommands\AddBrushStopCommand.cs" /> <Compile Include="UndoRedoCommands\AddNewSegmentCommand.cs" /> <Compile Include="UndoRedoCommands\ChangeLengthCommand.cs" /> @@ -754,7 +756,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs index 0b7d2ce88..65ffca36a 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs @@ -46,6 +46,8 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Tango.PPC.Jobs.ColorCorrectionTool; using Tango.PPC.Common.Printing; +using Tango.PPC.Jobs.Resume; +using Tango.Core.ExtensionMethods; namespace Tango.PPC.Jobs.ViewModels { @@ -229,12 +231,12 @@ namespace Tango.PPC.Jobs.ViewModels get { return _isBasicMode; } set { - if(_isBasicMode != value) - { - if(value == true && JobModel != null && JobModel.Segments.Count > 0) + if (_isBasicMode != value) + { + if (value == true && JobModel != null && JobModel.Segments.Count > 0) { var firstSegment = JobModel.Segments.Where(x => x.SegmentIndex == 1).FirstOrDefault(); - if(JobModel.Segments.Count > 1 || firstSegment.IsGradient ) + if (JobModel.Segments.Count > 1 || firstSegment.IsGradient) { SetOrDiscardAll(); return; @@ -262,11 +264,12 @@ namespace Tango.PPC.Jobs.ViewModels public bool IsWeightView { get { return _isWeigthView; } - set { - if(_isWeigthView != value) + set + { + if (_isWeigthView != value) { _isWeigthView = value; - + RaisePropertyChangedAuto(); } } @@ -277,10 +280,24 @@ namespace Tango.PPC.Jobs.ViewModels public bool ShowAdvanced { get { return _showAdvanced; } - set { _showAdvanced = value; - RaisePropertyChangedAuto();} + set + { + _showAdvanced = value; + RaisePropertyChangedAuto(); + } + } + + private JobResumeModel _resumeModel; + public JobResumeModel ResumeModel + { + get { return _resumeModel; } + set { _resumeModel = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasResumeModel)); } } + public bool HasResumeModel + { + get { return ResumeModel != null; } + } #endregion @@ -336,7 +353,7 @@ namespace Tango.PPC.Jobs.ViewModels public RelayCommand<SegmentsGroupModel> DeleteSegmentsGroupCommand { get; set; } public RelayCommand<SegmentsGroupModel> RepeatSegmentsGroupCommand { get; set; } - public RelayCommand NavigateBackToJobs { get; set; } + public RelayCommand NavigateBackToJobs { get; set; } #endregion @@ -417,13 +434,13 @@ namespace Tango.PPC.Jobs.ViewModels _not_show_warning = false; } - #endregion + #endregion #region Job Management /// <summary> - /// Loads the job. - /// </summary> + /// Loads the job. + /// </summary> private async void LoadJob() { try @@ -480,6 +497,20 @@ namespace Tango.PPC.Jobs.ViewModels .WithSegmentsGroups() .BuildAsync(); + try + { + ResumeModel = JobResumeDB.Default.Get(Job.Guid); + + if (ResumeModel != null) + { + LogManager.Log($"Job resume info found:\n{ResumeModel.ToJsonString()}"); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error retrieving job resume info from db."); + } + RaisePropertyChanged(nameof(CanEdit)); Job.NameChanged -= Job_NameChanged; @@ -511,7 +542,7 @@ namespace Tango.PPC.Jobs.ViewModels IsBasicMode = true; } else IsBasicMode = false; - IsWeightView = false; + IsWeightView = false; LoadJobModel(); @@ -592,7 +623,7 @@ namespace Tango.PPC.Jobs.ViewModels JobType = Job.JobType, InterSegmentLength = Job.InterSegmentLength, EnableInterSegment = Job.EnableInterSegment, - NumberSpools = (BuildProvider.IsEureka? Job.Spools : 1), + NumberSpools = (BuildProvider.IsEureka ? Job.Spools : 1), Copies = (BuildProvider.IsEureka ? Job.NumberOfUnits * Job.Spools : Job.NumberOfUnits) }; Dictionary<string, SegmentsGroupModel> guidToGroup = new Dictionary<string, SegmentsGroupModel>(); @@ -725,7 +756,17 @@ namespace Tango.PPC.Jobs.ViewModels startingJob = true; LogManager.Log("Start job command pressed. Starting job and navigating to job progress view..."); await Save(); - var handler = await PrintingManager.Print(Job, _db, new PrintingConfiguration() { }); + + var printConfig = new PrintingConfiguration(); + + if (HasResumeModel) + { + printConfig.FirstUnitStartPosition = ResumeModel.FirstUnitStartPosition; + printConfig.GlobalStartPosition = ResumeModel.GlobalStartPosition; + printConfig.RemainingUnits = ResumeModel.RemainingUnits; + } + + var handler = await PrintingManager.Print(Job, _db, printConfig); RaisePropertyChanged(nameof(CanEdit)); @@ -923,7 +964,7 @@ namespace Tango.PPC.Jobs.ViewModels .WithSpools() .BuildAsync(); if (JobModel != null) - { + { JobModel.Rml = Job.Rml; } @@ -936,7 +977,7 @@ namespace Tango.PPC.Jobs.ViewModels { innerSegment.UpdateWeightOnRMLChange(IsWeightView); innerSegment.UpdateBrushStops(); - + } else if (segment is SegmentsGroupModel group) { @@ -1275,21 +1316,6 @@ namespace Tango.PPC.Jobs.ViewModels MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; } - private void MachineOperator_PrintingStarted(object sender, PrintingEventArgs e) - { - RaisePropertyChanged(nameof(CanEdit)); - } - - private void MachineOperator_PrintingEnded(object sender, Integration.Operation.PrintingEventArgs e) - { - if (IsVisible) - { - _start_printing_btn.Push(); - } - - RaisePropertyChanged(nameof(CanEdit)); - } - /// <summary> /// Called when the navigation system has navigated to this VM view. /// </summary> @@ -1362,14 +1388,14 @@ namespace Tango.PPC.Jobs.ViewModels private async void NavigateBack() { - if (IsFree ) + if (IsFree) { - if(await OnNavigateBackRequest()) + if (await OnNavigateBackRequest()) { LogManager.Log("Back command to Jobs pressed."); await NavigationManager.NavigateTo<JobsV2Module>(nameof(JobsView)); } - + } } @@ -1490,11 +1516,11 @@ namespace Tango.PPC.Jobs.ViewModels DyeCommand.RaiseCanExecuteChanged(); } - private void SetOrDiscardAll() + private void SetOrDiscardAll() { InvokeUI(async () => { - IsBasicMode = await MessageDiscardAllChanges(); + IsBasicMode = await MessageDiscardAllChanges(); }); } @@ -1509,7 +1535,7 @@ namespace Tango.PPC.Jobs.ViewModels { //delete all var segments = JobModel.OrderedSegmentsWithGroups; - var firstSegment = JobModel.Segments.Where(x=>x.SegmentIndex == 1).FirstOrDefault(); + var firstSegment = JobModel.Segments.Where(x => x.SegmentIndex == 1).FirstOrDefault(); firstSegment.SegmentsGroupModel = null; JobModel.GroupingSegments.Clear(); JobModel.Segments.Clear(); @@ -1522,7 +1548,7 @@ namespace Tango.PPC.Jobs.ViewModels firstSegment.BrushStops.Add(firstbrush); firstSegment.ArrangeBrushStopsIndexes(); } - + return true; } return false; @@ -1737,5 +1763,82 @@ namespace Tango.PPC.Jobs.ViewModels } #endregion + + #region Machine Operator Events + + private void MachineOperator_PrintingStarted(object sender, PrintingEventArgs e) + { + RaisePropertyChanged(nameof(CanEdit)); + } + + private void MachineOperator_PrintingEnded(object sender, Integration.Operation.PrintingEventArgs e) + { + if (IsVisible) + { + _start_printing_btn.Push(); + } + + RaisePropertyChanged(nameof(CanEdit)); + + UpdateJobResume(e); + } + + + #endregion + + #region Resume + + private void UpdateJobResume(PrintingEventArgs e) + { + try + { + if (!e.JobHandler.Status.IsCompleted) + { + if (e.JobHandler.JobStatus.Progress <= 0) return; + + var model = JobResumeDB.Default.Get(e.Job.Guid); + bool insert = false; + if (model == null) + { + model = new JobResumeModel(); + insert = true; + } + + model.JobGuid = e.Job.Guid; + model.FirstUnitStartPosition = e.JobHandler.Status.CurrentUnitProgress; + model.RemainingUnits = e.JobHandler.Status.RemainingUnits; + model.GlobalStartPosition = e.JobHandler.JobStatus.Progress; + + if (insert) + { + JobResumeDB.Default.Add(model); + } + else + { + JobResumeDB.Default.Update(model); + } + + if (Job.Guid == e.Job.Guid) + { + ResumeModel = model; + } + } + else + { + JobResumeDB.Default.Delete(e.Job.Guid); + + if (Job.Guid == e.Job.Guid) + { + ResumeModel = null; + } + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error inserting/updating job resume info on db."); + } + } + + #endregion } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobEurekaView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobEurekaView.xaml index fa8fc0b9d..aa54beb9a 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobEurekaView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Views/JobEurekaView.xaml @@ -1358,7 +1358,18 @@ </DockPanel> <Canvas ClipToBounds="False" HorizontalAlignment="Right" Width="200"> - <touch:TouchButton Content="DYE" VerticalAlignment="Center" Height="55" Canvas.Top="10" Width="200" CornerRadius="30" BlurRadius="10" EnableDropShadow="False" Command="{Binding DyeCommand}" IsEnabled="{Binding MachineProvider.MachineOperator.CanPrint}"></touch:TouchButton> + <touch:TouchButton VerticalAlignment="Center" Height="55" Canvas.Top="10" Width="200" CornerRadius="30" BlurRadius="10" EnableDropShadow="False" Command="{Binding DyeCommand}" IsEnabled="{Binding MachineProvider.MachineOperator.CanPrint}"> + <touch:TouchButton.Style> + <Style TargetType="touch:TouchButton" BasedOn="{StaticResource {x:Type touch:TouchButton}}"> + <Setter Property="Content" Value="DYE"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding HasResumeModel}" Value="True"> + <Setter Property="Content" Value="RESUME"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </touch:TouchButton.Style> + </touch:TouchButton> </Canvas> </Grid> </Border> diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs index a76096725..db30c01b1 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs @@ -113,7 +113,7 @@ namespace Tango.PPC.Storage.ViewModels { if (Settings.StorageRootPath == null) { - Settings.StorageRootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Storage"); + Settings.StorageRootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Twine", "Storage"); Directory.CreateDirectory(Settings.StorageRootPath); } } |
