Skip to main content
Rollback to Revision 5
Source Link
Mathieu Guindon
  • 75.5k
  • 18
  • 194
  • 467

FINAL EDIT/SOLUTION

So after some thinking, this is now the final code for EDIT: I have extracted the HazenTask class..to another method to remove the abstract/base classresponsibility of the TideDeviceset staysaccessor. But I'm still in a roadblock on fixing the samecode smell I initially stated. I editted the code to reflect what I have now.

    internal Hazen(IRawDataReceiver rawDataReceiver) : base(rawDataReceiver)
    {
        _serialPortConnection = rawDataReceiver as SerialPortConnection;
    }
    [DataMember] private SerialPortConnection _serialPortConnection;

    [OnDeserialized] private void OnDeserialized(StreamingContext sc)
    {
        RawDataReceiver = _serialPortConnection;
    }

So as you can see, the [OnDeserialized] method will act as theEDIT2: This code is working really fine whether in constructorunit test afterand deserializationintegration test. Or more specifically, it mimics the base(rawDataReceiver) part of "actual" `constructor'

That'sso I'll leave it. Thanks @jeyoung and @JNS as is until someone points out that there is something wrong here or until a problem arises. Thank you very much!

FINAL EDIT/SOLUTION

So after some thinking, this is now the final code for the Hazen class.. the abstract/base class TideDevice stays the same.

    internal Hazen(IRawDataReceiver rawDataReceiver) : base(rawDataReceiver)
    {
        _serialPortConnection = rawDataReceiver as SerialPortConnection;
    }
    [DataMember] private SerialPortConnection _serialPortConnection;

    [OnDeserialized] private void OnDeserialized(StreamingContext sc)
    {
        RawDataReceiver = _serialPortConnection;
    }

So as you can see, the [OnDeserialized] method will act as the constructor after deserialization. Or more specifically, it mimics the base(rawDataReceiver) part of "actual" `constructor'

That's it. Thanks @jeyoung and @JNS.

EDIT: I have extracted the Task to another method to remove the responsibility of the set accessor. But I'm still in a roadblock on fixing the code smell I initially stated. I editted the code to reflect what I have now.

EDIT2: This code is working really fine whether in unit test and integration test, so I'll leave it as is until someone points out that there is something wrong here or until a problem arises. Thank you very much!

added 347 characters in body
Source Link

EDIT: I have extractedFINAL EDIT/SOLUTION

So after some thinking, this is now the final code for the TaskHazen to another method to remove the responsibility ofclass.. the setabstract accessor. But I'm still in a roadblock on fixing the code smell I initially stated. I editted/base class TideDevice stays the code to reflect what I have nowsame.

    internal Hazen(IRawDataReceiver rawDataReceiver) : base(rawDataReceiver)
    {
        _serialPortConnection = rawDataReceiver as SerialPortConnection;
    }
    [DataMember] private SerialPortConnection _serialPortConnection;

    [OnDeserialized] private void OnDeserialized(StreamingContext sc)
    {
        RawDataReceiver = _serialPortConnection;
    }

EDIT2: This code is working really fine whether inSo as you can see, the unit test[OnDeserialized] andmethod will act as the integration testconstructor after deserialization. Or more specifically, so I'll leave it as is until someone points out that there is something wrong here or until a problem arisesmimics the base(rawDataReceiver) part of "actual" `constructor'

That's it. Thank you very much!Thanks @jeyoung and @JNS.

EDIT: I have extracted the Task to another method to remove the responsibility of the set accessor. But I'm still in a roadblock on fixing the code smell I initially stated. I editted the code to reflect what I have now.

EDIT2: This code is working really fine whether in unit test and integration test, so I'll leave it as is until someone points out that there is something wrong here or until a problem arises. Thank you very much!

FINAL EDIT/SOLUTION

So after some thinking, this is now the final code for the Hazen class.. the abstract/base class TideDevice stays the same.

    internal Hazen(IRawDataReceiver rawDataReceiver) : base(rawDataReceiver)
    {
        _serialPortConnection = rawDataReceiver as SerialPortConnection;
    }
    [DataMember] private SerialPortConnection _serialPortConnection;

    [OnDeserialized] private void OnDeserialized(StreamingContext sc)
    {
        RawDataReceiver = _serialPortConnection;
    }

So as you can see, the [OnDeserialized] method will act as the constructor after deserialization. Or more specifically, it mimics the base(rawDataReceiver) part of "actual" `constructor'

That's it. Thanks @jeyoung and @JNS.

deleted 98 characters in body
Source Link
    internal Hazen(IRawDataReceiver rawDataReceiver) : base(rawDataReceiver)
    {
        SerialPortConnection = rawDataReceiver as SerialPortConnection;
    }
    private SerialPortConnection _serialPortConnection;
    [DataMember] private SerialPortConnection SerialPortConnection
    {
        get
        {
            return _serialPortConnection;
        }
        set
        {
            //TODO add null checker here
            _serialPortConnection = value;
            RawDataReceiver = value;
            Task.Factory.StartNew(async if() => 
            {
               value while!= (truenull)
                {
                    _serialPortConnection.Write("R");
                = value;
   await Task.Delay(Settings.SerialPortConnection.Default.WritingInterval);
              RawDataReceiver = }value;
            }, TaskCreationOptions.LongRunning);
        }
    }

EDIT: I have extracted the Task to another method to remove the responsibility of the set accessor. But I'm still in a roadblock on fixing the code smell I initially stated. I editted the code to reflect what I have now.

EDIT2: This code is working really fine whether in unit test and integration test, so I'll leave it as is until someone points out that there is something wrong here or until a problem arises. Thank you very much!

    internal Hazen(IRawDataReceiver rawDataReceiver) : base(rawDataReceiver)
    {
        SerialPortConnection = rawDataReceiver as SerialPortConnection;
    }
    private SerialPortConnection _serialPortConnection;
    [DataMember] private SerialPortConnection SerialPortConnection
    {
        get
        {
            return _serialPortConnection;
        }
        set
        {
            //TODO add null checker here
            _serialPortConnection = value;
            RawDataReceiver = value;
            Task.Factory.StartNew(async () => 
            {
                while (true)
                {
                    _serialPortConnection.Write("R");
                    await Task.Delay(Settings.SerialPortConnection.Default.WritingInterval);
                }
            }, TaskCreationOptions.LongRunning);
        }
    }
    internal Hazen(IRawDataReceiver rawDataReceiver) : base(rawDataReceiver)
    {
        SerialPortConnection = rawDataReceiver as SerialPortConnection;
    }
    private SerialPortConnection _serialPortConnection;
    [DataMember] private SerialPortConnection SerialPortConnection
    {
        get
        {
            return _serialPortConnection;
        }
        set
        {
            if(value != null)
            {
                _serialPortConnection = value;
                RawDataReceiver = value;
            }
        }
    }

EDIT: I have extracted the Task to another method to remove the responsibility of the set accessor. But I'm still in a roadblock on fixing the code smell I initially stated. I editted the code to reflect what I have now.

EDIT2: This code is working really fine whether in unit test and integration test, so I'll leave it as is until someone points out that there is something wrong here or until a problem arises. Thank you very much!

added 45 characters in body
Source Link
Loading
added 10 characters in body
Source Link
Loading
added 578 characters in body
Source Link
Loading
Source Link
Loading