コード例 #1
0
 public static string GetDriveSnapshotProviderName(string driveName)
 {
     //if(Utilities.PlatForm.IsUnixClient())
     return(FilesystemManager.GetDriveSnapshotType(driveName).ToString());
     //else
     //	return "VSS"; //new VSSProvider();
 }
コード例 #2
0
ファイル: Core.cs プロジェクト: Chemsorly/Conductor
        public override void Initialize()
        {
            //get frontend target
            var predictionTarget = GetPredictionTarget();

            //init fs manager
            _filesystemManager = new FilesystemManager();
            _filesystemManager.NewLogMessageEvent += CoreNotifyLogMessage;
            _filesystemManager.Initialize();

            //configuration manager
            _configManager = new ConfigurationManager(_filesystemManager);
            _configManager.NewLogMessageEvent += CoreNotifyLogMessage;
            _configManager.Initialize();

            //forward signalr manager
            _signalrservermanager = new SignalRServerManager();
            _signalrservermanager.NewClientEvent                 += delegate(WorkerClient client) { NewClientEvent?.Invoke(client); ClientsUpdated(_signalrservermanager.ConnectedClients.Count); };
            _signalrservermanager.ClientDisconnectedEvent        += delegate(WorkerClient client) { ClientDisconnectedEvent?.Invoke(client); ClientsUpdated(_signalrservermanager.ConnectedClients.Count); };
            _signalrservermanager.ClientUpdatedEvent             += delegate(WorkerClient client) { ClientUpdatedEvent?.Invoke(client); };
            _signalrservermanager.NewLogMessageEvent             += CoreNotifyLogMessage;
            _signalrservermanager.NewConsoleLogMessage           += delegate(WorkerClient pClient, string message) { NewConsoleLogMessage?.Invoke(pClient, message); };
            _signalrservermanager.NewClientErrorMessageEvent     += delegate(WorkerClient pClient, String pErrorMessage, List <String> pErrorLog, WorkPackage pWorkPackage) { _commandManager?.ReceiveErrorFromWorker(pErrorLog, pWorkPackage); };
            _signalrservermanager.WorkRequestedEvent             += SignalrmanagerOnWorkRequestedEvent;
            _signalrservermanager.TrainingResultsReceivedEvent   += SignalrmanagerOnTrainingResultsReceivedEvent;
            _signalrservermanager.PredictionResultsReceivedEvent += SignalrmanagerOnPredictionResultsReceivedEvent;
            _signalrservermanager.Initialize();

            //frontend signalr manager
            _signalrclientmanager = new SignalRClientManager();
            _signalrclientmanager.NewLogMessageEvent        += CoreNotifyLogMessage;
            _signalrclientmanager.PredictionRequestedEvent  += _signalrclientmanager_PredictionRequestedEvent;
            _signalrclientmanager.ConfigurationUpdatedEvent += delegate(ConductorConfiguration pConfiguration) { this._commandManager.UpdateConfiguration(pConfiguration); };
            _signalrclientmanager.ConnectedEvent            += delegate() { _commandManager.ReportConfiguration(); };
            if (!String.IsNullOrWhiteSpace(predictionTarget))
            {   //only connect to frontend if a target is specified
                _signalrclientmanager.Initialize($"{predictionTarget}/server/rnn");
                _signalrclientmanager.ConnectAsync()
                .ContinueWith(t =>
                {
                    this.ClientsUpdated(_signalrservermanager.ConnectedClients.Count);
                }, TaskContinuationOptions.OnlyOnRanToCompletion);
            }
            else
            {
                this.CoreNotifyLogMessage("SignalRClientManager will not attempt to connect to a frontend because none was specified.");
            }

            //create command manager
            _commandManager = new CommandManager(_configManager, _filesystemManager, _signalrservermanager.ConnectedClients);
            _commandManager.NewLogMessageEvent      += CoreNotifyLogMessage;
            _commandManager.PredictionFinishedEvent += _commandManager_PredictionFinishedEvent;
            _commandManager.StatusChangedEvent      += _commandManager_StatusChangedEvent;
            _commandManager.Initialize();

            base.Initialize();
        }
コード例 #3
0
 public ConfigurationManager(FilesystemManager pFilesystemManager)
 {
     _filesystemManager = pFilesystemManager;
 }
コード例 #4
0
ファイル: LVMProvider.cs プロジェクト: radtek/BackO
        public ISnapshot[] CreateVolumeSnapShot(List <FileSystem> volumes, string[] specialObjects, SnapshotSupportedLevel level)
        {
            ArrayList snapshots = new ArrayList();

            // We need the lvm block device path, so let's use VolumeManager
            FileSystem[] lvmVolumes = FilesystemManager.GetLVMDrives();
            foreach (FileSystem volume in volumes)
            {
                /*string blockDevice = String.Empty;
                 * foreach(SpecialDrive sd in lvmVolumes){
                 *      if(volumeName == sd.MountPoint)
                 *              blockDevice = sd.BlockDevice;
                 * }*/
                Snapshot sn = new Snapshot();
                sn.Type = this.Name;
                Logger.Append(Severity.DEBUG, "1/3 Snapshotting volume " + volume.MountPoint + " (" + volume.Path + ")");
                string           snapshotName = volume.MountPoint.Substring(1) + "__backup_DONOTREMOVE_" + DateTime.Now.ToString("yyyyMMdd-hh-mm-ss");
                string           lvmParams    = "lvcreate --size 1G --permission r --snapshot --name " + snapshotName + " " + volume.Path;
                ProcessStartInfo pi           = new ProcessStartInfo("lvm", lvmParams);
                pi.RedirectStandardOutput = true;
                pi.RedirectStandardError  = true;
                pi.UseShellExecute        = false;
                sn.TimeStamp = Utilities.Utils.GetUtcUnixTime(DateTime.UtcNow);
                Process p = Process.Start(pi);
                p.WaitForExit();
                // we don't check stdout nor stderr, due to how crappy is lvm can be in its output
                //(reports errors due to bad scanning which didn't prevent cnapshot from being created)
                //string stdOut = p.StandardOutput.ReadToEnd();
                string stdErr = p.StandardError.ReadToEnd();

                /*if(stdErr.Length >5) // something went wrong
                 *      throw new Exception("Unable to snapshot LVM volume '"+volumeName+"'. Error : '"+stdErr.Replace(Environment.NewLine, " - ")
                 +"' (std output was: '"+stdOut.Replace(Environment.NewLine, " - ")+"'). command was : 'lvm "+lvmParams+"'");
                 * else*/
                Logger.Append(Severity.DEBUG, "2/3 Successfully snapshotted " + volume.MountPoint + " to " + snapshotName);
                string mountPoint = ConfigManager.GetValue("Backups.TempFolder") + "/" + snapshotName + "/";
                Directory.CreateDirectory(mountPoint);
                // now mount it, the good old way
                string           mountCommand = volume.Path.Substring(0, volume.Path.LastIndexOf("/") + 1) + snapshotName + " " + mountPoint;
                ProcessStartInfo mountInfo    = new ProcessStartInfo("mount", mountCommand);
                mountInfo.RedirectStandardOutput = true;
                mountInfo.RedirectStandardError  = true;
                mountInfo.UseShellExecute        = false;
                Process mount = Process.Start(mountInfo);
                mount.WaitForExit();
                string mountOut = mount.StandardOutput.ReadToEnd();
                string mountErr = mount.StandardError.ReadToEnd();
                //if(mountErr != String.Empty) // something went wrong, on success the command returns nothing
                //	throw new Exception("Unable to mount snapshot for '"+volumeName+"'. Error : '"+mountErr+"' (std output was: '"+mountOut+"', command was 'mount "+mountCommand+"')");
                //else
                FileSystem[] lvmWithSnap = FilesystemManager.GetLVMDrives();
                bool         found       = false;
                foreach (FileSystem theVol in lvmWithSnap)
                {
                    if (snapshotName == theVol.MountPoint)
                    {
                        Logger.Append(Severity.DEBUG, "3/3 Successfully mounted " + snapshotName + " to " + mountPoint);
                        found = true;
                    }
                }
                if (found == false)
                {
                    throw new Exception("Unable to snapshot or mount for '" + volume.MountPoint + "'. mount Error : '" + mountErr + "', snapshot Error :" + stdErr);
                }
                sn.Path       = volume.MountPoint;
                sn.Id         = Guid.Empty;
                sn.MountPoint = mountPoint;
                snapshots.Add(sn);
            }
            return((ISnapshot[])snapshots.ToArray(typeof(ISnapshot)));
        }
コード例 #5
0
        /// <summary>
        /// Saves all data of tempTrack to the tracks
        /// </summary>
        private void Save()
        {
            SaveProperties();

            foreach (TrackData t in Tracks)
            {
                foreach (PropertyData p in properties)
                {
                    if (p.Edited)
                    {
                        switch (p.Name)
                        {
                        case "Title":
                            t.Title = tempTrack.Title;
                            break;

                        case "Artist":
                            t.Artist = tempTrack.Artist;
                            break;

                        case "Album":
                            t.Album = tempTrack.Album;
                            break;

                        case "Genre":
                            t.Genre = tempTrack.Genre;
                            break;

                        case "Track":
                            t.Track = tempTrack.Track;
                            break;
                        }
                        p.Edited = false;
                    }
                }
                try
                {
                    FilesystemManager.SaveTrack(t);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, U.T("MessageErrorUpdating", "Title"), MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            if (Tracks.Count == 1)
            {
                string oldPath = Tracks[0].Path;
                string newPath = Path.Combine(Path.GetDirectoryName(oldPath), Filename.Text);
                if (oldPath != newPath)
                {
                    try
                    {
                        File.Move(oldPath, newPath);
                        tempTrack.Path = newPath;
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message, U.T("MessageErrorRenaming", "Title"), MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }

            ToggleButtons();
        }
コード例 #6
0
 public EvaluationManager(FilesystemManager pFsManager)
 {
     fsManager = pFsManager;
 }
コード例 #7
0
        /// <summary>
        /// Parses an M3U playlist and returns the tracks of it.
        /// </summary>
        /// <param name="reader">The data stream of the playlist</param>
        /// <param name="path">The relative path of the tracks in the playlist</param>
        /// <returns>A collection of tracks represented by the playlist</returns>
        private static ObservableCollection <TrackData> ParseM3U(StreamReader reader, string path = "")
        {
            ObservableCollection <TrackData> ret = new ObservableCollection <TrackData>();
            string line;
            bool   ext = false;
            string inf = "";
            int    nr  = 0;

            while ((line = reader.ReadLine()) != null)
            {
                nr++;
                if (line == "#EXTM3U")
                {
                    ext = true;
                }
                else if (ext && line.StartsWith("#EXTINF:"))
                {
                    inf = line.Substring(8);
                }
                else if (line.StartsWith("#") || line == "")
                {
                    continue;
                }
                else
                {
                    string    p    = line;
                    TrackType type = MediaManager.GetType(p);
                    TrackData track;

                    switch (type)
                    {
                    case TrackType.File:

                        if (!File.Exists(p) && File.Exists(Path.Combine(path, p)))
                        {
                            p = Path.Combine(path, p);
                        }

                        if (File.Exists(path))
                        {
                            string length = "";
                            string artist = "";
                            string title  = "";
                            if (inf != "")
                            {
                                if (!inf.Contains(','))
                                {
                                    U.L(LogLevel.Warning, "PLAYLIST", "Bad format on line "
                                        + nr + ": expecting ','");
                                    continue;
                                }
                                string[] split = inf.Split(',');
                                length = split[0];
                                if (split[1].Contains('-'))
                                {
                                    artist = split[1].Split('-')[0];
                                    title  = split[1].Split('-')[1];
                                }
                                else
                                {
                                    title = split[1];
                                }
                            }
                            if (!FilesystemManager.PathIsAdded(path))
                            {
                                FilesystemManager.AddSource(p);
                            }
                            foreach (TrackData t in SettingsManager.FileTracks)
                            {
                                if (t.Path == path)
                                {
                                    if (!ret.Contains(t))
                                    {
                                        ret.Add(t);
                                    }
                                    break;
                                }
                            }
                            inf = "";
                        }
                        break;

                    case TrackType.WebRadio:
                        track = MediaManager.ParseURL(p);
                        if (track != null && !ret.Contains(track))
                        {
                            ret.Add(track);
                        }
                        break;

                    case TrackType.YouTube:
                        track = YouTubeManager.CreateTrack(p);
                        if (track != null && !ret.Contains(track))
                        {
                            ret.Add(track);
                        }
                        break;

                    case TrackType.SoundCloud:
                        track = SoundCloudManager.CreateTrack(p);
                        if (track != null && !ret.Contains(track))
                        {
                            ret.Add(track);
                        }
                        break;
                    }
                }
            }
            return(ret);
        }
コード例 #8
0
        /// <summary>
        /// Parses a PLS playlist and returns the tracks of it.
        /// </summary>
        /// <param name="reader">The data stream of the playlist</param>
        /// <param name="path">The relative path of the tracks in the playlist</param>
        /// <returns>A collection of tracks represented by the playlist</returns>
        private static ObservableCollection <TrackData> ParsePLS(StreamReader reader, string path = "")
        {
            ObservableCollection <TrackData> ret = new ObservableCollection <TrackData>();
            bool   hdr     = false;
            string version = "";
            int    noe     = 0;
            int    nr      = 0;
            string line;

            List <string> lines = new List <string>();

            while ((line = reader.ReadLine()) != null)
            {
                lines.Add(line);
                nr++;
                if (line == "[playlist]")
                {
                    hdr = true;
                }
                else if (!hdr)
                {
                    U.L(LogLevel.Warning, "PLAYLIST", "Bad format on line "
                        + nr + ": expecting '[playlist]'");
                }
                else if (line.StartsWith("NumberOfEntries="))
                {
                    noe = Convert.ToInt32(line.Split('=')[1]);
                }
                else if (line.StartsWith("Version="))
                {
                    version = line.Split('=')[1];
                }
            }

            if (!hdr)
            {
                U.L(LogLevel.Warning, "PLAYLIST", "No header found");
            }


            // It seems there's many Internet radios that doesn't specify a version,
            // so we can't be too picky about this one.
            //else if (version != "2")
            //    U.L(LogLevel.Warning, "PLAYLIST", "Unsupported version '" +
            //        version + "'");

            else
            {
                string[,] tracks = new string[noe, 3];
                nr = 0;
                foreach (string l in lines)
                {
                    if (l.StartsWith("File") || l.StartsWith("Title") || l.StartsWith("Length"))
                    {
                        int tmp   = 4;
                        int index = 0;
                        if (l.StartsWith("Title"))
                        {
                            tmp = 5; index = 1;
                        }
                        else if (l.StartsWith("Length"))
                        {
                            tmp = 6; index = 2;
                        }

                        string[] split  = l.Split('=');
                        int      number = Convert.ToInt32(split[0].Substring(tmp));

                        if (number > noe)
                        {
                            U.L(LogLevel.Warning, "PLAYLIST", "Bad format on line "
                                + nr + ": entry number is '" + number + "' but NumberOfEntries is '" + noe + "'");
                        }
                        else
                        {
                            tracks[number - 1, index] = split[1];
                        }
                    }
                    else if (!l.StartsWith("NumberOfEntries") && l != "[playlist]" && !l.StartsWith("Version="))
                    {
                        U.L(LogLevel.Warning, "PLAYLIST", "Bad format on line "
                            + nr + ": unexpected '" + l + "'");
                    }
                }
                for (int i = 0; i < noe; i++)
                {
                    string p = tracks[i, 0];

                    TrackType type = MediaManager.GetType(p);
                    TrackData track;

                    switch (type)
                    {
                    case TrackType.File:
                        if (!File.Exists(p) && File.Exists(Path.Combine(path, p)))
                        {
                            p = Path.Combine(path, p);
                        }

                        if (File.Exists(p))
                        {
                            if (!FilesystemManager.PathIsAdded(p))
                            {
                                FilesystemManager.AddSource(p);
                            }
                            foreach (TrackData t in SettingsManager.FileTracks)
                            {
                                if (t.Path == p)
                                {
                                    if (!ret.Contains(t))
                                    {
                                        ret.Add(t);
                                    }
                                    break;
                                }
                            }
                        }
                        break;

                    case TrackType.WebRadio:
                        track = MediaManager.ParseURL(p);
                        if (track != null && !ret.Contains(track))
                        {
                            if (String.IsNullOrWhiteSpace(track.Title))
                            {
                                track.Title = tracks[i, 1];
                            }
                            if (String.IsNullOrWhiteSpace(track.URL))
                            {
                                track.URL = p;
                            }
                            ret.Add(track);
                        }
                        break;

                    case TrackType.YouTube:
                        track = YouTubeManager.CreateTrack(p);
                        if (track != null && !ret.Contains(track))
                        {
                            ret.Add(track);
                        }
                        break;

                    case TrackType.SoundCloud:
                        track = SoundCloudManager.CreateTrack(p);
                        if (track != null && !ret.Contains(track))
                        {
                            ret.Add(track);
                        }
                        break;
                    }
                }
            }
            return(ret);
        }