blob: 03b1ffe8770b276db2f0ed06ecfd505afd70425e (
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
using Google.Protobuf;
using Google.Protobuf.Reflection;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Tango.PMR.Common;
using Tango.PMR.DataStore;
using Tango.PMR.Integration;
using Tango.PMR.Printing;
/// <summary>
/// Contains PMR extension methods.
/// </summary>
public static class ExtensionMethods
{
/// <summary>
/// Gets the protobuf <see cref="OriginalNameAttribute"/> attribute value from the message type.
/// </summary>
/// <param name="value">The value.</param>
/// <returns></returns>
public static String ToOriginalName(this MessageType value)
{
FieldInfo fi = value.GetType().GetField(value.ToString());
OriginalNameAttribute[] attributes = (OriginalNameAttribute[])fi.GetCustomAttributes(typeof(OriginalNameAttribute), false);
if (attributes != null &&
attributes.Length > 0)
return attributes[0].Name;
else
return value.ToString();
}
public static String ToOriginalName(this DataStoreMessageType value)
{
FieldInfo fi = value.GetType().GetField(value.ToString());
OriginalNameAttribute[] attributes = (OriginalNameAttribute[])fi.GetCustomAttributes(typeof(OriginalNameAttribute), false);
if (attributes != null &&
attributes.Length > 0)
return attributes[0].Name;
else
return value.ToString();
}
/// <summary>
/// Gets the message parser.
/// </summary>
/// <param name="message">The message.</param>
/// <returns></returns>
public static MessageParser GetParser(this IMessage message)
{
MessageParser parser = message.GetType().GetProperty("Parser").GetValue(message) as MessageParser;
return parser;
}
/// <summary>
/// Determines whether the specified intent requires a password.
/// </summary>
/// <param name="intent">The intent.</param>
/// <returns></returns>
public static bool RequiresPassword(this ExternalBridgeLoginIntent intent)
{
return
intent == ExternalBridgeLoginIntent.Diagnostics
||
intent == ExternalBridgeLoginIntent.FullControl;
}
/// <summary>
/// Gets the name of the generic request type.
/// </summary>
/// <param name="request">The request.</param>
/// <returns></returns>
public static String GetTypeName(this GenericRequest request)
{
try
{
return request.Type.Split(',').First().Split('.').Last();
}
catch
{
return request.Type;
}
}
/// <summary>
/// Gets the name of the generic response type.
/// </summary>
/// <param name="response">The response.</param>
/// <returns></returns>
public static String GetTypeName(this GenericResponse response)
{
try
{
return response.Type.Split(',').First().Split('.').Last();
}
catch
{
return response.Type;
}
}
/// <summary>
/// Determines whether this segment is a group.
/// </summary>
/// <param name="segment">The segment.</param>
/// <returns>
/// <c>true</c> if the specified segment is group; otherwise, <c>false</c>.
/// </returns>
public static bool IsGroup(this Tango.PMR.Exports.JobFileSegment segment)
{
return segment.Segments != null && segment.Segments.Count > 0;
}
/// <summary>
/// Gets the total nanoliter per centimeter for this stop.
/// </summary>
/// <param name="stop">The stop.</param>
/// <returns></returns>
public static double GetTotalNanoliterPerCentimeter(this JobBrushStop stop)
{
return stop.Dispensers.Where(x => x.DispenserLiquidType != DispenserLiquidType.Lubricant && x.DispenserLiquidType != DispenserLiquidType.Cleaner).Sum(x => x.NanoliterPerCentimeter);
}
/// <summary>
/// Sets the transparent ink nanoliter per centimeter.
/// </summary>
/// <param name="stop">The stop.</param>
/// <param name="nlPerCM">The nl per cm.</param>
/// <param name="minInkUptake">The minimum ink uptake.</param>
/// <param name="dyeingSpeed">The dyeing speed.</param>
/// <param name="nlPerStep">The nl per step.</param>
public static void NormalizeStop(this JobBrushStop stop, double nlPerCM, double minInkUptake, double dyeingSpeed)
{
double nlPcmSum = stop.Dispensers.Where(x => x.DispenserLiquidType != DispenserLiquidType.Cleaner && x.DispenserLiquidType != DispenserLiquidType.Lubricant && x.DispenserLiquidType != DispenserLiquidType.Transparent).Sum(x => x.NanoliterPerCentimeter);
var ti = stop.Dispensers.FirstOrDefault(x => x.DispenserLiquidType == DispenserLiquidType.Transparent);
if (ti == null) return;
//if (Math.Max(0, minInkUptake - nlPcmSum) < minInkUptake * 0.02d) return;
if (Math.Max(0, nlPerCM - nlPcmSum) < nlPerCM * 0.02d) return; //Daria change
double newNlCM = Math.Max(0, nlPerCM - nlPcmSum);
ti.NanoliterPerCentimeter = newNlCM;
ti.NanolitterPerSecond = newNlCM * dyeingSpeed;
}
}
|