Exemplo n.º 1
0
            /// <summary>
            /// SelectFilter method
            /// </summary>
            /// <param name="expression"></param>
            /// <returns></returns>
            public GlobalizationDataSet.CulturalResourcesDataTable SelectFilter(string expression)
            {
                GlobalizationDataSet.CulturalResourcesDataTable dt = new GlobalizationDataSet.CulturalResourcesDataTable();

                foreach (DataRow dr in this.Select(expression))
                {
                    dt.Rows.Add(dr.ItemArray);
                }

                return dt;
            }
Exemplo n.º 2
0
            /// <summary>
            /// SelectFilter method
            /// </summary>
            /// <param name="expression"></param>
            /// <returns></returns>
            public GlobalizationDataSet.CulturalResourcesDataTable SelectFilter(string expression)
            {
                GlobalizationDataSet.CulturalResourcesDataTable dt = new GlobalizationDataSet.CulturalResourcesDataTable();

                foreach (DataRow dr in this.Select(expression))
                {
                    dt.Rows.Add(dr.ItemArray);
                }

                return(dt);
            }
Exemplo n.º 3
0
            /// <summary>
            /// SelectDistinct() method
            /// </summary>
            /// <param name="FieldName"></param>
            /// <returns></returns>
            public GlobalizationDataSet.CulturalResourcesDataTable SelectDistinct(string FieldName)
            {
                GlobalizationDataSet.CulturalResourcesDataTable dt = new GlobalizationDataSet.CulturalResourcesDataTable();

                object LastValue = null;
                foreach (DataRow dr in this.Select("", FieldName))
                {
                    if (LastValue == null || !(ColumnEqual(LastValue, dr[FieldName])))
                    {
                        LastValue = dr[FieldName];
                        dt.Rows.Add(dr.ItemArray);
                    }
                }

                return dt;
            }
Exemplo n.º 4
0
            /// <summary>
            /// SelectDistinct() method
            /// </summary>
            /// <param name="FieldName"></param>
            /// <returns></returns>
            public GlobalizationDataSet.CulturalResourcesDataTable SelectDistinct(string FieldName)
            {
                GlobalizationDataSet.CulturalResourcesDataTable dt = new GlobalizationDataSet.CulturalResourcesDataTable();

                object LastValue = null;

                foreach (DataRow dr in this.Select("", FieldName))
                {
                    if (LastValue == null || !(ColumnEqual(LastValue, dr[FieldName])))
                    {
                        LastValue = dr[FieldName];
                        dt.Rows.Add(dr.ItemArray);
                    }
                }

                return(dt);
            }
Exemplo n.º 5
0
        /// <summary>
        /// CompileSatelliteAssemblies()
        /// </summary>
        /// <param name="targetCulture"></param>
        /// <param name="ds"></param>
        public void CompileSatelliteAssemblies(string targetCulture, GlobalizationDataSet ds)
        {
            //all columns are required except SourceValue

            string tempPath = Path.GetTempPath();

            applicationPath = applicationPath.Trim().ToLowerInvariant();

            if (applicationPath[applicationPath.Length - 1] != Path.DirectorySeparatorChar)
            {
                applicationPath += Path.DirectorySeparatorChar;
            }

            this.AppendToLog(SharedStrings.INSTALLING_LANGUAGE, targetCulture);

            GlobalizationDataSet.CulturalResourcesDataTable cultureTable = ds.CulturalResources;//.SelectFilter("CultureName='" + targetCulture + "'");

            GlobalizationDataSet.CulturalResourcesDataTable assembliesTable = cultureTable.SelectDistinct("AssemblyName");
            foreach (GlobalizationDataSet.CulturalResourcesRow assemblyRow in assembliesTable)
            {
                List <string> resourceList = new List <string>();

                GlobalizationDataSet.CulturalResourcesDataTable resourceTable = ds.CulturalResources.SelectFilter("AssemblyName='" + assemblyRow.AssemblyName + "'").SelectDistinct("ManifestResourceName");
                foreach (GlobalizationDataSet.CulturalResourcesRow resourceRow in resourceTable)
                {
                    string resourceFilename;
                    resourceFilename = resourceRow.ManifestResourceName.Substring(0, resourceRow.ManifestResourceName.Length - "resources".Length);
                    resourceFilename = Path.Combine(tempPath, resourceFilename + targetCulture + ".resources");

                    try
                    {
                        using (ResourceWriter writer = new ResourceWriter(resourceFilename))
                        {
                            GlobalizationDataSet.CulturalResourcesDataTable itemTable = ds.CulturalResources.SelectFilter("AssemblyName='" + assemblyRow.AssemblyName + "'").SelectFilter("ManifestResourceName='" + resourceRow.ManifestResourceName + "'");
                            foreach (GlobalizationDataSet.CulturalResourcesRow itemRow in itemTable)
                            {
                                writer.AddResource(itemRow.ResourceName, itemRow.ResourceValue);
                            }
                            writer.Close();
                        }

                        resourceList.Add(resourceFilename);
                    }
                    catch
                    {
                        foreach (string tempResourceFile in resourceList)
                        {
                            try
                            {
                                File.Delete(tempResourceFile);
                            }
                            catch
                            {
                                //eat
                            }
                        }

                        // kickout
                        throw;
                    }
                }

                string assemblyFilename = targetCulture + Path.DirectorySeparatorChar + assemblyRow.AssemblyName + ".resources.dll";
                assemblyFilename = Path.Combine(applicationPath, assemblyFilename);

                this.AppendToLog("Compiling " + assemblyRow.AssemblyName + " satellite assembly.");

                if (!Directory.Exists(Path.GetDirectoryName(assemblyFilename)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(assemblyFilename));
                }
                else if (File.Exists(assemblyFilename))
                {
                    File.Delete(assemblyFilename);
                }

                CSharpCodeProvider prov = new CSharpCodeProvider();
                CompilerParameters p    = new CompilerParameters();
                p.EmbeddedResources.AddRange(resourceList.ToArray());
                p.GenerateInMemory = false;
                p.OutputAssembly   = assemblyFilename;

                // setup references
                p.ReferencedAssemblies.Add("System.dll");


                Assembly mainAssembly = Assembly.Load(assemblyRow.AssemblyName);

                string version = GetSatelliteContractVersion(mainAssembly).ToString();
                if (version != assemblyRow.ResourceVersion.Trim())
                {
                    // warning! resource mismatch
                }

                string code = "[assembly: System.Reflection.AssemblyVersion(\"" + version + "\")] " +
                              "[assembly: System.Reflection.AssemblyFileVersion(\"" + version + "\")] " +
                              "[assembly: System.Reflection.AssemblyCulture(\"" + targetCulture + "\")]";
                CompilerResults res = prov.CompileAssemblyFromSource(p, code);

                foreach (string tempResourceFile in resourceList)
                {
                    File.Delete(tempResourceFile);
                }

                if (res.Errors.HasErrors)
                {
                    throw new GeneralException(GetString(res.Output));
                }
            }
        }