public DropBoxStorageProviderSession(DropBoxToken token, DropBoxConfiguration config, OAuthConsumerContext consumerContext, IStorageProviderService service)
 {
     SessionToken         = token;
     ServiceConfiguration = config;
     Service = service;
     Context = consumerContext;
 }
 public DropBoxStorageProviderSession(DropBoxToken token, DropBoxConfiguration config, OAuthConsumerContext consumerContext, IStorageProviderService service)
 {
     SessionToken = token;
     ServiceConfiguration = config;
     Service = service;
     Context = consumerContext;
 }
Ejemplo n.º 3
0
        private void bg_bgAppUpdateLog_DoWork(object sender, DoWorkEventArgs e)
        {
            config = DropBoxConfiguration.GetStandardConfiguration();
            if (IsolatedStorageFile.GetUserStoreForApplication().FileExists(FileName))
            {
                token = LoadAccessTokenFromIsolatedStorage();
            }
            else
            {
                requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, APP_KEY, APP_SECRET);
                //Put a breakpoint in the next line and make sure to visit AuthorizationUrl manually in the web browser
                String AuthorizationUrl = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(config, requestToken);
                token = DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(config, APP_KEY, APP_SECRET, requestToken);
            }
            m_dropBox.Open(config, token);

            //// get a specific directory in the cloud storage, e.g. /Public
            //var publicFolder = cloudStorage.GetFolder("/Photos");

            //foreach (var fof in publicFolder)
            //{
            //    //check if we have a directory
            //    Boolean bIsDirectory = fof is ICloudDirectoryEntry;

            //    //output the info
            //    Debug.WriteLine("{0}: {1}", bIsDirectory ? "DIR" : "FIL", fof.Name);
            //}

            //cloudStorage.Close();
        }
Ejemplo n.º 4
0
        public HappyPath()
        {
            var logger  = new Mock <ILogger>();
            var jobData = new DropBoxCrawlJobData(DropBoxConfiguration.Create());

            _sut = new CluedIn.Crawling.DropBox.Infrastructure.DropBoxClient(logger.Object, jobData, new RestClient());
        }
        private DropBoxStorageProviderSession Authorize(DropBoxToken token, DropBoxConfiguration configuration)
        {
            // Get a valid dropbox session through oAuth authorization
            var session = BuildSessionFromAccessToken(token, configuration);

            //( Get a valid root object
            return(GetRootBySessionExceptionHandled(session));
        }
Ejemplo n.º 6
0
        public override FileSystem.NetworkFileSystem CreateConnection()
        {
            DropBoxConfiguration config = DropBoxConfiguration.GetStandardConfiguration();

            config.APIVersion = DropBoxAPIVersion.V1;

            CloudStorage cs = new CloudStorage();

            ICloudStorageAccessToken tok = cs.DeserializeSecurityTokenEx(_tokenloc);

            cs.Open(config, tok);

            return(new FileSystem.SharpBoxFileSystem(cs));
        }
Ejemplo n.º 7
0
        public CloudService(Config config)
        {
            _config = config;

            _storageConfiguration = DropBoxConfiguration.GetStandardConfiguration();

            var requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(_storageConfiguration,
                                                                                  _config.Cloud.ConsumerKey,
                                                                                  _config.Cloud.ConsumerSecret);

            _accessToken = DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(_storageConfiguration,
                                                                                                  _config.Cloud.ConsumerKey,
                                                                                                  _config.Cloud.ConsumerSecret,
                                                                                                  requestToken);
        }
Ejemplo n.º 8
0
        protected DropBoxProviderTest()
        {
            Container          = new Mock <IWindsorContainer>();
            SystemContext      = new Mock <SystemContext>(Container.Object);
            TokenStore         = new Mock <IRelationalDataStore <Token> >();
            NameClientFactory  = new Mock <IDropBoxClientFactory>();
            ApplicationContext = new ApplicationContext(Container.Object);
            Logger             = new Mock <ILogger>();
            Configuration      = DropBoxConfiguration.Create();
            CrawlJobData       = new DropBoxCrawlJobData(Configuration);
            Client             = new Mock <DropBoxClient>(Logger.Object, CrawlJobData, new RestClient());
            Sut = new CluedIn.Provider.DropBox.DropBoxProvider(ApplicationContext, NameClientFactory.Object, Logger.Object, null, TokenStore.Object);

            NameClientFactory.Setup(n => n.CreateNew(It.IsAny <DropBoxCrawlJobData>())).Returns(() => Client.Object);
        }
        private void SetUpDropbox()
        {
            AllowClose  = false;
            _UsedConfig = DropBoxConfiguration.GetStandardConfiguration();
            _UsedConfig.AuthorizationCallBack = new Uri("http://better-explorer.com/");
            _UsedConfig.APIVersion            = DropBoxAPIVersion.V1;
            _CurrentRequestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(_UsedConfig, Networks.DropBoxAuth.Key, Networks.DropBoxAuth.Secret);
            string AuthUrl = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(_UsedConfig, _CurrentRequestToken);

            this.Navigated += HandleDropboxAuth;
            this.NavigateTo(AuthUrl);
            MainMenu.Visibility     = System.Windows.Visibility.Collapsed;
            this.Width              = 900;
            this.Height             = 650;
            BrowserFrame.Visibility = System.Windows.Visibility.Visible;
        }
Ejemplo n.º 10
0
        public CloudService(IConfigService configService)
        {
            _configService = configService;
            var config = _configService.Current;

            // currently using DropBox, but this could be made configurable

            _cloudStorageConfiguration = DropBoxConfiguration.GetStandardConfiguration();

            _cloudeStorageCredentials = new DropBoxCredentials
            {
                ConsumerKey    = config.Cloud.ConsumerKey,
                ConsumerSecret = config.Cloud.ConsumerSecret,
                UserName       = config.Cloud.UserName,
                Password       = config.Cloud.Password
            };
        }
Ejemplo n.º 11
0
            public GetDataTests()
            {
                var nameClientFactory = new Mock <IDropBoxClientFactory>();
                var stateMock         = new Mock <IAgentJobProcessorState <CrawlJobData> >();

                _clientMock = new Mock <IDropBoxClient>();

                _clientMock
                .Setup(x => x.GetCurrentAccountAsync())
                .Returns(Task.FromResult(new FullAccount()));

                _logMock = new Mock <ILogger>();

                nameClientFactory.Setup(x => x.CreateNew(It.IsAny <DropBoxCrawlJobData>())).Returns(_clientMock.Object);

                _sut = new CluedIn.Crawling.DropBox.DropBoxCrawler(nameClientFactory.Object, _logMock.Object, stateMock.Object);

                _crawlJobData = new DropBoxCrawlJobData(DropBoxConfiguration.Create());
            }
        public DropBoxCloudStorageManager(string key, string secret)
        {
            _configuration =
                CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox) as DropBoxConfiguration;
            _configuration.AuthorizationCallBack = new Uri("https://www.dropbox.com/home");

            _requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(_configuration, key, secret);

            try
            {
                _authorizationUrl =
                    DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(_configuration, _requestToken);
            }
            catch (NullReferenceException)
            {
                throw new ArgumentException("Invalid application key and/or secret");
            }

            _cloudStorage         = new CloudStorage();
            ApplicationFolderPath = "/";
        }
Ejemplo n.º 13
0
        public DropBoxTestFixture()
        {
            var executingFolder = new FileInfo(Assembly.GetExecutingAssembly().CodeBase.Substring(8)).DirectoryName;
            var p = new TestCrawlerHost(executingFolder, DropBoxConstants.ProviderName);

            // Use stub here to allow database logic to work in Provider.GetCrawlJobData
            if (!p.ContainerInstance.Kernel.HasComponent(typeof(IRelationalDataStore <Token>)))
            {
                p.ContainerInstance.Register(Component.For <IRelationalDataStore <Token> >()
                                             .Forward <ISimpleDataStore <Token> >()
                                             .Forward <IDataStore <Token> >()
                                             .Forward <IDataStore>()
                                             .Instance(new TokenDataStoreStub())
                                             .LifestyleSingleton());
            }

            ClueStorage = new ClueStorage();

            p.ProcessClue += CrawlerHost_ProcessClue;

            p.Execute(DropBoxConfiguration.Create(), DropBoxConstants.ProviderId);
        }
        public DropBoxStorageProviderSession BuildSessionFromAccessToken(DropBoxToken token, DropBoxConfiguration configuration)
        {
            // build the consumer context
            var consumerContext = new OAuthConsumerContext(token.BaseTokenInformation.ConsumerKey, token.BaseTokenInformation.ConsumerSecret);

            // build the session
            var session = new DropBoxStorageProviderSession(token, configuration, consumerContext, this);

            // go aahead
            return(session);
        }
Ejemplo n.º 15
0
        internal static CloudStorage InitCouldStorage(Form1 form, CloudStorage cloudStorage)
        {
            if (IsCloudStorageOpen(cloudStorage))
            {
                return(cloudStorage);
            }

            ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel;

            try
            {
                if (ConfigUtil.GetBoolParameter("ProxyEnabled"))
                {
                    if (String.IsNullOrEmpty(ConfigUtil.GetStringParameter("ProxyHost")))
                    {
                        WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("ProxyHostRequired", className));
                        return(null);
                    }

                    WebRequestManager.Instance.SetProxySettings(ConfigUtil.GetStringParameter("ProxyHost"), ConfigUtil.GetIntParameter("ProxyPort"), ProxyUtil.InitNetworkCredential());
                }

                DropBoxConfiguration standardConfiguration = DropBoxConfiguration.GetStandardConfiguration();

                try                                                                                                                                  //I try to authenticate myself with previous access token
                {
                    using (Stream tokenStream = new MemoryStream(Encoding.UTF8.GetBytes(PasswordUtil.GetStringParameter("LastDropboxAccessToken")))) //ConfigUtil.GetStringParameter("LastDropboxAccessToken")
                    {
                        if (tokenStream.Length == 0)
                        {
                            throw new UnauthorizedAccessException();
                        }

                        cloudStorage = new CloudStorage();
                        cloudStorage.Open(standardConfiguration, cloudStorage.DeserializeSecurityToken(tokenStream)); //cloudStorage.DeserializeSecurityToken(tokenStream, standardConfiguration)
                    }
                }
                catch (Exception) //No way, I should renew my access token
                {
                    standardConfiguration.AuthorizationCallBack = new Uri(ConstantUtil.dropboxAuthUrl);
                    DropBoxRequestToken requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(standardConfiguration, ConstantUtil.dropboxConsumerKey, ConstantUtil.dropboxConsumerSecret);

                    if (requestToken == null)
                    {
                        throw new UnauthorizedAccessException();
                    }

                    if (WindowManager.ShowInternalBrowser(form, DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(standardConfiguration, requestToken)) == DialogResult.Cancel)
                    {
                        return(null);
                    }

                    //OtherManager.StartProcess(form, DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(standardConfiguration, requestToken));
                    //if (WindowManager.ShowQuestionBox(form, LanguageUtil.GetCurrentLanguageString("SuccessfullyAuth", className)) != DialogResult.Yes)
                    //{
                    //    return null;
                    //}

                    ICloudStorageAccessToken accessToken = DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(standardConfiguration, ConstantUtil.dropboxConsumerKey, ConstantUtil.dropboxConsumerSecret, requestToken);

                    if (accessToken == null)
                    {
                        throw new UnauthorizedAccessException();
                    }

                    cloudStorage = new CloudStorage();
                    cloudStorage.Open(standardConfiguration, accessToken);

                    if (ConfigUtil.GetBoolParameter("RememberDropboxAccess"))
                    {
                        using (Stream tokenStream = cloudStorage.SerializeSecurityToken(accessToken))
                        {
                            PasswordUtil.UpdateParameter("LastDropboxAccessToken", new StreamReader(tokenStream).ReadToEnd()); //ConfigUtil.UpdateParameter("LastDropboxAccessToken", new StreamReader(tokenStream).ReadToEnd());
                        }
                    }
                    else
                    {
                        PasswordUtil.UpdateParameter("LastDropboxAccessToken", String.Empty); //ConfigUtil.UpdateParameter("LastDropboxAccessToken", String.Empty);
                    }

                    toolStripStatusLabel.Text = LanguageUtil.GetCurrentLanguageString("DropboxLogIn", className);
                }

                return(cloudStorage);
            }
            catch (UnauthorizedAccessException)
            {
                WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("UnauthorizedAccess", className));
                return(null);
            }
            catch (UriFormatException)
            {
                WindowManager.ShowAlertBox(form, LanguageUtil.GetCurrentLanguageString("UriFormat", className));
                return(null);
            }
            finally
            {
                form.Cursor = Cursors.Default;
            }
        }
Ejemplo n.º 16
0
 public GetHelperConfigurationBehaviour()
 {
     _jobData = new DropBoxCrawlJobData(DropBoxConfiguration.Create());
 }
        private DropBoxStorageProviderSession Authorize(DropBoxToken token, DropBoxConfiguration configuration)
        {
            // Get a valid dropbox session through oAuth authorization
            var session = BuildSessionFromAccessToken(token, configuration);

            //( Get a valid root object
            return GetRootBySessionExceptionHandled(session);
        }
        public DropBoxStorageProviderSession BuildSessionFromAccessToken(DropBoxToken token, DropBoxConfiguration configuration)
        {
            // build the consumer context
            var consumerContext = new OAuthConsumerContext(token.BaseTokenInformation.ConsumerKey, token.BaseTokenInformation.ConsumerSecret);

            // build the session
            var session = new DropBoxStorageProviderSession(token, configuration, consumerContext, this);

            // go aahead
            return session;
        }