示例#1
0
        public bool TakeOver(PackageContainerBase container)
        {
            try
            {
                // close old one
                if (Container != null)
                {
                    if (Container.IsOpen)
                    {
                        Container.Close();
                    }
                    Container = null;
                }

                // figure out, what to load
                Container = container;

                // success!
                return(true);
            }
            catch (Exception ex)
            {
                throw new PackageCentralException(
                          $"PackageCentral: while performing takeover " +
                          $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}");
            }
        }
示例#2
0
 public PackageContainerBase(CopyMode mode, PackageContainerBase other, PackageCentral packageCentral = null)
 {
     if ((mode & CopyMode.Serialized) > 0 && other != null)
     {
         // nothing here
     }
     if (packageCentral != null)
     {
         _packageCentral = packageCentral;
     }
 }
示例#3
0
 public PackageContainerBuffered(CopyMode mode, PackageContainerBase other,
                                 PackageCentral packageCentral = null)
     : base(mode, other, packageCentral)
 {
     if ((mode & CopyMode.Serialized) > 0 && other != null)
     {
     }
     if ((mode & CopyMode.BusinessData) > 0 && other is PackageContainerBuffered o)
     {
         IndirectLoadSave = o.IndirectLoadSave;
     }
 }
示例#4
0
 public PackageContainerRepoItem(CopyMode mode, PackageContainerBase other,
                                 PackageCentral packageCentral = null)
     : base(mode, other, packageCentral)
 {
     if ((mode & CopyMode.Serialized) > 0 && other is PackageContainerRepoItem o)
     {
         _assetIds       = new List <string>(o.AssetIds);
         _aasIds         = new List <string>(o.AasIds);
         _location       = "" + o.Location;
         _description    = "" + o.Description;
         _tag            = "" + o.Tag;
         this.CodeType2D = "" + o.CodeType2D;
     }
 }
示例#5
0
        public static PackageContainerBase GuessAndCreateFor(
            PackageCentral packageCentral,
            string location,
            string fullItemLocation,
            bool overrideLoadResident,
            PackageContainerBase takeOver = null,
            PackageContainerOptionsBase containerOptions = null,
            PackCntRuntimeOptions runtimeOptions         = null)
        {
            var task = Task.Run(() => GuessAndCreateForAsync(
                                    packageCentral, location, fullItemLocation, overrideLoadResident,
                                    takeOver, containerOptions, runtimeOptions));

            return(task.Result);
        }
示例#6
0
        public bool Load(
            PackageCentral packageCentral,
            string location,
            string fullItemLocation,
            bool overrideLoadResident,
            PackageContainerOptionsBase containerOptions = null,
            PackCntRuntimeOptions runtimeOptions         = null)
        {
            try
            {
                // close old one
                if (Container != null)
                {
                    if (Container.IsOpen)
                    {
                        Container.Close();
                    }
                    Container = null;
                }

                // figure out, what to load
                var task = Task.Run(async() => await PackageContainerFactory.GuessAndCreateForAsync(
                                        packageCentral,
                                        location,
                                        fullItemLocation,
                                        overrideLoadResident,
                                        null,
                                        containerOptions,
                                        runtimeOptions));
                var guess = task.Result;

                if (guess == null)
                {
                    return(false);
                }

                // success!
                Container = guess;
                return(true);
            }
            catch (Exception ex)
            {
                throw new PackageCentralException(
                          $"PackageCentral: while performing load from {location} " +
                          $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}", ex);
            }
        }
示例#7
0
        public static async Task <PackageContainerNetworkHttpFile> CreateAndLoadAsync(
            PackageCentral packageCentral,
            string location,
            string fullItemLocation,
            bool overrideLoadResident,
            PackageContainerBase takeOver = null,
            PackageContainerOptionsBase containerOptions = null,
            PackCntRuntimeOptions runtimeOptions         = null)
        {
            var res = new PackageContainerNetworkHttpFile(CopyMode.Serialized, takeOver,
                                                          packageCentral, location, containerOptions);

            if (overrideLoadResident || true == res.ContainerOptions?.LoadResident)
            {
                await res.LoadFromSourceAsync(fullItemLocation, runtimeOptions);
            }

            return(res);
        }
示例#8
0
        //
        // Constructors
        //

        /// <summary>
        /// By design, a PackageConnector is based on a PackageContainer. For some funcionality, it will require
        /// a link to the container. For some other, not.
        /// The basepoint is the left part of an URL, which forms an Endpoint; routes will generated to the right of
        /// it.
        /// </summary>
        public PackageConnectorHttpRest(PackageContainerBase container, Uri endpoint)
            : base(container)
        {
            _endpoint = endpoint;

            // split into base address and end part
            _baseAddress      = new Uri(endpoint.GetLeftPart(UriPartial.Authority));
            _endPointSegments = endpoint.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped);

            // make HTTP Client
            var handler = new HttpClientHandler();

            handler.DefaultProxyCredentials = CredentialCache.DefaultCredentials;

            _client = new HttpClient(handler);
            _client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));
            _client.BaseAddress = _baseAddress;
        }
示例#9
0
 public void Close()
 {
     try
     {
         // close old one
         if (Container != null)
         {
             if (Container.IsOpen)
             {
                 Container.Close();
             }
             Container = null;
         }
     }
     catch (Exception ex)
     {
         throw new PackageCentralException(
                   $"PackageCentral: while performing close " +
                   $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}");
     }
 }
示例#10
0
 public PackageContainerLocalFile(CopyMode mode, PackageContainerBase other,
                                  PackageCentral packageCentral = null,
                                  string sourceFn = null, PackageContainerOptionsBase containerOptions = null)
     : base(mode, other, packageCentral)
 {
     if ((mode & CopyMode.Serialized) > 0 && other != null)
     {
     }
     if ((mode & CopyMode.BusinessData) > 0 && other is PackageContainerLocalFile o)
     {
         sourceFn = o.Location;
     }
     if (sourceFn != null)
     {
         SetNewLocation(sourceFn);
     }
     if (containerOptions != null)
     {
         ContainerOptions = containerOptions;
     }
 }
示例#11
0
        public static async Task <PackageContainerBase> GuessAndCreateForAsync(
            PackageCentral packageCentral,
            string location,
            string fullItemLocation,
            bool overrideLoadResident,
            PackageContainerBase takeOver = null,
            PackageContainerOptionsBase containerOptions = null,
            PackCntRuntimeOptions runtimeOptions         = null)
        {
            // access
            if (location == null)
            {
                return(null);
            }
            var ll = location.ToLower();

            // guess
            runtimeOptions?.Log?.Info($"Trying to guess package container for {location} ..");
            var guess = PackageContainerGuess.FromLocation(location, runtimeOptions);

            if (guess == null)
            {
                runtimeOptions?.Log?.Info("Aborting");
                return(null);
            }

            // start
            runtimeOptions?.Log?.Info($".. with containerOptions = {containerOptions?.ToString()}");

            // TODO (MIHO, 2021-02-01): check, if demo option is still required
            if (ll.Contains("/demo"))
            {
                return(await Demo(packageCentral, location,
                                  overrideLoadResident, containerOptions, runtimeOptions));
            }

            // starts with http ?
            if (guess.GuessedType == typeof(PackageContainerNetworkHttpFile))
            {
                var cnt = await PackageContainerNetworkHttpFile.CreateAndLoadAsync(
                    packageCentral, location, fullItemLocation,
                    overrideLoadResident, takeOver,
                    containerOptions, runtimeOptions);

                if (cnt.ContainerOptions.StayConnected &&
                    guess.AasId.HasContent() &&
                    guess.HeadOfPath.HasContent())
                {
                    cnt.ConnectorPrimary = new PackageConnectorHttpRest(cnt,
                                                                        new Uri(guess.HeadOfPath + "/aas/" + guess.AasId));
                }

                return(cnt);
            }

            // check FileInfo for (possible?) local file
            FileInfo fi = null;

            try
            {
                fi = new FileInfo(location);
            }
            catch (Exception ex)
            {
                LogInternally.That.SilentlyIgnoredError(ex);
            }

            // if file, try to open (might throw exceptions!)
            if (fi != null)
            {
                // seems to be a valid (possible) file
                return(await PackageContainerLocalFile.CreateAndLoadAsync(
                           packageCentral, location, fullItemLocation, overrideLoadResident, takeOver, containerOptions));
            }

            // no??
            runtimeOptions?.Log?.Info($".. no any possible option for package container found .. Aborting!");
            return(null);
        }
示例#12
0
        //
        // Constructors
        //

        public PackageConnectorEventStore(PackageContainerBase container)
            : base(container)
        {
        }
示例#13
0
        //
        // Constructors
        //

        /// <summary>
        /// By design, a PackageConnector is based on a PackageContainer.
        /// </summary>
        public PackageConnectorBase(PackageContainerBase container)
        {
            _container = container;
        }