Example #1
0
        public void TestSanitizeDBNameOK()
        {
            string name    = "ok-name_$()+-/";
            var    storage = storageManager.Add(name);

            Assert.AreEqual(name, storage.Info.Name);
        }
Example #2
0
        public static T Get <T>(
            this IStorageManager storageManager,
            IKeyBuilder key,
            FallbackPolicy fallbackPolicy,
            Func <T> callback,
            ISerializer <T, string> serializer = null
            )
        {
            serializer = serializer ?? GetDefaultSerializer <T>();

            var item       = default(T);
            var serialized = storageManager.Get(key, fallbackPolicy);

            if (serialized == null || (item = serializer.Deserialize(serialized)) == null)
            {
                item       = callback();
                serialized = serializer.Serialize(item);
                storageManager.Add(key, serialized);
            }

            return(item);
        }
        protected void OnAddbuttonClicked(object sender, System.EventArgs e)
        {
            IStorage db;
            string   dbname = Helpers.MessagesHelpers.QueryMessage(this, Catalog.GetString("Database name"));

            if (dbname == null || dbname == "")
            {
                return;
            }

            if (manager.Databases.Where(d => d.Info.Name == dbname).Count() != 0)
            {
                var msg = Catalog.GetString("A database already exists with this name");
                Helpers.MessagesHelpers.ErrorMessage(this, msg);
                return;
            }

            db = manager.Add(dbname);
            if (db != null)
            {
                store.AppendValues(db);
            }
        }
        bool MigrateDB(IStorageManager manager, string databaseName, List<string> projectFiles)
        {
            IStorage database;
            Guid id = Guid.NewGuid ();
            int indexSteps = 4;
            float step = (float)1 / (projectFiles.Count * 2 + indexSteps);
            float percent = 0;
            List<Task> tasks = new List<Task> ();
            bool ret = true;

            Log.Information ("Start migrating " + databaseName);
            try {
                database = manager.Add (databaseName);
            } catch {
                database = manager.Databases.FirstOrDefault (d => d.Info.Name == databaseName);
            }

            if (database == null) {
                Log.Error ("Database with name " + databaseName + " is null");
                return false;
            }

            foreach (string projectFile in projectFiles) {
                var importTask = Task.Run (() => {
                    ProjectLongoMatch project = null;
                    try {
                        Log.Information ("Migrating project " + projectFile);
                        project = Serializer.Instance.Load<ProjectLongoMatch> (projectFile);
                    } catch (Exception ex) {
                        Log.Exception (ex);
                        ret = false;
                    }
                    percent += step;
                    progress.Report (percent, "Imported project " + project?.Description.Title, id);

                    if (project != null) {
                        if (project.LocalTeamTemplate.ID != Guid.Empty) {
                            teamNameToID [project.LocalTeamTemplate.Name] = project.LocalTeamTemplate.ID;
                        }
                        if (project.VisitorTeamTemplate.ID != Guid.Empty) {
                            teamNameToID [project.VisitorTeamTemplate.Name] = project.VisitorTeamTemplate.ID;
                        }
                        try {
                            ProjectMigration.Migrate0 (project, scoreNameToID, penaltyNameToID, teamNameToID, dashboardNameToID);
                            database.Store (project, true);
                        } catch (Exception ex) {
                            Log.Exception (ex);
                            ret = false;
                        }
                        percent += step;
                        progress.Report (percent, "Migrated project " + project?.Description.Title, id);
                        project.Dispose ();
                        project = null;
                        GC.Collect ();
                    }
                });
                tasks.Add (importTask);
            }
            Task.WaitAll (tasks.ToArray ());

            // Create a query and print the result to traverse the iterator
            Log.Information ("Projects index created:" + database.RetrieveAll<ProjectLongoMatch> ().Count ());
            percent += step;
            progress.Report (percent, "Projects index created", id);

            Log.Information ("Timeline events index created:" + database.RetrieveAll<TimelineEventLongoMatch> ().Count ());
            percent += step;
            progress.Report (percent, "Events index created", id);

            Log.Information ("Teams index created:" + database.RetrieveAll<SportsTeam> ().Count ());
            percent += step;
            progress.Report (percent, "Teams index created", id);

            Log.Information ("DAshboards index created:" + database.RetrieveAll<DashboardLongoMatch> ().Count ());
            percent += step;
            progress.Report (percent, "Dashboards index created", id);

            Log.Information ("Database " + databaseName + " migrated correctly");
            return ret;
        }
Example #5
0
        bool MigrateDB(IStorageManager manager, string databaseName, List <string> projectFiles)
        {
            IStorage    database;
            Guid        id         = Guid.NewGuid();
            int         indexSteps = 4;
            float       step       = (float)1 / (projectFiles.Count * 2 + indexSteps);
            float       percent    = 0;
            List <Task> tasks      = new List <Task> ();
            bool        ret        = true;

            Log.Information("Start migrating " + databaseName);
            try {
                database = manager.Add(databaseName);
            } catch {
                database = manager.Databases.FirstOrDefault(d => d.Info.Name == databaseName);
            }

            if (database == null)
            {
                Log.Error("Database with name " + databaseName + " is null");
                return(false);
            }

            foreach (string projectFile in projectFiles)
            {
                var importTask = Task.Run(() => {
                    LMProject project = null;
                    try {
                        Log.Information("Migrating project " + projectFile);
                        project = Serializer.Instance.Load <LMProject> (projectFile);
                    } catch (Exception ex) {
                        Log.Exception(ex);
                        ret = false;
                    }
                    percent += step;
                    progress.Report(percent, "Imported project " + project?.Description.Title, id);

                    if (project != null)
                    {
                        if (project.LocalTeamTemplate.ID != Guid.Empty)
                        {
                            teamNameToID [project.LocalTeamTemplate.Name] = project.LocalTeamTemplate.ID;
                        }
                        if (project.VisitorTeamTemplate.ID != Guid.Empty)
                        {
                            teamNameToID [project.VisitorTeamTemplate.Name] = project.VisitorTeamTemplate.ID;
                        }
                        try {
                            ProjectMigration.Migrate0(project, scoreNameToID, penaltyNameToID, teamNameToID, dashboardNameToID);
                            database.Store(project, true);
                        } catch (Exception ex) {
                            Log.Exception(ex);
                            ret = false;
                        }
                        percent += step;
                        progress.Report(percent, "Migrated project " + project?.Description.Title, id);
                        project.Dispose();
                        project = null;
                        GC.Collect();
                    }
                });
                tasks.Add(importTask);
            }
            Task.WaitAll(tasks.ToArray());

            // Create a query and print the result to traverse the iterator
            Log.Information("Projects index created:" + database.RetrieveAll <LMProject> ().Count());
            percent += step;
            progress.Report(percent, "Projects index created", id);

            Log.Information("Timeline events index created:" + database.RetrieveAll <LMTimelineEvent> ().Count());
            percent += step;
            progress.Report(percent, "Events index created", id);

            Log.Information("Teams index created:" + database.RetrieveAll <Team> ().Count());
            percent += step;
            progress.Report(percent, "Teams index created", id);

            Log.Information("DAshboards index created:" + database.RetrieveAll <Dashboard> ().Count());
            percent += step;
            progress.Report(percent, "Dashboards index created", id);

            Log.Information("Database " + databaseName + " migrated correctly");
            return(ret);
        }
Example #6
0
 public void CreateStorage_FailingManager_NullReturned()
 {
     storageManager = new FailingCouchbaseManager(dbPath);
     Assert.Throws <CouchbaseLiteException> (() => storageManager.Add("test"));
 }