コード例 #1
0
ファイル: DMDWS.asmx.cs プロジェクト: gnomix/T.A.L.K.
        public LookupResponse[] MultiLookup(LookupResponse[] lookup)
        {
            LookupResponse[] response = new LookupResponse[lookup.Length];
            int i = 0;
            foreach (LookupResponse l in lookup)
            {
                LookupResponse lr = new LookupResponse();
                lr.dirNum = l.dirNum;
                lr.callids = l.callids;
                string identity = "Inconnu";
                try
                {
                    foreach (DirectoryType dt in Global.directoryConfiguration)
                    {
                        FieldFormatter[] ffs = null;
                        if (dt.Item is SqlDatasourceType)
                        {
                            ffs = ((SqlDatasourceType)dt.Item).fieldFormatters;
                        }
                        else if (dt.Item is LdapDatasourceType)
                        {
                            ffs = ((LdapDatasourceType)dt.Item).fieldFormatters;
                        }
                        else if (dt.Item is CiscoDatasourceType)
                        {
                            ffs = ((CiscoDatasourceType)dt.Item).fieldFormatters;
                        }
                        List<string> filterCol = new List<string>();
                        string filter = "";
                        string identityCol = "";
                        foreach (FieldFormatter ff in ffs)
                        {
                            if (ff.fieldType == FieldType.Telephone)
                            {
                                filterCol.Add(ff.fieldName);
                                if (filter != "")
                                {
                                    filter += " OR " + ff.fieldName + " = '" + l.dirNum + "'";
                                }
                                else
                                {
                                    filter += ff.fieldName + " = '" + l.dirNum + "'";
                                }
                            }
                            else if (ff.fieldType == FieldType.Identity)
                            {
                                identityCol = ff.fieldName;
                            }
                        }

                        DataTable dtb = null;
                        if (HttpRuntime.Cache.Get(dt.name + "_formated") != null)
                        {
                            dtb = (DataTable)HttpRuntime.Cache.Get(dt.name + "_formated");
                            DataView dtbv = dtb.AsDataView();
                            dtbv.RowFilter = filter;
                            var name = from dtbvname in dtbv.ToTable().AsEnumerable()
                                       select dtbvname.Field<string>(identityCol);
                            identity = name.First();
                        }
                    }
                    lr.name = identity;
                    response[i] = lr;
                    i++;
                }
                catch (Exception e)
                {
                    log.Error("Unable to lookup " + l.dirNum + ": " + e.Message);
                    lr.name = identity;
                    response[i] = lr;
                    i++;
                }
            }
            return response;
        }
コード例 #2
0
        public LookupResponse[] MultiLookup(LookupResponse[] lookup)
        {
            LookupResponse[] response = new LookupResponse[lookup.Length];
            int i = 0;

            foreach (LookupResponse l in lookup)
            {
                LookupResponse lr = new LookupResponse();
                lr.dirNum  = l.dirNum;
                lr.callids = l.callids;
                string identity = "Inconnu";
                try
                {
                    foreach (DirectoryType dt in Global.directoryConfiguration)
                    {
                        FieldFormatter[] ffs = null;
                        if (dt.Item is SqlDatasourceType)
                        {
                            ffs = ((SqlDatasourceType)dt.Item).fieldFormatters;
                        }
                        else if (dt.Item is LdapDatasourceType)
                        {
                            ffs = ((LdapDatasourceType)dt.Item).fieldFormatters;
                        }
                        else if (dt.Item is CiscoDatasourceType)
                        {
                            ffs = ((CiscoDatasourceType)dt.Item).fieldFormatters;
                        }
                        List <string> filterCol   = new List <string>();
                        string        filter      = "";
                        string        identityCol = "";
                        foreach (FieldFormatter ff in ffs)
                        {
                            if (ff.fieldType == FieldType.Telephone)
                            {
                                filterCol.Add(ff.fieldName);
                                if (filter != "")
                                {
                                    filter += " OR " + ff.fieldName + " = '" + l.dirNum + "'";
                                }
                                else
                                {
                                    filter += ff.fieldName + " = '" + l.dirNum + "'";
                                }
                            }
                            else if (ff.fieldType == FieldType.Identity)
                            {
                                identityCol = ff.fieldName;
                            }
                        }

                        DataTable dtb = null;
                        if (HttpRuntime.Cache.Get(dt.name + "_formated") != null)
                        {
                            dtb = (DataTable)HttpRuntime.Cache.Get(dt.name + "_formated");
                            DataView dtbv = dtb.AsDataView();
                            dtbv.RowFilter = filter;
                            var name = from dtbvname in dtbv.ToTable().AsEnumerable()
                                       select dtbvname.Field <string>(identityCol);

                            identity = name.First();
                        }
                    }
                    lr.name     = identity;
                    response[i] = lr;
                    i++;
                }
                catch (Exception e)
                {
                    log.Error("Unable to lookup " + l.dirNum + ": " + e.Message);
                    lr.name     = identity;
                    response[i] = lr;
                    i++;
                }
            }
            return(response);
        }