Coder Social home page Coder Social logo

sunriax / update Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 46 KB

Library to update software from different sources with user defined models.

License: GNU General Public License v3.0

C# 94.56% Batchfile 5.44%
update download http ftp github update-service update-client ragae sunriax 0x007e

update's Introduction

Version: 1.0 Release Build Status codecov License: GPL v3

Update Tool

Description:

With Update Tool updates from different sources (e.g. GitHub, WWW, FTP, ...) can be made. An example library how UpdateModels are created can be found here.


Installation

To install Update Tool it is possible to download necessary libraries [zip | tar.gz] or install the library via nuget.

PM> Install-Package RaGae.Update

After adding/installing the UpdateLib in a project it is necessary to place the user update models to a directory in your project.

Installed Models

To copy the user created models to output folder it is necessary to setup the *.csproj file.

*.csproj

<Project Sdk="Microsoft.NET.Sdk">
  // ...

  <ItemGroup>
    <LibraryFiles Include="$(ProjectDir)Model\*" />
  </ItemGroup>

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Copy SourceFiles="@(LibraryFiles)" DestinationFolder="$(TargetDir)Model" SkipUnchangedFiles="true" />
  </Target>
  
  // ...
</Project>

Configuration with path or file after Installation

UpdateLib.Path.json

{
  "ReflectionConfig": [
    {
      "ReflectionPath": "Model",
      "FileSpecifier": "*UpdateModelLib.dll"
    }
  ]
}

UpdateLib.File.json

{
  "ReflectionConfig": [
    {
      "Files": [
        "RaGae.UpdateLib.TemplateUpdateModelLib.dll",
        "RaGae.UpdateLib.??UpdateModelLib.dll",
        "..."
      ]
    }
  ]
}

An example project howto use the Update Tool can be found within this repository in the MakeUpdate project.


Structure

Initialisation

Update update = new Update("Arguments from command line");

UpdateLib.json

{
  "ReflectionConfig": [
    {
        "ReflectionPath": "Model",
        "FileSpecifier": "*UpdateModelLib.dll"
    }
  ]
}

UserGeneratedUpdateModelLib.json

{
  "UpdateConfig": {
    "Model": "Template",
    "SkipBeforeUpdate": false,
    "SkipUpdate": false,
    "SkipAfterUpdate": false
  },
  "ReflectionConfig": [
    {
      "ReflectionPath": "Marshaler",
      "FileSpecifier": "*MarshalerLib.dll"
    }
  ],
  "ArgumentConfig": {
    "Schema": [
      {
        "Argument": [
          "p",
          "parameter"
        ],
        "Marshaler": "*",
        "Required": true
      }
    ],
    "Delimiter": "-:/"
  }
}

Arguments from CLI

The first argument contains the filename for configuration of UpdateLib and is not bypassed to the UpdateModel libraries. The subsequent arguments are passed to the update model.

UserUpdate.exe UpdateLib.json UserGeneratedUpdateModelLib.json -p "Test"
# or
UserUpdate.exe UpdateLib.json UserGeneratedUpdateModelLib.json -parameter "Test"
string[] args = {
    "UpdateLib.json",
    "UserGeneratedUpdateModelLib.json"
    "-p",
    "Test"
};
Update update = new Update(args);
update.UpdateMessage += Console.WriteLine;  // Get messages from UpdateModel
update.ExecuteUpdate();

Build your own Model

  1. Create a new VisualStudio .NET Standard Classlibrary (??UpdateModelLib)
  2. Link a new project reference to RaGae.UpdateLib.UpdateModelLib.dll (in this repository) or install as nuget (see below)
  3. Write Model (See example code below)
  4. Copy the TestUpdateModelLib.dll to the Model directory in your executable project
PM> Install-Package RaGae.Update.Model

Model with no arguments

UpdateLib.json

{
  "ReflectionConfig": [
    {
      "ReflectionPath": "Model",
      "FileSpecifier": "*UpdateModelLib.dll"
    }
  ]
}

TestUpdateModelLib.NoArguments.json

{
  "UpdateConfig": {
    "Model": "Test",
    "SkipBeforeUpdate": false,
    "SkipUpdate": false,
    "SkipAfterUpdate": false
  }
}
using System;
using RaGae.UpdateLib.UpdateModelLib;

namespace RaGae.UpdateLib.TestUpdateModelLib
{
    public class TestUpdateModel : UpdateModel
    {
        public override event WriteMessage UpdateMessage;

        private const string model = "Test";
        public override string Model { get => model.ToLower(); }

        // Necessary for reflector library, otherwise the class can not be found!
        // If the constructor is not used it can be private
        // If no arguments are passed to the model use this constructor
        private TestUpdateModel()
        {

        }

        // If no arguments are passed to the model the constructor can be removed!
        // public TestUpdateModel(IEnumerable<string> args) : base(args)
        // {
        //     // Initiate config
        //     this.config = new TestUpdateConfig()
        //     {
        //       // ...
        //     };
            
        // }

        public override void BeforeUpdate()
        {
            this.UpdateMessage?.Invoke("Things to do before update");
        }

        public override void Update()
        {
            this.UpdateMessage?.Invoke("Things to update");
        }

        public override void AfterUpdate()
        {
            this.UpdateMessage?.Invoke("Things to do after update");
        }
    }
}

Application

UserUpdate.exe UpdateLib.json TestUpdateModelLib.NoArguments.json
string[] args = {
    "UpdateLib.json",
    "TestUpdateModelLib.NoArguments.json"
};
Update update = new Update(args);
update.UpdateMessage += Console.WriteLine;  // Get messages from UpdateModel
update.ExecuteUpdate();

Model with arguments

Important: If arguments are used it is necessary to install required marshalers in the application folder. A readme howto do this can be found here.

UpdateLib.json

{
  "ReflectionConfig": [
    {
      "ReflectionPath": "Model",
      "FileSpecifier": "*UpdateModelLib.dll"
    }
  ]
}

TestUpdateModelLib.NoArguments.json

{
  "UpdateConfig": {
    "Model": "Test",
    "SkipBeforeUpdate": false,
    "SkipUpdate": false,
    "SkipAfterUpdate": false
  },
  "ReflectionConfig": [
    {
      "ReflectionPath": "Marshaler",
      "FileSpecifier": "*MarshalerLib.dll"
    }
  ],
  "ArgumentConfig": {
    "Schema": [
      {
        "Argument": [
          "p",
          "parameter"
        ],
        "Marshaler": "*",
        "Required": true
      }
    ],
    "Delimiter": "-:/"
  }
}
using System;
using RaGae.UpdateLib.UpdateModelLib;

namespace RaGae.UpdateLib.TestUpdateModelLib
{
    public class TestUpdateModel : UpdateModel
    {
        public override event WriteMessage UpdateMessage;

        private const string model = "Test";
        public override string Model { get => model.ToLower(); }

        private readonly TestUpdateConfig config;

        // Necessary for reflector library, otherwise the class can not be found!
        // If the constructor is not used it can be private
        // If no arguments are passed to the model use this constructor
        private TestUpdateModel()
        {

        }

        // If no arguments are passed to the model the constructor can be removed!
        public TestUpdateModel(IEnumerable<string> args) : base(args)
        {
            // Initiate config
            this.config = new TestUpdateConfig()
            {
              Parameter = base.argument.GetValue<string>("p")
              // or
              // Parameter = base.argument.GetValue<string>("parameter")
            };
            
        }

        public override void BeforeUpdate()
        {
            this.UpdateMessage?.Invoke("Things to do before update");
        }

        public override void Update()
        {
            this.UpdateMessage?.Invoke("Things to update");
            this.UpdateMessage?.Invoke($"Parameter {this.config.Parameter}");
        }

        public override void AfterUpdate()
        {
            this.UpdateMessage?.Invoke("Things to do after update");
        }

        internal class TestUpdateConfig
        {
          public string Parameter { get; set; }
        }
    }
}

Application

UserUpdate.exe UpdateLib.json UserGeneratedUpdateModelLib.json -p "Test"
# or
UserUpdate.exe UpdateLib.json UserGeneratedUpdateModelLib.json -parameter "Test"
string[] args = {
    "UpdateLib.json",
    "TestUpdateModelLib.NoArguments.json"
    "-p",
    // or
    // "-parameter",
    "Test"
};
Update update = new Update(args);
update.UpdateMessage += Console.WriteLine;  // Get messages from UpdateModel
update.ExecuteUpdate();

R. Gächter

update's People

Contributors

0x007e avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

00mjk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.