private void ConvertCommandExecute(object obj) { try { if (FileLocation == string.Empty) { MessageBox.Show("Must enter CIM/XML file.", "Info", MessageBoxButton.OK, MessageBoxImage.Information); return; } string log; nmsDelta = null; using (FileStream fs = File.Open(FileLocation, FileMode.Open)) { nmsDelta = adapter.CreateDelta(fs, SupportedProfiles.PowerTransformer, out log); ConvertReport = log; } if (nmsDelta != null) { //// export delta to file using (XmlTextWriter xmlWriter = new XmlTextWriter(".\\deltaExport.xml", Encoding.UTF8)) { xmlWriter.Formatting = Formatting.Indented; nmsDelta.ExportToXml(xmlWriter); xmlWriter.Flush(); } } } catch (Exception e) { MessageBox.Show(string.Format("An error occurred.\n\n{0}", e.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } FileLocation = string.Empty; }
private void ConvertCIMXMLToDMSNetworkModelDelta() { ////SEND CIM/XML to ADAPTER try { string log; nmsDelta = null; using (FileStream fs = File.Open(textBoxCIMFile.Text, FileMode.Open)) { nmsDelta = adapter.CreateDelta(fs, (SupportedProfiles)(comboBoxProfile.SelectedItem), out log); richTextBoxReport.Text = log; adapter.ApplyUpdates(nmsDelta); } if (nmsDelta != null) { //// export delta to file using (XmlTextWriter xmlWriter = new XmlTextWriter(".\\deltaExport.xml", Encoding.UTF8)) { xmlWriter.Formatting = Formatting.Indented; nmsDelta.ExportToXml(xmlWriter); xmlWriter.Flush(); } } } catch (Exception e) { MessageBox.Show(string.Format("An error occurred.\n\n{0}", e.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } buttonApplyDelta.Enabled = (nmsDelta != null); }
public void OnConvertCommand(string parameter) { ////SEND CIM/XML to ADAPTER try { if (cimLocationString == string.Empty) { MessageBox.Show("Must enter CIM/XML file.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string log = ""; nmsDelta = null; using (FileStream fs = File.Open(cimLocationString, FileMode.Open)) { //nmsDelta = adapter.CreateDelta(fs, selectedProfile, out log); LogResultString = log; } if (nmsDelta != null) { //// export delta to file using (XmlTextWriter xmlWriter = new XmlTextWriter(".\\deltaExport.xml", Encoding.UTF8)) { xmlWriter.Formatting = Formatting.Indented; nmsDelta.ExportToXml(xmlWriter); xmlWriter.Flush(); } } } catch (Exception e) { MessageBox.Show(string.Format("An error occurred.\n\n{0}", e.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ConvertCIMXMLToDMSNetworkModelDelta(EnumDescs enumDescs) { ////SEND CIM/XML to ADAPTER try { if (textBoxCIMFile.Text == string.Empty) { MessageBox.Show("Must enter CIM/XML file.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); Logger.LogInfo("Must enter CIM/XML file."); return; } StringBuilder log = new StringBuilder(); nmsDelta = null; using (FileStream fs = File.Open(textBoxCIMFile.Text, FileMode.Open)) { var result = adapter.CreateDelta(fs, (SupportedProfiles)(comboBoxProfile.SelectedItem), log); if (result.HasValue) { nmsDelta = result.Value; Logger.LogInfo(log.ToString()); richTextBoxReport.Text = log.ToString(); } } if (nmsDelta != null) { //// export delta to file using (XmlTextWriter xmlWriter = new XmlTextWriter(".\\deltaExport.xml", Encoding.UTF8)) { xmlWriter.Formatting = Formatting.Indented; nmsDelta.ExportToXml(xmlWriter, enumDescs); xmlWriter.Flush(); } } } catch (Exception e) { MessageBox.Show(string.Format("An error occurred.\n\n{0}", e.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Logger.LogError("An error occurred.", e); } buttonApplyDelta.Enabled = (nmsDelta != null); textBoxCIMFile.Text = string.Empty; }
/// <summary> /// Writes delta to log /// </summary> /// <param name="delta">delta instance which will be logged</param> public static void TraceDelta(Delta delta) { try { StringWriter stringWriter = new StringWriter(); XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter); xmlWriter.Formatting = Formatting.Indented; delta.ExportToXml(xmlWriter); xmlWriter.Flush(); CommonTrace.WriteTrace(CommonTrace.TraceInfo, stringWriter.ToString()); xmlWriter.Close(); stringWriter.Close(); } catch (Exception ex) { CommonTrace.WriteTrace(CommonTrace.TraceError, "Failed to trace delta with ID = {0}. Reason: {1}", delta.Id, ex.Message); } }
private void ConvertCIMXMLToDMSNetworkModelDelta() { ////SEND CIM/XML to ADAPTER try { if (TextBoxCIMFileText == string.Empty) { System.Windows.Forms.MessageBox.Show("Must enter CIM/XML file.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string log; nmsDelta = null; using (FileStream fs = File.Open(TextBoxCIMFileText, FileMode.Open)) { nmsDelta = adapter.CreateDelta(fs, (SupportedProfiles)(ComboBoxProfileSelectedItem), out log); RichTextBoxReportText = log; } if (nmsDelta != null) { //// export delta to file using (XmlTextWriter xmlWriter = new XmlTextWriter(".\\deltaExport.xml", Encoding.UTF8)) { xmlWriter.Formatting = Formatting.Indented; nmsDelta.ExportToXml(xmlWriter); xmlWriter.Flush(); } } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(string.Format("An error occurred.\n\n{0}", e.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } ButtonApplyDeltaEnabled = (nmsDelta != null); TextBoxCIMFileText = string.Empty; }
private static void Main(string[] args) { ResourceDescription baseVoltage1 = new ResourceDescription { Id = ModelCodeHelper.CreateGlobalId(0, (short)DMSType.BASEVOLTAGE, -1), Properties = new List <Property> { new Property(ModelCode.BASEVOLTAGE_NOMINALVOLTAGE, 110f), new Property(ModelCode.IDOBJ_NAME, "voltage 1"), new Property(ModelCode.IDOBJ_MRID, "mrid 1"), new Property(ModelCode.IDOBJ_DESCRIPTION, "voltage 1 description") } }; ResourceDescription baseVoltage2 = new ResourceDescription { Id = ModelCodeHelper.CreateGlobalId(0, (short)DMSType.BASEVOLTAGE, -2), Properties = new List <Property> { new Property(ModelCode.BASEVOLTAGE_NOMINALVOLTAGE, 20f), new Property(ModelCode.IDOBJ_NAME, "voltage 2"), new Property(ModelCode.IDOBJ_MRID, "mrid 2"), new Property(ModelCode.IDOBJ_DESCRIPTION, "voltage 2 description") } }; ResourceDescription location = new ResourceDescription { Id = ModelCodeHelper.CreateGlobalId(0, (short)DMSType.LOCATION, -1), Properties = new List <Property> { new Property(ModelCode.IDOBJ_MRID, "location mrid"), new Property(ModelCode.LOCATION_CORPORATECODE, "CorporationCode"), new Property(ModelCode.LOCATION_CATEGORY, "Category"), new Property(ModelCode.IDOBJ_NAME, "Location"), new Property(ModelCode.IDOBJ_DESCRIPTION, "Location description"), } }; ResourceDescription winding1 = new ResourceDescription() { Id = ModelCodeHelper.CreateGlobalId(0, (short)DMSType.POWERTRWINDING, -1), Properties = new List <Property> { new Property(ModelCode.POWERTRWINDING_CONNTYPE, (short)WindingConnection.Scott), new Property(ModelCode.POWERTRWINDING_GROUNDED, true), new Property(ModelCode.POWERTRWINDING_RATEDS, 66f), new Property(ModelCode.POWERTRWINDING_RATEDU, 55f), new Property(ModelCode.POWERTRWINDING_WINDTYPE, 1), new Property(ModelCode.POWERTRWINDING_PHASETOGRNDVOLTAGE, 220f), new Property(ModelCode.POWERTRWINDING_PHASETOPHASEVOLTAGE, 380f), new Property(ModelCode.CONDEQ_BASVOLTAGE, baseVoltage1.Id), new Property(ModelCode.IDOBJ_NAME, "winding 1"), new Property(ModelCode.IDOBJ_DESCRIPTION, "winding 1 description"), new Property(ModelCode.IDOBJ_MRID, "winding 1 mrid"), new Property(ModelCode.PSR_CUSTOMTYPE, "custom type"), new Property(ModelCode.EQUIPMENT_ISPRIVATE, true), new Property(ModelCode.EQUIPMENT_ISUNDERGROUND, false), new Property(ModelCode.CONDEQ_PHASES, (short)PhaseCode.ABCN), new Property(ModelCode.CONDEQ_RATEDVOLTAGE, 440f) } }; ResourceDescription winding2 = new ResourceDescription { Id = ModelCodeHelper.CreateGlobalId(0, (short)DMSType.POWERTRWINDING, -2), Properties = new List <Property> { new Property(ModelCode.POWERTRWINDING_CONNTYPE, (short)WindingConnection.Scott), new Property(ModelCode.POWERTRWINDING_GROUNDED, true), new Property(ModelCode.POWERTRWINDING_RATEDS, 66f), new Property(ModelCode.POWERTRWINDING_RATEDU, 55f), new Property(ModelCode.POWERTRWINDING_WINDTYPE, 1), new Property(ModelCode.POWERTRWINDING_PHASETOGRNDVOLTAGE, 220f), new Property(ModelCode.POWERTRWINDING_PHASETOPHASEVOLTAGE, 380f), new Property(ModelCode.CONDEQ_BASVOLTAGE, baseVoltage2.Id), new Property(ModelCode.IDOBJ_NAME, "winding 2"), new Property(ModelCode.IDOBJ_DESCRIPTION, "winding 2 description"), new Property(ModelCode.IDOBJ_MRID, "winding 2 mrid"), new Property(ModelCode.PSR_CUSTOMTYPE, "custom type"), new Property(ModelCode.EQUIPMENT_ISPRIVATE, true), new Property(ModelCode.EQUIPMENT_ISUNDERGROUND, false), new Property(ModelCode.CONDEQ_PHASES, (short)PhaseCode.ABCN), new Property(ModelCode.CONDEQ_RATEDVOLTAGE, 440f) } }; ResourceDescription tranformer = new ResourceDescription() { Id = ModelCodeHelper.CreateGlobalId(0, (short)DMSType.POWERTR, -1), Properties = new List <Property> { new Property(ModelCode.POWERTR_FUNC, 6), new Property(ModelCode.POWERTR_AUTO, true), new Property(ModelCode.PSR_LOCATION, location.Id), new Property(ModelCode.IDOBJ_NAME, "transformer 1"), new Property(ModelCode.IDOBJ_MRID, "transformer 1 mrid"), new Property(ModelCode.IDOBJ_DESCRIPTION, "transformer 1 description"), new Property(ModelCode.PSR_CUSTOMTYPE, "custom type"), new Property(ModelCode.EQUIPMENT_ISUNDERGROUND, false), new Property(ModelCode.EQUIPMENT_ISPRIVATE, true), } }; winding1.AddProperty(new Property(ModelCode.POWERTRWINDING_POWERTRW, tranformer.Id)); winding2.AddProperty(new Property(ModelCode.POWERTRWINDING_POWERTRW, tranformer.Id)); var delta = new Delta(); delta.InsertOperations.Add(baseVoltage1); delta.InsertOperations.Add(baseVoltage2); delta.InsertOperations.Add(location); delta.InsertOperations.Add(winding1); delta.InsertOperations.Add(winding2); delta.InsertOperations.Add(tranformer); XmlTextWriter writer = new XmlTextWriter("result.xml", Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.Indentation = 4; writer.WriteStartDocument(); delta.ExportToXml(writer); writer.WriteEndDocument(); writer.Dispose(); }
private void ConvertCIMXMLToDMSNetworkModelDelta() { ////SEND CIM/XML to ADAPTER try { if (textBoxCIMFile.Text == string.Empty) { MessageBox.Show("Must enter CIM/XML file.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string log; nmsDelta = null; using (FileStream fs = File.Open(textBoxCIMFile.Text, FileMode.Open)) { nmsDelta = adapter.CreateDelta(fs, (SupportedProfiles)(comboBoxProfile.SelectedItem), out log);//deltu sa operacijama, report(string) richTextBoxReport.Text = log; } if (nmsDelta != null) { //// export delta to file using (XmlTextWriter xmlWriter = new XmlTextWriter(".\\deltaExport.xml", Encoding.UTF8)) { xmlWriter.Formatting = Formatting.Indented; nmsDelta.ExportToXml(xmlWriter); xmlWriter.Flush(); } } } catch (Exception e) { MessageBox.Show(string.Format("An error occurred.\n\n{0}", e.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } /////citanje iz baze //List<Model> modeli = new List<Model>(); //using (SqlConnection _con = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=NMSDelta;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False")) //{ // using (SqlCommand cmd = new SqlCommand("SELECT Id, Name, Blob FROM dbo.Deltas", _con)) // { // _con.Open(); // using (SqlDataReader reader = cmd.ExecuteReader()) // { // // Check is the reader has any rows at all before starting to read. // if (reader.HasRows) // { // // Read advances to the next row. // while (reader.Read()) // { // Model m = new Model(); // // To avoid unexpected bugs access columns by name. // m.Id = reader.GetInt32(reader.GetOrdinal("Id")); // m.Name = reader.GetString(reader.GetOrdinal("Name")); // m.Name = m.Name.Trim(); // m.Offset = reader.GetBytes(reader.GetOrdinal("Blob"), 0, m.Blob, 0, 18000); // modeli.Add(m); // } // } // } // _con.Close(); // } //} //foreach (var m in modeli) //{ // if (m.Name.Equals(textBoxCIMFile.Text.Split('\\')[7])) // { // delta = Delta.Deserialize(m.Blob); // } //} //string name = ""; //Tuple<bool, long> search = null; //if (modeli.Count > 0) //{ // foreach (var m in modeli) // { // if (m.Name.Equals(textBoxCIMFile.Text.Split('\\')[7])) // { // //delta = Delta.Deserialize(m.Blob); // foreach (var rd in nmsDelta.InsertOperations) // { // for (int i = 0; i < rd.Properties.Count - 1; i++) // { // if (rd.Properties[i].Id.Equals(ModelCode.IDOBJ_MRID)) // { // search = delta.ContainsDeltaOperation1(DeltaOpType.Insert, rd.Properties[i].PropertyValue.StringValue); // if (!search.Item1) // { // newDelta.AddDeltaOperation(DeltaOpType.Insert, rd, true); // } // else // { // rd.Id = search.Item2; // newDelta.AddDeltaOperation(DeltaOpType.Update, rd, true); // } // } // } // } // foreach (var rd in delta.InsertOperations) // { // if (!nmsDelta.ContainsDeltaOperation(DeltaOpType.Insert, rd.Id)) // { // newDelta.AddDeltaOperation(DeltaOpType.Delete, rd, true); // } // } // //updateovati bazu sa nmsDeltom // //upis u bazu // //if (nmsDelta != null) // //{ // // string queryStmt1 = "INSERT INTO dbo.Deltas(Id, Name, Blob) VALUES(@Id, @Name, @Blob)"; // // using (SqlConnection _con = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=NMSDelta;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False")) // // { // // using (SqlCommand _cmd = new SqlCommand(queryStmt1, _con)) // // { // // SqlParameter param = _cmd.Parameters.Add("@Name", SqlDbType.NChar); // // SqlParameter param1 = _cmd.Parameters.Add("@Id", SqlDbType.Int); // // SqlParameter param2 = _cmd.Parameters.Add("@Blob", SqlDbType.VarBinary); // // param.Value = textBoxCIMFile.Text.Split('\\')[5]; // // param1.Value = ++modeli[modeli.Count - 1].Id; // // param2.Value = nmsDelta.Serialize(); // // _con.Open(); // // _cmd.ExecuteNonQuery(); // // _con.Close(); // // } // // } // //} // nmsDelta = newDelta; // nmsDelta.Id = 1; // if (nmsDelta != null) // { // //// export delta to file // using (XmlTextWriter xmlWriter = new XmlTextWriter(".\\deltaExport.xml", Encoding.UTF8)) // { // xmlWriter.Formatting = Formatting.Indented; // nmsDelta.ExportToXml(xmlWriter); // xmlWriter.Flush(); // } // } // } // else // { // //upis u bazu // if (nmsDelta != null) // { // string queryStmt1 = "INSERT INTO dbo.Deltas(Id, Name, Blob) VALUES(@Id, @Name, @Blob)"; // using (SqlConnection _con = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=NMSDelta;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False")) // { // using (SqlCommand _cmd = new SqlCommand(queryStmt1, _con)) // { // SqlParameter param = _cmd.Parameters.Add("@Name", SqlDbType.NChar); // SqlParameter param1 = _cmd.Parameters.Add("@Id", SqlDbType.Int); // SqlParameter param2 = _cmd.Parameters.Add("@Blob", SqlDbType.VarBinary); // param.Value = textBoxCIMFile.Text.Split('\\')[7]; // param1.Value = ++modeli[modeli.Count - 1].Id; // param2.Value = nmsDelta.Serialize(); // _con.Open(); // _cmd.ExecuteNonQuery(); // _con.Close(); // } // } // } // } // } //} //else //{ // //upis u bazu // if (nmsDelta != null) // { // string queryStmt1 = "INSERT INTO dbo.Deltas(Id, Name, Blob) VALUES(@Id, @Name, @Blob)"; // using (SqlConnection _con = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=NMSDelta;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False")) // { // using (SqlCommand _cmd = new SqlCommand(queryStmt1, _con)) // { // SqlParameter param = _cmd.Parameters.Add("@Name", SqlDbType.NChar); // SqlParameter param1 = _cmd.Parameters.Add("@Id", SqlDbType.Int); // SqlParameter param2 = _cmd.Parameters.Add("@Blob", SqlDbType.VarBinary); // param.Value = textBoxCIMFile.Text.Split('\\')[7]; // param1.Value = 1; // param2.Value = nmsDelta.Serialize(); // _con.Open(); // _cmd.ExecuteNonQuery(); // _con.Close(); // } // } // } //} buttonApplyDelta.Enabled = (nmsDelta != null); textBoxCIMFile.Text = string.Empty; }