Esempio n. 1
0
        public void AddCurrentTitle()
        {
            if (TitleCollectionManager.ContainsDisks(CurrentTitle.Disks))
            {
                OMLApplication.DebugLine("[Setup UI] Skipping title: " + CurrentTitle.Name + " because already in the collection");
                AddInHost.Current.MediaCenterEnvironment.Dialog(CurrentTitle.Name + " was found to already exist in your database and has been skipped.",
                                                                "Skipped Title",
                                                                DialogButtons.Ok,
                                                                2,
                                                                false);
                TotalTitlesSkipped++;
            }
            else
            {
                OMLApplication.DebugLine("[Setup UI] Adding title: " + CurrentTitle.Id);
                //_titleCollection.Add(CurrentTitle);
                TotalTitlesAdded++;
            }
            CurrentTitleIndex++;

            if (TotalTitlesFound > CurrentTitleIndex)
            {
                CurrentTitle = _titles[CurrentTitleIndex];
            }
            else
            {
                AllTitlesProcessed = true;
            }
        }
Esempio n. 2
0
 public void AddCheckedNode(TreeNode node)
 {
     OMLApplication.DebugLine("Adding node: " + node.FullPath);
     TreeView.CheckedNodes.Add(node);
     FirePropertyChanged("CheckedNodes");
     HasCheckedNodes = true;
 }
Esempio n. 3
0
 public void AddAllCurrentTitles()
 {
     OMLApplication.DebugLine("[Setup] Starting deferred all titles import");
     Application.DeferredInvokeOnWorkerThread(delegate
     {
         OMLApplication.DebugLine("[Setup] AddingAllCurrentTitles Started");
         AddingAllStarted = true;
         for (CurrentTitleIndex = CurrentTitleIndex; TotalTitlesFound > CurrentTitleIndex; CurrentTitleIndex++)
         {
             CurrentTitle = _titles[CurrentTitleIndex];
             if (TitleCollectionManager.ContainsDisks(CurrentTitle.Disks))
             {
                 OMLApplication.DebugLine("[Setup UI] Skipping title: " + CurrentTitle.Name + " because already in the collection");
                 TotalTitlesSkipped++;
             }
             else
             {
                 OMLApplication.DebugLine("[Setup UI] Adding title: " + CurrentTitle.Id);
                 //_titleCollection.Add(CurrentTitle);
                 TotalTitlesAdded++;
             }
         }
     }, delegate
     {
         OMLApplication.DebugLine("[Setup] AddingAllCurrentTitles Completed");
         AddingAllComplete  = true;
         AllTitlesProcessed = true;
         FirePropertyChanged("TotalTitlesAdded");
     }, null);
 }
Esempio n. 4
0
        public Setup()
        {
            LoadPlugins();
            AllTitlesProcessed = false;
            CurrentTitle       = null;
            CurrentTitleIndex  = 0;
            current            = this;
            //_titleCollection.loadTitleCollection();
            _ImporterSelection = new Choice();
            List <string> _Importers = new List <string>();

            foreach (OMLPlugin _plugin in availablePlugins)
            {
                OMLApplication.DebugLine("[Setup] Adding " + _plugin.Name + " to the list of Importers");
                _Importers.Add(_plugin.Description);
            }

            _ImporterSelection.Options        = _Importers;
            _ImporterSelection.ChosenChanged += delegate(object sender, EventArgs e)
            {
                OMLApplication.ExecuteSafe(delegate
                {
                    Choice c            = (Choice)sender;
                    ImporterDescription = @"Notice: " + GetPlugin().SetupDescription();
                    OMLApplication.DebugLine("Item Chosed: " + c.Options[c.ChosenIndex]);
                });
            };
        }
Esempio n. 5
0
        private void DeleteOldRegistryKey(AddInHost host)
        {
            // remove old HKCU key that caused settings to appear on the TV+Movies menu strip
            if (!host.MediaCenterEnvironment.Capabilities.ContainsKey("Console"))
            {
                try
                {
                    RegistryKey delKeyValue = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\" +
                                                                              @"Media Center\Extensibility\Categories\Services\" +
                                                                              @"Movies\{543d0438-b10d-43d8-a20d-f0c96db4e6bd}", true);
                    if (delKeyValue != null)
                    {
                        OMLApplication.DebugLine("[Launch] Deleting old registry key value");
                        delKeyValue.DeleteValue(@"UseCount");
                    }
                }
                catch (Exception) { } // we don't really care, just delete it if you find it

                try
                {
                    RegistryKey delSubKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\" +
                                                                            @"Media Center\Extensibility\Categories\Services\Movies", true);
                    if (delSubKey != null)
                    {
                        OMLApplication.DebugLine("[Launch] Deleting old registry key");
                        delSubKey.DeleteSubKey(@"{543d0438-b10d-43d8-a20d-f0c96db4e6bd}");
                    }
                }
                catch (Exception) { } // we don't really care, just delete it if you find it
            }
        }
Esempio n. 6
0
        public bool PlayMovie()
        {
            if (FileScanner.IsDVD(_mediaPath))
            {
                bool   isUNC = false;
                string path  = FileScanner.GetPlayStringForPath(_mediaPath);

                // the unc path requires that it start with // so remove \\ if it exists
                //http://discuss.mediacentersandbox.com/forums/thread/9307.aspx
                if (path.StartsWith("\\\\"))
                {
                    path  = path.Substring(2);
                    isUNC = true;
                }

                path = path.Replace("\\", "/");

                if (OMLApplication.IsWindows7 && isUNC)
                {
                    path = string.Format("//{0}", path);
                }
                else
                {
                    path = string.Format("DVD://{0}", path);
                }

                OMLApplication.DebugLine("[MoviePlayerDVD] Actual play string being passed to PlayMovie: {0}", path);
                return(PlayMovie(path));
            }
            return(false);
        }
Esempio n. 7
0
        private void Initialize(IEnumerable <Title> titles)
        {
            DateTime start = DateTime.Now;

            _jumpInListText       = new EditableText(this);
            _jumpInListText.Value = String.Empty;

            //FocusedItem = new GalleryItem(this, "", "", null);
            _categoryChoice = new Choice(this, "Categories");
            //CreateCategories();
            _moviesVirtualList = new VirtualList(this, null);

            //CreateSortLookup();

            if (_sortFunctionLookup.ContainsKey(OMLSettings.MovieSort))
            {
                _currentSort = _sortFunctionLookup[OMLSettings.MovieSort];
            }
            else
            {
                _currentSort = SortByNameAscending;
            }

            //SetupAlphaCharacters();

            LoadMovies(titles);
            OMLApplication.DebugLine("[MovieGallery] Initialize: time: {0}, items: {1}", DateTime.Now - start, this._movies.Count);
        }
Esempio n. 8
0
 public void PlayMedia()
 {
     OMLApplication.DebugLine("Playing trailer: {0}", this.TrailerUrl);
     AddInHost.Current.MediaCenterEnvironment.PlayMedia(Microsoft.MediaCenter.MediaType.Video, this.TrailerUrl, false);
     AddInHost.Current.MediaCenterEnvironment.MediaExperience.GoToFullScreen();
     AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.PropertyChanged += new PropertyChangedEventHandler(Transport_PropertyChanged);
 }
Esempio n. 9
0
        public void LocateExternalPlayerExecutable(Choice selector, EditableText textBox, Choice localFixedDrive)
        {
            string    driveLetterToScan = localFixedDrive.Chosen as String;
            DriveInfo dInfo             = new DriveInfo(driveLetterToScan);

            string startPath = null;

            switch ((ExternalPlayer.KnownPlayers)Enum.Parse(typeof(ExternalPlayer.KnownPlayers), selector.Chosen.ToString()))
            {
            case ExternalPlayer.KnownPlayers.WinDVD9:
                startPath = DefaultWinDVD9Path;
                break;

            case ExternalPlayer.KnownPlayers.PowerDVD8:
                startPath = DefaultPowerDVD8Path;
                break;

            case ExternalPlayer.KnownPlayers.TotalMediaTheater:
                startPath = DefaultTMTPath;
                break;

            // don't do anything if there's no mounting tool selected
            case ExternalPlayer.KnownPlayers.None:
            case ExternalPlayer.KnownPlayers.Other:
            default:
                return;
            }

            if (File.Exists(Path.Combine(dInfo.RootDirectory.FullName, startPath)))
            {
                textBox.Value = Path.Combine(dInfo.RootDirectory.FullName, startPath);
            }
            else
            {
                // let's scan all the folders for it
                OMLApplication.Current.IsBusy = true;
                Application.DeferredInvokeOnWorkerThread(delegate
                {
                    exePath = ScanAllFoldersForExecutable(dInfo.RootDirectory.FullName, Path.GetFileName(startPath));
                }, delegate
                {
                    OMLApplication.Current.IsBusy = false;
                    if (exePath.Length > 0)
                    {
                        OMLApplication.DebugLine("[Settings] Found Image Mounter: {0}", exePath);
                        textBox.Value = exePath;
                    }
                    else
                    {
                        AddInHost.Current.MediaCenterEnvironment.Dialog(
                            string.Format("The external player was not" +
                                          " found on the [{0}] drive.", driveLetterToScan),
                            "Failed to Find External Player",
                            Microsoft.MediaCenter.DialogButtons.Ok,
                            5, true);
                    }
                }, null);
            }
        }
Esempio n. 10
0
        public MoviePlayerWPL(MediaSource source)
        {
            _mItem = source;

            OMLApplication.DebugLine("[MoviePlayerWPL] Loading for playlist: " + _mItem.MediaPath);
            _wplm        = new WindowsPlayListManager(_mItem.MediaPath);
            _currentItem = 0;
        }
Esempio n. 11
0
        public void SearchForTitle(Title t)
        {
            UriBuilder uri = new UriBuilder(API_URL_SEARCH);

            uri.Query = "api_key=" + API_KEY + "&title=" + t.OriginalName;

            WebRequest  req = HttpWebRequest.Create(uri.Uri);
            WebResponse res = req.GetResponse();

            Stream stream = res.GetResponseStream();

            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(stream);

            XmlNodeList possibleMovieNodes = xDoc.SelectNodes("//moviematches//movie");

            foreach (XmlNode posssibleMovieNode in possibleMovieNodes)
            {
                XPathNavigator nav      = posssibleMovieNode.CreateNavigator();
                string         strScore = GetChildNodesValue(nav, "score");
                if (!string.IsNullOrEmpty(strScore))
                {
                    double score = 0;
                    try
                    {
                        double.TryParse(strScore, out score);
                        if (score == 1.0)
                        {
                            // its a perfect match, take it!
                            IList <string> backDropUrls = GrabBackDropUrls(nav);
                            DownloadBackDropsForTitle(t, backDropUrls);
                        }
                        else if (score >= 8.0)
                        {
                            // ok, its not perfect but its pretty good, take the top one
                            IList <string> backDropUrls = GrabBackDropUrls(nav);
                            DownloadBackDropsForTitle(t, backDropUrls);
                        }
                    }
                    catch (Exception)
                    {
                        OMLApplication.DebugLine("[TheMovieDbBackDropDownloader] Unable to parse a double from a string: {0}", strScore);
                    }
                }
            }
            if (stream != null)
            {
                stream.Close();
            }

            if (res != null)
            {
                res.Close();
            }
        }
Esempio n. 12
0
        public void Initialize(Dictionary <string, object> appInfo, Dictionary <string, object> entryPointInfo)
        {
            if (entryPointInfo.ContainsKey("Context"))
            {
                _id = (string)entryPointInfo["Context"];
            }

            OMLApplication.DebugLine("[Launch] Initialize() id: {0}", _id);

            StartOMLEngineService();

            OMLEngine.Utilities.RawSetup();
        }
Esempio n. 13
0
 public void Reset()
 {
     OMLApplication.DebugLine("Resetting the Setup object");
     _AllTitlesProcessed = false;
     _currentTitle       = null;
     _currentTitleIndex  = 0;
     _filename           = string.Empty;
     _loadComplete       = false;
     _loadStarted        = false;
     _titles             = null;
     //_titleCollection.loadTitleCollection();
     _treeView.CheckedNodes.Clear();
 }
Esempio n. 14
0
        public void Uninitialize()
        {
            if (OMLApplication.Current != null)
            {
                if (OMLApplication.Current.IsExtender && this.imp != null)
                {
                    this.imp.Leave();
                }

                OMLApplication.Current.Uninitialize();
                OMLApplication.DebugLine("[Launch] Uninitialize");
            }
        }
Esempio n. 15
0
 public void RemoveCheckedNode(TreeNode node)
 {
     OMLApplication.DebugLine("Removing node: " + node.Title);
     if (TreeView.CheckedNodes.Contains(node))
     {
         TreeView.CheckedNodes.Remove(node);
         FirePropertyChanged("CheckedNodes");
     }
     if (TreeView.CheckedNodes.Count > 0)
     {
         HasCheckedNodes = false;
     }
 }
Esempio n. 16
0
        public OMLPlugin GetPlugin()
        {
            string strChosenImporter = (string)Setup.Current._ImporterSelection.Chosen;

            OMLApplication.DebugLine("Chosen Importer is: " + strChosenImporter);
            for (int i = 0; i < availablePlugins.Count; i++)
            {
                if (availablePlugins[i].Description.CompareTo(strChosenImporter) == 0)
                {
                    return(availablePlugins[i]);
                }
            }
            return(null);
        }
Esempio n. 17
0
 public TreeNode(String title, String fullPath)
 {
     Title    = title;
     FullPath = fullPath;
     Checked.ChosenChanged += delegate(object sender, EventArgs e)
     {
         OMLApplication.ExecuteSafe(delegate
         {
             // this is the one that works
             OMLApplication.DebugLine("Changed: " + this.GetType().ToString());
             Setup.Current.AddCheckedNode(this);
         });
     };
 }
Esempio n. 18
0
 static void MergeFile(FileStream writter, string vob0, string vobx)
 {
     byte[] buffer = new byte[128 * 1024 * 1024];
     OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Appending '{0}' to '{1}'", vobx, vob0);
     using (FileStream reader = File.OpenRead(vobx))
         for (; ;)
         {
             int read = reader.Read(buffer, 0, buffer.Length);
             if (read == 0)
             {
                 break;
             }
             writter.Write(buffer, 0, read);
         }
 }
Esempio n. 19
0
 public void NoTitlesFoundNotice()
 {
     OMLApplication.Current.MediaCenterEnvironment.Dialog("No titles were found, would you like to try again?",
                                                          "Notice",
                                                          new object[] { DialogButtons.Yes, DialogButtons.No, },
                                                          0, true, null,
                                                          delegate(DialogResult result)
     {
         OMLApplication.DebugLine("[Setup UI] _NoTitlesFoundNoticeCallback called");
         if (result.CompareTo(DialogButtons.Yes) == 0)
         {
             OMLApplication.Current.MediaCenterEnvironment.Dialog("This functionality has not been completed",
                                                                  "Notice", DialogButtons.Ok, 10, false);
         }
     });
 }
Esempio n. 20
0
        private static string ScanAllFoldersForExecutable(string dir, string executable)
        {
            if (!Directory.Exists(dir))
            {
                return(string.Empty);
            }

            string        tmtPath = string.Empty;
            DirectoryInfo dInfo;

            FileSystemInfo[] items = new FileSystemInfo[0]; // this just needs to be init'd
            try
            {
                dInfo = new DirectoryInfo(dir);
                items = dInfo.GetFileSystemInfos();
            }
            catch (Exception e)
            {
                OMLApplication.DebugLine("Caught exception trying to scan {0}: {1}", dir, e.Message);
            }

            foreach (FileSystemInfo item in items)
            {
                if (item is DirectoryInfo)
                {
                    DirectoryInfo dirInfo = item as DirectoryInfo;
                    OMLApplication.DebugLine("[Settings] Scanning folder [{0}] for TMT", dirInfo.FullName);
                    tmtPath = ScanAllFoldersForExecutable(dirInfo.FullName, executable);
                    if (!string.IsNullOrEmpty(tmtPath))
                    {
                        return(tmtPath);
                    }
                }

                if (item is FileInfo)
                {
                    FileInfo fInfo = item as FileInfo;
                    if (fInfo.Name.Equals(executable, StringComparison.OrdinalIgnoreCase))
                    {
                        return(fInfo.FullName);
                    }
                }
            }
            return(string.Empty);
        }
Esempio n. 21
0
        private void BeginStart(object host)
        {
            OMLApplication.DebugLine("[Launch] Launch called");
            if (TestDBConnection((AddInHost)host))
            {
                DeleteOldRegistryKey((AddInHost)host);

                if (app == null)
                {
                    OMLApplication.DebugLine("[Launch] No Application found, creating...");
                    app = new OMLApplication(s_session, (AddInHost)host);
                }

                try
                {
                    if (OMLApplication.Current.IsExtender)
                    {
                        this.imp = new Impersonator();
                        this.imp.Enter();
                    }
                }
                catch (Exception ex)
                {
                    OMLApplication.DebugLine("Exception during this.imp.Enter(): {0}", ex);
                }

                app.Startup(_id);
            }
            else
            {
                //just going to do a retry for now-need to allow db change later...
                List <string> buttons = new List <string>();
                buttons.Add("Retry");
                buttons.Add("Cancel");
                Microsoft.MediaCenter.DialogResult res = ((AddInHost)host).MediaCenterEnvironment.Dialog("Unable to communicate with database. Would you like to retry or cancel?", "OPEN MEDIA LIBRARY", buttons, -1, true, null, delegate(Microsoft.MediaCenter.DialogResult dialogResult) { });
                if ((int)res == 100)
                {
                    Microsoft.MediaCenter.UI.Application.DeferredInvoke(new Microsoft.MediaCenter.UI.DeferredHandler(this.BeginStart), (object)host, new TimeSpan(1));
                }
                else
                {
                    s_session.Close();
                }
            }
        }
Esempio n. 22
0
 public void DownloadBackDropsForTitle(Title t, IList <string> urls)
 {
     foreach (string url in urls)
     {
         WebClient web      = new WebClient();
         string    filename = Path.Combine(FileSystemWalker.ImageDownloadDirectory, Guid.NewGuid().ToString());
         try
         {
             web.DownloadFile(url, filename);
             t.AddFanArtImage(filename);
         }
         catch (Exception e)
         {
             OMLApplication.DebugLine("[TheMovieDbBackDropDownloader] Error downloading backdrop file {0}: {1}",
                                      url, e.Message);
         }
     }
 }
Esempio n. 23
0
        private void LoadMovies(IEnumerable <Title> titles)
        {
            _movies = new List <MovieItem>();

            if (titles != null)
            {
                OMLApplication.DebugLine("[MovieGallery] LoadMovies: have TitleCollection");

                foreach (Title title in titles)
                {
                    //MovieItem movie = new MovieItem(title, this);
                    //AddMovie(movie);
                    _movies.Add(new MovieItem(title, this));
                }
            }

            SortMovies();
        }
Esempio n. 24
0
 private static void LoadPlugins()
 {
     if (availablePlugins.Count == 0)
     {
         List <PluginServices.AvailablePlugin> Pluginz = new List <PluginServices.AvailablePlugin>();
         string path = Path.GetDirectoryName(FileSystemWalker.PluginsDirectory + @"\\Plugins");
         OMLApplication.DebugLine("Path is: " + path);
         Pluginz = PluginServices.FindPlugins(path, "OMLSDK.IOMLPlugin");
         OMLPlugin objPlugin;
         // Loop through available plugins, creating instances and adding them
         foreach (PluginServices.AvailablePlugin oPlugin in Pluginz)
         {
             objPlugin = (OMLPlugin)PluginServices.CreateInstance(oPlugin);
             availablePlugins.Add(objPlugin);
         }
         Pluginz = null;
     }
 }
Esempio n. 25
0
        static public void Transport_PropertyChanged(IPropertyObject sender, string property)
        {
            OMLApplication.ExecuteSafe(delegate
            {
                MediaTransport t = (MediaTransport)sender;
                OMLApplication.DebugLine("[AppleTrailers] Transport_PropertyChanged: movie {0} property {1} playrate {2} state {3} pos {4}", OMLApplication.Current.NowPlayingMovieName, property, t.PlayRate, t.PlayState.ToString(), t.Position.ToString());
                if (property == "PlayState")
                {
                    OMLApplication.Current.NowPlayingStatus = t.PlayState;
                    OMLApplication.DebugLine("[AppleTrailers] MoviePlayerFactory.Transport_PropertyChanged: movie {0} state {1}", OMLApplication.Current.NowPlayingMovieName, t.PlayState.ToString());

                    if (t.PlayState == PlayState.Finished || t.PlayState == PlayState.Stopped)
                    {
                        OMLApplication.DebugLine("[AppleTrailers] Playstate is stopped, moving to previous page");
                        OMLApplication.Current.Session.BackPage();
                    }
                }
            });
        }
Esempio n. 26
0
        /// <summary>
        /// Finishes any slow data for a gallery item.
        /// </summary>
        private void CompleteGalleryItem(VirtualList list, int index)
        {
            MovieItem item = (MovieItem)list[index];

            if (item.LoadedCover)
            {
                return;
            }

            //if (item.MenuCoverArt != MovieItem.NoCoverImage)
            //  return;

            Image image = null;

            // too many threads started, kills the system
            //Microsoft.MediaCenter.UI.Application.DeferredInvokeOnWorkerThread(delegate
            //{
            try
            {
                // OMLApplication.DebugLine("[MovieGallery] CompleteGalleryItem [index: {0}, name: {1}], load menu art", index, item.Name);
                string imageFile = OMLSettings.UseOriginalCoverArt
                    ? item.TitleObject.FrontCoverPath
                    : item.TitleObject.FrontCoverMenuPath;
                if (!string.IsNullOrEmpty(imageFile) && File.Exists(imageFile))
                {
                    image = GalleryItem.LoadImage(imageFile);
                }
            }
            catch (Exception e)
            {
                OMLApplication.DebugLine("[MovieGallery] Error: {0}\n    {1}", e.Message, e.StackTrace);
            }
            //}, delegate
            //{
            if (image != null)
            {
                // OMLApplication.DebugLine("[MovieGallery] CompleteGalleryItem [index: {0}, name: {1}], set menu art", index, item.Name);
                item.MenuCoverArt = image;
                item.LoadedCover  = true;
            }
            //}, null);
        }
Esempio n. 27
0
        private void LoadDetails(MovieItem item)
        {
            // get the title from the db will full information
            Title title = OMLEngine.TitleCollectionManager.GetTitle(item.TitleObject.Id);

            // create a new movie item to use
            _movieDetails = new MovieItem(title, item.Gallery);

            //_localMedia = null;

            //DVDDiskInfo debug code
            //if (item.TitleObject.Disks.Count > 0)
            //{
            //    DVDDiskInfo info = item.TitleObject.Disks[0].DVDDiskInfo;
            //}

            if (!string.IsNullOrEmpty(item.TitleObject.FrontCoverPath))
            {
                if (File.Exists(item.TitleObject.FrontCoverPath))
                {
                    _fullCover = GalleryItem.LoadImage(item.TitleObject.FrontCoverPath);
                }
            }
            _diskChoice = new Choice();
            if (_movieDetails.Disks.Count > 0)
            {
                _diskChoice.Options = _movieDetails.FriendlyNamedDisks;
            }
            else
            {
                Disk[] temp = { new Disk() };
                temp[0].Name        = "Play Me";
                _diskChoice.Options = temp; // MCE barfs if Options is bound to empty List.
                OMLApplication.DebugLine("[MovieDetailsPage] Details Page.LoadMovies: no disks");
            }

            _watched.Chosen = (_movieDetails.TitleObject.WatchedCount != 0);

            SetupCastObjects();
        }
Esempio n. 28
0
        private void SetBackgroundImage()
        {
            // only setup the background images once
            if (backgroundImages != null)
            {
                return;
            }

            backgroundImages = new List <Image>(1);

            if (_movieDetails.TitleObject.FanArtPaths.Count != 0)
            {
                foreach (string file in _movieDetails.TitleObject.FanArtPaths)
                {
                    OMLApplication.DebugLine("[MovieDetailsPage] loading fanart image {0}", file);
                    backgroundImages.Add(new Image(string.Format("file://{0}", file)));
                }

                // set the background image
                BackgroundImage = backgroundImages[0];
            }
        }
Esempio n. 29
0
        public override void GetChildNodes()
        {
            if (!String.IsNullOrEmpty(FullPath))
            {
                ChildNodes.Clear();
                string[] directories = Directory.GetDirectories(FullPath);

                foreach (string directory in directories)
                {
                    try
                    {
                        DirectoryTreeNode node =
                            new DirectoryTreeNode(Path.GetFileName(directory), directory, TreeView);
                        node.Level    = Level + 1;
                        node.TreeView = TreeView;
                        TreeView.CheckedNodeChanged +=
                            new EventHandler <TreeNodeEventArgs>(TreeView_OnCheckedNodeChanged);
                        node.HasChildNodes = (Directory.GetDirectories(node.FullPath).Length > 0);
                        ChildNodes.Add(node);
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        OMLApplication.DebugLine("[DirectoryTreeNode] " + ex.Message);
                    }
                    catch (DriveNotFoundException ex)
                    {
                        OMLApplication.DebugLine("[DirectoryTreeNode] " + ex.Message);
                    }
                    catch (IOException ex)
                    {
                        OMLApplication.DebugLine("[DirectoryTreeNode] " + ex.Message);
                    }
                }
                HasChildNodes = (ChildNodes.Count > 0);
            }

            base.GetChildNodes();
        }
Esempio n. 30
0
        public void Enter()
        {
            if (!this.IsImpersonating)
            {
                this._token = new IntPtr(0);
                try
                {
                    string domain   = System.Environment.UserDomainName;
                    string username = OMLSettings.ImpersonationUsername;
                    string password = OMLSettings.ImpersonationPassword;

                    this._token = IntPtr.Zero;
                    if (!LogonUser(username, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref this._token))
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }
                    this.impContext = new WindowsIdentity(this._token).Impersonate();
                }
                catch (Exception e)
                {
                    OMLApplication.DebugLine("[Impersonator] Failed to impersonate: {0}", e.Message);
                }
            }
        }