Exemple #1
0
        private void InitializeDropDown()
        {
            XmlDocument doc     = new XmlDocument();
            var         dirPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            doc.Load(dirPath + @"\ViewAndUI\ResourceManager\Resource\lang_country_lists.xml");
            XmlNode nodeEle = doc.SelectSingleNode("//languages");


            XDocument document = XDocument.Load(dirPath + @".\ViewAndUI\ResourceManager\Resource\lang_country_lists.xml");

            langMap = document.Descendants("languages").Descendants("lang")
                      .ToDictionary(d => (string)d.Attribute("id"),
                                    d => (string)d.Attribute("name"));

            int           c          = langMap.Count;
            ExpandoObject utilExpObj = ResourceManagerUtil.getExpandoObj();

            foreach (XmlElement nodeE in nodeEle.ChildNodes)
            {
                AddProperty(expando, nodeE.GetAttribute("id"), nodeE.GetAttribute("name"));
                ResourceManagerUtil.AddProperty(utilExpObj, nodeE.GetAttribute("name"), nodeE.GetAttribute("id"));
            }

            XmlElement   node        = doc.CreateElement("lang");
            XmlAttribute idAttribute = doc.CreateAttribute("id");

            idAttribute.Value = "default_All";

            XmlAttribute nameAttribute = doc.CreateAttribute("name");

            nameAttribute.Value = "All";

            node.Attributes.Append(idAttribute);
            node.Attributes.Append(nameAttribute);

            nodeEle.InsertBefore(node, nodeEle.ChildNodes.Item(0));
            configLangCombo.ItemsSource = nodeEle;
            //configLangComboView.ItemsSource = nodeEle;
        }
        /// <summary>
        /// Sub menu click Handler for CopyTo/MoveTo
        /// </summary>
        private void subMenu_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mi = sender as MenuItem;

            if (mi != null)
            {
                string[]      destNameArray = mi.Header.ToString().Split(',');
                ExpandoObject expObj        = ResourceManagerUtil.getExpandoObj();
                //destNameArray[0].Equals("default_All") ? destNameArray[0] : GetProperty(expando, (ResourceManagerUtil.GetProperty(expObj, destNameArray[0]) as string));
                string      expStoredName      = (destNameArray[0].Equals("default_All") ? destNameArray[0] : (ResourceManagerUtil.GetProperty(expObj, destNameArray[0]) as string));
                string[]    expStoredNameArray = expStoredName.Split('_');
                string      destName           = (expStoredNameArray[0] + "_" + (expStoredNameArray[1].Equals("All") ? expStoredNameArray[1] : expStoredNameArray[1].ToUpper()) + "-" + destNameArray[1].Trim());
                MenuItem    cm  = mi.Parent as MenuItem;
                string      opt = cm.Header.ToString();//Either copy to or move to selected
                ProjectItem contentsDirItems = ResourceManagerUtil.getContentFolder(currProj);
                string[]    srcHierarchy     = parentSelected.Split('/');
                Boolean     isAllConf        = false;//since All Configuration points to directory res/contents folder, we have to change the path.
                ProjectItem destProjItem     = ResourceManagerUtil.getProjectItem(destName, contentsDirItems);
                string      projPath         = Path.GetDirectoryName(currProj.FullName);
                srcHierarchy = srcHierarchy.Take(srcHierarchy.Count() - 1).ToArray();
                if (srcHierarchy.Count() == 0)
                {
                    return;
                }
                if (srcHierarchy[0].Equals("ALL"))
                {
                    isAllConf    = true;
                    srcHierarchy = srcHierarchy.Skip(1).ToArray();
                }
                string srcPath = projPath.ToString() + "\\res\\contents\\" + String.Join("\\", srcHierarchy);

                string   extResult    = Path.GetExtension(String.Join("/", srcHierarchy));
                string[] srcPathArray = Path.GetDirectoryName(srcPath).Split(new string[] { srcHierarchy[0] }, StringSplitOptions.None);

                ProjectItem srcParentPrjItem = contentsDirItems;

                string srcLastItem = srcHierarchy.Last();
                foreach (string folderName in srcHierarchy)
                {
                    if (!object.ReferenceEquals(folderName, srcLastItem))
                    {
                        try
                        {
                            srcParentPrjItem = ResourceManagerUtil.getProjectItem(folderName, srcParentPrjItem);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }

                //If path is Folder
                if (extResult.Equals(""))
                {
                    if (isAllConf)
                    {
                        List <string> srcHierList = new List <string>(srcHierarchy);
                        srcHierList.Insert(0, "ALL");
                        srcHierarchy = srcHierList.ToArray();
                    }

                    for (int i = 1; i < srcHierarchy.Length - 1; i++)
                    {
                        if (i < 0)
                        {
                            break;
                        }
                        if (!srcHierarchy[i].Equals(""))
                        {
                            destProjItem = ResourceManagerUtil.addProjectFolder(srcHierarchy[i], destProjItem);
                        }
                    }
                    ResourceManagerUtil.copyDir(srcPath, destProjItem);
                }
                //If path is file
                else
                {
                    if (isAllConf)
                    {
                        srcPathArray = Path.GetDirectoryName(srcPath).Split(new string[] { "\\res\\contents\\" }, StringSplitOptions.None);
                    }
                    if (srcPathArray.Count() > 1)
                    {
                        foreach (string folderName in srcPathArray[1].Split('\\'))
                        {
                            if (!folderName.Equals(""))
                            {
                                destProjItem = ResourceManagerUtil.addProjectFolder(folderName, destProjItem);
                            }
                        }
                    }
                    ResourceManagerUtil.copyFile(srcPath, destProjItem);
                }

                if (opt.Equals("Move To"))
                {
                    try
                    {
                        ResourceManagerUtil.removeProjectItem(srcLastItem, srcParentPrjItem);
                    }
                    catch (Exception)
                    {
                        FileAttributes attr = File.GetAttributes(@srcPath);

                        //detect whether its a directory or file
                        if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            Directory.Delete(srcPath);
                        }
                        else
                        {
                            File.Delete(srcPath);
                        }
                    }
                }
            }
        }