aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-04 19:24:05 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-04 19:24:05 +0300
commitda9d6fd74eed7424836956811cff05bf4247ac40 (patch)
treee9acad3fba7efd30d51afe6cec5a3c916d2b30fa /Software/Visual_Studio
parent57a2806b7d5fe6f5656136258714201d60d9bfe4 (diff)
downloadTango-da9d6fd74eed7424836956811cff05bf4247ac40.tar.gz
Tango-da9d6fd74eed7424836956811cff05bf4247ac40.zip
Fixed issue with procedure Send method "messageName" entry and confusion with params array.
Improved intellisense for fields of declared libraries.
Diffstat (limited to 'Software/Visual_Studio')
-rw-r--r--Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/IProcedureContext.cs4
-rw-r--r--Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs6
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.BL/EntityRepositoryBase.cs54
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachineEventsService.cs33
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachinesService.cs33
-rw-r--r--Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs109
6 files changed, 155 insertions, 84 deletions
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/IProcedureContext.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/IProcedureContext.cs
index 9b2436c71..e93311d80 100644
--- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/IProcedureContext.cs
+++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/IProcedureContext.cs
@@ -96,7 +96,7 @@ namespace Tango.FSE.Procedures
/// <param name="timeout">The timeout in seconds.</param>
/// <param name="args">The arguments separated by commas.</param>
/// <returns></returns>
- IMessage Send(String messageName, int? timeout = null, params Object[] args);
+ IMessage Send(String messageName, TimeSpan? timeout = null, params Object[] args);
/// <summary>
/// Sends a request by name with optional comma separated arguments.
@@ -114,7 +114,7 @@ namespace Tango.FSE.Procedures
/// <param name="timeout">The timeout in seconds.</param>
/// <param name="args">The arguments separated by commas.</param>
/// <returns></returns>
- T Send<T>(String messageName, int? timeout = null, params Object[] args) where T : class, IMessage;
+ T Send<T>(String messageName, TimeSpan? timeout = null, params Object[] args) where T : class, IMessage;
/// <summary>
/// Sends a request by name with optional comma separated arguments.
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs
index fdfe6af9a..ef5664772 100644
--- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs
+++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures/ProcedureContext.cs
@@ -82,7 +82,7 @@ namespace Tango.FSE.Procedures
TangoIOC.Default.Inject(this);
}
- public IMessage Send(string messageName, int? timeout = null, params object[] args)
+ public IMessage Send(string messageName, TimeSpan? timeout = null, params object[] args)
{
var stubType = MessageFactory.GetAvailableRequestStubs().SingleOrDefault(x => x.Name.ToLower() == messageName.ToLower() || x.Name.Replace("Request", "").ToLower() == messageName.ToLower());
if (stubType == null)
@@ -123,7 +123,7 @@ namespace Tango.FSE.Procedures
}
}
- return Send(request as IMessage, timeout);
+ return Send(request as IMessage, timeout != null ? (int?)timeout.Value.TotalSeconds : null);
}
public IMessage Send(string messageName, params object[] args)
@@ -131,7 +131,7 @@ namespace Tango.FSE.Procedures
return Send(messageName, null, args);
}
- public T Send<T>(string messageName, int? timeout = null, params object[] args) where T : class, IMessage
+ public T Send<T>(string messageName, TimeSpan? timeout = null, params object[] args) where T : class, IMessage
{
return Send(messageName, timeout, args) as T;
}
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.BL/EntityRepositoryBase.cs b/Software/Visual_Studio/FSE/Tango.FSE.BL/EntityRepositoryBase.cs
index e14b61f22..3bc183d11 100644
--- a/Software/Visual_Studio/FSE/Tango.FSE.BL/EntityRepositoryBase.cs
+++ b/Software/Visual_Studio/FSE/Tango.FSE.BL/EntityRepositoryBase.cs
@@ -46,17 +46,38 @@ namespace Tango.FSE.BL
{
var entities = db.Set<TEntity>().Where(expression).ToList();
- using (var cache = DiskCache.CreateContext())
- {
- var collection = cache.Database.GetCollection<TCachedEntity>();
+ List<TCachedEntity> cachedEntities = new List<TCachedEntity>();
+ try
+ {
foreach (var entity in entities)
{
var cachedEntity = ConvertToCached(entity);
+ cachedEntities.Add(cachedEntity);
_memoryCache.Put(entity.Guid, cachedEntity);
- collection.Upsert(cachedEntity);
}
}
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Error occurred while trying to cache entities of type '{typeof(TEntity).Name}' to memory.");
+ }
+
+ try
+ {
+ using (var cache = DiskCache.CreateContext())
+ {
+ var collection = cache.Database.GetCollection<TCachedEntity>();
+
+ foreach (var cachedEntity in cachedEntities)
+ {
+ collection.Upsert(cachedEntity);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Error occurred while trying to cache entities of type '{typeof(TEntity).Name}' to disk.");
+ }
return entities;
}
@@ -104,12 +125,29 @@ namespace Tango.FSE.BL
{
var entity = db.Set<TEntity>().First(expression);
- using (var cache = DiskCache.CreateContext())
+ try
{
- var collection = cache.Database.GetCollection<TCachedEntity>();
- var cachedEntity = ConvertToCached(entity);
+ TCachedEntity cachedEntity = null;
+
+ cachedEntity = ConvertToCached(entity);
_memoryCache.Put(entity.Guid, cachedEntity);
- collection.Upsert(cachedEntity);
+
+ try
+ {
+ using (var cache = DiskCache.CreateContext())
+ {
+ var collection = cache.Database.GetCollection<TCachedEntity>();
+ collection.Upsert(cachedEntity);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Error caching entity '{entity.Guid}' of type '{typeof(TEntity).Name}' to disk.");
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Error caching entity '{entity.Guid}' of type '{typeof(TEntity).Name}'.");
}
return entity;
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachineEventsService.cs b/Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachineEventsService.cs
index bba9caf94..4b2609a94 100644
--- a/Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachineEventsService.cs
+++ b/Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachineEventsService.cs
@@ -43,26 +43,37 @@ namespace Tango.FSE.BL.Services
{
var eventTypes = db.EventTypes.ToList();
- using (var cache = DiskCache.CreateContext())
- {
- var collection = cache.Database.GetCollection<CachedEventType>(EVENT_TYPES_COLLECTION);
+ List<CachedEventType> cachedEventTypes = new List<CachedEventType>();
+ try
+ {
foreach (var eventType in eventTypes)
{
- try
- {
- var cachedEventType = CachedEventType.FromObservable<CachedEventType>(eventType);
+ var cachedEventType = CachedEventType.FromObservable<CachedEventType>(eventType);
+ _eventTypesCache.Put(cachedEventType.Guid, cachedEventType);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error caching event types on memory.");
+ }
- _eventTypesCache.Put(cachedEventType.Guid, cachedEventType);
+ try
+ {
+ using (var cache = DiskCache.CreateContext())
+ {
+ var collection = cache.Database.GetCollection<CachedEventType>(EVENT_TYPES_COLLECTION);
- collection.Upsert(cachedEventType);
- }
- catch (Exception ex)
+ foreach (var cachedEventType in cachedEventTypes)
{
- LogManager.Log(ex, $"Error caching event type '{eventType.Guid}' on disk.");
+ collection.Upsert(cachedEventType);
}
}
}
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error caching event types to disk.");
+ }
return eventTypes;
}
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachinesService.cs b/Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachinesService.cs
index 8e07551b1..c77bb79c0 100644
--- a/Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachinesService.cs
+++ b/Software/Visual_Studio/FSE/Tango.FSE.BL/Services/MachinesService.cs
@@ -265,26 +265,37 @@ namespace Tango.FSE.BL.Services
{
var machines = db.Machines.Where(x => allowAll || x.OrganizationGuid == CurrentUser.OrganizationGuid).Include(x => x.Organization).ToList();
- using (var cache = DiskCache.CreateContext())
- {
- var collection = cache.Database.GetCollection<CachedMachine>(MACHINES_COLLECTION);
+ List<CachedMachine> cachedMachines = new List<CachedMachine>();
+ try
+ {
foreach (var machine in machines)
{
- try
- {
- var cachedMachine = CachedMachine.FromObservable<CachedMachine>(machine);
+ var cachedMachine = CachedMachine.FromObservable<CachedMachine>(machine);
+ _machinesCache.Put(machine.SerialNumber, cachedMachine);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error caching machines (partial) to memory.");
+ }
- _machinesCache.Put(machine.SerialNumber, cachedMachine);
+ try
+ {
+ using (var cache = DiskCache.CreateContext())
+ {
+ var collection = cache.Database.GetCollection<CachedMachine>(MACHINES_COLLECTION);
- collection.Upsert(cachedMachine);
- }
- catch (Exception ex)
+ foreach (var cachedMachine in cachedMachines)
{
- LogManager.Log(ex, $"Error caching machine '{machine.SerialNumber}' on disk.");
+ collection.Upsert(cachedMachine);
}
}
}
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error caching machines (partial) to disk.");
+ }
return machines;
}
diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs
index a3a682833..0802cf456 100644
--- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs
+++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs
@@ -78,6 +78,22 @@ namespace Tango.Scripting.Editors
#region Mini Classes
+ private class KnownTypeResult
+ {
+ public KnownType KnownType { get; set; }
+ public bool IsStatic { get; set; }
+
+ public KnownTypeResult()
+ {
+
+ }
+
+ public KnownTypeResult(KnownType knownType)
+ {
+ KnownType = knownType;
+ }
+ }
+
private class ScriptClass
{
public String Name { get; set; }
@@ -493,19 +509,19 @@ namespace Tango.Scripting.Editors
if (e.Text == " " && previousWords.Count > 2 && previousWords[previousWords.Count - 2] == "=")
{
var expression = previousWords.First();
- var knownType = GetKnownTypeFromExpression(expression + ".");
+ var knownTypeResult = GetKnownTypeFromExpression(expression + ".");
- if (knownType != null && knownType.Type.IsEnum)
+ if (knownTypeResult != null && knownTypeResult.KnownType.Type.IsEnum)
{
completionWindow.HideCompletion();
IList<ICompletionData> data = new List<ICompletionData>();
- foreach (var field in knownType.Fields)
+ foreach (var field in knownTypeResult.KnownType.Fields)
{
data.Add(new FieldCompletionItem()
{
- Class = knownType.FriendlyName,
- Name = knownType.FriendlyName + "." + field.Name,
+ Class = knownTypeResult.KnownType.FriendlyName,
+ Name = knownTypeResult.KnownType.FriendlyName + "." + field.Name,
Type = field.ReturnTypeFriendlyName,
Description = field.Summary,
});
@@ -540,25 +556,25 @@ namespace Tango.Scripting.Editors
}
else if (e.Text == ".")
{
- var knownType = GetCurrentKnownType();
+ var knownTypeResult = GetCurrentKnownType();
IList<ICompletionData> data = new List<ICompletionData>();
- if (knownType != null)
+ if (knownTypeResult != null)
{
completionWindow.HideCompletion();
- if (!knownType.Type.IsEnum)
+ if (!knownTypeResult.KnownType.Type.IsEnum)
{
- var typeMembers = knownType.Members.ToList();
+ var typeMembers = knownTypeResult.KnownType.Members.ToList();
- foreach (var methodGroup in typeMembers.OfType<KnownTypeMethod>().Where(x => !x.IsStatic).GroupBy(x => x.NameWithTypeArguments))
+ foreach (var methodGroup in typeMembers.OfType<KnownTypeMethod>().Where(x => (!knownTypeResult.IsStatic && !x.IsStatic) || (knownTypeResult.IsStatic && x.IsStatic)).GroupBy(x => x.NameWithTypeArguments))
{
var method = methodGroup.First();
data.Add(new MethodCompletionItem()
{
- Class = knownType.FriendlyName,
+ Class = knownTypeResult.KnownType.FriendlyName,
Name = method.NameWithTypeArguments,
ReturnType = method.ReturnTypeFriendlyName,
Description = method.Summary,
@@ -571,7 +587,7 @@ namespace Tango.Scripting.Editors
{
data.Add(new EventCompletionItem()
{
- Class = knownType.FriendlyName,
+ Class = knownTypeResult.KnownType.FriendlyName,
Name = ev.Name,
Description = ev.Summary,
});
@@ -583,7 +599,7 @@ namespace Tango.Scripting.Editors
data.Add(new PropertyCompletionItem()
{
- Class = knownType.FriendlyName,
+ Class = knownTypeResult.KnownType.FriendlyName,
Name = member.Name,
Type = member.ReturnTypeFriendlyName,
Description = member.Summary,
@@ -592,11 +608,11 @@ namespace Tango.Scripting.Editors
}
else
{
- foreach (var field in knownType.Fields)
+ foreach (var field in knownTypeResult.KnownType.Fields)
{
data.Add(new FieldCompletionItem()
{
- Class = knownType.FriendlyName,
+ Class = knownTypeResult.KnownType.FriendlyName,
Name = field.Name,
Type = field.ReturnTypeFriendlyName,
Description = field.Summary,
@@ -672,34 +688,6 @@ namespace Tango.Scripting.Editors
ShowCompletionWindow(data, GetCurrentWord());
}
- else
- {
- //Maybe static ...
- var typeText = GetPreviousWord();
- knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == typeText || x.Alias == typeText);
-
- if (knownType != null)
- {
- var typeMembers = knownType.Members.ToList();
-
- foreach (var methodGroup in typeMembers.OfType<KnownTypeMethod>().Where(x => x.IsStatic).GroupBy(x => x.NameWithTypeArguments))
- {
- var method = methodGroup.First();
-
- data.Add(new MethodCompletionItem()
- {
- Class = knownType.FriendlyName,
- Name = method.NameWithTypeArguments,
- ReturnType = method.ReturnTypeFriendlyName,
- Description = method.Summary,
- Parameters = method.Parameters,
- Overloads = methodGroup.Count() - 1,
- });
- }
-
- ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord());
- }
- }
}
}
else if (e.Text == "(" || e.Text == ",")
@@ -1097,13 +1085,13 @@ namespace Tango.Scripting.Editors
return list;
}
- private KnownType GetCurrentKnownType()
+ private KnownTypeResult GetCurrentKnownType()
{
var expression = GetPreviousWords().LastOrDefault();
return GetKnownTypeFromExpression(expression);
}
- private KnownType GetKnownTypeFromExpression(String expression)
+ private KnownTypeResult GetKnownTypeFromExpression(String expression)
{
if (expression != null)
{
@@ -1124,7 +1112,7 @@ namespace Tango.Scripting.Editors
if (enumType != null)
{
- return enumType;
+ return new KnownTypeResult(enumType);
}
tree.RemoveAt(0);
@@ -1152,13 +1140,36 @@ namespace Tango.Scripting.Editors
knownType = _knownTypes.FirstOrDefault(x => x.Type.Namespace + "." + x.Type.Name == member.ReturnType.Namespace + "." + member.ReturnType.Name);
}
- return knownType;
+ return new KnownTypeResult(knownType);
+ }
+ else //Maybe a variable of a declared type...
+ {
+ if (tree.Count > 0)
+ {
+ var memberName = tree[0];
+ var declaredType = _declaredTypes.SingleOrDefault(x => x.Name == name);
+
+ if (declaredType != null)
+ {
+ var member = declaredType.Symbols.FirstOrDefault(x => x.Name == memberName);
+ if (member != null)
+ {
+ knownType = _knownTypes.SingleOrDefault(x => x.Name.ToLower() == member.Type.ToLower());
+
+ if (knownType != null)
+ {
+ return new KnownTypeResult(knownType);
+ }
+ }
+ }
+ }
}
}
else
{
//Maybe static...
- return _knownTypes.FirstOrDefault(x => x.Name == variableName);
+ var type = _knownTypes.FirstOrDefault(x => x.Name == variableName);
+ return type != null ? new KnownTypeResult(type) { IsStatic = true } : null;
}
}
}
@@ -1305,7 +1316,7 @@ namespace Tango.Scripting.Editors
foreach (var m in session.Type.Methods.Where(x => x.Name == session.MethodName))
{
MethodDescription method = new MethodDescription();
- method.ReturnType = session.Type.Name;
+ method.ReturnType = m.ReturnTypeFriendlyName;
method.Description = m.Summary;
method.Name = m.NameWithTypeArguments;
method.Class = session.Type.FriendlyName;