Esempio n. 1
0
        private bool ReadSld(string filename)
        {
            if (!SlideObject.IsSlide(filename) ||
                !File.Exists(filename)
                )
            {
                return(false);
            }

            FileInfo f = new FileInfo(filename);

            if ((_FileLength = f.Length) < _sldHeaderLength)
            {
                return(false);
            }
            _Slide = File.ReadAllBytes(filename);
            //----- Check Slide
            bool ret = DecodeSld();

            if (ret == false)
            {
                _Slide      = null;
                _FileLength = 0;
            }
            else
            {
                _FileName = filename;
                _Name     = System.IO.Path.GetFileNameWithoutExtension(filename);
            }
            return(ret);
        }
Esempio n. 2
0
 /// <summary>OnApplyTemplate overrides.</summary>
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     _Slide = new SlideObject(SlideFileName);
     _Slide.Draw(GetSlidePart());
 }
 /// <summary>OnApplyTemplate overrides.</summary>
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate () ;
     _Slide =new SlideObject (SlideFileName) ;
     _Slide.Draw (GetSlidePart ()) ;
 }
 public SlmProperties(SlideObject sld, SlideLibObject slb = null)
     : base()
 {
     if (slb != null)
     {
         slbName = slb._Name;
         slbFileName = slb._FileName;
         slbSize = slb._FileLength;
         slbNbSlide = slb._Slides.Count;
         slbVersion = "1.0";
     }
     if (sld != null)
     {
         sldName = sld._Name;
         sldFileName = sld._FileName;
         sldSize = sld._FileLength;
         sldWidth = (int)sld._Size.Width;
         sldHeight = (int)sld._Size.Height;
         sldVersion = sld._Version.ToString("#.0#");
     }
 }
        private void OpenLibrary_Click(object sender, RoutedEventArgs e)
        {
            e.Handled = true;
            if (_dirty)
            {
                if (System.Windows.MessageBox.Show("Save Library first?", "Slm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    if (!CheckLibraryFileName())
                        return;
                    _slideLib.Save();
                }
            }
            // Clear / New library
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.DefaultExt = ".slb"; // Default file extension
            dlg.Filter = "AutoCAD Slide Library|*.slb|AutoCAD Slide|*.sld"; // Filter files by extension
            Nullable<bool> result = dlg.ShowDialog();
            if (result == false)
                return;
            switch (System.IO.Path.GetExtension(dlg.FileName).ToLower())
            {
                case ".slb":
                    _slideLib = new SlideLibObject(dlg.FileName);
                    break;
                case ".sld":
                    _slide = new SlideObject(dlg.FileName);
                    break;
            }
            GenerateBadges();
            _dirty = false;

            preview.Slide = null;
            propertyGrid.SelectedObject = new SlmProperties(null, _slideLib);
        }
        private ObservableCollection<SlmVignette> MergeAndGenerateBadges(string[] files)
        {
            Point pt = Library.PointToScreen(new Point(0, 0));
            _margins = new Thickness(pt.X, pt.Y, pt.X + Library.ActualWidth, pt.Y + Library.ActualHeight);

            _waitThread = new Thread(this.RunWaitThread);
            _waitThread.IsBackground = true;
            _waitThread.SetApartmentState(ApartmentState.STA);
            _waitThread.Start();
            Thread.Sleep(0);

            ObservableCollection<SlmVignette> newItems = new ObservableCollection<SlmVignette>();
            ObservableCollection<SlmVignette> items = new ObservableCollection<SlmVignette>();
            if (Library.ItemsSource != null)
                items = new ObservableCollection<SlmVignette>((IEnumerable<SlmVignette>)Library.ItemsSource);
            foreach (string fileName in files)
            {
                if (SlideLibObject.IsSlideLibrary(fileName))
                {
                    SlideLibObject slb = new SlideLibObject(fileName);
                    //_slideLib._Slides =_slideLib._Slides.Concat (slb._Slides).GroupBy (d => d.Key)
                    //	.ToDictionary (d => d.Key, d => d.First ().Value) ;
                    foreach (KeyValuePair<string, SlideObject> slide in slb._Slides)
                    {
                        string name = slide.Key;
                        if (_slideLib._Slides.ContainsKey(slide.Key))
                        {
                            for (int i = 0; ; i++)
                            {
                                string st = name + i;
                                if (!_slideLib._Slides.ContainsKey(st))
                                {
                                    name = st;
                                    break;
                                }
                            }
                        }
                        _slideLib._Slides.Add(name, slide.Value);

                        SlmVignette badge = new SlmVignette()
                        {
                            Name = name,
                            Type = slide.Value._Size.Width + "x" + slide.Value._Size.Height,
                            Image = slide.Value.Export(70, 70)
                        };
                        items.Add(badge);
                        newItems.Add(badge);
                    }
                    _dirty = true;
                }
                if (SlideObject.IsSlide(fileName) && !_slideLib._Slides.ContainsKey(System.IO.Path.GetFileNameWithoutExtension(fileName)))
                {
                    SlideObject sld = new SlideObject(fileName);
                    sld._Name = System.IO.Path.GetFileNameWithoutExtension(fileName);
                    _slideLib._Slides.Add(sld._Name, sld);
                    _dirty = true;

                    SlmVignette badge = new SlmVignette()
                    {
                        Name = sld._Name,
                        Type = sld._Size.Width + "x" + sld._Size.Height,
                        Image = sld.Export(70, 70)
                    };
                    items.Add(badge);
                    newItems.Add(badge);
                }
                Thread.Sleep(0);
            }

            Library.ItemsSource = items;
            Library.Items.Refresh();

            Thread.Sleep(200);
            while (_waitDialog == null)
                Thread.Sleep(100);
            _waitDialog.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
            {
                _waitDialog.Close();
            }));
            if (_waitThread.IsAlive)
                _waitThread.Abort();

            return (newItems);
        }