Exchange Webservice get meeting ID from list of availability - exchangewebservices

I'm creating appointments like
Appointment appointment = new Appointment(service);
appointment.Subject = m.Subject;
appointment.Start = m.StartTime;
appointment.End = m.EndTime;
appointment.StartTimeZone = TimeZoneInfo.Utc;
appointment.EndTimeZone = TimeZoneInfo.Utc;
....
appointment.Save(folder, SendInvitationsMode.SendToNone);
I can then retrieve the CalIdVal
My system lists out appointments for users. I get this using
GetUserAvailabilityResults results = service.GetUserAvailability(attendees, tw, AvailabilityData.FreeBusyAndSuggestions);
I'd like to filter out the appointment created above.
But this list doesn't contain any IDs so I can't see how.
Any advice appreciated

You need to set the FreeBusyViewType in you GetUserAvailability to Detailed https://learn.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.freebusyviewtype?view=exchange-ews-api then you should get back a list of HexEntryId's for the appointments which you then can convert to EWSId so you can bind/filter eg
DateTime StartTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 0:00"));
DateTime EndTime = StartTime.AddDays(1);
TimeWindow tmTimeWindow = new TimeWindow(StartTime, EndTime);
AvailabilityOptions aoOptions = new AvailabilityOptions();
aoOptions.RequestedFreeBusyView = Microsoft.Exchange.WebServices.Data.FreeBusyViewType.DetailedMerged;
aoOptions.MeetingDuration = 30;
List<AttendeeInfo> atAttendeeList = new List<AttendeeInfo>();
atAttendeeList.Add(new AttendeeInfo("user#domain.com"));
GetUserAvailabilityResults avResponse = service.GetUserAvailability(atAttendeeList, tmTimeWindow, AvailabilityData.FreeBusy, aoOptions);
Int32 atnCnt = 0;
foreach (AttendeeAvailability avail in avResponse.AttendeesAvailability)
{
Console.WriteLine(atAttendeeList[atnCnt].SmtpAddress);
Int32 mc = 0;
var merged = avail.MergedFreeBusyStatus;
while (StartTime < EndTime)
{
Console.WriteLine(StartTime.ToString() + " " + merged[mc]);
mc++;
StartTime = StartTime.AddMinutes(30);
}
foreach (Microsoft.Exchange.WebServices.Data.CalendarEvent calendarItem in avail.CalendarEvents)
{
Console.WriteLine("Free/busy status: " + calendarItem.FreeBusyStatus);
Console.WriteLine("Start time: " + calendarItem.StartTime);
Console.WriteLine("End time: " + calendarItem.EndTime);
var convertedId = (AlternateId)service.ConvertId(new AlternateId(IdFormat.HexEntryId, calendarItem.Details.StoreId, "someemail#domain.com"), IdFormat.EwsId);
var apt = Appointment.Bind(service, new ItemId(convertedId.UniqueId));
}
atnCnt++;
}

Related

how to use for loop to read data from mysql table

I have mysql Database and i want to read data from there in my web application with for loop instead of foreach loop.
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
string query = "SELECT * FROM survey ORDER BY datetime DESC";
MySqlCommand com = new MySqlCommand(query, conn);
com.CommandTimeout = 0;
MySqlDataAdapter da = new MySqlDataAdapter(com);
DataTable ds = new DataTable();
da.Fill(ds);
conn.Close();
foreach (DataRow item in ds.Rows)
{
string unique = item.ItemArray[4].ToString();
var sur = db2.VoipSurveys.Where(a => a.UniqueId == unique).SingleOrDefault();
if (sur == null)
{
VoipSurvey vs = new VoipSurvey()
{
Date = Convert.ToDateTime(item.ItemArray[1]),
Point = Convert.ToInt32(item.ItemArray[2]),
CallerId = item.ItemArray[3].ToString(),
UniqueId = item.ItemArray[4].ToString(),
AgentNumber = item.ItemArray[5].ToString(),
AgentName = item.ItemArray[6].ToString(),
QueueNumber = item.ItemArray[7].ToString()
};
db2.VoipSurveys.Add(vs);
db2.SaveChanges();
}
}
I need reading data from specific index like reading data in mysql table from this Date until now. and i think my problem would be solved with for loop
You can use a DataView RowFilter also:
// Create a DataView
DataView dv = new DataView(dt);
dv.RowFilter = " (Date >= #" +
Dateyouwanttouse +
"# And Date <= #" +
DateTime.Now +
"# ) ";
Simply do this:
foreach (DataRowView rowView in dv)
{
DataRow row = rowView.Row;
// Do something //
}

Mysql NodeJs syncronous queries

Thank you for the answer,
I did that : i used "sync-mysql" :
but now its very very slow...
Maybe i could do the same code using Mysql NPM
Do you know how my code must look like if I want to use asyncronous function and doing the same thing as below ? It will help me a lot :)
I have almost finished my project and I only have this function left
const customer_booked = []
customer_booked[0] = []
customer_booked[1] = []
let sql = "SELECT * " +
"FROM customer as C " +
"WHERE customer_reference REGEXP '^[c]i*' "
if (filters[0].value.length){
sql += "AND C.customer_name LIKE '%" + filters[0].value + "%' "
}
if (filters[3].value.length){
sql += "LIMIT " + filters[3].value
}
var result = connection.query(sql);
const customers = [];
const booked = connection.query('SELECT cr.customer_id, a.codeAgent ' +
'FROM customer_reservation as cr ' +
'INNER JOIN agent as a ' +
'ON a.id = cr.agent_id')
booked.forEach(customer_booking => {
customer_booked[0].push(customer_booking.customer_id)
customer_booked[1].push(customer_booking.codeAgent)
});
result.forEach( customer => {
var months;
let d1 = new Date(customer.last_order);
let d2 = new Date();
months = (d2.getFullYear() - d1.getFullYear()) * 12;
months -= d1.getMonth() + 1;
months += d2.getMonth();
months = months <= 0 ? 0 : months;
if (customer_booked[0].includes(customer.customer_id)){
let code_agent_index = customer_booked[0].indexOf(customer.customer_id)
customer.available = 'booked'
customer._rowVariant = 'warning'
customer.agent_code = customer_booked[1][code_agent_index]
}
else if (months >= 12){
customer.available = 'available'
customer._rowVariant = 'success'
} else {
customer.available = 'notAvailable'
customer._rowVariant = 'danger'
}
let sql2 = "SELECT * " +
"FROM customer_addresses AS CA " +
"WHERE CA.customer_id = " + customer.id
customer.addresses = connection.query(sql2)
customers.push(customer);
//customers[customers.length].push()
})
callback(false, result)
You can use node.js async/await using IIFE, like this:
(async() => {
const users = await getUsers();
for(const user of users){
user.addresses = await getAddresses(user.id);
// your other code just translated to JS.
}
return users;
})()
So, the main idea is to await your async code.
For example we use IIFE (Immediately Invoked Function Expression) to access needed async/await and for tests.
In real code you should name functions with keyword async
Here is nice tutorials which could explain how to use async/await 1, 2

“SELECT * FROM book WHERE year=wyear AND account >= waccount1 AND account <= waccount1”

For several days I've been struggling to display data from the table in DataSet. When I do not put a condition in the WHERE, it displays the complete table, but only the rows in the table that meet the condition are required. If there are suggestions for a quicker view. Thanks a lot.
myConnectionString = pwput;
MySqlConnectionconpara = new MySql.Data.MySqlClient.MySqlConnection();
conpara.ConnectionString = myConnec DataSetionString;
try
{
conpara.Open();
if (conpara.State == ConnectionState.Open)
{
string waccoun1 = wnalog1.ToString();
string waccoun2 = wnalog2.ToString();
stringnupita = "SELECT * FROM book WHERE year=wyear AND account >=
waccount1 AND account <= waccount1";
MySqlCommandcmdnal = new MySqlCommand(nupita,conpara);
MySqlCommand(nupita,conpara);cmdnal.Parameters.AddWithValue("#year",
wyear);
MySqlDataAdapte radda = new MySqlataAdapter(cmdnal);
MySqlCommandBuildercbb = new MySqlCommandBuilder(adda);
DataSet dsd = new DataSet();
adda.Fill(dsd, "book");
conpara.Close();
if (dsd != null)
{
dataGridView1.DataSource = dsd;
dataGridView1.DataMember = "book";
Font = new System.Drawing.Font("Arial Unicode", 7);
dataGridView1.Font = Font;
{
You need to use parameters like so:
...
stringnupita = "SELECT * FROM book WHERE year=#year AND account >=
#waccount1 AND account <= #waccount2";
MySqlCommand(nupita,conpara);cmdnal.Parameters.AddWithValue("#year",
wyear);
MySqlCommand(nupita,conpara);cmdnal.Parameters.AddWithValue("#waccount1",
waccount1);
MySqlCommand(nupita,conpara);cmdnal.Parameters.AddWithValue("#waccount2",
waccount2);
...

How to create a google app script that delete temporary contacts after a while?

i'm looking to create an script that does the following:
Delete a contact marked to be deleted after an specific time.
Surely you have save a phone number you are only going to use once, so this would help to delete that contact of we forgot about it.
Ok, i'm answering my own question for if someone is interested.
First, you have to create a contact group in wich you are going to categorize this contacts (in the code is "Tiny", but you can named as you whish).
Second, when creating a contact, you should add a note like; "2 month" if you want the contact to get erased after 2 months, or "1 year", etc. The code is implemented only for months and year, but is easily modifiable if you want another time period, like days or weeks.
Here's the code:
function deleteTinyContacts() {
var group = ContactsApp.getContactGroup("Tiny");
var contacts = ContactsApp.getContactsByGroup(group)
var hoy = new Date();
Logger.log("today is " + hoy);
Logger.log("total contacts to delete: " + contacts.length);
for (var i = 0; i < contacts.length; i++) {
var date = contacts[i].getLastUpdated();
Logger.log(contacts[i].getFullName() + " was updated last in " + date);
var datediff = DateDiff.inMonths(date,hoy);
Logger.log("contact updated " + datediff + " months ago");
var note = contacts[i].getNotes();
var res = note.split(" ");
var Tmonths = calcMonths(res[1]);
var todelete = res[0]*Tmonths;
Logger.log("contact must be deleted after " + todelete + " months");
if (datediff>=todelete){
group.removeContact(contacts[i]);
}
}
}
var DateDiff = {
inDays: function(d1, d2) {
var t2 = d2.getTime();
var t1 = d1.getTime();
return parseInt((t2-t1)/(24*3600*1000));
},
inWeeks: function(d1, d2) {
var t2 = d2.getTime();
var t1 = d1.getTime();
return parseInt((t2-t1)/(24*3600*1000*7));
},
inMonths: function(d1, d2) {
var d1Y = d1.getFullYear();
var d2Y = d2.getFullYear();
var d1M = d1.getMonth();
var d2M = d2.getMonth();
return (d2M+12*d2Y)-(d1M+12*d1Y);
},
inYears: function(d1, d2) {
return d2.getFullYear()-d1.getFullYear();
}
}
function calcMonths(str){
if(str=="año"){return 12;}
else if(str=="mes"){return 1;}
}

SQL searching daily attributes error

I am trying to build an application which searches all attributes step by step daily and monthly using the between statement. The daily queries run, but monthly dones't run.
The code:
if (libs.conn.con.State == ConnectionState.Closed) libs.conn.baglanti.Open();
string today = "select getdate()";
SqlCommand today1 = new SqlCommand(today, libs.conn.con);
string today2 = today1.ExecuteScalar().ToString();
string[] day = today2.Split(' ');
day[0] += " 00:00:00";
string dayy = (DateTime.Now.Day).ToString();
string month = (DateTime.Now.Month).ToString();
string year = (DateTime.Now.Year).ToString();
string[] combine = new string[] { "1." };
combine[0] += month + ".";
combine[0] += year + " ";
combine[0] += "00:00:00";
string totalmonth = "(SELECT SUM(para) FROM statistics where datee between '"+combine[0]+"' AND '"+today2+"')";
SqlCommand totalmoneymonthlyquery = new SqlCommand(totalmoneymonth, libs.conn.baglanti);
string totalmoneymonthlyresult = totalmoneymonthlyquery.ExecuteScalar().ToString();
textBox7.Text = totalmoneymonthlyresult.ToString();
use
combine[0]=today2
use first
you may get parameter error to pull data.
String.Format("{0:d/M/yyyy HH:mm:ss}", dt);
String.Format("{0:d/M/yyyy HH:mm:ss}", dt);