Exemple #1
0
        /// <summary>
        /// Loads StreamSources from a specified file.
        /// </summary>
        /// <param name="fileName">The filename to load. If you are trying to load multiple distinct files, set bypassCache to true.</param>
        /// <param name="bypassCache">
        /// Set to true to always read from the disk and return a distinct copy
        /// Set to false to use the cached copy if available.
        /// </param>
        /// <returns>the StreamSources from the indicated file</returns>
        public static StartSources LoadFromFile(string fileName, bool bypassCache)
        {
            if ((_startSources == null) || bypassCache)
            {
                FileStream file = null;
                try
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(StartSources));
                    file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                    StartSources s = (StartSources)xmlSerializer.Deserialize(file);

                    if (bypassCache)
                    {
                        return(s);
                    }
                    else
                    {
                        _startSources = s;
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
                finally
                {
                    if (file != null)
                    {
                        file.Close();
                        file.Dispose();
                    }
                }
            }
            return(_startSources);
        }
Exemple #2
0
        /// <summary>
        /// Writes a <see cref="StreamSources"/> collection to disk at the <see cref="P:PersistFileName"/> location.
        /// </summary>
        /// <param name="sources">sources to write</param>
        public static void SaveToFile(StartSources startSources)
        {
            FileStream file = null;

            try
            {
                XmlSerializer xmlSerializer = new XmlSerializer(startSources.GetType());
                file = new FileStream(PersistFileName, FileMode.Create, FileAccess.Write, FileShare.None);
                xmlSerializer.Serialize(file, startSources);
            }
            finally
            {
                if (file != null)
                {
                    file.Close();
                    file.Dispose();
                }
            }
        }
Exemple #3
0
 public static void StartPushGraphs()
 {
     try
     {
         StreamSources streamSources = StreamSources.LoadFromFile(false);
         StartSources  startSources  = StartSources.LoadFromFile(false);
         if ((streamSources != null) && (startSources != null))
         {
             foreach (StartSource startSource in startSources.Items)
             {
                 StreamSourceInfo streamSourceInfo = streamSources.FindSource(startSource.SourceName);
                 if (streamSourceInfo != null)
                 {
                     AppLogger.Message(String.Format("Starting source {0}", streamSourceInfo.SourceName));
                     if (streamSourceInfo.DeviceAddress != null)
                     {
                         AppLogger.Message(String.Format("Starting Channel={0} Input={1}", streamSourceInfo.DeviceAddress.Channel, streamSourceInfo.DeviceAddress.Input));
                     }
                     OpenGraphRequest openGraphRequest = new OpenGraphRequest();
                     openGraphRequest.Id         = Guid.NewGuid();
                     openGraphRequest.SourceName = streamSourceInfo.SourceName;
                     openGraphRequest.UserName   = "******";
                     BaseGraph graph = BaseGraph.CreateInstance(streamSourceInfo, openGraphRequest);
                     graph.Run();
                     if (graph != null)
                     {
                         _graphMap.Add(streamSourceInfo.SourceName, graph);
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         AppLogger.Dump(e);
     }
 }