CSV samples

CSV file sample:

1,user1,user1@email.com
2,user2,user2@email.com
3,user3,user3@email.com

Authentication:

//LoadAssembly:System.dll

using System;
using System.IO;
using NSi.AutoStore.Capture.DataModel;

public static class Script
{
  public static void CustomAuthenticate(MetadataCollection authData, AuthResult result)
  {
    //Sample custom authentication for a configuration with two authentication prompts: Username and Password
    string username = authData.GetData("Username");
    string password = authData.GetData("Password");

    string filePath = "<CSV File Path>";
    using (StreamReader reader = File.OpenText(filePath))
    {
      string line;
      while ((line = reader.ReadLine()) != null)
      {
        string[] row = line.Split(',');
        if (username.Equals(row[1]) && password.Equals(row[0]))
        {
          result.IsAuthenticated = true;
          result.UserInfo = new UserInfo();
          result.UserInfo.UserName = row[1];
          result.UserInfo.Email = row[2];
          break;
        }
      }
    }
  }
}

Data lookup:

//LoadAssembly:System.dll

using System;
using System.IO;
using NSi.AutoStore.Capture.DataModel;

public static class Script
{
  public static void Form_OnLoad(MFPEventData eventData)
  {
    //Initialize dynamic field
    ListField userList = new ListField();
    userList.Name = "UserList";
    userList.Display = "User List";
    userList.RaiseFindEvent = true;    
    //Can populate data here
    PopulateUser(userList, null);
    eventData.Form.Fields.Add(userList);
  }

  public static void UserList_OnFind(MFPEventData eventData)
  {
    //Can populate data here, filtered by search criteria
    ListField userList = (ListField)eventData.Form.Fields.GetField("UserList");
    PopulateUser(userList, eventData.SearchCriteria);
  }

  private static void PopulateUser(ListField userList, string searchCriteria)
  {
    if (userList == null)
    {
      userList = new ListField();
    }
    userList.Items.Clear();
    bool isSearchable = string.IsNullOrEmpty(searchCriteria) ? false : true;
    string filePath = "<CSV File Path>";
    using (StreamReader reader = File.OpenText(filePath))
    {
      string line;
      while((line = reader.ReadLine()) != null)
      {
        string[] row = line.Split(',');
        if (!isSearchable)
        {
          ListItem item = new ListItem(row[1], row[0]);
          userList.Items.Add(item);
        }  
        else if (row[1].Contains(searchCriteria))
        {
          ListItem item = new ListItem(row[1], row[0]);
          userList.Items.Add(item);
        }      
      }
    }
  }
}