CiscoIPPhoneDirectoryType Read16_CiscoIPPhoneDirectoryType(bool isNullable, bool checkType) {
     System.Xml.XmlQualifiedName xsiType = checkType ? GetXsiType() : null;
     bool isNull = false;
     if (isNullable) isNull = ReadNull();
     if (checkType) {
     if (xsiType == null || ((object) ((System.Xml.XmlQualifiedName)xsiType).Name == (object)id64_CiscoIPPhoneDirectoryType && (object) ((System.Xml.XmlQualifiedName)xsiType).Namespace == (object)id2_Item)) {
     }
     else
         throw CreateUnknownTypeException((System.Xml.XmlQualifiedName)xsiType);
     }
     if (isNull) return null;
     CiscoIPPhoneDirectoryType o;
     o = new CiscoIPPhoneDirectoryType();
     CiscoIPPhoneDirectoryEntryType[] a_2 = null;
     int ca_2 = 0;
     CiscoIPPhoneSoftKeyType[] a_3 = null;
     int ca_3 = 0;
     bool[] paramsRead = new bool[4];
     while (Reader.MoveToNextAttribute()) {
         if (!IsXmlnsAttribute(Reader.Name)) {
             UnknownNode((object)o);
         }
     }
     Reader.MoveToElement();
     if (Reader.IsEmptyElement) {
         Reader.Skip();
         o.@DirectoryEntry = (CiscoIPPhoneDirectoryEntryType[])ShrinkArray(a_2, ca_2, typeof(CiscoIPPhoneDirectoryEntryType), true);
         o.@SoftKey = (CiscoIPPhoneSoftKeyType[])ShrinkArray(a_3, ca_3, typeof(CiscoIPPhoneSoftKeyType), true);
         return o;
     }
     Reader.ReadStartElement();
     Reader.MoveToContent();
     int whileIterations15 = 0;
     int readerCount15 = ReaderCount;
     while (Reader.NodeType != System.Xml.XmlNodeType.EndElement && Reader.NodeType != System.Xml.XmlNodeType.None) {
         if (Reader.NodeType == System.Xml.XmlNodeType.Element) {
             if (!paramsRead[0] && ((object) Reader.LocalName == (object)id43_Title && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 if (ReadNull()) {
                     o.@Title = null;
                 }
                 else {
                     o.@Title = Reader.ReadElementString();
                 }
                 paramsRead[0] = true;
             }
             else if (!paramsRead[1] && ((object) Reader.LocalName == (object)id44_Prompt && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 if (ReadNull()) {
                     o.@Prompt = null;
                 }
                 else {
                     o.@Prompt = Reader.ReadElementString();
                 }
                 paramsRead[1] = true;
             }
             else if (((object) Reader.LocalName == (object)id65_DirectoryEntry && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 a_2 = (CiscoIPPhoneDirectoryEntryType[])EnsureArrayIndex(a_2, ca_2, typeof(CiscoIPPhoneDirectoryEntryType));a_2[ca_2++] = Read10_CiscoIPPhoneDirectoryEntryType(false, true);
             }
             else if (((object) Reader.LocalName == (object)id45_SoftKey && (object) Reader.NamespaceURI == (object)id2_Item)) {
                 a_3 = (CiscoIPPhoneSoftKeyType[])EnsureArrayIndex(a_3, ca_3, typeof(CiscoIPPhoneSoftKeyType));a_3[ca_3++] = Read3_CiscoIPPhoneSoftKeyType(false, true);
             }
             else {
                 UnknownNode((object)o, @":Title, :Prompt, :DirectoryEntry, :SoftKey");
             }
         }
         else {
             UnknownNode((object)o, @":Title, :Prompt, :DirectoryEntry, :SoftKey");
         }
         Reader.MoveToContent();
         CheckReaderCount(ref whileIterations15, ref readerCount15);
     }
     o.@DirectoryEntry = (CiscoIPPhoneDirectoryEntryType[])ShrinkArray(a_2, ca_2, typeof(CiscoIPPhoneDirectoryEntryType), true);
     o.@SoftKey = (CiscoIPPhoneSoftKeyType[])ShrinkArray(a_3, ca_3, typeof(CiscoIPPhoneSoftKeyType), true);
     ReadEndElement();
     return o;
 }
 void Write16_CiscoIPPhoneDirectoryType(string n, string ns, CiscoIPPhoneDirectoryType o, bool isNullable, bool needType) {
     if ((object)o == null) {
         if (isNullable) WriteNullTagLiteral(n, ns);
         return;
     }
     if (!needType) {
         System.Type t = o.GetType();
         if (t == typeof(CiscoIPPhoneDirectoryType)) {
         }
         else {
             throw CreateUnknownTypeException(o);
         }
     }
     WriteStartElement(n, ns, o, false, null);
     if (needType) WriteXsiType(@"CiscoIPPhoneDirectoryType", @"");
     WriteNullableStringLiteral(@"Title", @"", ((global::System.String)o.@Title));
     WriteNullableStringLiteral(@"Prompt", @"", ((global::System.String)o.@Prompt));
     {
         CiscoIPPhoneDirectoryEntryType[] a = (CiscoIPPhoneDirectoryEntryType[])o.@DirectoryEntry;
         if (a != null) {
             for (int ia = 0; ia < a.Length; ia++) {
                 Write10_CiscoIPPhoneDirectoryEntryType(@"DirectoryEntry", @"", ((CiscoIPPhoneDirectoryEntryType)a[ia]), false, false);
             }
         }
     }
     {
         CiscoIPPhoneSoftKeyType[] a = (CiscoIPPhoneSoftKeyType[])o.@SoftKey;
         if (a != null) {
             for (int ia = 0; ia < a.Length; ia++) {
                 Write3_CiscoIPPhoneSoftKeyType(@"SoftKeyItem", @"", ((CiscoIPPhoneSoftKeyType)a[ia]), false, false);
             }
         }
     }
     WriteEndElement(o);
 }
Пример #3
0
        public void GetResultsForCiscoIPPhone(string directory, string givenName, string sn, string telephonenumber, string pos)
        {
            string gn     = "givenName";
            string name   = "sn";
            string tel    = "telephonenumber";
            string filter = "";
            CiscoIPPhoneDirectoryType             dir   = new CiscoIPPhoneDirectoryType();
            List <CiscoIPPhoneDirectoryEntryType> entry = new List <CiscoIPPhoneDirectoryEntryType>();

            try
            {
                dir.Title = "Recherche répertoire";
                foreach (DirectoryType dt in Global.directoryConfiguration)
                {
                    if (dt.name == directory)
                    {
                        if (dt.Item is SqlDatasourceType)
                        {
                            SqlDatasourceType sdt = dt.Item as SqlDatasourceType;
                            if (sdt.ipphonefilter != null)
                            {
                                gn   = sdt.ipphonefilter.firstnamemap;
                                name = sdt.ipphonefilter.lastnamemap;
                                tel  = sdt.ipphonefilter.telephonenumbermap;
                            }
                        }
                        else if (dt.Item is LdapDatasourceType)
                        {
                            LdapDatasourceType ldt = dt.Item as LdapDatasourceType;
                            if (ldt.ipphonefilter != null)
                            {
                                gn   = ldt.ipphonefilter.firstnamemap;
                                name = ldt.ipphonefilter.lastnamemap;
                                tel  = ldt.ipphonefilter.telephonenumbermap;
                            }
                        }
                        else if (dt.Item is CiscoDatasourceType)
                        {
                            CiscoDatasourceType cdt = dt.Item as CiscoDatasourceType;
                            if (cdt.ipphonefilter != null)
                            {
                                gn   = cdt.ipphonefilter.firstnamemap;
                                name = cdt.ipphonefilter.lastnamemap;
                                tel  = cdt.ipphonefilter.telephonenumbermap;
                            }
                        }
                        filter = gn + " LIKE '" + givenName.Trim() + "*' AND " + name + " LIKE '" + sn.Trim() + "*' AND " + tel + " LIKE '" + telephonenumber.Trim() + "*'";
                    }
                }

                DataTable results      = null;
                int       identityCol  = 0;
                int       telephoneCol = 0;
                foreach (DirectoryType dt in Global.directoryConfiguration)
                {
                    if (dt.name == directory)
                    {
                        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;
                        }
                        int cpt = 0;
                        foreach (FieldFormatter ff in ffs)
                        {
                            if (ff.fieldType == FieldType.Identity)
                            {
                                identityCol = cpt;
                            }
                            if (ff.fieldType == FieldType.Telephone)
                            {
                                telephoneCol = cpt;
                            }

                            cpt++;
                        }

                        break;
                    }
                }
                if (HttpRuntime.Cache.Get(directory + "_" + filter) != null)
                {
                    results = (DataTable)HttpRuntime.Cache.Get(directory + "_" + filter);
                }
                else
                {
                    if (HttpRuntime.Cache.Get(directory) != null)
                    {
                        DataSet  fromCache = (DataSet)HttpRuntime.Cache.Get(directory);
                        DataView dv        = null;
                        try
                        {
                            if (fromCache != null)
                            {
                                dv           = fromCache.Tables[0].AsDataView();
                                dv.RowFilter = filter;
                                DataTable calcTable = dv.ToTable("CalcTable");
                                foreach (DirectoryType dt in Global.directoryConfiguration)
                                {
                                    if (dt.name == directory)
                                    {
                                        FieldFormatter[] ffs  = null;
                                        List <string>    cols = new List <string>();
                                        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;
                                        }

                                        foreach (FieldFormatter ff in ffs)
                                        {
                                            cols.Add(ff.fieldName);
                                            if (!calcTable.Columns.Contains(ff.fieldName))
                                            {
                                                DataColumn dc = new DataColumn();
                                                dc.DataType   = typeof(string);
                                                dc.ColumnName = ff.fieldName;
                                                dc.Expression = ff.value;
                                                calcTable.Columns.Add(dc);
                                            }
                                        }
                                        DataView sortedView = calcTable.AsDataView();
                                        if (cols.Count > 0)
                                        {
                                            sortedView.Sort = cols[identityCol];
                                        }
                                        results      = sortedView.ToTable("Results", false, cols.ToArray());
                                        dv           = results.AsDataView();
                                        dv.RowFilter = results.Columns[telephoneCol].ColumnName + " <> ''";
                                        results      = dv.ToTable();
                                        HttpRuntime.Cache.Insert(directory + "_" + filter, results, null, DateTime.Now.AddMinutes(Double.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings.Get("DMDRefreshTimer"))), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                log.Debug("Cache is null, no data to retreive...");
                            }
                        }
                        catch (Exception e)
                        {
                            log.Error("Error while searching: " + e.Message);
                        }
                    }
                }
                if (results.Rows.Count > 0)
                {
                    if ((Int32.Parse(pos) + 32) >= results.Rows.Count)
                    {
                        dir.Prompt  = "Enreg. " + (Int32.Parse(pos) + 1).ToString() + " à " + results.Rows.Count.ToString() + " sur " + results.Rows.Count.ToString();
                        dir.SoftKey = new CiscoIPPhoneSoftKeyType[4];

                        dir.SoftKey[0]                  = new CiscoIPPhoneSoftKeyType();
                        dir.SoftKey[0].Name             = "Compos.";
                        dir.SoftKey[0].URL              = "SoftKey:Dial";
                        dir.SoftKey[0].URLDown          = "";
                        dir.SoftKey[0].Postion          = 1;
                        dir.SoftKey[0].PostionSpecified = true;

                        dir.SoftKey[1]                  = new CiscoIPPhoneSoftKeyType();
                        dir.SoftKey[1].Name             = "EditNum.";
                        dir.SoftKey[1].URL              = "SoftKey:EditDial";
                        dir.SoftKey[1].URLDown          = "";
                        dir.SoftKey[1].Postion          = 2;
                        dir.SoftKey[1].PostionSpecified = true;


                        dir.SoftKey[2]                  = new CiscoIPPhoneSoftKeyType();
                        dir.SoftKey[2].Name             = "Quitter";
                        dir.SoftKey[2].URL              = "SoftKey:Exit";
                        dir.SoftKey[2].URLDown          = "";
                        dir.SoftKey[2].Postion          = 3;
                        dir.SoftKey[2].PostionSpecified = true;

                        dir.SoftKey[3]                  = new CiscoIPPhoneSoftKeyType();
                        dir.SoftKey[3].Name             = "Recher.";
                        dir.SoftKey[3].URL              = this.Context.Request.Url.AbsoluteUri.Substring(0, this.Context.Request.Url.AbsoluteUri.LastIndexOf("/") + 1) + "SearchForCiscoIPPhone?directory=" + System.Web.HttpUtility.UrlEncode(directory);
                        dir.SoftKey[3].URLDown          = "";
                        dir.SoftKey[3].Postion          = 4;
                        dir.SoftKey[3].PostionSpecified = true;
                    }
                    else
                    {
                        dir.Prompt = "Enreg. " + (Int32.Parse(pos) + 1).ToString() + " à " + (Int32.Parse(pos) + 32).ToString() + " sur " + results.Rows.Count.ToString();
                        this.Context.Response.AddHeader("Refresh", ";url=" + this.Context.Request.Url.AbsoluteUri.Substring(0, this.Context.Request.Url.AbsoluteUri.LastIndexOf("/") + 1) + "GetResultsForCiscoIPPhone?directory=" + System.Web.HttpUtility.UrlEncode(directory) + "&givenName=" + System.Web.HttpUtility.UrlEncode(givenName) + "&sn=" + System.Web.HttpUtility.UrlEncode(sn) + "&telephonenumber=" + System.Web.HttpUtility.UrlEncode(telephonenumber) + "&pos=" + System.Web.HttpUtility.UrlEncode((Int32.Parse(pos) + 32).ToString()));
                        dir.SoftKey = new CiscoIPPhoneSoftKeyType[5];

                        dir.SoftKey[0]                  = new CiscoIPPhoneSoftKeyType();
                        dir.SoftKey[0].Name             = "Compos.";
                        dir.SoftKey[0].URL              = "SoftKey:Dial";
                        dir.SoftKey[0].URLDown          = "";
                        dir.SoftKey[0].Postion          = 1;
                        dir.SoftKey[0].PostionSpecified = true;

                        dir.SoftKey[1]                  = new CiscoIPPhoneSoftKeyType();
                        dir.SoftKey[1].Name             = "EditNum.";
                        dir.SoftKey[1].URL              = "SoftKey:EditDial";
                        dir.SoftKey[1].URLDown          = "";
                        dir.SoftKey[1].Postion          = 2;
                        dir.SoftKey[1].PostionSpecified = true;

                        dir.SoftKey[2]                  = new CiscoIPPhoneSoftKeyType();
                        dir.SoftKey[2].Name             = "Quitter";
                        dir.SoftKey[2].URL              = "SoftKey:Exit";
                        dir.SoftKey[2].URLDown          = "";
                        dir.SoftKey[2].Postion          = 3;
                        dir.SoftKey[2].PostionSpecified = true;

                        dir.SoftKey[3]                  = new CiscoIPPhoneSoftKeyType();
                        dir.SoftKey[3].Name             = "Suivant";
                        dir.SoftKey[3].URL              = "SoftKey:Update";
                        dir.SoftKey[3].URLDown          = "";
                        dir.SoftKey[3].Postion          = 4;
                        dir.SoftKey[3].PostionSpecified = true;

                        dir.SoftKey[4]                  = new CiscoIPPhoneSoftKeyType();
                        dir.SoftKey[4].Name             = "Recher.";
                        dir.SoftKey[4].URL              = this.Context.Request.Url.AbsoluteUri.Substring(0, this.Context.Request.Url.AbsoluteUri.LastIndexOf("/") + 1) + "SearchForCiscoIPPhone?directory=" + System.Web.HttpUtility.UrlEncode(directory);
                        dir.SoftKey[4].URLDown          = "";
                        dir.SoftKey[4].Postion          = 5;
                        dir.SoftKey[4].PostionSpecified = true;
                    }
                    for (int cptRow = Int32.Parse(pos); cptRow <= Int32.Parse(pos) + 31; cptRow++)
                    {
                        if (cptRow < results.Rows.Count)
                        {
                            CiscoIPPhoneDirectoryEntryType dirEntry = new CiscoIPPhoneDirectoryEntryType();
                            dirEntry.Name      = (string)results.Rows[cptRow][identityCol];
                            dirEntry.Telephone = (string)results.Rows[cptRow][telephoneCol];
                            entry.Add(dirEntry);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    dir.Prompt  = "Pas d'enregistrement trouvé";
                    dir.SoftKey = new CiscoIPPhoneSoftKeyType[2];

                    dir.SoftKey[0]                  = new CiscoIPPhoneSoftKeyType();
                    dir.SoftKey[0].Name             = "Quitter";
                    dir.SoftKey[0].URL              = "SoftKey:Exit";
                    dir.SoftKey[0].URLDown          = "";
                    dir.SoftKey[0].Postion          = 3;
                    dir.SoftKey[0].PostionSpecified = true;

                    dir.SoftKey[1]                  = new CiscoIPPhoneSoftKeyType();
                    dir.SoftKey[1].Name             = "Recher.";
                    dir.SoftKey[1].URL              = this.Context.Request.Url.AbsoluteUri.Substring(0, this.Context.Request.Url.AbsoluteUri.LastIndexOf("/") + 1) + "SearchForCiscoIPPhone?directory=" + System.Web.HttpUtility.UrlEncode(directory);
                    dir.SoftKey[1].URLDown          = "";
                    dir.SoftKey[1].Postion          = 1;
                    dir.SoftKey[1].PostionSpecified = true;
                }

                dir.DirectoryEntry = entry.ToArray();

                //return dir;
                CiscoIPPhoneDirectoryTypeSerializer xml      = new CiscoIPPhoneDirectoryTypeSerializer();
                System.Xml.XmlWriterSettings        settings = new System.Xml.XmlWriterSettings();;
                settings.Encoding = System.Text.Encoding.UTF8;
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                System.Xml.XmlWriter   xw = System.Xml.XmlWriter.Create(ms, settings);
                System.Xml.Serialization.XmlSerializerNamespaces xmlnsEmpty = new System.Xml.Serialization.XmlSerializerNamespaces();
                xmlnsEmpty.Add("", "");
                xml.Serialize(xw, dir, xmlnsEmpty);
                ms.Position = 0;
                this.Context.Response.ContentType     = "text/xml";
                this.Context.Response.ContentEncoding = System.Text.Encoding.UTF8;
                this.Context.Response.Write(GetStringFromStream(ms));
            }
            catch (Exception e)
            {
                log.Error("Unable to build Cisco Ipphone Directory Type: " + e.Message);
                this.Context.Response.Redirect(this.Context.Request.Url.AbsoluteUri.Substring(0, this.Context.Request.Url.AbsoluteUri.LastIndexOf("/") + 1) + "Error?error=" + System.Web.HttpUtility.UrlEncode(e.Message), false);
                //return dir;
            }
        }