Beispiel #1
0
        /// <summary>
        /// initialise updater.
        /// </summary>
        /// <param name="updateDir"></param>
        public UpdateController(string updateDir, TroubleShooterClient client)
        {
            this._client = client;
            _updateDir   = updateDir;
            ElipticCurve curve = ElipticCurve.secp160r1();

            _keyGen       = new ECKeysGenerator(curve);
            _verifier     = new ECSignature(curve);
            _diffieHelman = new ECDiffieHelman(curve);
        }
Beispiel #2
0
        /// <summary>
        /// - gets a new version of patches and questions
        /// - tries to compile patches and questions if update was successfull
        ///   otherwise the latest compiled dll is used "Patches.dll"
        /// - creates patches instances and builds problem tree.
        /// </summary>
        private TroubleShooter()
        {
            //load run data if process started using Kros.TroubleShooterInputs method
            RunData = Runner.GetData();
            //init web api client
            Client = new TroubleShooterClient();
            //create update dir
            if (!Directory.Exists(SOURCES_LOCATION))
            {
                Directory.CreateDirectory(SOURCES_LOCATION);
            }
            //get latest source files if server is online... check if its a new version
            UpdateController updater = new UpdateController(SOURCES_LOCATION, Client);

            ServerOnline = Client.TryConnection();
            IsNewVersion = ServerOnline && updater.Execute();
            //recompile if its a new version
            if (IsNewVersion)
            {
                Compiler.Compile(SOURCES_LOCATION);
            }
            //load last time compiled assembly
            sourcesAssembly = Compiler.LoadPatchAssembly();
            //init triubleshooter
            Patches = new List <Patch>();
            if (sourcesAssembly != null)
            {
#if DEBUG
                //patche sa podarilo skompilovat ale ak ich chcem debugovat pozijeme tie v tejto assembly
                //tiez by bolo fajn mat v priecinku s troubleshooterom aj runData subor pre debugovanie...
                sourcesAssembly = this.GetType().Assembly;
#endif
                //register all patches, create its instances
                var compiledPatches = (from type in sourcesAssembly.GetTypes()
                                       where type.IsSubclassOf(typeof(Patch))
                                       select(Patch) Activator.CreateInstance(type)).ToList();
                foreach (Patch patch in compiledPatches)
                {
                    Patches.Add(patch);
                }
                //initialise a root question -  decorated by RootQuestionAttribute
                RootQuestion = (from type in sourcesAssembly.GetTypes()
                                where type.IsSubclassOf(typeof(Question))
                                where type.GetCustomAttributes(typeof(RootQuestionAttribute)).Count() != 0
                                select(Question) Activator.CreateInstance(type)).FirstOrDefault();
            }
        }