예제 #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
        //
        // 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;

            OpenIDClient.auth = endpoint.ToString().Contains("?auth");
            if (endpoint.ToString().Contains("?ssi"))
            {
                string[] s = endpoint.ToString().Split('=');
                OpenIDClient.ssiURL = s[1];
            }
            if (endpoint.ToString().Contains("?keycloak"))
            {
                string[] s = endpoint.ToString().Split('=');
                OpenIDClient.keycloak = s[1];
            }
        }
예제 #3
0
 public PackageContainerBase(CopyMode mode, PackageContainerBase other, PackageCentral packageCentral = null)
 {
     if ((mode & CopyMode.Serialized) > 0 && other != null)
     {
         // nothing here
     }
     if (packageCentral != null)
     {
         _packageCentral = packageCentral;
     }
 }
예제 #4
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;
     }
 }
예제 #5
0
 /// <summary>
 /// Create new event data.
 /// </summary>
 /// <param name="container">Identification of the container</param>
 /// <param name="reason">The reason</param>
 /// <param name="thisRef">Changed Referable itself</param>
 /// <param name="parentRef">A Referable, which contains the changed Referable.</param>
 /// <param name="createAtIndex">If create, at which index; else: -1</param>
 /// <param name="info">Human readable information</param>
 public PackCntChangeEventData(PackageContainerBase container,
                               PackCntChangeEventReason reason,
                               AdminShell.Referable thisRef   = null,
                               AdminShell.Referable parentRef = null,
                               int createAtIndex = -1,
                               string info       = null)
 {
     Container  = container;
     Reason     = reason;
     ThisElem   = thisRef;
     ParentElem = parentRef;
     NewIndex   = createAtIndex;
     Info       = info;
 }
 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;
     }
 }
        public static PackageContainerBase GuessAndCreateFor(
            PackageCentral packageCentral,
            string location,
            string fullItemLocation,
            bool overrideLoadResident,
            PackageContainerBase takeOver                = null,
            PackageContainerListBase containerList       = null,
            PackageContainerOptionsBase containerOptions = null,
            PackCntRuntimeOptions runtimeOptions         = null)
        {
            var task = Task.Run(() => GuessAndCreateForAsync(
                                    packageCentral, location, fullItemLocation, overrideLoadResident,
                                    takeOver, containerList, containerOptions, runtimeOptions));

            return(task.Result);
        }
예제 #8
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, 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);
            }
        }
        public static async Task <PackageContainerLocalFile> CreateAndLoadAsync(
            PackageCentral packageCentral,
            string location,
            string fullItemLocation,
            bool overrideLoadResident,
            PackageContainerBase takeOver = null,
            PackageContainerOptionsBase containerOptions = null,
            PackCntRuntimeOptions runtimeOptions         = null)
        {
            var res = new PackageContainerLocalFile(
                CopyMode.Serialized, takeOver,
                packageCentral, location, containerOptions);

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

            return(res);
        }
예제 #10
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}");
     }
 }
예제 #11
0
 public PackageContainerNetworkHttpFile(CopyMode mode, PackageContainerBase other,
                                        PackageCentral packageCentral = null,
                                        string sourceUri = null, PackageContainerOptionsBase containerOptions = null)
     : base(mode, other, packageCentral)
 {
     if ((mode & CopyMode.Serialized) > 0 && other != null)
     {
     }
     if ((mode & CopyMode.BusinessData) > 0 && other is PackageContainerNetworkHttpFile o)
     {
         sourceUri = o.Location;
     }
     if (sourceUri != null)
     {
         SetNewLocation(sourceUri);
     }
     if (containerOptions != null)
     {
         ContainerOptions = containerOptions;
     }
 }
        public static async Task <PackageContainerBase> GuessAndCreateForAsync(
            PackageCentral packageCentral,
            string location,
            string fullItemLocation,
            bool overrideLoadResident,
            PackageContainerBase takeOver                = null,
            PackageContainerListBase containerList       = 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, containerList,
                    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);
        }
        //
        // Constructors
        //

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

        public PackageConnectorEventStore(PackageContainerBase container)
            : base(container)
        {
        }