Exemple #1
0
        public override global::System.Data.DataSet Clone()
        {
            GlobalizationDataSet cln = ((GlobalizationDataSet)(base.Clone()));

            cln.InitVars();
            cln.SchemaSerializationMode = this.SchemaSerializationMode;
            return(cln);
        }
Exemple #2
0
        public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs)
        {
            GlobalizationDataSet ds = new GlobalizationDataSet();

            global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
            global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
            global::System.Xml.Schema.XmlSchemaAny         any      = new global::System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                try {
                    global::System.Xml.Schema.XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                    {
                        schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) &&
                                    (s1.ReadByte() == s2.ReadByte()));)
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return(type);
                            }
                        }
                    }
                }
                finally {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return(type);
        }
Exemple #3
0
        void WriteResourcesToDatabase(GlobalizationDataSet ds, IDbDriver db)
        {
            AppendToLog("Please wait...");

            List<TableColumn> columns = new List<TableColumn>();

            columns.Add(new TableColumn("AssemblyName", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("ManifestResourceName", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("ResourceName", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("ResourceValue", GenericDbColumnType.StringLong, false));
            columns.Add(new TableColumn("ResourceType", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("ResourceVersion", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("SourceCultureName", GenericDbColumnType.String, 255, false));
            columns.Add(new TableColumn("SourceValue", GenericDbColumnType.StringLong, 255, false));

            //columns.Add(new TableColumn("CreationDate", GenericDbColumnType.String, 255, false));

            DbDriverInfo dbInfo = new DbDriverInfo();
            dbInfo.DBName = "CulturalResources";
            dbInfo.DBCnnStringBuilder = new System.Data.OleDb.OleDbConnectionStringBuilder();
            dbInfo.DBCnnStringBuilder.ConnectionString = db.ConnectionString;
            dbFactory.CreatePhysicalDatabase(dbInfo);
            //            db.CreateDatabase("CulturalResources");

            string tableName = ds.CulturalResources.TableName;

            db.CreateTable(tableName, columns);

            StringBuilder sb = new StringBuilder();
            sb.Append("insert into ");
            sb.Append(tableName);
            sb.Append(" (");
            for (int x = 0; x < columns.Count; x++)
            {
                sb.Append(columns[x].Name);
                if (x < columns.Count - 1)
                {
                    sb.Append(", ");
                }
            }
            sb.Append(") values ");
            sb.Append(" (");
            for (int x = 0; x < columns.Count; x++)
            {
                sb.Append("@");
                sb.Append(columns[x].Name);
                if (x < columns.Count - 1)
                {
                    sb.Append(", ");
                }
            }
            sb.Append(")");
            Query insertQuery = db.CreateQuery(sb.ToString());
            for (int x = 0; x < columns.Count; x++)
            {
                insertQuery.Parameters.Add(new QueryParameter("@" + columns[x].Name, DbType.String, columns[x].Name, columns[x].Name));
            }

            sb.Remove(0, sb.Length);

            sb.Append("update [").Append(tableName);
            sb.Append(StringLiterals.RIGHT_SQUARE_BRACKET).Append(StringLiterals.SPACE);
            sb.Append("set").Append(StringLiterals.SPACE);
            for (int x = 0; x < columns.Count; x++)
            {
                sb.Append(StringLiterals.LEFT_SQUARE_BRACKET);
                sb.Append(columns[x].Name);
                sb.Append(StringLiterals.RIGHT_SQUARE_BRACKET);
                sb.Append(StringLiterals.EQUAL);
                sb.Append("@NewValue").Append(StringLiterals.SPACE);
                sb.Append(", ");
            }
            sb.Append("where ");
            for (int x = 0; x < columns.Count; x++)
            {
                sb.Append(columns[x].Name).Append(StringLiterals.SPACE);
                sb.Append(StringLiterals.EQUAL);
                sb.Append("@OldValue");
                if (columns.Count > 1)
                {
                    sb.Append(" and");
                }
            }
            Query updateQuery = db.CreateQuery(sb.ToString());
            for (int x = 0; x < columns.Count; x++)
            {
                updateQuery.Parameters.Add(new QueryParameter("@NewValue", DbType.String, columns[x].Name, columns[x].Name));
                updateQuery.Parameters.Add(new QueryParameter("@OldValue", DbType.String, columns[x].Name, columns[x].Name));
                updateQuery.Parameters[1].SourceVersion = DataRowVersion.Original;
            }

            db.Update(ds.Tables[0], tableName, insertQuery, null);
        }
Exemple #4
0
        GlobalizationDataSet ReadResourcesFromDatabase(IDbDriver dataSource, string tableName)
        {
            AppendToLog("Reading database");

            GlobalizationDataSet ds = new GlobalizationDataSet();

            if (string.IsNullOrEmpty(tableName))
            {
                // default table name
                tableName = ds.CulturalResources.TableName;
            }

            DataTable dt = dataSource.GetTableData(tableName);

            try
            {
                DataTableReader reader = new DataTableReader(dt);
                ds.CulturalResources.BeginLoadData();
                ds.CulturalResources.Load(reader);
                ds.CulturalResources.EndLoadData();
            }
            catch (Exception ex)
            {
                throw new GeneralException("Import database format is invalid.", ex);
            }

            return ds;
        }
Exemple #5
0
        GlobalizationDataSet ExtractResourcesToDataSet(string sourceCulture, string targetCulture, ITranslator translator)
        {
            int resourceCount = 0;

            GlobalizationDataSet ds = new GlobalizationDataSet();

            List<string> files = GetAssemblyFileList(applicationPath);

            foreach (string file in files)
            {
                int fileResourceCount = 0;

                GlobalizationDataSet.CulturalResourcesRow newrow;

                Assembly resourceAssembly = ResolveResourceAssembly(file, sourceCulture);

                // skip missing satellite assemblies
                if (resourceAssembly == null) continue;

                string[] resourceNames = resourceAssembly.GetManifestResourceNames();
                foreach (string resourceName in resourceNames)
                {

                    this.AppendToLog("Processing resource '{0}'", resourceName);

                    string manifestResourceName = resourceName;

                    // trim off any culture specification from satellite manifest resource name
                    if (manifestResourceName.EndsWith("." + sourceCulture + ".resources", true, CultureInfo.InvariantCulture))
                    {
                        manifestResourceName = manifestResourceName.Substring(0, manifestResourceName.Length - (1 + sourceCulture.Length + ".resources".Length));
                        manifestResourceName += ".resources";
                    }

                    if (manifestResourceName.EndsWith(".resources"))
                    {
                        using (ResourceReader reader = new ResourceReader(resourceAssembly.GetManifestResourceStream(resourceName)))
                        {
                            bool isSharedStrings = manifestResourceName.EndsWith("SharedStrings.resources");

                            IDictionaryEnumerator enumerator = reader.GetEnumerator();
                            while (enumerator.MoveNext())
                            {
                                if (isSharedStrings || IsTextResource(enumerator.Entry))
                                {
                                    fileResourceCount++;

                                    string assemblyName = resourceAssembly.GetName().Name;

                                    // discard any .resource suffix on the end (satellite assemblies)
                                    if (assemblyName.EndsWith(".resources", true, CultureInfo.InvariantCulture))
                                    {
                                        assemblyName = assemblyName.Substring(0, assemblyName.Length - ".resources".Length);
                                    }

                                    string sourceText = enumerator.Value.ToString();

                                    this.AppendToLog(SharedStrings.TRANSLATING, sourceText);

                                    string translatedText = translator.Translate(sourceCulture, targetCulture, sourceText);

                                    newrow = ds.CulturalResources.NewCulturalResourcesRow();
                                    newrow.AssemblyName = assemblyName;
                                    newrow.ResourceVersion = this.GetSatelliteContractVersion(resourceAssembly).ToString();
                                    newrow.ManifestResourceName = manifestResourceName;
                                    newrow.ResourceName = enumerator.Key.ToString();
                                    newrow.ResourceValue = translatedText;
                                    newrow.ResourceType = enumerator.Value.GetType().FullName;
                                    newrow.SourceCultureName = sourceCulture;
                                    newrow.SourceValue = sourceText;

                                    ds.CulturalResources.AddCulturalResourcesRow(newrow);

                                }
                            }
                        }
                    }
                    else
                    {
                        // embedded resource does not end with .resources
                        continue;
                    }
                }

                this.AppendToLog(SharedStrings.EXTRACTION_COUNT, file, fileResourceCount);
                resourceCount += fileResourceCount;
            }

            this.AppendToLog(SharedStrings.EXTRACTION_COMPLETE, resourceCount);

            return ds;
        }
Exemple #6
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().ToLower();

            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));
                }
            }
        }
Exemple #7
0
            public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs)
            {
                global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
                global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
                GlobalizationDataSet ds = new GlobalizationDataSet();

                global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.MaxOccurs       = decimal.MaxValue;
                any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(1);
                any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute1.Name       = "namespace";
                attribute1.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute1);
                global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute2.Name       = "tableTypeName";
                attribute2.FixedValue = "CulturalResourcesDataTable";
                type.Attributes.Add(attribute2);
                type.Particle = sequence;
                global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
                if (xs.Contains(dsSchema.TargetNamespace))
                {
                    global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                    global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                    try {
                        global::System.Xml.Schema.XmlSchema schema = null;
                        dsSchema.Write(s1);
                        for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                        {
                            schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                            s2.SetLength(0);
                            schema.Write(s2);
                            if ((s1.Length == s2.Length))
                            {
                                s1.Position = 0;
                                s2.Position = 0;
                                for (; ((s1.Position != s1.Length) &&
                                        (s1.ReadByte() == s2.ReadByte()));)
                                {
                                    ;
                                }
                                if ((s1.Position == s1.Length))
                                {
                                    return(type);
                                }
                            }
                        }
                    }
                    finally {
                        if ((s1 != null))
                        {
                            s1.Close();
                        }
                        if ((s2 != null))
                        {
                            s2.Close();
                        }
                    }
                }
                xs.Add(dsSchema);
                return(type);
            }