예제 #1
0
        private static void UpdateAppSoftwareFilesAndCodes(Client client, AppsClient.AppsClientConfig clientConfig, ref AppsClient.AppsResult result)
        {
            var softwareFilesDB = client.DB.GetCollection <SoftwareFile>("SoftwareFiles");

            //softwareFilesDB.DeleteMany(sf => sf.AppID == client.App.AppID);

            //Update software files
            foreach (string csFileFullName in clientConfig.CSFileFullNames)
            {
                if (System.IO.File.Exists(csFileFullName))
                {
                    string csContents = System.IO.File.ReadAllText(csFileFullName);

                    //Look for already-saved cs file in app
                    var existingFileList = client.App.SoftwareFiles.Where(f => f.FullName == csFileFullName);

                    if (existingFileList.Count() == 1)
                    {
                        //We've already gotten it, refresh and save
                        var existingFile = existingFileList.Single();
                        existingFile.Contents = csContents;
                        existingFile.FullName = csFileFullName;
                        existingFile.Updated  = DateTime.Now;
                        existingFile.AppID    = client.App.AppID;

                        softwareFilesDB.Upsert(existingFile);

                        UpdateCSFileCodes(client, existingFile, ref result);
                    }
                    else if (existingFileList.Count() == 0)
                    {
                        //Haven't seen this one, add it to app
                        var newFile = new SoftwareFile
                        {
                            Contents     = csContents,
                            Created      = DateTime.Now,
                            FileLanguage = SoftwareFileLanguages.CSharp,
                            FullName     = csFileFullName,
                            AppID        = client.App.AppID
                        };

                        softwareFilesDB.Insert(newFile);

                        client.App.SoftwareFiles.Add(newFile);

                        UpdateCSFileCodes(client, newFile, ref result);
                    }
                    else
                    {
                        new AppFlows.Helpers.AppsSystem.Fail("More than one copy of csfile in app: " + existingFileList.Count().ToString(), ref result);
                    }
                }
                else
                {
                    new AppFlows.Helpers.AppsSystem.Fail("Incoming config cs file path not found.", ref result);
                }

                client.App.Updated = DateTime.Now;
            }
        }
        public void GetANewDatabaseOnFirstRegistration()
        {
            var appsData = new Moq.Mock <AppsDesktop.AppsData>(Moq.MockBehavior.Strict);
            var db       = new Moq.Mock <LiteDB.LiteDatabase>(Moq.MockBehavior.Strict);

            var config = new AppsClient.AppsClientConfig();
            var result = new AppsClient.AppsResult();

            //Business.AppsHelper.RegisterClient(appsData.Object, db.Object, config, ref result);
        }
예제 #3
0
        /// <summary>
        /// Called whenever client starts up (Run).
        ///
        ///See https://github.com/rbrooks33/Brooksoft.Apps.DevOps/discussions/3
        ///
        /// Scenarios
        /// 1.) New client (no database yet or database deleted)
        ///
        /// 2.) Existing client (sunny day, database exists
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public async Task SendAppsClientConfig(AppsClient.AppsClientConfig config)
        {
            var result = new AppsClient.AppsResult();

            try
            {
                AppsHelper.RegisterClient(_data, AppsDB, config, ref result);
            }
            catch (System.Exception ex)
            {
                new AppFlows.Helpers.AppsSystem.Exception(ex, ref result);
            }
        }
예제 #4
0
        public static void RegisterClient(AppsData data, LiteDB.LiteDatabase appsDb, AppsClient.AppsClientConfig config, ref AppsClient.AppsResult result)
        {
            var objs = appsDb.GetCollection <App>("Apps");
            var apps = objs.Query().Where(a => a.MachineName == config.MachineName && a.WorkingFolder == config.WorkingDirectory);
            App app  = null;

            if (apps.Count() == 0)
            {
                app = new App()
                {
                    Created       = DateTime.Now,
                    MachineName   = config.MachineName,
                    WorkingFolder = config.WorkingDirectory,
                    Updated       = DateTime.Now,
                    IsEnabled     = true,
                    LocalHostPort = config.LocalHostPort
                };

                objs.Insert(app);
            }
            else if (apps.Count() == 1)
            {
                app               = apps.Single();
                app.Updated       = DateTime.Now;
                app.LocalHostPort = config.LocalHostPort;
                objs.Upsert(app);
            }
            else
            {
                new AppFlows.Helpers.AppsSystem.Fail("Found more than one matching app for incoming config: " + apps.Count().ToString(), ref result);
            }

            var client = new Client(app, ref result);

            AppsHelper.UpdateAppSoftwareFilesAndCodes(client, config, ref result);
        }