NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using Jsi.DataCollection.DataContracts;
using Jsi.DataCollection.DataContracts.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SampleCdrLoader
{
[Export(typeof(IDataCollectionComponent))]
public class SampleCdrLoader : IDataCollectionComponent
{
/// <summary>
/// Loader name
/// </summary>
public string Name => "Sample CDR Loader";

/// <summary>
/// Helper method to read csv files
/// </summary>
/// <param name="path">Path to the files</param>
/// <returns>A list of lines, each line is a list of strings</returns>
public static List<List<string>> GetLines(string path)
{
var lines = new List<List<string>>();

foreach (var line in File.ReadAllLines(path))
{
lines.Add(line.Split(',').ToList());
}

return lines;
}

/// <summary>
/// Checks if loader can process the given file
/// </summary>
/// <param name="filePath">The path to the file</param>
/// <param name="workingDirectory">Working directory to use</param>
/// <returns>True if file can be processed, false otherwise</returns>
public bool CanHandle(string filePath, string workingDirectory)
{
if (filePath.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
{
// Get the header line
var firstLine = GetLines(filePath).First();

return
firstLine.Count == 7 && // Make sure there are exactly 7 coloumns
firstLine[0] == "Timestamp" &&
firstLine[1] == "Target Number" &
firstLine[2] == "Associate Number" &&
firstLine[3] == "Type" &&
firstLine[4] == "Direction" &&
firstLine[5] == "Duration" &&
firstLine[6] == "Text";
}
//TODO: Implement this method. It should return true if file is a .#.sample.csv with expected
// headers, # is your student number
throw new NotImplementedException();
}

/// <summary>
/// Import a file. Create and upload sessions from the given file
/// </summary>
/// <param name="filePath">Path to the file</param>
/// <param name="workingDirectory">Working directory to use</param>
/// <param name="context">Provides functionality required to create and upload sessions</param>
public void Import(string filePath, string workingDirectory, IImportContext context)
{
foreach (var line in GetLines(filePath))
{
if (line[0] != "Timestamp"){
var session = context.CreateSession(Name, null, false);
session.StartTime = DateTime.Parse(line[0]);
if (line[3] == "sms")
{
session.SetSessionType(SessionTypes.Sms);
session.SetSessionType("text/plain");
session.SetPreview(line[6]);
session.DisplayTypeID = SessionDisplayType.CcrSms;
}
else
{
session.SetSessionType(SessionTypes.Telephony);
session.DurationInSeconds = (int)TimeSpan.Parse(line[5]).TotalSeconds;
session.DisplayTypeID = SessionDisplayType.CcrVoice;
}


if (line[4] == "out")
{
session.SetDirection(Directions.Outgoing);

var inv = context.CreateInvolvement(InvolvementRoles.From, true);
inv.Msisdn = line[1];
session.AddInvolvement(inv);

var inv2 = context.CreateInvolvement(InvolvementRoles.To, false);
inv2.Msisdn = line[2];
session.AddInvolvement(inv2);
} else
{
session.SetDirection(Directions.Incoming);
var inv = context.CreateInvolvement(InvolvementRoles.From, false);
inv.Msisdn = line[2];
session.AddInvolvement(inv);

var inv2 = context.CreateInvolvement(InvolvementRoles.To, true);
inv2.Msisdn = line[1];
session.AddInvolvement(inv2);
}

context.UploadSession(session);
}
}




//TODO: Implement this method. This is where we create and upload sessions
throw new NotImplementedException();
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.