示例#1
0
        public void Publish(string logicalTablePath)
        {
            if (logicalTablePath.Equals("cout", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            if (Configuration.ShouldPublish)
            {
                Trace.WriteLine($"PUBLISH: {logicalTablePath}");

                foreach (StreamAttributes item in LocalProvider.Enumerate(logicalTablePath, EnumerateTypes.File, true))
                {
                    using (Stream target = RemoteProvider.OpenWrite(item.Path))
                    {
                        using (Stream source = LocalProvider.OpenRead(item.Path))
                        {
                            source.CopyTo(target);
                        }
                    }
                }

                Trace.WriteLine($"Done with PUBLISH: {logicalTablePath}");
            }
        }
示例#2
0
        public ItemVersions ItemVersions(LocationType location, string itemName)
        {
            ItemVersions versions = LocalProvider.ItemVersions(location, itemName);

            versions.Merge(RemoteProvider.ItemVersions(location, itemName));
            return(versions);
        }
示例#3
0
        public void Delete(string logicalPath)
        {
            Trace.WriteLine($"DELETE: {logicalPath}");
            LocalProvider.Delete(logicalPath);

            if (Configuration.ShouldPublish)
            {
                Trace.Write($"DELETE: {logicalPath} in {RemoteProvider.Description}");
                RemoteProvider.Delete(logicalPath);
            }
        }
        /// <summary>
        /// make request with RemoteProvider
        /// </summary>
        static void Test2()
        {
            var                   client    = new WebHttpClient <IQueryService>(baseAddress);
            IQueryProvider        provider  = new RemoteProvider(client);
            Query <Customer>      query     = new Query <Customer>(provider);
            IQueryable <Customer> queryable = from c in ((IQueryable <Customer>)query)
                                              where c.ID > 5 && c.ID < 10
                                              select c;

            List <Customer> results = queryable.ToList();
        }
示例#5
0
        /// <summary>
        /// Initializes the RESTful API with a specified base URL, port and an instance to a <paramref name="remoteProvider"/>.
        /// </summary>
        /// <param name="baseUrl">The base URL.</param>
        /// <param name="port">The port. If set to zero the port is assumed to be in the <paramref name="baseUrl"/></param>
        /// <param name="remoteProvider">The remote data provider.</param>
        public static void InitializeRest(string baseUrl, int port, RemoteProvider remoteProvider)
        {
            if (port > 0)
            {
                var builder = new UriBuilder(new Uri(baseUrl))
                {
                    Port = port
                };
                baseUrl = builder.Uri.AbsoluteUri;
            }

            RemoteProvider = remoteProvider;

            AmpRemoteController.CreateInstance(baseUrl);
        }
示例#6
0
        public StreamAttributes Attributes(string logicalPath)
        {
            // Use the local file first, if found
            StreamAttributes attributes = LocalProvider.Attributes(logicalPath);

            // Return remote metadata instead if the local doesn't exist and the remote does
            if (!attributes.Exists)
            {
                StreamAttributes remoteAttributes = RemoteProvider.Attributes(logicalPath);
                if (remoteAttributes.Exists)
                {
                    attributes = remoteAttributes;
                }
            }

            return(attributes);
        }
示例#7
0
        public void Test2()
        {
            var              client   = new WebHttpClient <IQueryService>(baseAddress);
            IQueryProvider   provider = new RemoteProvider(client);
            Query <Customer> query    = new Query <Customer>(provider);

            ThreadPool.QueueUserWorkItem(state =>
            {
                IQueryable <Customer> queryable = from c in new Query <Customer>()
                                                  where c.ID <= 30 &&
                                                  c.Country == "Spain" ||
                                                  c.ContactTitle == "Owner"
                                                  select c;

                List <Customer> results = queryable.ToList();
                int count = queryable.Count();
            });
        }
示例#8
0
        public Stream OpenRead(string logicalPath)
        {
            // If configured to only use remote configuration, don't use the local copy for Config and Query
            if (Configuration.UseRemoteConfiguration)
            {
                if (logicalPath.StartsWith("Config\\", StringComparison.OrdinalIgnoreCase) || logicalPath.StartsWith("Query\\", StringComparison.OrdinalIgnoreCase))
                {
                    return(RemoteProvider.OpenRead(logicalPath));
                }
            }

            // Read the local copy first, if found
            if (LocalProvider.Attributes(logicalPath).Exists)
            {
                return(LocalProvider.OpenRead(logicalPath));
            }

            // If there's a remote copy, use that
            if (LocalProvider.Attributes(logicalPath).Exists == false && RemoteProvider.Attributes(logicalPath).Exists == true)
            {
                if (Configuration.ShouldDownload)
                {
                    // Download the file if configured to
                    Trace.WriteLine($"DOWNLOAD: {logicalPath}");
                    using (Stream target = LocalProvider.OpenWrite(logicalPath))
                    {
                        using (Stream source = RemoteProvider.OpenRead(logicalPath))
                        {
                            source.CopyTo(target);
                        }
                    }

                    return(LocalProvider.OpenRead(logicalPath));
                }

                return(RemoteProvider.OpenRead(logicalPath));
            }

            // If neither location had the item, throw
            throw new IOException($"\"{logicalPath}\" did not exist in {LocalProvider.Description} or {RemoteProvider.Description}");
        }
示例#9
0
        public IEnumerable <StreamAttributes> Enumerate(string underLogicalPath, EnumerateTypes types, bool recursive)
        {
            // Track item paths we've already returned
            HashSet <string> pathsSeen = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            // Return all local items first
            foreach (StreamAttributes item in LocalProvider.Enumerate(underLogicalPath, types, recursive))
            {
                pathsSeen.Add(item.Path);
                yield return(item);
            }

            // Return remote items which we didn't already return seeing locally
            foreach (StreamAttributes remoteItem in RemoteProvider.Enumerate(underLogicalPath, types, recursive))
            {
                if (pathsSeen.Add(remoteItem.Path))
                {
                    yield return(remoteItem);
                }
            }
        }
示例#10
0
        public override void ExecuteCommand()
        {
            var    agent     = base.Arguments[0];
            var    packageId = base.Arguments[1];
            string defaultEmail;

            agent = RemoteProvider.ResolveAndValidateAgent(agent, out defaultEmail);
            var remoteApiKey = GetRemoteApiKey(agent, true);

            if (string.IsNullOrEmpty(remoteApiKey))
            {
                throw new CommandLineException(Local.NoAgentApiKeyFound, new[] { Utility.GetRemoteDisplayName(agent) });
            }
            //if (!System.Messaging.MessageQueue.Exists(remoteQueue))
            //    throw new CommandLineException(Local.NoRemoteQueueFound, new object[] { remoteQueue });
            //
            DeployMessage.Item[] items;
            bool fromSpec;

            if (Path.GetFileName(packageId).EndsWith(PackageReferenceRepository.PackageReferenceFile, StringComparison.OrdinalIgnoreCase))
            {
                if (IncludeDependency)
                {
                    throw new CommandLineException("Message needed");
                }
                fromSpec   = true;
                Prerelease = true;
                items      = DeployPackagesFromConfigFile(GetPackageReferenceFile(packageId));
                if (items == null)
                {
                    Console.WriteLine(Local.DeployCommandNoItemsFound, packageId);
                    return;
                }
            }
            else
            {
                fromSpec = !IncludeDependency;
                items    = new[] { new DeployMessage.Item {
                                       PackageId = packageId, Version = Version
                                   } };
            }
            var bus = ServiceBusManager.Current;

            DeployReply.WaitState waitState = null;
            if (Wait)
            {
                waitState = new DeployReply.WaitState
                {
                    Success = b => Console.WriteLine(b),
                    Failure = () => Console.WriteLine("didn't get in time {0}, {1}", agent, packageId),
                }
            }
            ;
            bus.Send(agent, new DeployMessage
            {
                ApiKey         = remoteApiKey,
                WantReply      = Wait,
                FromSpec       = fromSpec,
                Items          = items,
                ExcludeVersion = !IncludeVersion,
                Prerelease     = Prerelease,
                Email          = Email ?? defaultEmail,
                Project        = Project,
            });
            Console.WriteLine(Local.DeployCommandSent, agent, packageId);
            if (waitState != null)
            {
                Console.WriteLine("Waiting for reply...");
                waitState.DoWait();
            }
        }
示例#11
0
        public override void ExecuteCommand()
        {
            var agent     = Arguments[0];
            var packageId = Arguments[1];

            agent = RemoteProvider.ResolveAndValidateAgent(agent, out var defaultEmail);
            var remoteApiKey = GetRemoteApiKey(agent, true);

            if (string.IsNullOrEmpty(remoteApiKey))
            {
                throw new CommandLineException(Local.NoAgentApiKeyFound, new[] { Utility.GetRemoteDisplayName(agent) });
            }
            //if (!System.Messaging.MessageQueue.Exists(remoteQueue))
            //    throw new CommandLineException(Local.NoRemoteQueueFound, new object[] { remoteQueue });
            //
            var items = GetItemsFromPackage(packageId, out var fromSpec);

            if (items == null)
            {
                Console.WriteLine(Local.DeployCommandNoItemsFound, packageId);
                return;
            }
            DeployReply.WaitState waitState = null;
            if (Wait)
            {
                waitState = new DeployReply.WaitState
                {
                    Success = x => Console.WriteLine(x),
                    Failure = () => Console.WriteLine($"Did not receive in time {agent}, {packageId}"),
                }
            }
            ;
            BusDispacher.Send(agent, new DeployMessage
            {
                ApiKey         = remoteApiKey,
                WantReply      = Wait,
                FromSpec       = fromSpec,
                Items          = items,
                ExcludeVersion = !IncludeVersion,
                Prerelease     = Prerelease,
                Email          = Email ?? defaultEmail,
                Project        = Project,
            });
            Console.WriteLine(Local.DeployCommandSent, agent, packageId);
            if (waitState != null)
            {
                Console.WriteLine("Waiting for reply...");
                waitState.DoWait();
            }
        }

        DeployMessage.Item[] GetItemsFromPackage(string packageId, out bool fromSpec)
        {
            if (Path.GetFileName(packageId).EndsWith(Constants.PackageReferenceFile, StringComparison.OrdinalIgnoreCase))
            {
                if (IncludeDependency)
                {
                    throw new CommandLineException("Message needed");
                }
                fromSpec   = true;
                Prerelease = true;
                return(DeployPackagesFromConfigFile(GetPackageReferenceFile(packageId)));
            }
            // single
            fromSpec = !IncludeDependency;
            return(new[] { new DeployMessage.Item {
                               PackageId = packageId, Version = Version
                           } });
        }

        string GetRemoteApiKey(string remote, bool throwIfNotFound = true)
        {
            if (!string.IsNullOrEmpty(ApiKey))
            {
                return(ApiKey);
            }
            string str = null;

            if (Arguments.Count > 2)
            {
                str = Arguments[2];
            }
            if (string.IsNullOrEmpty(str))
            {
                str = Utility.GetRemoteApiKey(Settings, remote, throwIfNotFound);
            }
            return(str);
        }