Example #1
0
        public PresenterPersistentState(
            Persistence.IStorageManager storageManager,
            string globalStateStorageEntryName,
            string logSourceSpecificStateSectionName,
            IChangeNotification changeNotification,
            Func <ImmutableHashSet <string> > availableTagsSelector,
            Func <IEnumerable <ILogSource> > sourcesSelector
            )
        {
            this.changeNotification        = changeNotification;
            this.stateEntry                = storageManager.GetEntry(globalStateStorageEntryName);
            this.logSourceStateSectionName = logSourceSpecificStateSectionName;
            this.availableTagsSelector     = CreateAvailableTagsSelectorAdapter(availableTagsSelector);
            this.sourcesSelector           = sourcesSelector;

            this.getDefaultPredicate = Selectors.Create(
                this.availableTagsSelector,
                availableTags => TagsPredicate.MakeMatchAnyPredicate(availableTags)
                );

            this.getTagsPredicate = Selectors.Create(
                getDefaultPredicate,
                sourcesSelector,
                () => savedTagsRevision,
                (defaultPredicate, sources, _revision) => LoadPredicate(sources, defaultPredicate, logSourceStateSectionName)
                );
        }
Example #2
0
 public Factory(
     Persistence.IStorageManager storageManager,
     Telemetry.ITelemetryCollector telemetryCollector
     )
 {
     this.cacheEntry         = storageManager.GetEntry("user-code-cache", 0x81012232);
     this.telemetryCollector = telemetryCollector;
 }
Example #3
0
 public PresentaterPersistentState(
     Persistence.IStorageManager storageManager,
     string globalStateStorageEntryName,
     string logSourceSpecificStateSectionName
     )
 {
     this.stateEntry = storageManager.GetEntry(globalStateStorageEntryName);
     this.logSourceStateSectionName = logSourceSpecificStateSectionName;
 }
Example #4
0
        public UserDefinedSearchesManager(
            Persistence.IStorageManager storage,
            IFiltersFactory filtersFactory,
            ISynchronizationContext modelThreadSynchronization
            )
        {
            this.filtersFactory       = filtersFactory;
            this.storageEntry         = new Lazy <Persistence.IStorageEntry>(() => storage.GetEntry("UserDefinedSearches"));
            this.changeHandlerInvoker = new AsyncInvokeHelper(modelThreadSynchronization, HandleChange);

            LoadItems();
        }
Example #5
0
 public Factory(
     Persistence.IStorageManager storageManager,
     Telemetry.ITelemetryCollector telemetryCollector,
     IMetadataReferencesProvider metadataReferencesProvider,
     IAssemblyLoader assemblyLoader
     )
 {
     this.cacheEntry                 = storageManager.GetEntry("user-code-cache", 0x81012232);
     this.telemetryCollector         = telemetryCollector;
     this.metadataReferencesProvider = metadataReferencesProvider ?? new DefaultMetadataReferencesProvider();
     this.assemblyLoader             = assemblyLoader ?? new DefaultAssemblyLoader();
 }
        public static void Init(
            Dialog.IPresenter optionsDialogPresenter,
            Plugins.IPageAvailability pluginsPageAvailability,
            Persistence.IStorageManager storageManager,
            MainForm.IPresenter mainFormPresenter,
            IAlertPopup popup
            )
        {
            async void handler(object s, EventArgs e)
            {
                mainFormPresenter.Loaded -= handler;
                if (pluginsPageAvailability.IsAvailable)
                {
                    bool showOffer    = false;
                    var  storageEntry = storageManager.GetEntry("PluginsInstallationOffer");
                    using (var section = storageEntry.OpenXMLSection("state", Persistence.StorageSectionOpenFlag.ReadWrite))
                    {
                        if (section.Data.Root == null)
                        {
                            showOffer = true;
                            section.Data.Add(new XElement("root"));
                        }
                    }
                    if (showOffer)
                    {
                        await Task.Delay(1000);

                        string pluginsLocation = "LogJoint options dialog";
                        if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                        {
                            pluginsLocation = "menu LogJoint -> Preferences... -> Plug-ins";
                        }
                        else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                        {
                            pluginsLocation = "Options... -> Configuration... -> Plug-ins";
                        }
                        if (popup.ShowPopup(
                                "Plug-ins",
                                "LogJoint offers features via plug-ins. Do you want to choose plug-ins now?" + Environment.NewLine + Environment.NewLine +
                                "You can manage plug-ins any time in " + Environment.NewLine +
                                pluginsLocation,
                                AlertFlags.YesNoCancel
                                ) == AlertFlags.Yes)
                        {
                            optionsDialogPresenter.ShowDialog(Dialog.PageId.Plugins);
                        }
                    }
                }
            }

            mainFormPresenter.Loaded += handler;
        }
Example #7
0
        public TelemetryCollector(
            Persistence.IStorageManager storage,
            ITelemetryUploader telemetryUploader,
            IInvokeSynchronization synchronization,
            MultiInstance.IInstancesCounter instancesCounter,
            IShutdown shutdown,
            ILogSourcesManager logSourcesManager,
            IMemBufferTraceAccess traceAccess
            )
        {
            this.telemetryUploader = telemetryUploader;
            this.synchronization   = synchronization;
            this.traceAccess       = traceAccess;

            this.telemetryStorageEntry = storage.GetEntry("telemetry");
            this.sessionStartedMillis  = Environment.TickCount;

            this.currentSessionId = telemetryUploader.IsTelemetryConfigured ?
                                    ("session" + Guid.NewGuid().ToString("n")) : null;

            this.transactionInvoker = new AsyncInvokeHelper(synchronization,
                                                            (Action)(() => DoSessionsRegistryTransaction(TransactionFlag.Default)), new object[0]);

            shutdown.Cleanup += (s, e) => shutdown.AddCleanupTask(DisposeAsync());

            if (currentSessionId != null)
            {
                CreateCurrentSessionSection();
                InitStaticTelemetryProperties();

                logSourcesManager.OnLogSourceAdded += (s, e) =>
                {
                    ++totalNfOfLogs;
                    var nfOfSimultaneousLogs = logSourcesManager.Items.Count();
                    maxNfOfSimultaneousLogs = Math.Max(maxNfOfSimultaneousLogs, nfOfSimultaneousLogs);
                };
            }

            if (telemetryUploader.IsTelemetryConfigured && instancesCounter.IsPrimaryInstance)
            {
                this.workerCancellation     = new CancellationTokenSource();
                this.workerCancellationTask = new TaskCompletionSource <int>();
                this.worker = TaskUtils.StartInThreadPoolTaskScheduler(Worker);
            }
        }
Example #8
0
        public TelemetryCollector(
            Persistence.IStorageManager storage,
            ITelemetryUploader telemetryUploader,
            ISynchronizationContext synchronization,
            MultiInstance.IInstancesCounter instancesCounter,
            IShutdown shutdown,
            IMemBufferTraceAccess traceAccess,
            ITraceSourceFactory traceSourceFactory
            )
        {
            this.trace             = traceSourceFactory.CreateTraceSource("Telemetry");
            this.telemetryUploader = telemetryUploader;
            this.synchronization   = synchronization;
            this.traceAccess       = traceAccess;

            this.telemetryStorageEntry = storage.GetEntry("telemetry");
            this.sessionStartedMillis  = Environment.TickCount;

            this.currentSessionId = telemetryUploader.IsTelemetryConfigured ?
                                    ("session" + Guid.NewGuid().ToString("n")) : null;

            this.transactionInvoker = new AsyncInvokeHelper(synchronization,
                                                            () => DoSessionsRegistryTransaction(TransactionFlag.Default));

            shutdown.Cleanup += (s, e) => shutdown.AddCleanupTask(DisposeAsync());

            if (currentSessionId != null)
            {
                CreateCurrentSessionSection();
                InitStaticTelemetryProperties();
            }

            if (telemetryUploader.IsTelemetryConfigured && instancesCounter.IsPrimaryInstance)
            {
                this.workerCancellation     = new CancellationTokenSource();
                this.workerCancellationTask = new TaskCompletionSource <int>();
                this.worker = TaskUtils.StartInThreadPoolTaskScheduler(Worker);
            }
        }
Example #9
0
        private static Persistence.IStorageEntry CreateLogSourceSpecificStorageEntry(
            ILogProviderFactory providerFactory,
            IConnectionParams connectionParams,
            Persistence.IStorageManager storageManager
            )
        {
            var identity = providerFactory.GetConnectionId(connectionParams);

            if (string.IsNullOrWhiteSpace(identity))
            {
                throw new ArgumentException("Invalid log source identity");
            }

            // additional hash to make sure that the same log opened as
            // different formats will have different storages
            ulong numericKey = storageManager.MakeNumericKey(
                providerFactory.CompanyName + "/" + providerFactory.FormatName);

            var storageEntry = storageManager.GetEntry(identity, numericKey);

            storageEntry.AllowCleanup();             // log source specific entries can be deleted if no space is available

            return(storageEntry);
        }
Example #10
0
        public AutoUpdater(
            MultiInstance.IInstancesCounter mutualExecutionCounter,
            IUpdateDownloader updateDownloader,
            ITempFilesManager tempFiles,
            IShutdown shutdown,
            IInvokeSynchronization eventInvoker,
            IFirstStartDetector firstStartDetector,
            Telemetry.ITelemetryCollector telemetry,
            Persistence.IStorageManager storage
            )
        {
            this.mutualExecutionCounter = mutualExecutionCounter;
            this.updateDownloader       = updateDownloader;
            this.tempFiles            = tempFiles;
            this.manualCheckRequested = new TaskCompletionSource <int>();
            this.firstStartDetector   = firstStartDetector;

            this.managedAssembliesPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            this.updateInfoFilePath    = Path.Combine(managedAssembliesPath, updateInfoFileName);
            this.installationDir       = Path.GetFullPath(
                Path.Combine(managedAssembliesPath, installationPathRootRelativeToManagedAssembliesLocation));

            this.eventInvoker = eventInvoker;
            this.telemetry    = telemetry;
            this.storage      = storage;

            shutdown.Cleanup += (s, e) => ((IDisposable)this).Dispose();

            this.updatesStorageEntry = storage.GetEntry("updates");

            bool isFirstInstance        = mutualExecutionCounter.IsPrimaryInstance;
            bool isDownloaderConfigured = updateDownloader.IsDownloaderConfigured;

            if (!isDownloaderConfigured)
            {
                trace.Info("autoupdater is disabled - update downloader not configured");
                isActiveAutoUpdaterInstance = false;

                state = AutoUpdateState.Disabled;
            }
            else if (!isFirstInstance)
            {
                trace.Info("autoupdater is deactivated - not a first instance of logjoint");
                isActiveAutoUpdaterInstance = false;

                state = AutoUpdateState.Inactive;
            }
            else
            {
                trace.Info("autoupdater is enabled");
                isActiveAutoUpdaterInstance = true;

                state = AutoUpdateState.Idle;

                workerCancellation      = new CancellationTokenSource();
                workerCancellationToken = workerCancellation.Token;
                workerCancellationTask  = new TaskCompletionSource <int>();

                worker = TaskUtils.StartInThreadPoolTaskScheduler(Worker);
            }
        }
Example #11
0
        public AutoUpdater(
            IFactory factory,
            MultiInstance.IInstancesCounter mutualExecutionCounter,
            IShutdown shutdown,
            ISynchronizationContext eventInvoker,
            Telemetry.ITelemetryCollector telemetry,
            Persistence.IStorageManager storage,
            ITraceSourceFactory traceSourceFactory,
            Extensibility.IPluginsManagerInternal pluginsManager,
            IChangeNotification changeNotification
            )
        {
            this.updateDownloader = factory.CreateAppUpdateDownloader();
            this.checkRequested   = new TaskCompletionSource <int>();
            this.factory          = factory;
            this.pluginsManager   = pluginsManager;
            this.trace            = traceSourceFactory.CreateTraceSource("AutoUpdater");

            var entryAssemblyLocation = Assembly.GetEntryAssembly()?.Location;

            if (entryAssemblyLocation != null)
            {
                this.managedAssembliesPath = Path.GetDirectoryName(entryAssemblyLocation);
                this.updateInfoFilePath    = Path.Combine(managedAssembliesPath, Constants.updateInfoFileName);
                this.installationDir       = Path.GetFullPath(
                    Path.Combine(managedAssembliesPath, Constants.installationPathRootRelativeToManagedAssembliesLocation));
            }

            this.eventInvoker = eventInvoker;
            this.telemetry    = telemetry;
            this.storage      = storage;

            shutdown.Cleanup += (s, e) => ((IDisposable)this).Dispose();

            this.updatesStorageEntry = storage.GetEntry("updates");

            bool isFirstInstance        = mutualExecutionCounter.IsPrimaryInstance;
            bool isDownloaderConfigured = updateDownloader.IsDownloaderConfigured;

            if (entryAssemblyLocation == null)
            {
                trace.Info("autoupdater is disabled - no entry assembly");
                isActiveAutoUpdaterInstance = false;

                state = AutoUpdateState.Disabled;
            }
            else if (!isDownloaderConfigured)
            {
                trace.Info("autoupdater is disabled - update downloader not configured");
                isActiveAutoUpdaterInstance = false;

                state = AutoUpdateState.Disabled;
            }
            else if (!isFirstInstance)
            {
                trace.Info("autoupdater is deactivated - not a first instance of logjoint");
                isActiveAutoUpdaterInstance = false;

                state = AutoUpdateState.Inactive;
            }
            else
            {
                trace.Info("autoupdater is enabled");
                isActiveAutoUpdaterInstance = true;

                state = AutoUpdateState.Idle;

                workerCancellation      = new CancellationTokenSource();
                workerCancellationToken = workerCancellation.Token;
                workerCancellationTask  = new TaskCompletionSource <int>();

                changeListenerSubscription = changeNotification.CreateSubscription(Updaters.Create(
                                                                                       () => pluginsManager.InstallationRequests,
                                                                                       (_, prev) =>
                {
                    if (prev != null)
                    {
                        checkRequested.TrySetResult(1);
                    }
                }
                                                                                       ));

                worker = TaskUtils.StartInThreadPoolTaskScheduler(Worker);
            }
        }