Example #1
0
        /// <summary>
        /// </summary>
        public static void OnStart()
        {
            Statistic.Instantiate();

            ScmManager = new ScmManager();
            IOQueue    = new AsyncIOQueue();
            ManifestDownloadManager = new ManifestDownloadManager();

            DownloadManager = new DownloadManager();
            DownloadManager.OnRequestReplicatedBuilds += (List <Guid> SelectTags, List <Guid> IgnoreTags, DateTime NewerThan) =>
            {
                NetClient.RequestFilteredBuilds(SelectTags, IgnoreTags, NewerThan);

                Settings.ReplicationNewerThanTime = DownloadManager.ReplicationNewerThanTime;
                SaveSettings();
            };

            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Initializing settings");
            InitSettings();

            NetClient          = new Core.Client.Client();
            RemoteActionClient = new RemoteActionClient(NetClient, ManifestDownloadManager);

            TagRegistry   = new TagRegistry();
            RouteRegistry = new RouteRegistry(null, TagRegistry);
            BuildRegistry = new BuildManifestRegistry(TagRegistry);

            StorageManager = new StorageManager(Settings.StorageLocations, ManifestDownloadManager, BuildRegistry, IOQueue, Settings.StorageHeuristic, Settings.PrioritizeKeepingBuildTagIds, Settings.PrioritizeDeletingBuildTagIds);

            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Setting up network client");
            BuildRegistry.Open(Path.Combine(AppDataDir, "Manifests"), int.MaxValue);

            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Setting up network client");
            NetClient.Start(
                Settings.ServerHostname,
                Settings.ServerPort,
                Settings.ClientPortRangeMin,
                Settings.ClientPortRangeMax,
                Settings.AllowRemoteActions,
                Settings.TagIds,
                BuildRegistry,
                StorageManager,
                ManifestDownloadManager,
                TagRegistry,
                RouteRegistry
                );
            NetClient.TagIds = new List <Guid>(Settings.TagIds);

            // Setup the virtual file system we will store our available builds in.
            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Setting up build file system");

            BuildFileSystem = new VirtualFileSystem();
            NetClient.OnClientTagsUpdatedByServer += () =>
            {
                Settings.TagIds = NetClient.TagIds;

                NetClient.RestartConnections();
                SaveSettings();
            };
            NetClient.OnTagListRecieved += (List <Tag> InTags) =>
            {
                TagRenderer.InvalidateResources();
            };
            NetClient.OnPermissionsUpdated += () =>
            {
                BuildFileSystem.ForceRefresh();
                DownloadManager.ForceRefresh();
            };
            NetClient.OnBuildPublished += (string Path, Guid Id) =>
            {
                BuildFileSystem.ForceRefresh();
                DownloadManager.ForceRefresh();
            };
            NetClient.OnBuildUpdated += (string Path, Guid Id) =>
            {
                BuildFileSystem.ForceRefresh();
                DownloadManager.ForceRefresh();
            };
            NetClient.OnConnectedToServer      += () => { BuildFileSystem.ForceRefresh(); };
            NetClient.OnFilteredBuildsRecieved += (Builds) =>
            {
                DownloadManager.RecieveReplicatedBuilds(Builds);
            };
            NetClient.OnBuildsRecieved += (RootPath, Builds) =>
            {
                List <VirtualFileSystemInsertChild> NewChildren = new List <VirtualFileSystemInsertChild>();
                foreach (NetMessage_GetBuildsResponse.BuildInfo Build in Builds)
                {
                    NewChildren.Add(
                        new VirtualFileSystemInsertChild
                    {
                        VirtualPath = Build.VirtualPath,
                        CreateTime  = Build.Guid == Guid.Empty ? DateTime.UtcNow : Build.CreateTime,
                        Metadata    = Build
                    }
                        );
                }

                BuildFileSystem.ReconcileChildren(RootPath, NewChildren);
            };
            BuildFileSystem.OnRequestChildren += (FileSystem, Path) =>
            {
                if (NetClient.IsConnected)
                {
                    NetClient.RequestBuilds(Path);
                }
            };
            BuildFileSystem.Init();

            // Setup download managers for the manifest and app level.
            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Setting up manifest download manager");

            ManifestDownloadManager.Start(
                StorageManager,
                Settings.ManifestDownloadStates,
                BuildRegistry,
                IOQueue
                );

            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Setting up download manager");

            DownloadManager.Start(
                ManifestDownloadManager,
                Settings.DownloadStates,
                BuildFileSystem,
                ScmManager,
                Settings.ReplicationNewerThanTime
                );

            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Setting up update download");

            // Ensure we are downloading the latest update.
            string UpdateDownloadName = "$ Buildsync Update $";

            foreach (DownloadState State in DownloadManager.States.States)
            {
                if (State.Name == UpdateDownloadName)
                {
                    InternalUpdateDownload = State;
                    break;
                }
            }

            if (InternalUpdateDownload == null)
            {
                InternalUpdateDownload = DownloadManager.AddDownload(UpdateDownloadName, "$Internal$/Updates", 2, BuildSelectionRule.Newest, BuildSelectionFilter.None, "", "", true, false, "", "", new List <Guid>(), new List <Guid>());
            }

            // Make sure we have to get the latest manifest id before updating.
            InternalUpdateDownload.ActiveManifestId = Guid.Empty;

            // Clean up any orphan builds.
            StorageManager.CleanUpOrphanBuilds();

            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Complete");
        }
Example #2
0
        /// <summary>
        /// </summary>
        public static void ApplySettings()
        {
            // Server settings.
            if (NetClient != null)
            {
                Logger.Log(LogLevel.Info, LogCategory.Main, "ApplySettings: Apply client settings");

                if (NetClient.ServerHostname != Settings.ServerHostname ||
                    NetClient.ServerPort != Settings.ServerPort ||
                    NetClient.PeerListenPortRangeMin != Settings.ClientPortRangeMin ||
                    NetClient.PeerListenPortRangeMax != Settings.ClientPortRangeMax ||
                    !NetClient.TagIds.IsEqual(Settings.TagIds) ||
                    NetClient.AllowRemoteActions != Settings.AllowRemoteActions)
                {
                    NetClient.ServerHostname         = Settings.ServerHostname;
                    NetClient.ServerPort             = Settings.ServerPort;
                    NetClient.PeerListenPortRangeMin = Settings.ClientPortRangeMin;
                    NetClient.PeerListenPortRangeMax = Settings.ClientPortRangeMax;
                    NetClient.TagIds             = new List <Guid>(Settings.TagIds);
                    NetClient.AllowRemoteActions = Settings.AllowRemoteActions;

                    NetClient.RestartConnections();
                    SaveSettings();
                }
            }

            // Storage settings.
            if (StorageManager != null && StorageManager.MoveLocations(Settings.StorageLocations))
            {
                Logger.Log(LogLevel.Info, LogCategory.Main, "ApplySettings: Apply storage path change");

                using (MoveStorageDirectoryForm Dialog = new MoveStorageDirectoryForm())
                {
                    Dialog.ShowDialog();
                }

                SaveSettings();
            }

            if (StorageManager != null && (
                    Settings.StorageHeuristic != StorageManager.StorageHeuristic ||
                    !StorageManager.StoragePrioritizeKeepingBuildTagIds.IsEqual(Settings.PrioritizeKeepingBuildTagIds) ||
                    !StorageManager.StoragePrioritizeDeletingBuildTagIds.IsEqual(Settings.PrioritizeDeletingBuildTagIds)
                    ))
            {
                Logger.Log(LogLevel.Info, LogCategory.Main, "ApplySettings: Apply manifest download manager settings");

                StorageManager.StorageHeuristic = Settings.StorageHeuristic;
                StorageManager.StoragePrioritizeKeepingBuildTagIds  = Settings.PrioritizeKeepingBuildTagIds;
                StorageManager.StoragePrioritizeDeletingBuildTagIds = Settings.PrioritizeDeletingBuildTagIds;

                SaveSettings();
            }

            if (StorageManager != null)
            {
                StorageManager.ResetPruneTimeout();
            }

            // Add SCM Providers.
            Logger.Log(LogLevel.Info, LogCategory.Main, "ApplySettings: Apply SCM Providers");
            foreach (ScmWorkspaceSettings ScmSettings in Settings.ScmWorkspaces)
            {
                // Check if a provider already exists for this.
                bool Exists = false;
                foreach (IScmProvider Provider in ScmManager.Providers)
                {
                    if (Provider.Server == ScmSettings.Server &&
                        Provider.Username == ScmSettings.Username &&
                        Provider.Password == ScmSettings.Password &&
                        FileUtils.NormalizePath(Provider.Root) == FileUtils.NormalizePath(ScmSettings.Location))
                    {
                        Exists = true;
                        break;
                    }
                }

                if (Exists)
                {
                    continue;
                }

                // Add new provider.
                switch (ScmSettings.ProviderType)
                {
                case ScmProviderType.Perforce:
                {
                    ScmManager.AddProvider(new PerforceScmProvider(ScmSettings.Server, ScmSettings.Username, ScmSettings.Password, ScmSettings.Location));
                    break;
                }

                case ScmProviderType.Git:
                {
                    ScmManager.AddProvider(new GitScmProvider(ScmSettings.Server, ScmSettings.Username, ScmSettings.Password, ScmSettings.Location));
                    break;
                }

                default:
                {
                    Debug.Assert(false);
                    break;
                }
                }
            }

            // Remove old providers.
            foreach (IScmProvider Provider in ScmManager.Providers.ToArray())
            {
                bool Exists = false;
                foreach (ScmWorkspaceSettings ScmSettings in Settings.ScmWorkspaces)
                {
                    if (Provider.Server == ScmSettings.Server &&
                        Provider.Username == ScmSettings.Username &&
                        Provider.Password == ScmSettings.Password &&
                        FileUtils.NormalizePath(Provider.Root) == FileUtils.NormalizePath(ScmSettings.Location))
                    {
                        Exists = true;
                        break;
                    }
                }

                if (!Exists)
                {
                    ScmManager.RemoveProvider(Provider);
                }
            }

            // Bandwidth settings.
            Logger.Log(LogLevel.Info, LogCategory.Main, "ApplySettings: Apply general settings");
            NetConnection.GlobalBandwidthThrottleIn.MaxRate  = Settings.BandwidthMaxDown;
            NetConnection.GlobalBandwidthThrottleOut.MaxRate = Settings.BandwidthMaxUp;
            NetConnection.CompressDataDuringTransfer         = Settings.CompressDataDuringTransfer;

            // General settings.
            ManifestDownloadManager.SkipValidation          = Settings.SkipValidation;
            ManifestDownloadManager.SkipDiskAllocation      = Settings.SkipDiskAllocation;
            ManifestDownloadManager.AutoFixValidationErrors = Settings.AutoFixValidationErrors;

            DownloadManager.AutoReplicate       = Settings.AutoReplicate;
            DownloadManager.ReplicateSelectTags = Settings.ReplicateSelectTags;
            DownloadManager.ReplicateIgnoreTags = Settings.ReplicateIgnoreTags;

            // General settings.
            Logger.MaximumVerbosity = Program.Settings.LoggingLevel;

            // Launch settings.
            Logger.Log(LogLevel.Info, LogCategory.Main, "ApplySettings: Apply launch on startup options");
            ProcessUtils.SetLaunchOnStartup("Build Sync - Client", Settings.RunOnStartup);

            Logger.Log(LogLevel.Info, LogCategory.Main, "ApplySettings: Finished");
        }