public bool Backend_AddContract(string clientName, string clientRegno, string clientPhone, string clientEmail, string clientAddress, long facilityId, long areaId, DateTime startDate, string settlementMethod) { Trace.WriteLine("Backend_AddContract"); bool result = false; long newContractId = -1; DataManager dataMan = new DataManager(); long clientId = dataMan.CheckUserExists(clientRegno); if (clientId > -1) { if (dataMan.CheckActiveContractExists(clientRegno) > -1) { result = false; } else { newContractId = dataMan.AddContract(clientId, areaId, facilityId, startDate, settlementMethod); result = true; } } else { clientId = dataMan.AddUser(clientName, clientRegno, clientPhone, clientEmail, clientAddress); newContractId = dataMan.AddContract(clientId, areaId, facilityId, startDate, settlementMethod); result = true; } if (result && newContractId != -1) { NotifyNetworkOwner(newContractId); } return result; }
public AreaData[] Backend_GetAreas() { Trace.WriteLine("Backend_GetAreas"); AreaData[] result = new AreaData[0]; DataManager dataMan = new DataManager(); result = dataMan.GetAreas(); return result; }
internal contractMessage GetContractMessageNO1(long contractId) { DataManager dataMan = new DataManager(); cMsg = new contractMessage(); cMsg.messageRecieverParty =""; cMsg.messageSenderParty = "T1ES1"; PartyType provider = new PartyType(); CompanyData companyData = dataMan.GetCompanyData("T1ES1"); provider.name = companyData.Name; provider.registryCode = companyData.RegCode; provider.address = companyData.Address; provider.contactPhone = companyData.ContactPhone; provider.contactEmail = companyData.ContactEmail; cMsg.ProviderParty = provider; ContractData contractData = dataMan.GetContractData(contractId); cMsg.messageRecieverParty = contractData.AreaNetworkOwner; contractMessageClientParty client = new contractMessageClientParty(); client.name = contractData.ClientName; client.registryCode = contractData.ClientRegNo.ToString(); client.address = contractData.ClientAddress; client.contactPhone = contractData.ClientPhone; client.contactEmail = contractData.ClientEmail; client.facilityId = contractData.FacilityId.ToString(); client.areaId = contractData.AreaId.ToString(); cMsg.ClientParty = client; contractMessageContractInfo contract = new contractMessageContractInfo(); contract.startDateSpecified = true; contract.startDate = contractData.StartDate; contract.contractId = contractData.ContractId.ToString(); cMsg.contractInfo = contract; return cMsg; }
public bool Frontend_AuthenticateClient(string clientRegno, string password) { Trace.WriteLine("Frontend_AuthenticateClient"); DataManager dataMan = new DataManager(); return dataMan.CheckUserExists(clientRegno) > -1; }
public FacilityData[] Backend_GetFacilities() { Trace.WriteLine("Backend_GetFacilities"); FacilityData[] result = new FacilityData[0]; DataManager dataMan = new DataManager(); result = dataMan.GetFacilities(); return result; }
public void ReceiveSupplierChangeConfirmation(contractMessage msgZ04) { Trace.WriteLine("ReceiveSupplierChangeConfirmation " + msgZ04.ClientParty.registryCode); long contractId = -1; try { DataManager dataMan = new DataManager(); contractId = dataMan.SaveConfirmation(msgZ04); } catch (Exception rsccExc) { Trace.WriteLine("Error receiving supplier change confirmation: " + rsccExc.Message); } }
public void SendConsumptionForecast(long contractId) { Trace.WriteLine("SendConsumptionForecast"); try { DataManager dataMan = new DataManager(); electricityProfile ep = new electricityProfile(); Random rn = new Random(); ContractData contractData = dataMan.GetContractData(contractId); ep.areaId = contractData.AreaId.ToString(); ep.amount = rn.Next(100, 200).ToString(); ep.contractId = contractData.ContractId.ToString(); ep.dateStart = contractData.StartDate; ep.dateEnd = DateTime.Now; ep.fromId = "T1ES1"; //send to first krado ep.toId = "T1RK1"; try { ep.messageId = dataMan.SaveComposedMessage(ep).ToString(); t1rk1Client = new KradoServiceSoapClient(); balanceInvoice bi = t1rk1Client.presumableLoadProfile(ep); this.ReceiveBalanceInvoice(bi); } catch (Exception rk1Exc) { Trace.WriteLine("Error sending consumption forecast to T1RK1: " + rk1Exc.Message); } //send to second krado ep.toId = "T1RK2"; try { ep.messageId = dataMan.SaveComposedMessage(ep).ToString(); t1rk2Client = new ReceiveClient(); string tmp = t1rk2Client.ReceiveCfFromEs("some piparkoogid from T1ES1"); } catch (Exception rk2Exc) { Trace.WriteLine("Error sending consumption forecast to T1RK2: " + rk2Exc.Message); } } catch (Exception scfExc) { Trace.WriteLine("Error sending consumption forecast: " + scfExc.Message); } }
public void ReceiveMeterReading(t1es1.t1rk1.meterReading msgReading) { Trace.WriteLine("ReceiveMeterReading"); try { DataManager dataMan = new DataManager(); dataMan.SaveReadings(msgReading); try { this.SendConsumptionForecast(Int64.Parse(msgReading.contractId)); } catch (Exception scfExc) { Trace.WriteLine("Error sending forecast for cId: " + msgReading.contractId + "|" + scfExc.Message); } } catch (Exception rmrExc) { Trace.WriteLine("Error receiving meter reading: " + rmrExc.Message); } }
public int ReceivePreliminaryLoadProfileShares(electricityProfile msgProfile) { Trace.WriteLine("ReceivePreliminaryLoadProfileShares"); int result = 0; try { DataManager dataMan = new DataManager(); dataMan.SaveProfile(msgProfile); result = 1; } catch (Exception rcpExc) { Trace.WriteLine("Error in RPLPS: " + rcpExc.Message); result = 0; } return result; }
public int ReceiveConsumptionProfile(electricityProfile profile) { Trace.WriteLine("ReceiveConsumptionProfile"); int result = 0; try { DataManager dataMan = new DataManager(); dataMan.SaveProfile(profile); result = 1; } catch (Exception rcpExc) { Trace.WriteLine("Error in RCP: " + rcpExc.Message); result = 0; } return result; }
public void ReceiveCustomerChangedSupplier(contractMessage msgZ05) { Trace.WriteLine("ReceiveCustomerChangedSupplier" + msgZ05.ClientParty.registryCode); long contractId = -1; try { DataManager dataMan = new DataManager(); contractId = dataMan.SaveSupplierChange(msgZ05); } catch (Exception rccsExc) { Trace.WriteLine("Error receiving customerChangedSupplier: " + rccsExc.Message); } if (contractId != -1) { try { this.SendConsumptionForecast(contractId); } catch (Exception scfExc) { Trace.WriteLine("Error sending forecast for cId: " + contractId + "|" + scfExc.Message); } } }
public int ReceiveBalanceInvoice(balanceInvoice invoice) { Trace.WriteLine("ReceiveBalanceInvoice"); int result = 0; try { DataManager dataMan = new DataManager(); ContractData cData = dataMan.GetContractData(Int64.Parse(invoice.contractId)); if (cData.EndDate < new DateTime(1990, 1, 1)) { Trace.WriteLine("Contract is not terminated. Message not saved, returning 1, finishing."); return 1; } if (dataMan.SaveInvoice(invoice) == 1) { try { MailMessage mail = new MailMessage("*****@*****.**", cData.ClientEmail); mail.Subject = "T1ES1: Invoice nr." + invoice.invoiceNo; mail.Body = String.Format("Congratulations: you have received invoice nr. {0}, dated by {1}, made by {5}. Please make payment with amount {2} before {3}, or you will be banned with our mighty banhammer!\n You can see your invoices in our User frontend at {4} on the 'Invoices' page.", invoice.invoiceNo, invoice.date.ToString("dd.MM.yyyy"), invoice.amount.ToString("0.00"), invoice.dueDate.ToString("dd.MM.yyyy"), "http://sandstorm.cs.ut.ee/ESI/2011/otido/Frontend/", invoice.kradoId); SmtpClient sc = new SmtpClient("mailhost.ut.ee"); sc.Send(mail); result = 1; } catch (Exception mailSendExc) { Trace.WriteLine("Error sending email: " + mailSendExc.Message); result = 0; } }; } catch (Exception rbiExc) { Trace.WriteLine("Error receiving balance invoice: " + rbiExc.Message); result = 0; } return result; }
public void ReceiveAperak(responseMessage msg) { Trace.WriteLine("ReceiveAperak "); try { Random rn = new Random(); DataManager dataMan = new DataManager(); dataMan.SaveAperak(msg); } catch (Exception raExc) { Trace.WriteLine("Error receiving APERAK: " + raExc.Message); } }
public void NotifyNetworkOwner(long contractId) { Trace.WriteLine("NotifyNetworkOwner: " + contractId.ToString()); try { ContractMessageProducer cmp = new ContractMessageProducer(); contractMessage cMsg = cmp.GetContractMessageNO1(contractId); if (cMsg.messageRecieverParty == "T1NO1") { Trace.WriteLine("Owner is T1NO1"); DataManager dataMan = new DataManager(); cMsg.messageId = dataMan.SaveComposedMessage(cMsg).ToString(); ContractMessageService container = new ContractMessageService(cMsg); t1no1Client = new ContractMessageServicePortTypeClient(); t1no1Client.ContractMessageService(container); Trace.WriteLine("Sent to T1NO1"); } else if (cMsg.messageRecieverParty == "T1NO2") { Trace.WriteLine("Owner is T1NO2"); establishContractRequest cMsgR = new establishContractRequest(); cMsgR.messageType = "L"; cMsgR.messageRecipient = cMsg.messageRecieverParty; cMsgR.sendTime = DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'"); cMsgR.messageSender = cMsg.messageSenderParty; cMsgR.ES_edielId = cMsg.messageSenderParty; cMsgR.ES_name = cMsg.ProviderParty.name; cMsgR.ES_registryCode = cMsg.ProviderParty.registryCode; cMsgR.ES_address = cMsg.ProviderParty.address; cMsgR.ES_phone = cMsg.ProviderParty.contactPhone; cMsgR.ES_email = cMsg.ProviderParty.contactEmail; cMsgR.CL_name = cMsg.ClientParty.name; cMsgR.CL_registryCode = cMsg.ClientParty.registryCode; cMsgR.CL_address = cMsg.ClientParty.address; cMsgR.CL_phone = cMsg.ClientParty.contactPhone; cMsgR.CL_email = cMsg.ClientParty.contactEmail; cMsgR.CL_areaId = cMsg.ClientParty.areaId; cMsgR.CL_facilityId = cMsg.ClientParty.facilityId; cMsgR.startDate = cMsg.contractInfo.startDate.ToString("yyyy-MM-dd"); DataManager dataMan = new DataManager(); cMsg.messageId = dataMan.SaveComposedMessage(cMsg).ToString(); cMsgR.messageId = cMsg.messageId; t1no2Client = new T1NO2WSClient("T1NO2WSPort"); string tmp = t1no2Client.establishContract(cMsgR.messageId, cMsgR.messageType, cMsgR.messageRecipient, cMsgR.sendTime, cMsgR.messageSender, cMsgR.ES_edielId, cMsgR.ES_name, cMsgR.ES_registryCode, cMsgR.ES_address, cMsgR.ES_phone, cMsgR.ES_email, cMsgR.CL_name, cMsgR.CL_registryCode, cMsgR.CL_address, cMsgR.CL_phone, cMsgR.CL_email, cMsgR.CL_areaId, cMsgR.CL_facilityId, cMsgR.startDate); Trace.WriteLine("Sent to T1NO2"); } } catch (Exception notifyExc) { Trace.WriteLine("Error notifying NO: " + notifyExc.Message); } }
public balanceInvoice[] Frontend_GetInvoicesByClientRegno(string clientRegno) { Trace.WriteLine("Frontend_GetInvoicesByClientRegno"); balanceInvoice[] result = new balanceInvoice[0]; DataManager dataMan = new DataManager(); return dataMan.GetUserInvoices(clientRegno); }
public ContractData[] Frontend_GetContractsByClientRegno(string clientRegno) { Trace.WriteLine("Frontend_GetContractsByClientRegno:" + clientRegno); ContractData[] result = new ContractData[0]; DataManager dataMan = new DataManager(); result = dataMan.GetUserContracts(clientRegno); return result; }