Пример #1
0
        public static string LoadDictionaries(string Locale, int ObjectType)
        {
            /************************************************************************/

            /*
             *        <Dictionaries>
             *              -- Common
             *              -- Current user
             *              <CurrentUser>
             *              </CurrentUser>
             *              <PortalConfig>
             *              </PortalConfig>
             *              <Priority>
             *                      <Item>
             *                              <Value/>
             *                              <Data/>
             *                      </Item>
             *              </Priority>
             *
             *              -- For Incident
             *              <IncidentType>
             *                      ...
             *              </IncidentType>
             *              <Severity>
             *                      ...
             *              </Severity>
             *
             *              <IncidentOrganization>
             *                      ...
             *              </IncidentOrganization>
             *
             *              <IncidentContact>
             *                      ...
             *              </IncidentContact>
             *
             *              <IncidentBox>
             *                  ...
             *              </IncidentBox>
             *
             *              -- For Event
             *              <EventType>
             *                      ...
             *              </EventType>
             *
             *              <Organizers>
             *              </Organizers>
             *
             *              <EventOrganization>
             *                      ...
             *              </EventOrganization>
             *
             *              <EventContact>
             *                      ...
             *              </EventContact>
             *
             *              -- For ToDo
             *              <CompletionType>
             *                      ...
             *              </CompletionType>
             *
             *              <ToDoOrganization>
             *                      ...
             *              </ToDoOrganization>
             *
             *              <ToDoContact>
             *                      ...
             *              </ToDoContact>
             *
             *              -- For Task
             *              <CompletionType>
             *                      ...
             *              </CompletionType>
             *
             *              -- For Project
             *              <ProjectType>
             *                      ...
             *              </ProjectType>
             *
             *              <ProjectOrganization>
             *                      ...
             *              </ProjectOrganization>
             *
             *              <ProjectContact>
             *                      ...
             *              </ProjectContact>
             *
             *              <ProjectManager>
             *                      <User>
             *                              <UserId>
             *                              <FirstName>
             *                              <LastName>
             *                      </User>
             *                      ...
             *              </ProjectManager>
             *
             *              <ExecuteveManager>
             *                      <User>
             *                              <UserId>
             *                              <FirstName>
             *                              <LastName>
             *                      </User>
             *                      ...
             *              </ExecuteveManager>
             *
             *              <ProjectStatus>
             *                      ...
             *              </ProjectStatus>
             *
             *              <ProjectCalendar>
             *                      ...
             *              </ProjectCalendar>
             *
             *              <ProjectTemplate>
             *                      ...
             *              </ProjectTemplate>
             *
             *              <ProjectPriority>
             *                      ...
             *              </ProjectPriority>
             *
             *              <ProjectPortfolio>
             *                      ...
             *              </ProjectPortfolio>
             *
             *              <ProjectPhase>
             *                      ...
             *              </ProjectPhase>
             *              -- For List
             *              <ListStatus>
             *                      ...
             *              </ListStatus>
             *              <ListType>
             *                      ...
             *              </ListType>
             *              <ListTemplate>
             *                      ...
             *              </ListTemplate>
             *        </Dictionaries>
             *
             *      /************************************************************************/
            int LanguageId = WebServicesHelper.GetLanguageIdByLocale(Locale);

            XmlDocument xmlDictionariesList = new XmlDocument();

            xmlDictionariesList.LoadXml("<Dictionaries></Dictionaries>");

            XmlNode xmlDictionariesNode = xmlDictionariesList.SelectSingleNode("Dictionaries");

            // Step 1. Build Common Dictionaryes [2/9/2004]
            // Step 1.0 Current User information
            XmlNode xmlCurrentUserNode = xmlDictionariesList.CreateElement("CurrentUser");

            InsertXMLItem(xmlCurrentUserNode, "UserId", Security.CurrentUser.UserID.ToString());
            InsertXMLItem(xmlCurrentUserNode, "FirstName", Security.CurrentUser.FirstName);
            InsertXMLItem(xmlCurrentUserNode, "LastName", Security.CurrentUser.LastName);
            InsertXMLItem(xmlCurrentUserNode, "Email", Security.CurrentUser.Email);
            InsertXMLItem(xmlCurrentUserNode, "IsAdmin", Security.IsUserInGroup(InternalSecureGroups.Administrator).ToString());
            InsertXMLItem(xmlCurrentUserNode, "IsPM", Security.IsUserInGroup(InternalSecureGroups.ProjectManager).ToString());
            InsertXMLItem(xmlCurrentUserNode, "IsPPM", Security.IsUserInGroup(InternalSecureGroups.PowerProjectManager).ToString());
            InsertXMLItem(xmlCurrentUserNode, "IsHDM", Security.IsUserInGroup(InternalSecureGroups.HelpDeskManager).ToString());
            InsertXMLItem(xmlCurrentUserNode, "TimeOffset", User.GetCurrentBias(Security.CurrentUser.TimeZoneId).ToString());

            xmlDictionariesNode.AppendChild(xmlCurrentUserNode);

            // OZ: Portal Config 2008-07-18
            XmlNode xmlPortalConfigNode = xmlDictionariesList.CreateElement("PortalConfig");

            InsertXMLItem(xmlPortalConfigNode, "WorkTimeStart", PortalConfig.WorkTimeStart);
            InsertXMLItem(xmlPortalConfigNode, "WorkTimeFinish", PortalConfig.WorkTimeFinish);
            xmlDictionariesNode.AppendChild(xmlPortalConfigNode);


            // Step 1.1. Priority [2/9/2004]
            XmlNode xmlPriorityNode = xmlDictionariesList.CreateElement("Priority");

            using (IDataReader PriorityReader = WebServicesHelper.GetListPriorities(LanguageId))
            {
                while (PriorityReader.Read())
                {
                    InsertDictionaryItem(xmlPriorityNode, PriorityReader["PriorityName"].ToString(), PriorityReader["PriorityId"].ToString());
                }
                PriorityReader.Close();
            }
            xmlDictionariesNode.AppendChild(xmlPriorityNode);

            // Step 2. Build Specific Dictionaries [2/9/2004]
            switch ((ObjectTypes)ObjectType)
            {
            case ObjectTypes.Issue:
                //  [2/9/2004]
                XmlNode xmlIncidentTypeNode = xmlDictionariesList.CreateElement("IncidentType");
                using (IDataReader incidentTypesReader = Incident.GetListIncidentTypes())
                {
                    while (incidentTypesReader.Read())
                    {
                        InsertDictionaryItem(xmlIncidentTypeNode, incidentTypesReader["TypeName"].ToString(), incidentTypesReader["TypeId"].ToString());
                    }
                    incidentTypesReader.Close();
                }
                xmlDictionariesNode.AppendChild(xmlIncidentTypeNode);
                //  [2/9/2004]
                XmlNode xmlSeverityTypeNode = xmlDictionariesList.CreateElement("Severity");
                using (IDataReader severityTypesReader = Incident.GetListIncidentSeverity())
                {
                    while (severityTypesReader.Read())
                    {
                        InsertDictionaryItem(xmlSeverityTypeNode, severityTypesReader["SeverityName"].ToString(), severityTypesReader["SeverityId"].ToString());
                    }
                    severityTypesReader.Close();
                }
                xmlDictionariesNode.AppendChild(xmlSeverityTypeNode);

                // IncidentOrganization [11/21/2006]
                InsertOrganizationDictionaryItemList(xmlDictionariesNode, "IncidentOrganization");

                // IncidentContacts [11/21/2006]
                InsertContactDictionaryItemList(xmlDictionariesNode, "IncidentContact");

                // IncidentBox [12/12/2006]
                XmlNode xmlIncidentBoxNode = xmlDictionariesList.CreateElement("IncidentBox");
                foreach (EMail.IncidentBox box in EMail.IncidentBox.List())
                {
                    InsertDictionaryItem(xmlIncidentBoxNode, box.Name, box.IncidentBoxId.ToString());
                }
                xmlDictionariesNode.AppendChild(xmlIncidentBoxNode);

                break;

            case ObjectTypes.CalendarEntry:
                //  [2/9/2004]
                XmlNode xmlEventTypeNode = xmlDictionariesList.CreateElement("EventType");
                using (IDataReader eventTypesReader = CalendarEntry.GetListEventTypes())
                {
                    while (eventTypesReader.Read())
                    {
                        InsertDictionaryItem(xmlEventTypeNode, eventTypesReader["TypeName"].ToString(), eventTypesReader["TypeId"].ToString());
                    }
                    eventTypesReader.Close();
                }
                xmlDictionariesNode.AppendChild(xmlEventTypeNode);

                // Organizers [5/6/2004]
                XmlNode xmlEventOrganizersNode = xmlDictionariesList.CreateElement("Organizers");
                using (IDataReader eventOrganizersReader = CalendarView.GetListPeopleForCalendar())
                {
                    InsertUserInformation(xmlEventOrganizersNode, (int)Security.CurrentUser.UserID);

                    while (eventOrganizersReader.Read())
                    {
                        if ((int)eventOrganizersReader["Level"] == 1)
                        {
                            InsertUserInformation(xmlEventOrganizersNode, (int)eventOrganizersReader["UserId"]);
                        }
                        //InsertDictionaryItem(xmlEventTypeNode,eventTypesReader["TypeName"].ToString(),eventTypesReader["TypeId"].ToString());
                    }
                    eventOrganizersReader.Close();
                }
                xmlDictionariesNode.AppendChild(xmlEventOrganizersNode);

                // EventOrganization [11/21/2006]
                InsertOrganizationDictionaryItemList(xmlDictionariesNode, "EventOrganization");

                // EventContacts [11/21/2006]
                InsertContactDictionaryItemList(xmlDictionariesNode, "EventContact");

                break;

            case ObjectTypes.Task:
                //  [2/9/2004]
                XmlNode xmlTaskCompTypeNode = xmlDictionariesList.CreateElement("CompletionType");
                using (IDataReader taskCompTypesReader = WebServicesHelper.GetListTaskCompletionTypes(LanguageId))
                {
                    while (taskCompTypesReader.Read())
                    {
                        InsertDictionaryItem(xmlTaskCompTypeNode, taskCompTypesReader["CompletionTypeName"].ToString(), taskCompTypesReader["CompletionTypeId"].ToString());
                    }
                    taskCompTypesReader.Close();
                }
                xmlDictionariesNode.AppendChild(xmlTaskCompTypeNode);
                break;

            case ObjectTypes.ToDo:
                //  [2/9/2004]
                InsertDictionaryItemList(xmlDictionariesNode, "CompletionType", WebServicesHelper.GetListToDoCompletionTypes(LanguageId), "CompletionTypeName", "CompletionTypeId");

                // ToDoOrganization [11/21/2006]
                InsertOrganizationDictionaryItemList(xmlDictionariesNode, "ToDoOrganization");

                // ToDoContacts [11/21/2006]
                InsertContactDictionaryItemList(xmlDictionariesNode, "ToDoContact");

                break;

            case ObjectTypes.Project:
                if (!Project.CanCreate())
                {
                    throw new AccessDeniedException();
                }
                // ProjectType [3/30/2004]
                InsertDictionaryItemList(xmlDictionariesNode, "ProjectType", Project.GetListProjectTypes(), "TypeName", "TypeId");

                // ProjectClient [3/30/2004]
                //InsertDictionaryItemList(xmlDictionariesNode,"ProjectClient", Project.GetListClients(),"ClientName", "ClientId");

                // ProjectOrganization [11/21/2006]
                InsertOrganizationDictionaryItemList(xmlDictionariesNode, "ProjectOrganization");

                // ProjectContacts [11/21/2006]
                InsertContactDictionaryItemList(xmlDictionariesNode, "ProjectContact");

                // ProjectStatus [3/30/2004]
                InsertDictionaryItemList(xmlDictionariesNode, "ProjectStatus", WebServicesHelper.GetListProjectStatus(LanguageId), "StatusName", "StatusId");

                // ProjectCalendar [3/30/2004]
                InsertDictionaryItemList(xmlDictionariesNode, "ProjectCalendar", Project.GetListCalendars(0), "CalendarName", "CalendarId");

                // ProjectCurrency [3/30/2004]
                InsertDictionaryItemList(xmlDictionariesNode, "ProjectCurrency", Project.GetListCurrency(), "CurrencySymbol", "CurrencyId");

                // ProjectManager [3/30/2004]
                XmlNode xmlManagersNode = xmlDictionariesList.CreateElement("ProjectManager");

                if (Security.IsUserInGroup(InternalSecureGroups.PowerProjectManager))
                {
                    using (IDataReader iManagers = SecureGroup.GetListAllUsersInGroup((int)InternalSecureGroups.ProjectManager))
                    {
                        while (iManagers.Read())
                        {
                            InsertUserInformation(xmlManagersNode, (int)iManagers["UserId"]);
                        }
                        iManagers.Close();
                    }
                }
                else
                {
                    InsertUserInformation(xmlManagersNode, Security.CurrentUser.UserID);
                }
                xmlDictionariesNode.AppendChild(xmlManagersNode);

                // ExecutiveManager [3/30/2004]
                XmlNode xmlExManagersNode = xmlDictionariesList.CreateElement("ExecutiveManager");
                using (IDataReader iExManagers = SecureGroup.GetListAllUsersInGroup((int)InternalSecureGroups.ProjectManager))
                {
                    while (iExManagers.Read())
                    {
                        InsertUserInformation(xmlExManagersNode, (int)iExManagers["UserId"]);
                    }
                    iExManagers.Close();
                }
                xmlDictionariesNode.AppendChild(xmlExManagersNode);

                // Templates [3/17/2005]
                InsertDictionaryItemList(xmlDictionariesNode, "ProjectTemplate", ProjectTemplate.GetListProjectTemplate(), "TemplateName", "TemplateId");

                // Priority [3/17/2005]
                InsertDictionaryItemList(xmlDictionariesNode, "ProjectPriority", Project.GetListPriorities(), "PriorityName", "PriorityId");

                // Portfolio [3/17/2005]
                InsertDictionaryItemList(xmlDictionariesNode, "ProjectPortfolio", ProjectGroup.GetProjectGroups(), "Title", "ProjectGroupId");

                // Phases [3/24/2005]
                InsertDictionaryItemList(xmlDictionariesNode, "ProjectPhase", Project.GetListProjectPhases(), "PhaseName", "PhaseId");

                // TimeTrackingTemplates [2008-10-29]
                InsertTimeTrackingTemplatesDictionaryItemList(xmlDictionariesNode, "TimeTrackingTemplates");

                break;

            case ObjectTypes.List:
                /*
                 * // Statuses [04/11/2005]
                 * InsertDictionaryItemList(xmlDictionariesNode, "ListStatus", List.GetListStatus(), "StatusName", "StatusId");
                 *
                 * // Types [04/11/2005]
                 * InsertDictionaryItemList(xmlDictionariesNode, "ListType", List.GetListType(), "TypeName", "TypeId");
                 *
                 * // Templates [04/11/2005]	// TODO: move to business and use InsertDictionaryItemList instead
                 * XmlNode xmlListTemplateRootNode = xmlDictionariesNode.OwnerDocument.CreateElement("ListTemplate");
                 * Mediachase.MetaDataPlus.Configurator.MetaClassCollection mcc = Mediachase.MetaDataPlus.Configurator.MetaClass.GetList(Mediachase.IBN.Business.List.ListTemplateRoot, true);
                 * foreach (Mediachase.MetaDataPlus.Configurator.MetaClass mc in mcc)
                 * {
                 *      XmlNode xmlDictionaryItemNode = xmlListTemplateRootNode.OwnerDocument.CreateElement("Item");
                 *      XmlNode xmlValueNode = xmlListTemplateRootNode.OwnerDocument.CreateElement("Value");
                 *      XmlNode xmlDataNode = xmlListTemplateRootNode.OwnerDocument.CreateElement("Data");
                 *
                 *      xmlValueNode.InnerText = mc.FriendlyName;
                 *      xmlDataNode.InnerText = mc.Id.ToString();
                 *
                 *      xmlDictionaryItemNode.AppendChild(xmlValueNode);
                 *      xmlDictionaryItemNode.AppendChild(xmlDataNode);
                 *
                 *      xmlListTemplateRootNode.AppendChild(xmlDictionaryItemNode);
                 * }
                 * xmlDictionariesNode.AppendChild(xmlListTemplateRootNode);
                 */

                break;
            }

            return(xmlDictionariesList.InnerXml);
        }