コード例 #1
0
ファイル: MongoDb.cs プロジェクト: spetz/Symmetry
        public static ISynchronizer GetSynchronizer()
        {
            var connectionString = "mongodb://localhost:27017";
            var collection       = "Users";
            var source           = "Symmetry-Source";
            var destination      = "Symmetry-Destination";

            var dataSource = MongoDbDataSource <User>
                             .Create(connectionString, source)
                             .WithQuery(q => q.Where(x => x.Name != string.Empty))
                             .WithCollection(collection)
                             .Build();

            var dataDestination = MongoDbDataSource <User>
                                  .Create(connectionString, destination)
                                  .WithCollection(collection)
                                  .Build();

            var dataStore = MongoDbDataStore <User>
                            .Create(connectionString, destination)
                            .WithCollection(collection)
                            .Build();

            var synchronizerConfiguration = SynchronizerConfiguration <User>
                                            .Create()
                                            .WithDataSource(() => dataSource)
                                            .WithDataDestination(() => dataDestination)
                                            .WithDataStore(() => dataStore)
                                            .WithComparer(() => ObjectComparer <User> .Create((a, b) => a.Name == b.Name))
                                            .Build();

            return(Synchronizer <User>
                   .Create(synchronizerConfiguration)
                   .Build());
        }
コード例 #2
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Format is: BasicSynchronization.exe sitecollectionurl username password");
                return;
            }
            string webUrl   = args[0];
            string username = args[1];
            string password = args[2];

            var baseFolder        = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            var sourcePath        = System.IO.Path.Combine(baseFolder, @"Files\Style Library");
            var destinationFolder = "~site/style library";

            var config = new SynchronizerConfiguration();

            config.Log            = new ConsoleUpgradeLog(true);
            config.ContextManager = new BasicContextManager(webUrl, username, password);

            var sync   = new Synchronizer(config);
            var result = sync.SynchronizeFolder(sourcePath, destinationFolder);

            Console.WriteLine(result.Successful ? "Done" : "Failed");
        }
コード例 #3
0
        public static ISynchronizer GetSynchronizer()
        {
            var sourceUsers = new List <User>
            {
                new User("user1"),
                new User("user2"),
                new User("user3"),
            };

            var destinationUsers = new List <User>
            {
                new User("user1"),
                new User("user5")
            };

            var dataSource = MemoryDataSource <User>
                             .Create(sourceUsers)
                             .Build();

            var dataDestination = MemoryDataSource <User>
                                  .Create(destinationUsers)
                                  .Build();

            var dataStore = MemoryDataStore <User>
                            .Create()
                            .Build();

            var synchronizerConfiguration = SynchronizerConfiguration <User>
                                            .Create()
                                            .WithDataSource(() => dataSource)
                                            .WithDataDestination(() => dataDestination)
                                            .WithDataStore(() => dataStore)
                                            .WithComparer(() => ObjectComparer <User> .Create((a, b) => a.Name == b.Name))
                                            .Build();

            return(Synchronizer <User>
                   .Create(synchronizerConfiguration)
                   .Build());
        }
コード例 #4
0
        private static void SynchroniseFiles(string webUrl, string username, string password)
        {
            Console.WriteLine();
            Console.WriteLine("= Synchronise Files =");

            var config = new SynchronizerConfiguration();

            config.ContextManager = new BasicContextManager(webUrl, username, password);
            config.HashProvider   = new WebPropertyHashProvider("Test_UploadHash", null);

            // Will substitute '~site/' and '~sitecollection/'
            config.Preprocessors.Add(new UrlTokenPreprocessor());

            // Will substitute '$key$' with value
            var substitutionVariables = new Dictionary <string, string>();

            substitutionVariables.Add("Message", "Hello");
            config.Preprocessors.Add(new VariableSubstitutionPreprocessor(substitutionVariables));

            var baseFolder               = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            var scriptsSource            = System.IO.Path.Combine(baseFolder, "Scripts");
            var scriptsDestinationFolder = "~site/_catalogs/masterpage/scripts";

            // Ensure folder exists, then synchronise all changed files
            var sync   = new Synchronizer(config);
            var folder = sync.EnsureFolder(scriptsDestinationFolder);
            var result = sync.SynchronizeFolder(scriptsSource, scriptsDestinationFolder);

            // Use the hash in a script link
            var jqueryResult = result.Files.First(i => i.ServerRelativeUrl.EndsWith("jquery-2.1.4.min.js", StringComparison.InvariantCultureIgnoreCase));

            sync.EnsureSiteScriptLink("ScriptLink.jQuery", "~sitecollection/_catalogs/masterpage/scripts/jquery-2.1.4.min.js", 10000);

            var exampleResult = result.Files.First(i => i.ServerRelativeUrl.EndsWith("ionfar.example.js", StringComparison.InvariantCultureIgnoreCase));

            //            sync.EnsureSiteScriptLink("ScriptLink.IonFar.Example", exampleResult.ServerRelativeUrl + "?v=" + HttpServerUtility.UrlTokenEncode(exampleResult.Hash), 10100);
            sync.EnsureSiteScriptLink("ScriptLink.IonFar.Example", "~sitecollection/_catalogs/masterpage/scripts/ionfar.example.js?v=" + HttpServerUtility.UrlTokenEncode(exampleResult.Hash), 10100);
        }