示例#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
        private void TextBoxContextMenu_TextChanged(object sender, TextChangedEventArgs e)
        {
            var tb = sender as TextBox;
            var fi = this.rightClickSelectedItem;

            if (tb?.Name == "TextBoxTag" && fi != null)
            {
                fi.Tag = tb.Text;
            }

            if (tb?.Name == "TextBoxDescription" && fi != null)
            {
                fi.Description = tb.Text;
            }

            if (tb?.Name == "TextBoxCode" && fi != null)
            {
                fi.CodeType2D = tb.Text;
            }

            if (tb?.Name == "TextBoxUpdatePeriod" && fi != null)
            {
                if (fi.ContainerOptions == null)
                {
                    fi.ContainerOptions = PackageContainerOptionsBase.CreateDefault(Options.Curr);
                }
                if (Int32.TryParse("" + tb.Text, out int i))
                {
                    fi.ContainerOptions.UpdatePeriod = Math.Max(OptionsInformation.MinimumUpdatePeriod, i);
                }
            }
        }
示例#3
0
 public PackageContainerLocalFile(
     PackageCentral packageCentral,
     string sourceFn, PackageContainerOptionsBase containerOptions = null)
     : base(packageCentral)
 {
     Init();
     SetNewLocation(sourceFn);
     if (containerOptions != null)
     {
         ContainerOptions = containerOptions;
     }
 }
示例#4
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);
        }
示例#5
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);
            }
        }
示例#6
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);
        }
示例#7
0
        //
        // Constructor
        //

        public static PackageContainerOptionsBase CreateDefault(
            OptionsInformation opts,
            bool loadResident = false)
        {
            // first act
            var res = new PackageContainerOptionsBase();

            res.LoadResident = loadResident;
            if (opts == null)
            {
                return(res);
            }

            // now take some user options, as well
            res.StayConnected = opts.DefaultStayConnected;
            res.UpdatePeriod  = Math.Max(OptionsInformation.MinimumUpdatePeriod, opts.DefaultUpdatePeriod);

            // ok
            return(res);
        }
示例#8
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;
     }
 }
        //
        // UI higher-level stuff (taken over and maintained in from MainWindow.CommandBindings.cs)
        //

        public void CommandBinding_FileRepoAll(Control senderList, PackageContainerListBase fr, string cmd)
        {
            // access
            if (cmd == null || _flyout == null)
            {
                return;
            }
            cmd = cmd.ToLower().Trim();

            // modify list
            if (fr != null && RepoList != null && RepoList.Contains(fr))
            {
                if (cmd == "filerepoclose")
                {
                    if (AnyUiMessageBoxResult.OK != _flyout.MessageBoxFlyoutShow(
                            "Close file repository? Pending changes might be unsaved!",
                            "AASX File Repository",
                            AnyUiMessageBoxButton.OKCancel, AnyUiMessageBoxImage.Hand))
                    {
                        return;
                    }

                    RepoList.Remove(fr);
                }

                if (cmd == "item-up")
                {
                    // TODO (MIHO, 2021-01-09): check to use moveup/down of the PackageContainerListBase
                    int i = RepoList.IndexOf(fr);
                    if (i > 0)
                    {
                        RepoList.RemoveAt(i);
                        RepoList.Insert(i - 1, fr);
                    }
                }

                if (cmd == "item-down")
                {
                    // TODO (MIHO, 2021-01-09): check to use moveup/down of the PackageContainerListBase
                    int i = RepoList.IndexOf(fr);
                    if (i < RepoList.Count - 1)
                    {
                        RepoList.RemoveAt(i);
                        RepoList.Insert(i + 1, fr);
                    }
                }

                if (cmd == "filereposaveas")
                {
                    // prepare dialogue
                    var outputDlg = new Microsoft.Win32.SaveFileDialog();
                    outputDlg.Title    = "Select AASX file repository to be saved";
                    outputDlg.FileName = "new-aasx-repo.json";

                    if (fr is PackageContainerListLocal frl && frl.Filename.HasContent())
                    {
                        outputDlg.InitialDirectory = Path.GetDirectoryName(frl.Filename);
                        outputDlg.FileName         = Path.GetFileName(frl.Filename);
                    }

                    outputDlg.DefaultExt = "*.json";
                    outputDlg.Filter     = "AASX repository files (*.json)|*.json|All files (*.*)|*.*";

                    if (Options.Curr.UseFlyovers && _flyout != null)
                    {
                        _flyout.StartFlyover(new EmptyFlyout());
                    }
                    var res = outputDlg.ShowDialog();
                    if (Options.Curr.UseFlyovers && _flyout != null)
                    {
                        _flyout.CloseFlyover();
                    }

                    if (res != true)
                    {
                        return;
                    }

                    // OK!
                    var fn = outputDlg.FileName;
                    try
                    {
                        Log.Singleton.Info($"Saving AASX file repository to {fn} ..");
                        fr.SaveAsLocalFile(fn);
                        if (fr is PackageContainerListLocal frl2)
                        {
                            frl2.Filename = fn;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Singleton.Error(ex, $"When saving AASX file repository to {fn}");
                    }
                }

                if (cmd == "filerepoquery")
                {
                    // dialogue
                    var uc = new SelectFromRepositoryFlyout();
                    uc.Margin = new Thickness(10);
                    if (uc.LoadAasxRepoFile(items: fr.EnumerateItems()))
                    {
                        uc.ControlClosed += () =>
                        {
                            var fi = uc.ResultItem;
                            var fn = fi?.Location;
                            if (fn != null)
                            {
                                // start animation
                                fr.StartAnimation(fi,
                                                  PackageContainerRepoItem.VisualStateEnum.ReadFrom);

                                try
                                {
                                    // load
                                    Log.Singleton.Info("Switching to AASX repository file {0} ..", fn);
                                    FileDoubleClick?.Invoke(senderList, fr, fi);
                                }
                                catch (Exception ex)
                                {
                                    Log.Singleton.Error(
                                        ex, $"When switching to AASX repository file {fn}.");
                                }
                            }
                        };
                        _flyout.StartFlyover(uc);
                    }
                }

                if (cmd == "filerepomakerelative")
                {
                    if (fr is PackageContainerListLocal frl)
                    {
                        // make sure
                        if (AnyUiMessageBoxResult.OK != _flyout.MessageBoxFlyoutShow(
                                "Make filename relative to the locaton of the file repository? " +
                                "This enables re-locating the repository.",
                                "AASX File Repository",
                                AnyUiMessageBoxButton.OKCancel, AnyUiMessageBoxImage.Hand))
                        {
                            return;
                        }

                        if (!frl.Filename.HasContent())
                        {
                            Log.Singleton.Error("AASX file repository has no valid filename!");
                            return;
                        }

                        // execute (is data binded)
                        try
                        {
                            Log.Singleton.Info("Make AASX file names relative to {0}",
                                               Path.GetFullPath(Path.GetDirectoryName("" + frl.Filename)));
                            frl.MakeFilenamesRelative();
                        }
                        catch (Exception ex)
                        {
                            Log.Singleton.Error(
                                ex, $"When making AASX file names in repository relative.");
                        }
                    }
                }

                if (cmd == "filerepoprint")
                {
                    // try print
                    try
                    {
                        AasxPrintFunctions.PrintRepositoryCodeSheet(
                            repoDirect: fr, title: "AASX file repository");
                    }
                    catch (Exception ex)
                    {
                        Log.Singleton.Error(ex, "When printing, an error occurred");
                    }
                }

                if (cmd == "filerepoaddcurrent")
                {
                    // check
                    var veAas = _manageVisuElems?.GetSelectedItem() as VisualElementAdminShell;

                    var veEnv = veAas?.FindFirstParent((ve) =>
                                                       (ve is VisualElementEnvironmentItem vev &&
                                                        vev.theItemType == VisualElementEnvironmentItem.ItemType.Package), includeThis: false)
                                as VisualElementEnvironmentItem;

                    if (veAas == null || veAas.theAas == null || veAas.theEnv == null || veAas.thePackage == null ||
                        veEnv == null || !veEnv.thePackageSourceFn.HasContent())
                    {
                        _flyout.MessageBoxFlyoutShow(
                            "No valid AAS selected. The application needs to be in edit mode. " +
                            "Aborting.", "AASX File repository",
                            AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Error);
                        return;
                    }

                    // generate appropriate container
                    var cnt = PackageContainerFactory.GuessAndCreateFor(
                        null, veEnv.thePackageSourceFn, veEnv.thePackageSourceFn,
                        overrideLoadResident: false,
                        containerOptions: PackageContainerOptionsBase.CreateDefault(Options.Curr));
                    if (cnt is PackageContainerRepoItem ri)
                    {
                        ri.Env = veAas.thePackage;
                        ri.CalculateIdsTagAndDesc();
                        fr.Add(ri);
                    }
                }

                if (cmd == "filerepomultiadd")
                {
                    // get the input files
                    var inputDlg = new Microsoft.Win32.OpenFileDialog();
                    inputDlg.Title  = "Multi-select AASX package files to be in repository";
                    inputDlg.Filter = "AASX package files (*.aasx)|*.aasx" +
                                      "|AAS XML file (*.xml)|*.xml|All files (*.*)|*.*";
                    inputDlg.Multiselect = true;

                    _flyout.StartFlyover(new EmptyFlyout());
                    var res = inputDlg.ShowDialog();
                    _flyout.CloseFlyover();

                    if (res != true || inputDlg.FileNames.Length < 1)
                    {
                        return;
                    }

                    // loop
                    foreach (var fn in inputDlg.FileNames)
                    {
                        fr.AddByAasxFn(_packageCentral, fn);
                    }
                }

                if (cmd == "filerepoaddfromserver")
                {
                    // read server address
                    var uc = new TextBoxFlyout("REST endpoint (without \"/server/listaas\"):",
                                               AnyUiMessageBoxImage.Question);
                    uc.Text = Options.Curr.DefaultConnectRepositoryLocation;
                    _flyout.StartFlyoverModal(uc);
                    if (!uc.Result)
                    {
                        return;
                    }

                    // execute
                    try
                    {
                        var conn = new PackageConnectorHttpRest(null, new Uri(uc.Text));

                        var task  = Task.Run(() => conn.GenerateRepositoryFromEndpointAsync());
                        var items = task.Result;
                        if (items == null || items.Count < 1)
                        {
                            Log.Singleton.Error($"When adding file repo items from REST server {uc.Text}," +
                                                $"the function returned NO items!");
                            return;
                        }

                        // loop
                        foreach (var fi in items)
                        {
                            fr.Add(fi);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Singleton.Error(ex, $"When adding file repo items from REST server {uc.Text}, " +
                                            $"an error occurred");
                    }
                }
            }
        }
示例#10
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));
        }
示例#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);
        }