Пример #1
0
        public void AddByAasPackage(PackageCentral packageCentral, AdminShellPackageEnv env, string fn)
        {
            // access
            if (env == null)
            {
                return;
            }

            // ok, add
            var fi = PackageContainerFactory.GuessAndCreateFor(
                packageCentral,
                location: fn,
                fullItemLocation: fn,
                overrideLoadResident: false,
                containerOptions: PackageContainerOptionsBase.CreateDefault(Options.Curr));

            if (fi is PackageContainerRepoItem ri)
            {
                fi.Env = env;
                ri.CalculateIdsTagAndDesc();
                ri.VisualState = PackageContainerRepoItem.VisualStateEnum.ReadFrom;
                ri.VisualTime  = 2.0;
                this.Add(ri);
            }
        }
Пример #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 PackageContainerLocalFile(
     PackageCentral packageCentral,
     string sourceFn, PackageContainerOptionsBase containerOptions = null)
     : base(packageCentral)
 {
     Init();
     SetNewLocation(sourceFn);
     if (containerOptions != null)
     {
         ContainerOptions = containerOptions;
     }
 }
Пример #5
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;
     }
 }
Пример #6
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);
        }
Пример #7
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);
            }
        }
Пример #8
0
 public PackageContainerRepoItem(string assetId, string fn, string aasId = null, string description = "",
                                 string tag = "", string code = "", PackageCentral packageCentral = null)
     : base(packageCentral)
 {
     _location = fn;
     if (assetId != null)
     {
         this.AssetIds.Add(assetId);
     }
     if (aasId != null)
     {
         this.AasIds.Add(aasId);
     }
     _description    = description;
     _tag            = tag;
     this.CodeType2D = code;
 }
Пример #9
0
        public void AddByAasxFn(PackageCentral packageCentral, string fn)
        {
            try
            {
                // load
                var pkg = new AdminShellPackageEnv(fn);

                // for each Admin Shell and then each Asset
                this.AddByAasPackage(packageCentral, pkg, fn);

                // close directly!
                pkg.Close();
            }
            catch (Exception ex)
            {
                AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
            }
        }
Пример #10
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);
        }
Пример #11
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;
     }
 }
Пример #12
0
        public static async Task <PackageContainerBase> Demo(
            PackageCentral packageCentral,
            string location,
            bool overrideLoadResident,
            PackageContainerOptionsBase containerOptions = null,
            PackCntRuntimeOptions ro = null)
        {
            // Log location
            ro?.Log?.Info($"Perform Demo() for location {location}");

            // ask for a list
            var li1 = new List <SelectFromListFlyoutItem>();

            li1.Add(new SelectFromListFlyoutItem("AAAAAAAAAAAAAAAAAAAAAAAAAAA", "A"));
            li1.Add(new SelectFromListFlyoutItem("bbbbbbbbbbbb", "B"));
            li1.Add(new SelectFromListFlyoutItem("CCCCCCCCCCCCCCCCCC  CCCCC", "C"));

            var waitLi1 = new TaskCompletionSource <SelectFromListFlyoutItem>();

            ro?.AskForSelectFromList?.Invoke("Testselect", li1, waitLi1);
            var xx = await waitLi1.Task;

            ro?.Log?.Info($".. selected item is {"" + xx?.Text}");

            // ask for a list
            var li2 = new List <SelectFromListFlyoutItem>();

            li2.Add(new SelectFromListFlyoutItem("111111111", "A"));
            li2.Add(new SelectFromListFlyoutItem("222222222222222222222222", "B"));
            li2.Add(new SelectFromListFlyoutItem("3333333333333  3333", "C"));

            var waitLi2 = new TaskCompletionSource <SelectFromListFlyoutItem>();

            ro?.AskForSelectFromList?.Invoke("Testselect", li2, waitLi2);
            var xy = await waitLi2.Task;

            ro?.Log?.Info($".. selected item is {"" + xy?.Text}");

            // ask for credentials
            var waitCre = new TaskCompletionSource <PackageContainerCredentials>();

            ro?.AskForCredentials?.Invoke("Fill user credentials", waitCre);
            var xz = await waitCre.Task;

            ro?.Log?.Info($".. credentials are {"" + xz?.Username} and {"" + xz?.Password}");

            // debug some important blocks of text
            ro?.Log?.Info(StoredPrint.Color.Yellow, "Showing fingerprint:");
            var sum = "";

            for (int i = 0; i < 1000; i++)
            {
                sum += $"{i} ";
            }
            ro?.Log?.Info($"Showing fingerprint: {sum}");

            // done
            ro?.Log?.Info($".. demo loading from internet ..");
            return(await PackageContainerNetworkHttpFile.CreateAndLoadAsync(
                       packageCentral,
                       "http://admin-shell-io.com:51310/server/getaasx/0",
                       "http://admin-shell-io.com:51310/server/getaasx/0",
                       // "http://localhost:51310/server/getaasx/0",
                       overrideLoadResident, null, containerOptions, ro));
        }
Пример #13
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);
        }
Пример #14
0
 public PackageContainerBase(PackageCentral packageCentral)
 {
     _packageCentral = packageCentral;
 }
Пример #15
0
 public PackageContainerBuffered(PackageCentral packageCentral) : base(packageCentral)
 {
 }
Пример #16
0
 public PackageContainerRepoItem(PackageCentral packageCentral) : base(packageCentral)
 {
 }