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);
        }
示例#2
0
        public static async Task <PackageContainerNetworkHttpFile> CreateAndLoadAsync(
            PackageCentral packageCentral,
            string location,
            string fullItemLocation,
            bool overrideLoadResident,
            PackageContainerBase takeOver                = null,
            PackageContainerListBase containerList       = null,
            PackageContainerOptionsBase containerOptions = null,
            PackCntRuntimeOptions runtimeOptions         = null)
        {
            var res = new PackageContainerNetworkHttpFile(CopyMode.Serialized, takeOver,
                                                          packageCentral, location, containerOptions);

            res.ContainerList = containerList;

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

            return(res);
        }
        public static PackageContainerListBase CreateDemoData()
        {
            var tr = new PackageContainerListBase();

            tr.Add(new PackageContainerRepoItem("http://pk.festo.com/111111111111", "1.aasx"));
            tr.Add(new PackageContainerRepoItem("http://pk.festo.com/222222222222", "2.aasx"));
            tr.Add(new PackageContainerRepoItem("http://pk.festo.com/333333333333", "3.aasx"));

            tr.FileMap[0].Description = "Additional info";
            tr.FileMap[0].AasIds.Add("http://smart.festo.com/cdscsdbdsbchjdsbjhcbhjdsbchjsdbhjcsdbhjcdsbhjcsbdhj");
            tr.FileMap[0].VisualState = PackageContainerRepoItem.VisualStateEnum.Activated;
            tr.FileMap[0].VisualTime  = 6.0;

            tr.FileMap[1].Description = "Additional info";
            tr.FileMap[1].VisualState = PackageContainerRepoItem.VisualStateEnum.ReadFrom;
            tr.FileMap[1].VisualTime  = 3.0;

            tr.FileMap[2].VisualState = PackageContainerRepoItem.VisualStateEnum.WriteTo;
            tr.FileMap[2].VisualTime  = 4.5;

            return(tr);
        }
        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);
        }