Graphics

 View Only
Expand all | Collapse all

C# app wiht datalinq method for Xpression

  • 1.  C# app wiht datalinq method for Xpression

    Posted 03-02-2023 09:07

    I'm thinking about making a C# app to replace my Dashboard. I've watched the Write a C Sharp or Visual Basic App XpressionU video. This video shows some great functionality, and I'd love to use C# instead of Dashboard, mostly because I think it is easier and has much more capability. HOWEVER, I can't decide what would be the best way to simulate how Dashboard shares all of the Parameters through an XML file. I suppose I could just write an XML file from my app anytime something changes that I could need in Xpression. Would this be my best bet, or should I consider a different way? The only thing I could image that could be problematic with this method is that I think I could run into file sharing issues. For example, might I have issues if Datalinq is reading the XML file while I'm trying to write the file in C#? I'm not sure how Dahsboard does it, but I'm just brainstorming before I go to far down the rabbit hole. Any thoughts?



    ------------------------------
    Roger Heyward
    ------------------------------


  • 2.  RE: C# app wiht datalinq method for Xpression

    Posted 03-02-2023 09:43

    Why not just send the values directly to the objects and cut out the need for datalinq and XML all together? 



    ------------------------------
    Simon Redmile
    Senior Graphic Programmer & Designer
    Ross Video
    Bristol United Kingdom
    ------------------------------



  • 3.  RE: C# app wiht datalinq method for Xpression

    Posted 03-02-2023 09:58

    I suppose that would work. Although I will really need to think through all of the ways that I am already using my Dashboard. So, is the other way, with an XML file, out of the question?



    ------------------------------
    Roger Heyward
    ------------------------------



  • 4.  RE: C# app wiht datalinq method for Xpression

    Posted 03-02-2023 10:00

    No you can write to a XML and datalinq will read it. Right now I am using an XML that is being regularly written to and faced no issues. You also have the RSS option as well. 



    ------------------------------
    Simon Redmile
    Senior Graphic Programmer & Designer
    Ross Video
    Bristol United Kingdom
    ------------------------------



  • 5.  RE: C# app wiht datalinq method for Xpression

    Posted 03-02-2023 10:20

    Oh! That's awesome. I read this post on stackoverflow, and it got me wondering if maybe I should be setting the  FileShare property to ReadWrite when I open the file to save new data to it. What did you do?



    ------------------------------
    Roger Heyward
    ------------------------------



  • 6.  RE: C# app wiht datalinq method for Xpression

    Posted 03-02-2023 10:32

    I didn't write the software that writes the XML sorry, I just receive it. Have you tried testing anything at this stage or just speculating? 



    ------------------------------
    Simon Redmile
    Senior Graphic Programmer & Designer
    Ross Video
    Bristol United Kingdom
    ------------------------------



  • 7.  RE: C# app wiht datalinq method for Xpression

    Posted 03-02-2023 11:20

    Yeah. I'm just brainstorming, right now, and I think that this FileShare idea only applies to the app itself, so I don't think that this is what I'm worried about. I'm worried about what Datalinq (a separate consumer of the XML file) is doing and if it will create conflicts with my app when it read/writes the file. I suppose I'll just have to make try it.



    ------------------------------
    Roger Heyward
    ------------------------------



  • 8.  RE: C# app wiht datalinq method for Xpression

    Posted 03-03-2023 10:26

    We've been using this method for a few years now - except we write JSON files, not XML, but the principal is the same. We write to these files as often as once every 10 seconds (occasionally faster) and collisions with Datalinq reading the file as we are writing them are rare. In the event of a collision, we just wait 1 second and try again and repeat this x number of times.

    We are currently visiting the idea of changing the way we do things because of some issues we have had with Datalinq. Nothing major, Datalinq works fine, but we are now considering writing the data directly to the fields on the graphics to give us more control over things.

    There are pros and cons to each method, so you will probably have to compromise at some point.



    ------------------------------
    JohnCorigliano
    Senior Software Engineer
    ISC
    ------------------------------



  • 9.  RE: C# app wiht datalinq method for Xpression

    Posted 03-06-2023 13:29

    I'm glad you brought that up. I think I'm going to give that a try with json. I found this post on stackoverflow, and maybe you can give me some advice here. I thought it might be a good idea to use the following technique to avoid locking up my app while serializing/reading/writing the file. Still, I'm thinking that the IOException could be the problem I'm worried about from Datalinq reading while I'm trying to write. Do I need to be concerned about this or will "await" avoid this exception?

    using System.Text.Json;
    using System.Text.Json.Serialization;
    
    List<data> _data = new List<data>();
    _data.Add(new data()
    {
        Id = 1,
        SSN = 2,
        Message = "A Message"
    });
    
    await using FileStream createStream = File.Create(@"D:\path.json");
    await JsonSerializer.SerializeAsync(createStream, _data);


    ------------------------------
    Roger Heyward
    ------------------------------



  • 10.  RE: C# app wiht datalinq method for Xpression

    Posted 03-07-2023 07:37

    async/await does not handle errors. It just lets your program to do stuff in the background, allowing the main program to keep going. It's probably not even necessary here since writing to a file should not take much time. If you want to handle errors, you need use exception handling.

    try
    {
        File.WriteAllText(@"D:\path.json", JsonSerializer.Serialize(_data));
    }
    catch (Exception e)
    {
        // If this code is reached, an error has occurred.
    }


    ------------------------------
    JohnCorigliano
    Senior Software Engineer
    ISC
    ------------------------------



  • 11.  RE: C# app wiht datalinq method for Xpression

    Posted 03-07-2023 08:25

    ok. thanks for the help.



    ------------------------------
    Roger Heyward
    ------------------------------