Beispiel #1
0
        public static void SavePreferences(InterfacePreferences preferences)
        {
#if DEBUG
            return;
#endif
            XmlSerializer    mySerializer = new XmlSerializer(typeof(InterfacePreferences));
            MemoryStream     stream       = new MemoryStream();
            Utf8StringWriter myWriter     = new Utf8StringWriter();
            mySerializer.Serialize(myWriter, preferences);
            //StreamReader reader = new StreamReader(stream);

            string text = myWriter.ToString();
            logger.Info("text = " + text);
            myWriter.Close();

            using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.DatabaseConnString))
            {
                conn.Open();
                string     cmdString = "UPDATE Settings SET SettingValue = @SettingValue WHERE ID = 1";
                SqlCommand updateCmd = new SqlCommand(cmdString, conn);
                updateCmd.Parameters.AddWithValue("@SettingValue", text);
                if (updateCmd.ExecuteNonQuery() > 0)
                {
                    //DesktopApplication.ShowDialog("Saved", "Interface updated.");
                    conn.Close();
                }
                else
                {
                    //DesktopApplication.ShowDialog("Error", "Interface failed to save.");
                    logger.Error("Dicom Interface failed to save user preferences: " + text);
                    conn.Close();
                }
            }
        }
Beispiel #2
0
        public static InterfacePreferences GetPreferences()
        {
            logger.Trace("GetPreferences()...");
            InterfacePreferences InterfacePreferences = null;

#if DEBUG
            InterfacePreferences          = new InterfacePreferences();
            InterfacePreferences.AETitle  = "DESKTOP-UR5U52N";
            InterfacePreferences.HostName = "DESKTOP-UR5U52N";
            InterfacePreferences.Port     = 1040;
            return(InterfacePreferences);
#endif
            using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.DatabaseConnString))
            {
                conn.Open();
                string        cmdText = "SELECT * FROM Settings WHERE ID = 1";
                string        xmlString;
                SqlCommand    cmd    = new SqlCommand(cmdText, conn);
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        xmlString = reader["SettingValue"].ToString();
                        XmlSerializer serializer = new XmlSerializer(typeof(InterfacePreferences));
                        // convert string to stream
                        byte[] byteArray = Encoding.UTF8.GetBytes(xmlString);
                        //byte[] byteArray = Encoding.ASCII.GetBytes(contents);

                        MemoryStream stream = new MemoryStream(byteArray);
                        try
                        {
                            InterfacePreferences = (InterfacePreferences)serializer.Deserialize(stream);
                        }
                        catch (Exception ex)
                        {
                            InterfacePreferences         = new InterfacePreferences();
                            InterfacePreferences.AETitle = "Failed to deserialized " + ex.Message;
                        }
                        continue;
                    }
                }
                else
                {
                    InterfacePreferences         = new InterfacePreferences();
                    InterfacePreferences.AETitle = "HELLO WORLD FROM NULL";
                }
            }
            return(InterfacePreferences);
        }
Beispiel #3
0
 public DicomConnector(List <StoredDicomServer> servers)
 {
     logger.Trace("Instantiating Dicom connector..");
     DicomServers = servers;
     DicomTranslator.connector = this;
     _preferences           = DicomModule.GetPreferences();
     server                 = DicomServer.Create <CStoreSCP>(_preferences.Port);
     _preferences.HostName  = Dns.GetHostName();
     _preferences.IPAddress = GetLocalIPAddress();
     logger.Info("DicomServer AETITLE: {0}; IPAddress: {1}; Port {2}; TimeoutDelay: {3}; HostName: {4}", _preferences.AETitle, _preferences.IPAddress, _preferences.Port, _preferences.TimeoutDelay, _preferences.HostName);
     DicomModule.SavePreferences(_preferences);
     logger.Info("Server is listening: " + server.IsListening);
     ReceivedFiles = new List <DicomFile>();
     logger.Trace("Instantiating Dicom connector... done.");
 }