Esempio n. 1
0
        /// <summary>
        /// Runs the sync command
        /// </summary>
        /// <param name="options">Fetch command options</param>
        public static void FetchUpdates(FetchUpdatesOptions options)
        {
            Endpoint upstreamEndpoint;
            CompressedMetadataStore baselineSource;

            Console.WriteLine("Opening query results file");
            baselineSource = CompressedMetadataStore.Open(options.MetadataSourcePath);
            if (baselineSource == null)
            {
                ConsoleOutput.WriteRed("Cannot open the query result file!");
                return;
            }

            ConsoleOutput.WriteGreen("Done!");
            upstreamEndpoint = baselineSource.UpstreamSource;

            // The filter to apply when fetching updates
            QueryFilter queryToRun = null;

            queryToRun = baselineSource.Filters.FirstOrDefault();
            if (queryToRun != null)
            {
                ConsoleOutput.WriteCyan("Using the filter from the baseline source. Command line filters are ignored!");
            }

            if (queryToRun == null)
            {
                // A new query will be created based on command line options
                try
                {
                    queryToRun = MetadataSync.CreateValidFilterFromOptions(options, baselineSource);
                }
                catch (Exception ex)
                {
                    ConsoleOutput.WriteRed(ex.Message);
                    return;
                }
            }

            using (var syncResult = new CompressedMetadataStore(baselineSource))
            {
                if (!string.IsNullOrEmpty(options.AccountName) && !string.IsNullOrEmpty(options.AccountGuid))
                {
                    if (!Guid.TryParse(options.AccountGuid, out Guid accountGuid))
                    {
                        ConsoleOutput.WriteRed("The account GUID must be a valid GUID string");
                        return;
                    }

                    syncResult.SetUpstreamCredentials(options.AccountName, accountGuid);
                }

                FetchUpdates(queryToRun, syncResult);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Fetches categories from an upstream server
        /// </summary>
        /// <param name="options">Pre-Fetch command options</param>
        public static void FetchCategories(FetchCategoriesOptions options)
        {
            Endpoint upstreamEndpoint;

            if (!string.IsNullOrEmpty(options.UpstreamEndpoint))
            {
                upstreamEndpoint = new Endpoint(options.UpstreamEndpoint);
            }
            else
            {
                upstreamEndpoint = Endpoint.Default;
            }

            CompressedMetadataStore syncResult;

            string destinationFile;

            if (!string.IsNullOrEmpty(options.OutFile))
            {
                if (Path.GetExtension(options.OutFile).ToLower() != ".zip")
                {
                    ConsoleOutput.WriteRed("The out file must have .zip extension");
                    return;
                }

                destinationFile = options.OutFile;
            }
            else
            {
                destinationFile = $"QueryResult-{DateTime.Now.ToFileTime()}.zip";
            }

            Console.WriteLine($"Creating compressed metadata store {destinationFile}");
            syncResult = new CompressedMetadataStore(destinationFile, upstreamEndpoint);

            if (!string.IsNullOrEmpty(options.AccountName) &&
                !string.IsNullOrEmpty(options.AccountGuid))
            {
                if (!Guid.TryParse(options.AccountGuid, out Guid accountGuid))
                {
                    ConsoleOutput.WriteRed("The account GUID must be a valid GUID string");
                    return;
                }

                syncResult.SetUpstreamCredentials(options.AccountName, accountGuid);
            }

            FetchUpdates(null, syncResult);
        }