Example #1
0
        public SmallTalksDectectorData GetSmallTalksDetectorDataFromSource(SourceProvider source)
        {
            var rules = _fileService.ReadRulesFromFile(source.Intents);
            var data  = _conversionService.ToDetectorData(rules);

            return(data);
        }
Example #2
0
        public override void ExecuteCommand()
        {
            //First argument should be the package ID
            string packageId = Arguments[0];
            //Second argument should be the package Version
            string packageVersion = Arguments[1];

            //If the user passed a source use it for the gallery location
            string source  = SourceProvider.ResolveAndValidateSource(Source) ?? NuGetConstants.DefaultGalleryServerUrl;
            var    gallery = new PackageServer(source, CommandLineConstants.UserAgent);

            //If the user did not pass an API Key look in the config file
            string apiKey = GetApiKey(source);

            string sourceDisplayName = CommandLineUtility.GetSourceDisplayName(source);

            if (NoPrompt || Console.Confirm(String.Format(CultureInfo.CurrentCulture, NuGetResources.DeleteCommandConfirm, packageId, packageVersion, sourceDisplayName)))
            {
                Console.WriteLine(NuGetResources.DeleteCommandDeletingPackage, packageId, packageVersion, sourceDisplayName);
                gallery.DeletePackage(apiKey, packageId, packageVersion);
                Console.WriteLine(NuGetResources.DeleteCommandDeletedPackage, packageId, packageVersion);
            }
            else
            {
                Console.WriteLine(NuGetResources.DeleteCommandCanceled);
            }
        }
Example #3
0
        public override void ExecuteCommand()
        {
            if (SourceProvider == null)
            {
                throw new InvalidOperationException(LocalizedResourceManager.GetString("Error_SourceProviderIsNull"));
            }
            if (Settings == null)
            {
                throw new InvalidOperationException(LocalizedResourceManager.GetString("Error_SettingsIsNull"));
            }

            //Frist argument should be the ApiKey
            string apiKey = Arguments[0];

            //If the user passed a source use it for the gallery location
            string source;

            if (String.IsNullOrEmpty(Source))
            {
                source = NuGetConstants.DefaultGalleryServerUrl;
            }
            else
            {
                source = SourceProvider.ResolveAndValidateSource(Source);
            }

            SettingsUtility.SetEncryptedValueForAddItem(Settings, ConfigurationConstants.ApiKeys, source, apiKey);

            string sourceName = CommandLineUtility.GetSourceDisplayName(source);

            Console.WriteLine(LocalizedResourceManager.GetString("SetApiKeyCommandApiKeySaved"), apiKey, sourceName);
        }
Example #4
0
        private void PrintRegisteredSourcesDetailed()
        {
            var sourcesList = SourceProvider.LoadPackageSources().ToList();

            if (!sourcesList.Any())
            {
                Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandNoSources"));
                return;
            }
            Console.PrintJustified(0, LocalizedResourceManager.GetString("SourcesCommandRegisteredSources"));
            Console.WriteLine();
            var sourcePadding = new String(' ', 6);

            for (int i = 0; i < sourcesList.Count; i++)
            {
                var source      = sourcesList[i];
                var indexNumber = i + 1;
                var namePadding = new String(' ', i >= 9 ? 1 : 2);
                Console.WriteLine(
                    "  {0}.{1}{2} [{3}]",
                    indexNumber,
                    namePadding,
                    source.Name,
                    source.IsEnabled ? LocalizedResourceManager.GetString("SourcesCommandEnabled") : LocalizedResourceManager.GetString("SourcesCommandDisabled"));
                Console.WriteLine("{0}{1}", sourcePadding, source.Source);
            }
        }
Example #5
0
        private void EnableOrDisableSource(bool enabled)
        {
            if (String.IsNullOrEmpty(Name))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired"));
            }

            var sourceList     = SourceProvider.LoadPackageSources().ToList();
            var existingSource = sourceList.Where(ps => String.Equals(Name, ps.Name, StringComparison.OrdinalIgnoreCase));

            if (!existingSource.Any())
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNoMatchingSourcesFound"), Name);
            }

            foreach (var source in existingSource)
            {
                source.IsEnabled = enabled;
            }

            SourceProvider.SavePackageSources(sourceList);
            Console.WriteLine(
                enabled ? LocalizedResourceManager.GetString("SourcesCommandSourceEnabledSuccessfully") : LocalizedResourceManager.GetString("SourcesCommandSourceDisabledSuccessfully"),
                Name);
        }
Example #6
0
        private void EnableOrDisableSource(bool enabled)
        {
            if (string.IsNullOrEmpty(Name))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired"));
            }

            var packageSource = SourceProvider.GetPackageSourceByName(Name);

            if (packageSource == null)
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNoMatchingSourcesFound"), Name);
            }

            if (enabled && !packageSource.IsEnabled)
            {
                SourceProvider.EnablePackageSource(Name);
            }
            else if (!enabled && packageSource.IsEnabled)
            {
                SourceProvider.DisablePackageSource(Name);
            }

            Console.WriteLine(
                enabled ? LocalizedResourceManager.GetString("SourcesCommandSourceEnabledSuccessfully") : LocalizedResourceManager.GetString("SourcesCommandSourceDisabledSuccessfully"),
                Name);
        }
Example #7
0
        internal string AssignId(SourceProvider sp, string name)
        {
            if (this.srcProviders.ContainsValue(sp))
            {
                return(sp.Id);
            }

            var id = SafeId(name);

            if (this.srcProviders.ContainsKey(name))
            {
                string tmpId;
                var    i = 0;
                do
                {
                    tmpId = string.Format("{0}{1:X}", id, i++);
                }while (this.srcProviders.ContainsKey(tmpId));

                id = tmpId;
            }

            this.srcProviders.Add(id, sp);

            return(id);
        }
Example #8
0
        public static IPostService CreatePostService(Container parentContainer, Container configurationContainer)
        {
            var container = new Container();

            var config = configurationContainer.GetInstance <INewsFeedConfiguration>();

            ICacheService <PostId, Post> postCache = CacheServiceBuilder <PostId, Post> .CreateService(config.PostInvalidationTime,
                                                                                                       CacheItemPriority.NotRemovable);

            ICacheService <string, IEnumerable <PostSummary> > postSummaryCache =
                CacheServiceBuilder <string, IEnumerable <PostSummary> > .CreateService(config.SummariesInvalidationTime,
                                                                                        CacheItemPriority.Default);

            container.RegisterInstance(SourceProvider.GetPostSource(parentContainer));

            container.Register <IPostService, PostServiceCache>();

            container.RegisterInstance(postCache);

            container.RegisterInstance(postSummaryCache);

            container.Verify();

            return(container.GetInstance <IPostService>());
        }
Example #9
0
        private void RemoveSource()
        {
            if (string.IsNullOrEmpty(Name))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired"));
            }
            // Check to see if we already have a registered source with the same name or source
            var sourceList      = SourceProvider.LoadPackageSources().ToList();
            var matchingSources = sourceList.Where(ps => string.Equals(Name, ps.Name, StringComparison.OrdinalIgnoreCase)).ToList();

            if (!matchingSources.Any())
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNoMatchingSourcesFound"), Name);
            }

            if (Trust)
            {
                matchingSources.ForEach(p => SourceProvider.DeleteTrustedSource(p.Name));
            }
            else
            {
                var trustedSourceList = matchingSources.Where(p => p.TrustedSource != null).Select(p => UpdateServiceIndexTrustedSource(p));
                SourceProvider.SaveTrustedSources(trustedSourceList);
            }

            sourceList.RemoveAll(matchingSources.Contains);
            SourceProvider.SavePackageSources(sourceList);
            Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandSourceRemovedSuccessfully"), Name);
        }
Example #10
0
        protected IReadOnlyCollection <Configuration.PackageSource> GetPackageSources(Configuration.ISettings settings)
        {
            var availableSources = SourceProvider.LoadPackageSources().Where(source => source.IsEnabled);
            var packageSources   = new List <Configuration.PackageSource>();

            if (!NoCache && !ExcludeCacheAsSource)
            {
                // Add the v3 global packages folder
                var globalPackageFolder = SettingsUtility.GetGlobalPackagesFolder(settings);

                if (!string.IsNullOrEmpty(globalPackageFolder) && Directory.Exists(globalPackageFolder))
                {
                    packageSources.Add(new FeedTypePackageSource(globalPackageFolder, FeedType.FileSystemV3));
                }
            }

            foreach (var source in Source)
            {
                packageSources.Add(Common.PackageSourceProviderExtensions.ResolveSource(availableSources, source));
            }

            if (Source.Count == 0)
            {
                packageSources.AddRange(availableSources);
            }

            foreach (var source in FallbackSource)
            {
                packageSources.Add(Common.PackageSourceProviderExtensions.ResolveSource(packageSources, source));
            }

            return(packageSources);
        }
Example #11
0
        public string ResolveSource(string packagePath, string configurationDefaultPushSource = null)
        {
            string source = Source;

            if (String.IsNullOrEmpty(source))
            {
                source = Settings.GetConfigValue("DefaultPushSource");
            }

            if (String.IsNullOrEmpty(source))
            {
                source = configurationDefaultPushSource;
            }

            if (!String.IsNullOrEmpty(source))
            {
                source = SourceProvider.ResolveAndValidateSource(source);
            }
            else
            {
                source = packagePath.EndsWith(PackCommand.SymbolsExtension, StringComparison.OrdinalIgnoreCase)
                    ? NuGetConstants.DefaultSymbolServerUrl
                    : NuGetConstants.DefaultGalleryServerUrl;
            }
            return(source);
        }
        /// <summary>
        /// Compares the source and destination keys, and returns the comparison result.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work.</param>
        /// <returns>The comparison result.</returns>
        public async Task <KeysComparisonResult <TKey> > CompareAsync(CancellationToken cancellationToken)
        {
            Validate();

            var comparisonResult       = new KeysComparisonResult <TKey>();
            SortedSet <TKey> sourceSet = new SortedSet <TKey>()
            , destinationSet           = new SortedSet <TKey>();

            // Get entries from source and destination at the same time
            var tskSrc  = Task.Run(async() => AddKeysToSet(sourceSet, await SourceProvider.GetAsync(cancellationToken).ConfigureAwait(false), "source list"), cancellationToken);
            var tskDest = Task.Run(async() => AddKeysToSet(destinationSet, await DestinationProvider.GetAsync(cancellationToken).ConfigureAwait(false), "destination list"), cancellationToken);

            await Task.WhenAll(tskSrc, tskDest).ConfigureAwait(false);

            // Compare keys
            foreach (var srcKey in sourceSet)
            {
                if (destinationSet.Remove(srcKey))
                {
                    comparisonResult.Matches.Add(srcKey);
                }
                else
                {
                    comparisonResult.KeysInSourceOnly.Add(srcKey);
                }
            }

            foreach (var destKey in destinationSet)
            {
                comparisonResult.KeysInDestinationOnly.Add(destKey);
            }

            return(comparisonResult);
        }
        /// <summary>
        /// Synchronizes the items that exist in the source only.
        /// </summary>
        /// <param name="batchKeys">The keys of the items.</param>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work.</param>
        /// <returns></returns>
        private async Task SyncItemsInSourceOnlyBatchAsync(List <TKey> batchKeys, CancellationToken cancellationToken)
        {
            if (!batchKeys.Any())
            {
                return;
            }

            switch (Configurations.SyncMode.ItemsInSourceOnly)
            {
            case SyncItemOperation.None:      // do nothing
                break;

            case SyncItemOperation.Add:
                var comparisonResult = new ComparisonResult <TItem>();
                comparisonResult.ItemsInSourceOnly.AddRange(await SourceProvider.GetAsync(batchKeys, cancellationToken).ConfigureAwait(false));
                await SyncAsync(comparisonResult, cancellationToken).ConfigureAwait(false);

                break;

            case SyncItemOperation.Delete:
                BeforeDeletingItemsFromSourceAction?.Invoke(batchKeys);
                await SourceProvider.DeleteAsync(batchKeys, cancellationToken).ConfigureAwait(false);

                break;

            default:
                throw new NotSupportedException($"Not supported source {nameof(SyncItemOperation)} '{Configurations.SyncMode.ItemsInSourceOnly.ToString()}'.");
            }
        }
Example #14
0
        private string GetCacheFile(SourceProvider type)
        {
            switch (type)
            {
            case SourceProvider.Pocket:
                return(string.Format(PocketCache, _authenticationService.LoggedInPocketUser.Username));

            case SourceProvider.Instapaper:
                return(string.Format(InstapaperCache, _authenticationService.LoggedInInstapaperUser.ID));

            case SourceProvider.Readability:
                return(string.Format(ReadabilityCache, _authenticationService.LoggedInReadabilityUser.Name));

            case SourceProvider.Local:
                return(LocalCache);

            case SourceProvider.InProgress:
                return(InProgressCache);

            case SourceProvider.Recent:
                return(RecentCache);

            default:
                return(null);
            }
        }
Example #15
0
        private async Task <CacheResponse> GetItemsFromCache(SourceProvider source)
        {
            var filename = GetFileName(GetCacheFile(source));

            if (await _storage.Local.FileExistsAsync(filename))
            {
                var items = new List <ReaderItem>();
                using (var file = await _storage.Local.OpenFileForReadAsync(filename))
                {
                    using (var reader = new BinaryReader(file))
                    {
                        try
                        {
                            items = reader.ReadList <ReaderItem>();
                        }
                        catch
                        {
                        }
                    }
                }

                var expired = CacheHasExpired(source);

                return(new CacheResponse(items ?? new List <ReaderItem>(), expired));
            }

            return(new CacheResponse(new List <ReaderItem>(), false));
        }
Example #16
0
        private bool CacheHasExpired(SourceProvider type)
        {
            DateTime?date;

            switch (type)
            {
            case SourceProvider.Pocket:
                date = _cacheSince.PocketSince;
                break;

            case SourceProvider.Instapaper:
                date = _cacheSince.InstapaperSince;
                break;

            case SourceProvider.Readability:
                date = _cacheSince.ReadabilitySince;
                break;

            default:
                return(true);
            }

            var expired = true;

            if (date.HasValue)
            {
                var difference = DateTime.Now - date.Value;
                expired = difference.TotalMinutes > 15;
            }

            return(expired);
        }
Example #17
0
        public Task PropertyOnBinaryOperationAsync(int literal, BinaryOperatorKind @operator, bool isRightSideExpression)
        {
            string testSource;
            string fixedSource;

            if (isRightSideExpression)
            {
                testSource  = SourceProvider.GetTargetExpressionBinaryExpressionCode(literal, @operator, withPredicate: false, "Count");
                fixedSource = SourceProvider.GetTargetPropertyBinaryExpressionCode(literal, @operator, SourceProvider.MemberName);
            }
            else
            {
                testSource  = SourceProvider.GetTargetExpressionBinaryExpressionCode(@operator, literal, withPredicate: false, "Count");
                fixedSource = SourceProvider.GetTargetPropertyBinaryExpressionCode(@operator, literal, SourceProvider.MemberName);
            }

            testSource = SourceProvider.GetCodeWithExpression(
                testSource, additionalNamspaces: SourceProvider.ExtensionsNamespace);

            fixedSource = SourceProvider.GetCodeWithExpression(
                fixedSource, additionalNamspaces: SourceProvider.ExtensionsNamespace);

            int line   = VerifierBase.GetNumberOfLines(testSource) - 3;
            int column = isRightSideExpression ?
                         21 + 3 + GetOperatorLength(SourceProvider, @operator) :
                         21;

            return(VerifyAsync(SourceProvider.MemberName, testSource, fixedSource, extensionsSource: null, line, column));
        }
Example #18
0
        public void ConfigureScriptsAndAttributes()
        {
            EnsureChildControls();

            this.Attributes.Add("name", UniqueID);

            if (RequestDelay.HasValue)
            {
                InnerTextBox.Attributes["requestDelay"] = RequestDelay.Value.ToString();
            }

            if (ExpandOnFocus)
            {
                InnerTextBox.Attributes["expandOnFocus"] = "true";
            }

            if (OptimizedMode.HasValue)
            {
                InnerTextBox.Attributes["optimizedMode"] = OptimizedMode.Value.ToString().ToLower();
            }

            if (SourceProvider.HasValue())
            {
                InnerTextBox.Attributes["SourceProvider"] = SourceProvider;
            }

            if (ClientSide)
            {
                InnerTextBox.Attributes["clientSide"] = "true";
            }

            if (AutoPostBack)
            {
                InnerTextBox.Attributes["AutoPostBack"] = "true";
            }

            if (OnSelectedValueChange.HasValue())
            {
                InnerTextBox.Attributes["OnSelectedValueChange"] = OnSelectedValueChange;
            }

            if (OnCollapse.HasValue())
            {
                InnerTextBox.Attributes["OnCollapse"] = OnCollapse;
            }

            if (NotFoundText.HasValue())
            {
                InnerTextBox.Attributes["NotFoundText"] = NotFoundText;
            }

            if (WatermarkText.HasValue())
            {
                var water = new TextBoxWatermarkExtender {
                    WatermarkText = WatermarkText, TargetControlID = InnerTextBox.ID, WatermarkCssClass = InnerTextBox.CssClass.WithSuffix(" waterMark")
                };
                Controls.Add(water);
            }
        }
Example #19
0
 public Task NonZeroEqualsCount_NoDiagnostic(bool withPredicate)
 => this.VerifyAsync(
     testSource:
     SourceProvider.GetCodeWithExpression(
         SourceProvider.GetEqualsTargetExpressionInvocationCode(1, withPredicate),
         SourceProvider.ExtensionsNamespace),
     extensionsSource:
     SourceProvider.IsAsync ? SourceProvider.GetExtensionsCode(SourceProvider.ExtensionsNamespace, SourceProvider.ExtensionsClass) : null);
Example #20
0
 public Task RightNotTargetCountComparison_NoDiagnostic(int value, BinaryOperatorKind @operator, bool withPredicate)
 => this.VerifyAsync(
     testSource:
     SourceProvider.GetCodeWithExpression(
         SourceProvider.GetTargetExpressionBinaryExpressionCode(@operator, value, withPredicate),
         SourceProvider.TestNamespace),
     extensionsSource:
     SourceProvider.GetExtensionsCode(SourceProvider.TestNamespace, SourceProvider.TestExtensionsClass));
Example #21
0
 public Task LeftCountNotComparison_NoDiagnostic(bool withPredicate)
 => this.VerifyAsync(
     testSource:
     SourceProvider.GetCodeWithExpression(
         SourceProvider.GetTargetExpressionBinaryExpressionCode(BinaryOperatorKind.Add, int.MaxValue, withPredicate),
         SourceProvider.ExtensionsNamespace),
     extensionsSource:
     SourceProvider.IsAsync ? SourceProvider.GetExtensionsCode(SourceProvider.ExtensionsNamespace, SourceProvider.ExtensionsClass) : null);
Example #22
0
 public IEnumerable <T> Parse(string source)
 {
     using (var s = SourceProvider.GetStreamReader(source))
     {
         return(StreamParser.Parse(s)
                .Select(v => ValueNormalizer.Normalize(v)));
     }
 }
Example #23
0
 public Task ZeroEqualsNotCount_NoDiagnostic()
 => this.VerifyAsync(
     testSource:
     SourceProvider.GetCodeWithExpression(
         SourceProvider.GetEqualsTargetExpressionInvocationCode(0, false, "Sum"),
         SourceProvider.ExtensionsNamespace),
     extensionsSource:
     SourceProvider.IsAsync ? SourceProvider.GetExtensionsCode(SourceProvider.ExtensionsNamespace, SourceProvider.ExtensionsClass) : null);
Example #24
0
 public Task ZeroEqualsProperty_Fixed()
 => VerifyAsync(
     methodName: null,
     testSource: SourceProvider.GetCodeWithExpression(
         SourceProvider.GetTargetPropertyEqualsInvocationCode(0, SourceProvider.MemberName)),
     fixedSource: SourceProvider.GetCodeWithExpression(
         SourceProvider.GetFixedIsEmptyPropertyCode(negate: false)),
     extensionsSource: null);
        private IEnumerator OnInputFieldValueChanged(string input)
        {
            yield return(new WaitForSeconds(_autocompleteDelay));

            var results = SourceProvider.Find(input);

            PopulateWithResults(results);
        }
Example #26
0
 public Task RightNotCountComparison_NoDiagnostic(int value, BinaryOperatorKind @operator)
 => this.VerifyAsync(
     testSource:
     SourceProvider.GetCodeWithExpression(
         SourceProvider.GetTargetExpressionBinaryExpressionCode(value, @operator, false, "Sum"),
         SourceProvider.ExtensionsNamespace),
     extensionsSource:
     SourceProvider.IsAsync ? SourceProvider.GetExtensionsCode(SourceProvider.ExtensionsNamespace, SourceProvider.ExtensionsClass) : null);
Example #27
0
 private void UpdateSoftware(SoftwareInfo software)
 {
     software.Category = CategoryProvider.GetCategory(software);
     software.Source   = SourceProvider.GetSource(software);
     software.Build    = BuildProvider.GetBuild(software);
     software.Compiler = CompilerProvider.GetCompiler(software);
     software.Encoding = EncodingProvider.GetEncoding(software);
 }
Example #28
0
        private void UpdatePackageSource()
        {
            if (String.IsNullOrEmpty(Name))
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired"));
            }

            var sourceList          = SourceProvider.LoadPackageSources().ToList();
            int existingSourceIndex = sourceList.FindIndex(ps => Name.Equals(ps.Name, StringComparison.OrdinalIgnoreCase));

            if (existingSourceIndex == -1)
            {
                throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNoMatchingSourcesFound"), Name);
            }
            var existingSource = sourceList[existingSourceIndex];

            if (!String.IsNullOrEmpty(Source) && !existingSource.Source.Equals(Source, StringComparison.OrdinalIgnoreCase))
            {
                if (!PathValidator.IsValidSource(Source))
                {
                    throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandInvalidSource"));
                }

                // If the user is updating the source, verify we don't have a duplicate.
                bool duplicateSource = sourceList.Any(ps => String.Equals(Source, ps.Source, StringComparison.OrdinalIgnoreCase));
                if (duplicateSource)
                {
                    throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandUniqueSource"));
                }
                existingSource = new Configuration.PackageSource(Source, existingSource.Name);
            }

            ValidateCredentials();

            sourceList.RemoveAt(existingSourceIndex);

            if (!string.IsNullOrEmpty(UserName))
            {
                var hasExistingAuthTypes = existingSource.Credentials?.ValidAuthenticationTypes.Any() ?? false;
                if (hasExistingAuthTypes && string.IsNullOrEmpty(ValidAuthenticationTypes))
                {
                    Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandClearingExistingAuthTypes"), Name);
                }

                var credentials = Configuration.PackageSourceCredential.FromUserInput(
                    Name,
                    UserName,
                    Password,
                    StorePasswordInClearText,
                    ValidAuthenticationTypes);
                existingSource.Credentials = credentials;
            }


            sourceList.Insert(existingSourceIndex, existingSource);
            SourceProvider.SavePackageSources(sourceList);
            Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandUpdateSuccessful"), Name);
        }
Example #29
0
        private async Task <IList <string> > GetListEndpointsAsync()
        {
            var configurationSources = SourceProvider.LoadPackageSources()
                                       .Where(p => p.IsEnabled)
                                       .ToList();

            IList <Configuration.PackageSource> packageSources;

            if (Source.Count > 0)
            {
                packageSources
                    = Source
                      .Select(s => Common.PackageSourceProviderExtensions.ResolveSource(configurationSources, s))
                      .ToList();
            }
            else
            {
                packageSources = configurationSources;
            }

            var sourceRepositoryProvider = new CommandLineSourceRepositoryProvider(SourceProvider);

            var listCommandResourceTasks = new List <Task <ListCommandResource> >();

            foreach (var source in packageSources)
            {
                var sourceRepository = sourceRepositoryProvider.CreateRepository(source);
                listCommandResourceTasks.Add(sourceRepository.GetResourceAsync <ListCommandResource>());
            }
            var listCommandResources = await Task.WhenAll(listCommandResourceTasks);

            var listEndpoints = new List <string>();

            for (int i = 0; i < listCommandResources.Length; i++)
            {
                string listEndpoint        = null;
                var    listCommandResource = listCommandResources[i];
                if (listCommandResource != null)
                {
                    listEndpoint = listCommandResource.GetListEndpoint();
                }

                if (listEndpoint != null)
                {
                    listEndpoints.Add(listEndpoint);
                }
                else
                {
                    var message = string.Format(
                        LocalizedResourceManager.GetString("ListCommand_ListNotSupported"),
                        packageSources[i].Source);

                    Console.LogWarning(message);
                }
            }

            return(listEndpoints);
        }
Example #30
0
        /// <summary>
        /// Reports a discovered test case to the message bus, after updating the source code information
        /// (if desired).
        /// </summary>
        /// <param name="testCase"></param>
        /// <param name="includeSourceInformation"></param>
        /// <param name="messageBus"></param>
        /// <returns></returns>
        protected bool ReportDiscoveredTestCase(ITestCase testCase, bool includeSourceInformation, IMessageBus messageBus)
        {
            if (includeSourceInformation && SourceProvider != null)
            {
                testCase.SourceInformation = SourceProvider.GetSourceInformation(testCase);
            }

            return(messageBus.QueueMessage(new TestCaseDiscoveryMessage(testCase)));
        }
Example #31
0
        public void SetTile(bool isTransparent, SourceProvider source)
        {
            NormalBackground.Visibility = isTransparent ? Visibility.Collapsed : Visibility.Visible;
            TransparentBackrgound.Visibility = isTransparent ? Visibility.Visible : Visibility.Collapsed;

            switch (source)
            {
                case SourceProvider.Instapaper:
                    InstapaperIcon.Visibility = Visibility.Visible;
                    break;
                case SourceProvider.Pocket:
                    PocketIcon.Visibility = Visibility.Visible;
                    break;
                case SourceProvider.Readability:
                    ReadabilityIcon.Visibility = Visibility.Visible;
                    break;
                case SourceProvider.Local:
                    LocalIcon.Visibility = Visibility.Visible;
                    break;
            }
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="MapperProvider">The mapper provider.</param>
 /// <param name="QueryProvider">The query provider.</param>
 /// <param name="SchemaProvider">The schema provider.</param>
 /// <param name="SourceProvider">The source provider.</param>
 /// <param name="Databases">The databases.</param>
 public ORMManager(Mapper.Manager MapperProvider,
     QueryProvider.Manager QueryProvider,
     Schema.Manager SchemaProvider,
     SourceProvider.Manager SourceProvider,
     IEnumerable<IDatabase> Databases)
 {
     Contract.Requires<ArgumentNullException>(MapperProvider != null, "MapperProvider");
     Contract.Requires<ArgumentNullException>(QueryProvider != null, "QueryProvider");
     Contract.Requires<ArgumentNullException>(SchemaProvider != null, "SchemaProvider");
     Contract.Requires<ArgumentNullException>(SourceProvider != null, "SourceProvider");
     Contract.Requires<ArgumentNullException>(Databases != null, "Databases");
     this.Mappings = new ListMapping<IDatabase, IMapping>();
     this.MapperProvider = MapperProvider;
     this.QueryProvider = QueryProvider;
     this.SchemaProvider = SchemaProvider;
     this.SourceProvider = SourceProvider;
     SetupMappings(Databases);
     foreach (IDatabase Database in Mappings.Keys.Where(x => x.Update))
     {
         this.SchemaProvider.Setup(Mappings, QueryProvider, Database, SourceProvider.GetSource(Database.GetType()));
     }
 }
Example #33
0
        internal string AssignId(SourceProvider sp, string name)
        {
            if (this.srcProviders.ContainsValue(sp))
                return sp.Id;

            var id = SafeId(name);

            if (this.srcProviders.ContainsKey(name))
            {
                string tmpId;
                var i = 0;
                do
                {
                    tmpId = string.Format("{0}{1:X}", id, i++);
                }
                while (this.srcProviders.ContainsKey(tmpId));

                id = tmpId;
            }

            this.srcProviders.Add(id, sp);

            return id;
        }
Example #34
0
 public async Task<bool> UnpinSource(SourceProvider source)
 {
     return false;
 }
Example #35
0
 public DateTime? GetSinceDate(SourceProvider type)
 {
     switch (type)
     {
         case SourceProvider.Pocket:
             return _cacheSince.PocketSince;
         case SourceProvider.Instapaper:
             return _cacheSince.InstapaperSince;
         case SourceProvider.Readability:
             return _cacheSince.ReadabilitySince;
         default:
             return null;
     }
 }
 public DateTime? GetSinceDate(SourceProvider type)
 {
     throw new NotImplementedException();
 }
Example #37
0
 private string GetCacheFile(SourceProvider type)
 {
     switch (type)
     {
         case SourceProvider.Pocket:
             return string.Format(PocketCache, _authenticationService.LoggedInPocketUser.Username);
         case SourceProvider.Instapaper:
             return string.Format(InstapaperCache, _authenticationService.LoggedInInstapaperUser.ID);
         case SourceProvider.Readability:
             return string.Format(ReadabilityCache, _authenticationService.LoggedInReadabilityUser.Name);
         case SourceProvider.Local:
             return LocalCache;
         case SourceProvider.InProgress:
             return InProgressCache;
         case SourceProvider.Recent:
             return RecentCache;
         default:
             return null;
     }
 }
Example #38
0
        private async Task SetSinceDate(SourceProvider type, DateTime? date = null)
        {
            switch (type)
            {
                case SourceProvider.Pocket:
                    _cacheSince.PocketSince = date;
                    break;
                case SourceProvider.Instapaper:
                    _cacheSince.InstapaperSince = date;
                    break;
                case SourceProvider.Readability:
                    _cacheSince.ReadabilitySince = date;
                    break;
                default:
                    return;
            }

            await WriteSinceToStorage().ConfigureAwait(false);
        }
Example #39
0
        private async Task WriteItemsToDisk(IList<ReaderItem> items, SourceProvider source)
        {
            var filename = GetFileName(GetCacheFile(source));

            using (var file = await _storage.Local.CreateFileAsync(filename))
            {
                using (var writer = new BinaryWriter(file))
                {
                    writer.WriteList(items);
                }
            }

            await SetSinceDate(source, DateTime.Now).ConfigureAwait(false);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 public LDAPSchemaGenerator(QueryProvider.Manager Provider, SourceProvider.Manager SourceProvider)
 {
     this.Provider = Provider;
     this.SourceProvider = SourceProvider;
 }
Example #41
0
        private bool CacheHasExpired(SourceProvider type)
        {
            DateTime? date;
            switch (type)
            {
                case SourceProvider.Pocket:
                    date = _cacheSince.PocketSince;
                    break;
                case SourceProvider.Instapaper:
                    date = _cacheSince.InstapaperSince;
                    break;
                case SourceProvider.Readability:
                    date = _cacheSince.ReadabilitySince;
                    break;
                default:
                    return true;
            }

            var expired = true;
            if (date.HasValue)
            {
                var difference = DateTime.Now - date.Value;
                expired = difference.TotalMinutes > 15;
            }

            return expired;
        }
Example #42
0
        private async Task<CacheResponse> GetItemsFromCache(SourceProvider source)
        {
            var filename = GetFileName(GetCacheFile(source));

            if (await _storage.Local.FileExistsAsync(filename))
            {
                var items = new List<ReaderItem>();
                using (var file = await _storage.Local.OpenFileForReadAsync(filename))
                {
                    using (var reader = new BinaryReader(file))
                    {
                        try
                        {
                            items = reader.ReadList<ReaderItem>();
                        }
                        catch
                        {
                        }
                    }
                }

                var expired = CacheHasExpired(source);

                return new CacheResponse(items ?? new List<ReaderItem>(), expired);
            }

            return new CacheResponse(new List<ReaderItem>(), false);
        }
Example #43
0
		/// <summary>Sets the ScopeProvider to be used.</summary>
		/// <remarks>Sets the ScopeProvider to be used.</remarks>
		public virtual void SetSourceProvider(SourceProvider sourceProvider)
		{
			this.sourceProvider = sourceProvider;
		}
Example #44
0
 public TileMessage(SourceTile tile, SourceProvider provider)
 {
     Tile = tile;
     SourceProvider = provider;
 }
Example #45
0
		/// <summary>
		/// Sets the
		/// <see cref="SourceProvider">SourceProvider</see>
		/// that provides the source to be displayed
		/// for script evaluation.
		/// </summary>
		public virtual void SetSourceProvider(SourceProvider sourceProvider)
		{
			dim.SetSourceProvider(sourceProvider);
		}
Example #46
0
        public async Task<bool> PinSource(SourceProvider source)
        {
            var id = ToString(source);
            if (string.IsNullOrEmpty(id)) return false;

            var uri = GetTileUrl(source.ToString());

            //var file = GetTileFile(source.ToString(), _settingsService.UseTransparentTile);
            //var tile = new SourceTile();
            //tile.SetTile(_settingsService.UseTransparentTile, source);

            //await SaveVisualElementToFile(tile, file, 360, 360);
            
            var arguments = string.Format(Arguments, source);

            try
            {
                var secondaryTile = new SecondaryTile(id, source.ToLocalisedSource(), arguments, new Uri(uri, UriKind.Absolute), TileSize.Square150x150) {BackgroundColor = Colors.Transparent};
                secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true;
                secondaryTile.VisualElements.ForegroundText = ForegroundText.Dark;
                secondaryTile.VisualElements.Square30x30Logo = new Uri(uri);

                return await secondaryTile.RequestCreateAsync();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("PinSource(" + source + ")", ex);
                return false;
            }
        }
Example #47
0
 private static string ToString(SourceProvider source)
 {
     switch (source)
     {
         case SourceProvider.Local:
             return Constants.Tiles.LocalId;
         case SourceProvider.Instapaper:
             return Constants.Tiles.InstapaperId;
         case SourceProvider.Readability:
             return Constants.Tiles.ReadabilityId;
         case SourceProvider.Pocket:
             return Constants.Tiles.PocketId;
         default:
             return string.Empty;
     }
 }
Example #48
0
        public async Task<bool> UnpinSource(SourceProvider source)
        {
            var id = ToString(source);
            if (string.IsNullOrEmpty(id)) return false;

            var tiles = await SecondaryTile.FindAllAsync();
            var tile = tiles.FirstOrDefault(x => x.TileId == id);
            if (tile == null) return false;

            return await tile.RequestDeleteAsync();
        }
Example #49
0
 public ArchiveMessage(SourceProvider source, ReaderItem item, Action action)
 {
     SourceProvider = source;
     Item = item;
     Action = action;
 }