How to convert an event in string format into DDay.iCal Event? - dday

I have an event string like so:
BEGIN:VEVENT
CREATED;
VALUE=DATE:00010101
DTSTAMP:20150527T074655Z
DTSTART;VALUE=DATE:00010101
EFFECTIVEDATETIME:2015-05-27T07:46:55.3203522+00:00
RRULE:FREQ=DAILY;BYHOUR=12;BYMINUTE=0
SEQUENCE:0
SUMMARY:BLAH
UID:0622249b-7161-4e31-9517-f51dddaa4cd8
END:VEVENT
How do I Deserialize this into DDay.iCal event?

You can't deserialize that, because you have invented things that aren't part of the icalendar spec, and aren't supported by ical.net (dday.ical is now ical.net). These things are malformed, or don't exist:
CREATED;
VALUE=DATE:00010101
EFFECTIVEDATETIME:2015-05-27T07:46:55.3203522+00:00
Have a look at the VEVENT documentation for valid VEVENT blocks:
http://www.kanzaki.com/docs/ical/vevent.html
Your question speaks to a weakness of the ical.net API: you can't deserialize icalendar components in a piecemeal fashion. In a perfect world, you would be able to pass your string to the Event constructor, and it would do the right thing.
I have an open ticket to re-evaluate ical.net's parsing and serialization which will cover this use case. Getting there will take some time.
https://github.com/rianjs/ical.net/issues/22

Related

Chaining type providers

I am wondering if it is possible to create an XmlProvider from the data provided by an SqlDataProvider.
Naively it would be something like this:
type sql = SqlDataProvider<...>
let xml =
query {
for item in sql.GetDataContext().Main.Items do
select item.XmlData
head
}
type xmlType = XmlProvider<xml>
Of course this fails because xml is not a literal.
I'm curious if this is possible.
The short answer is: Yes.
And then the ifs and buts:
Given that the returned xml is structured (as in: about equal each time) then providing an example which is a literal would be ok.
Then the data from the database could be parsed like:
let someXmlDataNowType = xmlType.Parse(xml)
This is probably not what you want or asked about, but then again the short answer is: No ;-)
If you have a lot of queries with different XML my take would have been to write some code to generate the different XML in some files and even possibly write the f# automagically...

Understanding concepts of twiter4j

Can someone tell whether my understanding is correct.
twitterstream.addlistener(listner)
is for each tweet we are capturing?
Dataobjectfactory.getRawjson(status)
converts object into json string?
First of all, twitterstream.addlistener(listner) is for generating a listener in twitterstream to listen all tweets which hit your conditions. So, that means you do not have to add more than one listener to get all the tweets. However, you might add more than one listener for different purposes like getting tweets only having a particular hashtag with each listener, etc..
The second thing you asked (Dataobjectfactory.getRawjson(status)) is returning the json formatted string of the caught tweet status.

Serializing JSON with configured serializer

I am using ASP.Net Web API with JSON.Net to serialize. I had to configure the serializer to handle ISO dates properly like this:
var iso = new IsoDateTimeConverter {
DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffK"
};
GlobalConfiguration.Configuration.Formatters.JsonFormatter
.SerializerSettings.Converters.Add(iso);
This works fine when I am passing my objects down via the WebAPI. My problem, however, is that I have another place where I want to explicitly call the serialization:
#Html.Raw(JsonConvert.SerializeObject(Model));
In this case, it doesn't use the configuration I set up. I am aware that I can pass the iso converter into the SerializeObject call, but I prefer to avoid this and get a hold of a configured serialzer for obvious reasons.
Any ideas?
If you're going to do JSON serialization yourself, you have to pass the settings you want explicitly. There's no way around it. The best I can think of if you want to reuse the same serializer settings is to do something like this:
JsonConvert.SerializeObject(Model, GlobalConfiguration.Configuration.Formatters.
JsonFormatter.SerializerSettings)

Syncing EKRecurrenceRules with Cloud Service RFC 2445 iCalendar specification RRULE

I'm trying to create a cloud based service which stores recurring Events. I have chosen to do this using the icalendar RRULE standards (RFC2445) and use a database schema as below exposed via cloud based service.
EventID
EventName
EventDescripton
Start
End
RecurrenceRule <-- Store RFC 2445 iCalendar specification RRULE (recurrence)
Active
Deleted
DateCreated
DateLastUpdated
I beleive that the EKRecurrenceRules are RFC 2445 compliant, however by storing the string representation of the RRULE or description of the EKRecurrenceRule makes for a more cross platform compliant architecture.
I am able to create a EKRecurrenceRule on the client side easily and extract the RRULE from the EKRecurrenceRule description property. However, my question is how to convert that description property back to an EKRecurrenceRule object on the client when extracted from the cloud service? It seems stupid Apple would expose a property to extract the compliant RRULE but not provide any way to convert an RRULE to a native object.
I'd like to avoid storing individual components of the EKRecurrence rule if possible.
you might be able to use this library:
https://github.com/FabienDiTore/ios-rrule_parser
to create an EKRecurrenceRule. If you do, please let me know.
...extract the RRULE from the EKRecurrenceRule description property
This seems fraught with peril. The documentation for -[id<NSObject> description] only guarantees that it returns "a string that describes the contents of the receiver" - EKRecurrenceRule's implementation might not give a proper RRULE in the future, or might change just barely enough that "extracting" the RRULE won't work. (This is probably why Apple doesn't provide anything to convert an RRULE back to an EKRecurrenceRule - they didn't mean for you to be able to extract and work with the RRULE in the first place.)
It seems to me that a better solution would be to find or write a library or EKRecurrenceRule category that provides a proper - (NSString *)rrule accessor and perhaps a corresponding - (id)initWithRRule:(NSString *)rrule initializer. That way, you can avoid relying on undocumented behavior and be confident that you can convert between RRULEs and EKRecurrenceRule instances in the way that you want.

Convert any record to a string and back?

How can I convert any record type to a single String and back? Perhaps load the record into a stream and read it as a String? The records I'm using won't have any special types included - they're just using simple things like String, Integer, PChar, DWORD, and Array of [String], etc. and nothing like classes or functions.
This string will further be saved into various places, such as a flat text file, database record, sent over the network, etc. The string contents may be transferred by other means between each of these, such as copying the string from a text file and saving it to a database record. The general idea is that the string will be compatible enough to save anywhere, move it around, and load it back in to its original state. I do understand I need to be able to recognize what type of record it is and assign it accordingly, and that part I don't need help with.
You can serialize your record using the RTTI, from here you can use XML, JSON or other format to persist the record data.
If you don't want write your own method to serialize the records try these alternatives.
superobject (using the TSuperRttiContext class you can serialize a record to JSON)
TKBDynamic
SynCommons unit from Synopse.
XmlSerial unit (Object and Record Serialization and De-serialization to XML) from Robert Love

Resources