How to get a Flag property from email message? - exchangewebservices

Can I somehow get a Flag property from EmailMessage or Item object? There is no getFlag() method, I also didn't find it in item.getPropertyBag(). I'm using ews-java-api-2.0. flag setting on outlook web app

There is a strongly type flag property in EWS in 2013 and greater so you could modify the EWS Java source to cater for that. Otherwise if you use the underlying Extended properties you can get the same information eg
ExtendedPropertyDefinition PR_FLAG_STATUS = new ExtendedPropertyDefinition(0x1090, MapiPropertyType.Integer);
ExtendedPropertyDefinition FlagRequest = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, 0x8530, MapiPropertyType.String);
PropertySet fiFindItemPropset = new PropertySet(BasePropertySet.FirstClassProperties);
fiFindItemPropset.Add(FlagRequest);
fiFindItemPropset.Add(PR_FLAG_STATUS);
FolderId FolderToAccess = new FolderId(WellKnownFolderName.Inbox, MailboxToAccess);
ItemView ivItemView = new ItemView(1000);
ivItemView.PropertySet = fiFindItemPropset;
FindItemsResults<Item> FindItemResults = null;
do
{
FindItemResults = service.FindItems(FolderToAccess, ivItemView);
foreach (Item itItem in FindItemResults.Items)
{
Console.WriteLine(itItem.Subject);
Object FlagValue = null;
if (itItem.TryGetProperty(FlagRequest, out FlagValue))
{
Console.WriteLine("Flag : " + FlagValue);
}
Object PR_FLAG_STATUS_Value = null;
if (itItem.TryGetProperty(PR_FLAG_STATUS, out PR_FLAG_STATUS_Value))
{
Console.WriteLine("PR_FLAG_STATUS : " + PR_FLAG_STATUS_Value);
}
}
ivItemView.Offset += FindItemResults.Items.Count;
} while (FindItemResults.MoreAvailable);
Theres a full list of flag properties https://msdn.microsoft.com/en-us/library/ee201258(v=exchg.80).aspx

Related

Send unassigned JSON properties to server when using stringify i.e. retain properties name whether property value is empty/null

I have two model properties:
ng-model="category.name" mandatory field
ng-model="category.desc" optional
This is how I am sending data to the server (ASP.net)
var rdt = "{'dt':" + JSON.stringify($scope.category) + "}";
However, if an optional property has an unassigned value, the property name is not found server side and gives an error. Are there any ways to retain unassigned properties of JSON?
You have several solutions:
Solution 1: Initialize the variables in your scope for example:
$scope.category.desc = null
Solution 2: Create a function to take care of that
function ToJson(object, properties) {
var result = {};
for(var i = 0; i < properties.lenght; i++) {
var property = properties[i];
if(!object[property]) {
result[property] = null;
} else {
result[property] = object[property];
}
}
return JSON.stringify(result);
}
// And then use it like this:
var rdt = "{'dt':" + ToJson($scope.category, ["name", "desc"]) + "}";

Can't load a service for category "ExternalGraphicFactory"

I'm using geotools-18.5, with JavaFx in Inteliji IDE.
When I want to create PointSymbolizer from a svg or png image.
StyleBuilder builder = new StyleBuilder();
ExternalGraphic extGraphic = builder.createExternalGraphic("file:/home/cuongnv/test.svg", "svg");
I build code OK, but when run, I received warning:
WARNING: Can't load a service for category "ExternalGraphicFactory".
Provider org.geotools.renderer.style.ImageGraphicFactory could not be
instantiated.
Can someone help me ?
Here is full code:
private Style createStyleBuilder(){
StyleBuilder builder = new StyleBuilder();
FilterFactory2 ff = builder.getFilterFactory();
// RULE 1
// first rule to draw cities
// define a point symbolizer representing a city
Graphic city = builder.createGraphic();
city.setSize(ff.literal(50));
ExternalGraphic extGraphic = builder.createExternalGraphic("file:/home/cuongnv/Javafx/GeoTool/geotools_fx_tutorial-master/geotools-fx/src/main/resources/images/console.svg", "svg"); // svg
city.addExternalGraphic(extGraphic);
PointSymbolizer pointSymbolizer = builder.createPointSymbolizer(city);
Rule rule1 = builder.createRule(pointSymbolizer);
rule1.setName("rule1");
rule1.getDescription().setTitle("City");
rule1.getDescription().setAbstract("Rule for drawing cities");
Rule rules[] = new Rule[] {rule1};
FeatureTypeStyle featureTypeStyle = builder.createFeatureTypeStyle("Feature", rules);
Style style = builder.createStyle();
style.setName("style");
style.getDescription().setTitle("User Style");
style.getDescription().setAbstract("Definition of Style");
style.featureTypeStyles().add(featureTypeStyle);
return style;
}
TYPE = DataUtilities.createType(
"Dataset",
"geometry:Geometry:srid=4326"
+ ","
+ "name:String,"
+ "id:String"
);
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
com.vividsolutions.jts.geom.Point point = geometryFactory.createPoint(new Coordinate(x,y));
featureBuilder.add(point);
SimpleFeature feature = featureBuilder.buildFeature(null);
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection("internal", TYPE);
featureCollection.add(feature);
Style style = createStyleBuilder();
Layer layer = new FeatureLayer(featureCollection, style);
layer.setTitle("New Point");
mapContent.layers().add(layer);
You have set the image mime type incorrectly, it should be:
ExternalGraphic extGraphic = builder.createExternalGraphic("file:/stuff/ian/geoserver/data/styles/burg02.svg", "image/svg"); // svg
and all will work.
EDIT
If you are still having issues then try adding this code to the end of the createStyle module and look at the generated SVG, possibly in GeoServer to test it out.
SLDTransformer styleTransform = new SLDTransformer();
StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
UserLayer layer = sf.createUserLayer();
layer.setLayerFeatureConstraints(new FeatureTypeConstraint[] {null});
sld.addStyledLayer(layer);
layer.addUserStyle(style);
try {
String xml = styleTransform.transform(sld);
System.out.println(xml);
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

How can I add an attachment to a MailMessage?

I've got this code that sends a simple email using SmtpClient, MailMessage, and MailAddress objects:
private void EmailMessage(string msg)
{
string TO_EMAIL = "cshannon#proactusa.com";
var windowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent();
string userName = windowsIdentity.Name;
string subject = string.Format("Log msg from Report Runner app sent {0}; user was {1}", DateTime.Now.ToLongDateString(), userName);
string body = msg;
var SmtpServer = new SmtpClient(ReportRunnerConstsAndUtils.EMAIL_SERVER);
var SendMe = new MailMessage();
SendMe.To.Add(TO_EMAIL);
SendMe.Subject = subject;
SendMe.From = new MailAddress(ReportRunnerConstsAndUtils.FROM_EMAIL);
SendMe.Body = body;
try
{
SmtpServer.UseDefaultCredentials = true;
SmtpServer.Send(SendMe);
}
}
I also need, though, to attach a file to an email. I was doing it using Outlook like so:
Application app = new Application();
MailItem mailItem = app.CreateItem(OlItemType.olMailItem);
. . .
FileInfo[] rptsToEmail = GetLastReportsGenerated();
foreach (var file in rptsToEmail)
{
String fullFilename = String.Format("{0}\\{1}", uniqueFolder, file.Name);
if (!file.Name.Contains(PROCESSED_FILE_APPENDAGE))
{
mailItem.Attachments.Add(fullFilename);
}
}
mailItem.Importance = OlImportance.olImportanceNormal;
mailItem.Display(false);
...but I need to move away from using Outlook for this. Here the MailItem is a Microsoft.Office.Interop.Outlook.MailItem
How can I add attachments in the simple MailMessage I need to use now?
Setting the Importance is not too important, I don't think, but the Display is something I will need to set for the MailMessage, too.
Easy:
if (!file.Name.Contains(PROCESSED_FILE_APPENDAGE))
{
var attachment = new Attachment(fullFilename);
mailMsg.Attachments.Add(attachment);
}
mailMsg.Priority = MailPriority.Normal;

How to Use Xamarin.Forms and GoogleMaps/GeoLocation

I am writing a Xamarin.Forms PCL app, to support iOS and Android OS for my app.
In the root project, I have a view containing a ViewList and a map (from Xamarin.Forms.Maps).
I learnt I have to use CustomRenderer for each platform to add customized behavior. What I am trying to achieve to add a LocationManager/GeoLocation to identify the users position via GPS and show his position with a pin/marker. Additionally to that, I get positions from the root project of several persons which pins must also be shown within the map.
Should I have to use an interface exporting functionality or use an appropriate custom map renderer?
I have no idea to achieve that, the examples at the Xamarin.Forms website and research within Stackoverflow do not give a hint.
Here is some code I have so far (extract):
using System;
using Awesome;
using Xamarin.Forms;
using Xamarin.Forms.Maps;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using Plugin.Geolocator;
using System.Threading.Tasks;
namespace KiLa
{
public class KidsFinder : ContentPage, ITabPage
{
public string TabIcon => FontAwesome.FAMapMarker;
public string SelectedTabIcon => FontAwesome.FAMapMarker;
private Boolean _showKidsList;
private ListView _listView;
public ObservableCollection<KidsViewModel> kidsList = new ObservableCollection<KidsViewModel>();
public KidsFinder ()
{
Title = "KidsFinder";
// Define listView
// Any near/identified kids? Mockup
// TODO: get real data
Boolean kidsPresent = true;
// Initial height of map
double mapHeight = 300.0;
// coordinates of Beuth Hochschule, Haus Gauss
double latitude = 52.543100;
double longitude = 13.351450;
// Show/hide kidsList (listView)
//Boolean showKidsList = false;
_showKidsList = false;
// Define toggleButton
Button toggleButton = new Button();
toggleButton.Text = "Verstecke Liste";
toggleButton.Clicked += new EventHandler(OnClickEvent);
if(kidsPresent == true)
{
toggleButton.IsVisible = true;
mapHeight = 200.0;
_showKidsList = true;
} else
{
toggleButton.IsVisible = false;
mapHeight = 300.0;
_showKidsList = false;
}
// Mockup some kids
Position pos1 = new Position(latitude + 0.002, longitude + 0.002);
Position pos2 = new Position (latitude - 0.002, longitude - 0.002);
kidsList.Add(new KidsViewModel{Name="Tim", ActualPositon=pos1, DistanceToEducator=5.4});
kidsList.Add(new KidsViewModel{Name="Sabine", ActualPositon=pos2, DistanceToEducator=20.4});
_listView = new ListView();
_listView.ItemsSource = kidsList;
//listView.VerticalOptions = LayoutOptions.FillAndExpand;
_listView.ItemTemplate = new DataTemplate (typeof(KidsCustomCell));
_listView.RowHeight = 50;
if (_showKidsList == false) {
_listView.IsVisible = false;
} else {
_listView.IsVisible = true;
}
// Define mapView
var kidsMap = new KidsMap ();
kidsMap.MapType = MapType.Street;
kidsMap.WidthRequest = 960;
kidsMap.HeightRequest = mapHeight;
kidsMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(latitude,longitude), Distance.FromMiles(0.3)));
// Set label of pins with kids names,
foreach (KidsViewModel kvm in kidsList) {
Pin pin = new Pin() {
Label = kvm.Name,
Position = kvm.ActualPositon
};
kidsMap.Pins.Add(pin);
}
You should use GetLocation and declare the permissions necessary to use the LocationServices
[assembly: UsesPermission(Manifest.Permission.AccessFineLocation)]
[assembly: UsesPermission(Manifest.Permission.AccessCoarseLocation)]
This is not strictly necessary for obtaining the GPS coordinates of the device, but this example will attempt to provide a street address for the current location:
[assembly: UsesPermission(Manifest.Permission.Internet)]
Add a method called InitializeLocationManager to activity
void InitializeLocationManager()
{
_locationManager = (LocationManager) GetSystemService(LocationService);
Criteria criteriaForLocationService = new Criteria
{
Accuracy = Accuracy.Fine
};
IList<string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);
if (acceptableLocationProviders.Any())
{
_locationProvider = acceptableLocationProviders.First();
}
else
{
_locationProvider = string.Empty;
}
Log.Debug(TAG, "Using " + _locationProvider + ".");
}
The LocationManager class will listen for GPS updates from the device and notify the application by way of events. In this example we ask Android for the best location provider that matches a given set of Criteria and provide that provider to LocationManager.
For more details how to get current location using Xamarin Forms, follow this link: https://developer.xamarin.com/recipes/android/os_device_resources/gps/get_current_device_location/

MS Exchange Web-Services: How to get items with 'Flag' set?

Does anyone know how to get all the items that are flagged inside the Inbox using Microsoft Exchange Web-Services?
Apparently they are neither inside Tasks folder (even though they appear there in Outlook), nor do they have IsReminderSet set to true.
Following attempts either return only appointments or true tasks only, but not flagged messages:
var msgsView = new ItemView(100);
var msgsFilter = new SearchFilter.IsEqualTo(ItemSchema.IsReminderSet, true);
var flagged = exSvc.FindItems(WellKnownFolderName.Inbox, msgsFilter, msgsView);
or
var taskView = new ItemView(100);
var tasks = exSvc.FindItems(WellKnownFolderName.Tasks, taskView);
neither work.
I know this question is old, but I just found list sample code which looks like it might do the trick (I haven't tested it myself yet)
source: http://independentsoft.de/exchangewebservices/tutorial/findmessageswithflag.html
IsEqualTo restriction1 = new IsEqualTo(MessagePropertyPath.FlagStatus, "1"); //FlagStatus.Complete
IsEqualTo restriction2 = new IsEqualTo(MessagePropertyPath.FlagStatus, "2"); //FlagStatus.Marked
Or restriction3 = new Or(restriction1, restriction2);
FindItemResponse response = service.FindItem(StandardFolder.Inbox
, MessagePropertyPath.AllPropertyPaths, restriction3);
for (int i = 0; i < response.Items.Count; i++)
{
if (response.Items[i] is Message)
{
Message message = (Message)response.Items[i];
Console.WriteLine("Subject = " + message.Subject);
Console.WriteLine("FlagStatus = " + message.FlagStatus);
Console.WriteLine("FlagIcon = " + message.FlagIcon);
Console.WriteLine("FlagCompleteTime = " + message.FlagCompleteTime);
Console.WriteLine("FlagRequest = " + message.FlagRequest);
Console.WriteLine("-----------------------------------------------");
}
}