Exemplo n.º 1
0
        internal static Party LoadParty(PartyInfo info, StringBuilder sb)
        {
            var party = Env.Current.StaticData.GetPartyByCode(info.Code) ??
                        Env.Current.StaticData.GetPartyByProperty(Party.CounterParty, PartyMlpCode, info.Code);
            if (party == null)
            {
                party = new Party
                   {
                       Code = info.Code,
                       RoleList = info.RoleList,
                       Name = info.Name
                   };
                party.SetProperty(PartyCode2, info.Code2);
                party.SetProperty(PartyLabel, info.Label);
                party.SetProperty(PartyDisplay, info.Display);
                party.SetProperty(PartyMlpCode, info.Code);
                return party;
            }            

            
            {
                var display = party.GetProperty(PartyDisplay);
                var code2 = party.GetProperty(PartyCode2);
                var label = party.GetProperty(PartyLabel);
                var mlpCode = party.GetProperty(PartyMlpCode);
                var name = party.Name;
                var changed = false;
                if (info.Code != null && (mlpCode == null || !mlpCode.Equals(info.Code)))
                {
                    party.SetProperty(PartyMlpCode, info.Code);
                    changed = true;
                }
                if (info.Name != null && (name == null || !name.Equals(info.Name)))
                {
                    party.Name = info.Name;
                    changed = true;
                }
                if (info.Display != null && (display == null || !display.Equals(info.Display)))
                {
                    party.SetProperty(PartyDisplay, info.Display);
                    changed = true;
                }
                if (info.Code2 != null && (code2 == null || !code2.Equals(info.Code2)))
                {
                    party.SetProperty(PartyCode2, info.Code2);
                    changed = true;
                }
                if (info.Label != null && (label == null || !label.Equals(info.Label)))
                {
                    party.SetProperty(PartyLabel, info.Label);
                    changed = true;
                }
                foreach (var r in info.RoleList)
                {
                    if (!party.RoleList.Contains(r))
                    {
                        party.RoleList = info.RoleList;
                        changed = true;
                        break;
                    }
                }
                if (changed)
                {
                    party.Action = UpdateAction;
                    return party;
                }
                
            }
            return null;
        }
Exemplo n.º 2
0
        internal static IList<PartyInfo> ReadPartyData(FilterData filterData, StringBuilder sb)
        {
            var fileName = filterData.FileName;

            if (!File.Exists(fileName))
            {
                if (sb != null) sb.Append("File " + fileName + " not found\n");
                return new List<PartyInfo>();
            }

            var list = new List<PartyInfo>();
            using (var stream = File.OpenRead(fileName))
            {
                using (var reader = new StreamReader(stream))
                {
                    string line;
                    var header = reader.ReadLine();
                    if (string.IsNullOrEmpty(header))
                    {
                        Logger.Error("[Error Read File] Empty Headers ... ");
                        return new List<PartyInfo>();
                    }
                    var headers = new Dictionary<string, int>();
                    using (var csvParser = new TextFieldParser(new StringReader(header)))
                    {
                        csvParser.SetDelimiters(new[] { "," });
                        var hss = csvParser.ReadFields();
                        int idx = 0;
                        foreach (var s in hss)
                        {
                            headers[s.Trim()] = idx++;
                        }
                    }

                    while ((line = reader.ReadLine()) != null)
                    {
                        //Parse Line here
                        if (string.IsNullOrEmpty(line)) break; //we are at end
                        var pinfo = new PartyInfo(line, headers);
                        list.Add(pinfo);
                    }
                }
            }
            return list;
        }