Example #1
0
        private static void SetToken(Dictionary <string, string> args)
        {
            Global.Initialize(false);

            AdapterBase adapter = GetAdapter(args);
            string      file;

            if (!args.TryGetValue("file", out file))
            {
                throw new Exception("/file is required");
            }

            if (adapter.Configuration.AdapterTypeId == OneDriveAdapter.TargetTypeId)
            {
                string        tokenContent = File.ReadAllText(file);
                TokenResponse token        = JsonConvert.DeserializeObject <TokenResponse>(tokenContent);

                // Encrypt the token if not already encrypted
                token.Protect();

                ((OneDriveAdapterConfiguration)adapter.Configuration).CurrentToken = token;

                adapter.SaveConfiguration();
            }
            else
            {
                AdapterRegistration registration =
                    AdapterRegistry.GetRegistrationByTypeId(adapter.Configuration.AdapterTypeId);

                throw new Exception(
                          string.Format("Cannot set token from adapter with type {0} ({1})",
                                        registration.AdapterType.Name, adapter.Configuration.AdapterTypeId));
            }
        }
Example #2
0
        public static void RegisterDependencies(AdapterRegistration adapterDelegate)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <EmployeesService>().As <IEmployeesService>();
            builder.RegisterType <ClientsService>().As <IClientsService>();
            builder.RegisterType <PropertyInsuranceDefinitionService>().As <IPropertyInsuranceDefinitionService>();
            builder.RegisterType <VehicleInsuranceDefinitionService>().As <IVehicleInsuranceDefinitionService>();

            adapterDelegate(builder);

            _container = builder.Build().BeginLifetimeScope();
        }
Example #3
0
        public static void RegisterDependencies(AdapterRegistration adapterDelegate)
        {
            var builder = new ContainerBuilder();


            var importer = new Importer();

            var logger      = importer.Loggers.First();
            var dataStorage = importer.DataStorages.First();

            logger.Log("Starting up... Registering dependencies.", LogSeverity.Info);
            if (importer.Loggers.Count() > 1)
            {
                logger.Log($"Detected two logging plugins, defaulting to {logger.GetType().FullName}",
                           LogSeverity.Warning);
            }
            else
            {
                logger.Log($"Loaded logging plugin: {logger.GetType().FullName}", LogSeverity.Info);
            }

            if (importer.DataStorages.Count() > 1)
            {
                logger.Log($"Detected two storage plugins, defaulting to {dataStorage.GetType().FullName}",
                           LogSeverity.Warning);
            }
            else
            {
                logger.Log($"Loaded storage plugin: {dataStorage.GetType().FullName}", LogSeverity.Info);
            }

            builder.RegisterInstance(dataStorage).As <IDataStorage>().SingleInstance();
            builder.RegisterInstance(logger).As <ILogger>().SingleInstance();
            builder.RegisterType <AssemblyMetadataExtractor>().As <IAssemblyMetadataExtractor>().SingleInstance();
            builder.RegisterType <NamespaceMetadataExtractor>().As <INamespaceMetadataExtractor>().SingleInstance();
            builder.RegisterType <TypeMetadataExtractor>().As <ITypeMetadataExtractor>().SingleInstance();
            builder.RegisterType <MethodMetadataExtractor>().As <IMethodMetadataExtractor>().SingleInstance();
            builder.RegisterType <MetadataDetailsProvider>().As <IMetadataDetailsProvider>().SingleInstance();
            builder.RegisterType <BrowserViewModel>().SingleInstance();

            builder.RegisterType <ClassNodeViewModel>();
            builder.RegisterType <MethodNodeViewModel>();

            adapterDelegate(builder);

            _container = builder.Build().BeginLifetimeScope();


            logger.Log("Registered all dependencies.", LogSeverity.Info);
        }
Example #4
0
        public static SyncRelationship Load(Guid relationshipId)
        {
            string relationshipDir           = Path.Combine(Global.AppDataRoot, relationshipId.ToString("N"));
            RelationshipConfiguration config = RelationshipConfiguration.Load(relationshipDir);

            Logger.RelationshipLoaded(
                config.RelationshipId,
                new Dictionary <string, object>()
            {
                { "Name", config.Name },
                { "RelationshipId", config.RelationshipId },
                { "InitiallyCreatedUtc", config.InitiallyCreatedUtc },
                { "Scope", config.Scope }
            });

            SyncRelationship relationship = new SyncRelationship(config);

            // Get the adapters from the configuration for this relationship
            foreach (AdapterConfiguration adapterConfig in config.Adapters)
            {
                // Get the adapter registration information for this type of adapter
                AdapterRegistration registration =
                    AdapterRegistry.GetRegistrationByTypeId(adapterConfig.AdapterTypeId);

                if (registration == null)
                {
                    throw new Exception("No adapter registration found with TypeId " + adapterConfig.AdapterTypeId);
                }

                // Create the adapter object based on its config from the database
                AdapterBase adapter = (AdapterBase)Activator.CreateInstance(
                    registration.AdapterType,
                    relationship,
                    adapterConfig);

                relationship.Adapters.Add(adapter);

                // Load adapter-specific configuration settings
                adapter.LoadConfiguration();
            }

            return(relationship);
        }
Example #5
0
        private static void ExtractToken(Dictionary <string, string> args)
        {
            Global.Initialize(false);

            AdapterBase adapter = GetAdapter(args);

            bool   formatToken = args.ContainsKey("formatToken");
            string file;

            args.TryGetValue("file", out file);

            if (adapter.Configuration.AdapterTypeId == OneDriveAdapter.TargetTypeId)
            {
                TokenResponse token = ((OneDriveAdapterConfiguration)adapter.Configuration).CurrentToken;

                if (args.ContainsKey("decrypt"))
                {
                    token.Unprotect();
                }

                string formattedToken = JsonConvert.SerializeObject(token, formatToken ? Formatting.Indented : Formatting.None);

                if (string.IsNullOrEmpty(file))
                {
                    Console.WriteLine(formattedToken);
                }
                else
                {
                    File.WriteAllText(file, formattedToken);
                }
            }
            else
            {
                AdapterRegistration registration =
                    AdapterRegistry.GetRegistrationByTypeId(adapter.Configuration.AdapterTypeId);

                throw new Exception(
                          string.Format("Cannot extract token from adapter with type {0} ({1})",
                                        registration.AdapterType.Name, adapter.Configuration.AdapterTypeId));
            }
        }
Example #6
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject jObject = JObject.Load(reader);
            Guid    typeId  = Guid.Parse(jObject["AdapterTypeId"].Value <string>());

            //if (typeId == OneDriveAdapter.TargetTypeId)
            //{
            //    return JsonConvert.DeserializeObject<OneDriveAdapterConfiguration>(
            //        jObject.ToString(),
            //        SerializerSettings);
            //}

            //if (typeId == WindowsFileSystemAdapter.TargetTypeId)
            //{
            //    return JsonConvert.DeserializeObject<WindowsFileSystemAdapterConfiguration>(
            //        jObject.ToString(),
            //        SerializerSettings);
            //}

            //if (typeId == BackblazeB2Adapter.TargetTypeId)
            //{
            //    return JsonConvert.DeserializeObject<BackblazeB2AdapterConfiguration>(
            //        jObject.ToString(),
            //        SerializerSettings);
            //}

            AdapterRegistration registration = AdapterRegistry.GetRegistrationByTypeId(typeId);

            if (registration == null)
            {
                throw new Exception("No adapter registration found with TypeId " + typeId);
            }

            return(JsonConvert.DeserializeObject(
                       jObject.ToString(),
                       registration.AdapterConfigurationType,
                       SerializerSettings));

            //throw new NotImplementedException("Cannot read adapter configuration for type ID " + typeId);
        }