aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Updater/Properties/Settings.Designer.cs
blob: a18e7398e9a71dd74a0827ee42a0908980edd3b7 (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
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Tango.MachineStudio.Updater.Properties
{


    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
    {

        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

        public static Settings Default
        {
            get
            {
                return defaultInstance;
            }
        }
    }
}
.mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using Google.Protobuf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.ExtensionMethods;
using Tango.Core.Threading;
using Tango.Logging;
using Tango.PMR;
using Tango.PMR.Common;
using Tango.PMR.Integration;

namespace Tango.Transport
{
    /// <summary>
    /// Represents a generic transport message.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <seealso cref="Tango.Transport.TransportMessageBase" />
    internal class TransportMessage<T> : TransportMessageBase
    {
        private bool exceptionRaised;

        private TaskCompletionSource<T> _completionSource;
        private bool taskCompleted;

        public Subject<T> ContinuesResponseSubject { get; set; }

        public DateTime LastResponseTime { get; set; }

        public bool Completed { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="TransportMessage{T}"/> class.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="message">The message.</param>
        /// <param name="direction">The direction.</param>
        /// <param name="toBytes">To bytes.</param>
        /// <param name="completionSource">The completion source.</param>
        public TransportMessage(string token, object message, TransportMessageDirection direction, Func<byte[]> toBytes, TaskCompletionSource<T> completionSource) : base(token, message, direction, toBytes)
        {
            _completionSource = completionSource;
        }

        /// <summary>
        /// Notifies the message observer of the new result.
        /// </summary>
        /// <param name="result">The result.</param>
        public override void SetResult(object result, bool completed)
        {
            Completed = completed;

            Action setResultAction = () => 
            {
                try
                {
                    if (!IsContinuous)
                    {
                        if (!taskCompleted)
                        {
                            taskCompleted = true;

                            if (_completionSource.GetType() == typeof(TaskCompletionSource<IMessage>))
                            {
                                _completionSource.SetResult((T)result.GetType().GetProperty("Message").GetValue(result));
                            }
                            else if (_completionSource.GetType() == typeof(TaskCompletionSource<MessageContainer>))
                            {
                                _completionSource.SetResult((T)result.GetType().GetProperty("Container").GetValue(result));
                            }
                            else
                            {
                                _completionSource.SetResult((T)result);
                            }
                        }
                    }
                    else
                    {
                        LastResponseTime = DateTime.Now;
                        AtLeastOneResponseReceived = true;

                        if (ContinuesResponseSubject.GetType() == typeof(Subject<IMessage>))
                        {
                            ContinuesResponseSubject.OnNext((T)result.GetType().GetProperty("Message").GetValue(result));
                        }
                        else if (ContinuesResponseSubject.GetType() == typeof(Subject<MessageContainer>))
                        {
                            ContinuesResponseSubject.OnNext((T)result.GetType().GetProperty("Container").GetValue(result));
                        }
                        else
                        {
                            ContinuesResponseSubject.OnNext((T)result);
                        }

                        if (completed)
                        {
                            ContinuesResponseSubject.OnCompleted();
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogManager.Log(ex, $"Error while settings result for message.");
                    try
                    {
                        SetException(ex);
                    }
                    catch (Exception e)
                    {
                        LogManager.Log(e, $"Error while settings exception for message.");
                    }
                }
            };

            if (ThreadingMode == TransportThreadingMode.NewThread)
            {
                ThreadFactory.StartNew(() =>
                {
                    setResultAction();
                });
            }
            else
            {
                Task.Factory.StartNew(() =>
                {
                    setResultAction();
                });
            }
        }

        /// <summary>
        /// Notifies the message observer of an exception.
        /// </summary>
        /// <param name="ex">The ex.</param>
        public override void SetException(Exception ex)
        {
            if (exceptionRaised || taskCompleted)
            {
                return;
            }

            Completed = true;
            exceptionRaised = true;

            Action setExceptionAction = () => 
            {
                if (!IsContinuous)
                {
                    if (!taskCompleted)
                    {
                        taskCompleted = true;

                        if (!(ex is ContinuousResponseAbortedException) && !(ex is TransporterDisconnectedException))
                        {
                            LogManager.Log($"{TransportComponentName}: Request failed '{GetActualMessageTypeName()}'...\n{ex.FlattenException()}", LogCategory.Error);
                        }
                        _completionSource.SetException(ex);
                    }
                }
                else
                {
                    if (!(ex is ContinuousResponseAbortedException) && !(ex is TransporterDisconnectedException))
                    {
                        LogManager.Log($"{TransportComponentName}: Request failed '{GetActualMessageTypeName()}'...\n{ex.FlattenException()}", LogCategory.Error);
                    }

                    AtLeastOneResponseReceived = true;
                    ContinuesResponseSubject.OnError(ex);
                }
            };

            if (ThreadingMode == TransportThreadingMode.NewThread)
            {
                ThreadFactory.StartNew(() =>
                {
                    setExceptionAction();
                });
            }
            else
            {
                Task.Factory.StartNew(() =>
                {
                    setExceptionAction();
                });
            }
        }

        public override string GetActualMessageTypeName()
        {
            return GetActualMessageTypeName(Message);
        }

        public override object GetActualMessage()
        {
            object obj = null;

            if (Message is ITangoMessage)
            {
                obj = Message.GetType().GetProperty("Message").GetValue(Message);
            }
            else if (Message is MessageContainer)
            {
                obj = Message;
            }
            else
            {
                obj = Message;
            }

            return obj;
        }

    }
}