private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // init library
            activeVisualObjectLib = new WpfMtpControl.MtpVisualObjectLib();
            activeVisualObjectLib.LoadStatic(null);

            // find file, remember Submodel element for it, find filename
            // (ConceptDescription)(no-local)[IRI]http://www.admin-shell.io/mtp/v1/MTPSUCLib/ModuleTypePackage
            var simIdFn = new AdminShell.Key("ConceptDescription", false,
                                             "IRI", "http://www.admin-shell.io/mtp/v1/MTPSUCLib/ModuleTypePackage");

            this.activeMtpFileElem = theSubmodel?.submodelElements?.FindFirstSemanticIdAs <AdminShell.File>(simIdFn);
            var inputFn = this.activeMtpFileElem?.value;

            if (inputFn == null)
            {
                return;
            }

            // access file
            if (CheckIfPackageFile(inputFn))
            {
                inputFn = thePackage.MakePackageFileAvailableAsTempFile(inputFn);
            }

            // load file
            LoadFile(inputFn);

            // fit it
            this.mtpVisu.ZoomToFitCanvas();

            // double click handler
            this.mtpVisu.MtpObjectDoubleClick += MtpVisu_MtpObjectDoubleClick;
        }
Exemple #2
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // initialize symbol library
            this.theSymbolLib = new MtpSymbolLib();

            var ISO10628 = new ResourceDictionary();

            ISO10628.Source = new Uri(
                "pack://application:,,,/WpfMtpControl;component/Resources/PNID_DIN_EN_ISO_10628.xaml");
            this.theSymbolLib.ImportResourceDicrectory("PNID_ISO10628", ISO10628);

            var FESTO = new ResourceDictionary();

            FESTO.Source = new Uri(
                "pack://application:,,,/WpfMtpControl;component/Resources/PNID_Festo.xaml");
            this.theSymbolLib.ImportResourceDicrectory("PNID_Festo", FESTO);

            // initialize visual object libraries
            activeVisualObjectLib = new WpfMtpControl.MtpVisualObjectLib();
            activeVisualObjectLib.LoadStatic(this.theSymbolLib);

            // gather infos
            var ok = GatherMtpInfos(this.thePreLoadInfo);

            if (ok && this.activeMtpFileFn != null)
            {
                // access file
                var inputFn = this.activeMtpFileFn;
                if (CheckIfPackageFile(inputFn))
                {
                    inputFn = thePackage.MakePackageFileAvailableAsTempFile(inputFn);
                }

                // load file
                LoadFile(inputFn);

                // fit it
                this.mtpVisu.ZoomToFitCanvas();

                // double click handler
                this.mtpVisu.MtpObjectDoubleClick += MtpVisu_MtpObjectDoubleClick;
            }

            // Timer for status
            System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            // ReSharper disable once RedundantDelegateCreation
            dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
            dispatcherTimer.Start();
        }
Exemple #3
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // initialize symbol library
            this.theSymbolLib = new MtpSymbolLib();

            var ISO10628 = new ResourceDictionary();

            ISO10628.Source = new Uri(
                "pack://application:,,,/WpfMtpControl;component/Resources/PNID_DIN_EN_ISO_10628.xaml");
            this.theSymbolLib.ImportResourceDicrectory("PNID_ISO10628", ISO10628);

            var FESTO = new ResourceDictionary();

            FESTO.Source = new Uri(
                "pack://application:,,,/WpfMtpControl;component/Resources/PNID_Festo.xaml");
            this.theSymbolLib.ImportResourceDicrectory("PNID_Festo", FESTO);

            // initialize visual object libraries
            activeVisualObjectLib = new WpfMtpControl.MtpVisualObjectLib();
            activeVisualObjectLib.LoadStatic(this.theSymbolLib);

            // gather infos
            var ok = GatherMtpInfos();

            if (ok && this.activeMtpFileFn != null)
            {
                // access file
                var inputFn = this.activeMtpFileFn;
                if (CheckIfPackageFile(inputFn))
                {
                    inputFn = thePackage.MakePackageFileAvailableAsTempFile(inputFn);
                }

                // load file
                LoadFile(inputFn);

                // fit it
                this.mtpVisu.ZoomToFitCanvas();

                // double click handler
                this.mtpVisu.MtpObjectDoubleClick += MtpVisu_MtpObjectDoubleClick;
            }
        }
Exemple #4
0
        private void DispatcherTimer_Tick(object sender, EventArgs e)
        {
            // each tick check for one image, if a preview shall be done
            if (theDocEntitiesToPreview != null && theDocEntitiesToPreview.Count > 0 &&
                numDocEntitiesInPreview < maxDocEntitiesInPreview)
            {
                // pop
                DocumentEntity ent = null;
                lock (theDocEntitiesToPreview)
                {
                    ent = theDocEntitiesToPreview[0];
                    theDocEntitiesToPreview.RemoveAt(0);
                }

                try
                {
                    // temp input
                    var inputFn = ent?.DigitalFile;
                    if (inputFn != null)
                    {
                        // from package?
                        if (CheckIfPackageFile(inputFn))
                        {
                            inputFn = thePackage.MakePackageFileAvailableAsTempFile(ent.DigitalFile);
                        }

                        // temp output
                        string outputFn = System.IO.Path.GetTempFileName().Replace(".tmp", ".png");

                        // remember these for later deletion
                        ent.DeleteFilesAfterLoading = new[] { inputFn, outputFn };

                        // start process
                        string arguments = string.Format("-flatten -density 75 \"{0}\"[0] \"{1}\"", inputFn, outputFn);
                        string exeFn     = System.IO.Path.Combine(
                            System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "convert.exe");

                        var startInfo = new ProcessStartInfo(exeFn, arguments)
                        {
                            WindowStyle = ProcessWindowStyle.Hidden
                        };

                        var process = new Process {
                            StartInfo = startInfo, EnableRaisingEvents = true
                        };

                        DocumentEntity lambdaEntity   = ent;
                        string         outputFnBuffer = outputFn;
                        process.Exited += (sender2, args) =>
                        {
                            // release number of parallel processes
                            lock (mutexDocEntitiesInPreview)
                            {
                                numDocEntitiesInPreview--;
                            }

                            // take over data?
                            if (lambdaEntity.ImgContainer != null)
                            {
                                // trigger display image
                                lambdaEntity.ImageReadyToBeLoaded = outputFnBuffer;
                            }
                        };

                        try
                        {
                            process.Start();
                        }
                        catch (Exception ex)
                        {
                            AdminShellNS.LogInternally.That.Error(
                                ex, $"Failed to start the process: {startInfo.FileName} " +
                                $"with arguments {string.Join(" ", startInfo.Arguments)}");
                        }

                        // limit the number of parallel executions
                        lock (mutexDocEntitiesInPreview)
                        {
                            numDocEntitiesInPreview++;
                        }
                    }
                }
                catch (Exception ex)
                {
                    AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                }
            }

            // over all items in order to check, if a prepared image shall be displayed
            foreach (var x in this.ScrollMainContent.Items)
            {
                var de = x as DocumentEntity;
                if (de == null)
                {
                    continue;
                }

                if (de.ImageReadyToBeLoaded != null)
                {
                    // never again
                    var tempFn = de.ImageReadyToBeLoaded;
                    de.ImageReadyToBeLoaded = null;

                    // try load
                    try
                    {
                        // convert here, as the tick-Thread in STA / UI thread
                        var bi  = new BitmapImage(new Uri(tempFn, UriKind.RelativeOrAbsolute));
                        var img = new Image();
                        img.Source            = bi;
                        de.ImgContainer.Child = img;

                        // now delete the associated files file!
                        if (de.DeleteFilesAfterLoading != null)
                        {
                            foreach (var fn in de.DeleteFilesAfterLoading)
                            {
                                // it is quite likely (e.g. http:// files) that the delete fails!
                                try
                                {
                                    File.Delete(fn);
                                }
                                catch (Exception ex)
                                {
                                    AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                                }
                            }
                        }

                        // remember in the cache
                        if (referableHashToCachedBitmap != null &&
                            !referableHashToCachedBitmap.ContainsKey(de.ReferableHash))
                        {
                            referableHashToCachedBitmap[de.ReferableHash] = bi;
                        }
                    }
                    catch (Exception ex)
                    {
                        AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                    }
                }
            }
        }