Exemplo n.º 1
0
        private void GenerationProcess()
        {
            this._StartTime = DateTime.Now;
            this._GeneratedServicesCount = 0;
            this.CollectInformation();
            CreateDirectories();
            this._dcTypes = this._TypeChache.GetSortedDCTypes();
            var task1         = Task.Factory.StartNew(GenerateServices);
            var task2         = Task.Factory.StartNew(this.GenerateClient);
            var assemblyName1 = new AssemblyName("Camstar.WCFSilverlightService");

            if (this._Settings.IsGenerateSilverlight)
            {
                DCTypeStore dCTypeStore = new DCTypeStore();
                new AssemblyGenerator(
                    DefineDynamicAssembly(assemblyName1, this._Settings.ClientOutputDirectory,
                                          typeof(Camstar.WCF.Service.ServiceBase).Assembly.GetName().Version.ToString())
                    .DefineDynamicModule(assemblyName1.Name + Constants.File.DllFileExt,
                                         assemblyName1.Name + Constants.File.DllFileExt, false), dCTypeStore, "Camstar.WCF.Service",
                    typeof(Camstar.WCF.Service.ServiceBase).Assembly, "Camstar.WCF.Service").GenerateCommonTypes();
            }

            var           assemblyName2      = new AssemblyName("Camstar.WCFSilverlightClient");
            var           now                = DateTime.Now;
            var           generationTime     = TimeSpan.MinValue;
            var           num                = 0;
            var           disassembleProcess = (Process)null;
            List <DCType> dcTypeList         = new List <DCType>();

            if (this._Settings.IsGenerateSilverlight)
            {
                this.CollectSilverlightInformation();
                DCTypeStore dCTypeStore     = new DCTypeStore();
                var         assemblyBuilder = DefineDynamicAssembly(assemblyName2,
                                                                    this._Settings.ClientSilverlightOutputDirectory,
                                                                    typeof(WCFServiceBase).Assembly.GetName().Version.ToString());
                var moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName2.Name + Constants.File.DllFileExt,
                                                                        assemblyName2.Name + Constants.File.DllFileExt, false);
                var assemblyGenerator = new AssemblyGenerator(moduleBuilder, dCTypeStore,
                                                              "Camstar.WCF.ObjectStack", typeof(WCFServiceBase).Assembly, "Camstar.WCF.Services");
                assemblyGenerator.GenerateCommonTypes();
                ClientGenerator clientGenerator = new ClientGenerator(moduleBuilder, dCTypeStore,
                                                                      "Camstar.WCF.Services", "Camstar.WCF.Services", true);
                dcTypeList = this._TypeSilverlightChache.GetSortedDCTypes();
                foreach (DCType dCType in dcTypeList)
                {
                    assemblyGenerator.AddDC(dCType);
                }
                for (var current = 0; current < dcTypeList.Count; ++current)
                {
                    this.OnStateChanged(GeneratingPhase.SilverlightDataContract, current, dcTypeList.Count,
                                        dcTypeList[current].Name);
                    clientGenerator.AddDC(dcTypeList[current]);
                }

                for (var current = 0; current < this._ExposedSilverlightServices.Count; ++current)
                {
                    this.OnStateChanged(GeneratingPhase.SilverlightServiceContract, current,
                                        this._ExposedSilverlightServices.Count, this._ExposedSilverlightServices[current].Name);
                    clientGenerator.AddService(this._ExposedSilverlightServices[current]);
                    if (this._ExposedSilverlightServices[current].ExposedState != ExposedServiceStateType.Base)
                    {
                        ++num;
                    }
                }

                assemblyBuilder.Save(assemblyName2.Name + Constants.File.DllFileExt);
                disassembleProcess = this.Disassemble(this._Settings.ClientSilverlightOutputDirectory + "\\",
                                                      assemblyName2.Name);
                generationTime = DateTime.Now - now;
            }

            Task.WaitAll(task1, task2);
            this.WriteServicesConfiguration();
            this.WriteClientConfiguration();
            if (this._Settings.IsGenerateSilverlight)
            {
                this.AssembleSilverlight(disassembleProcess, this._Settings.ClientSilverlightOutputDirectory + "\\",
                                         assemblyName2.Name);
            }
            this.DisperseFiles();
            this._CompleteInformation = new CompleteInformation(this._dcTypes.Count, this._GeneratedServicesCount + 3,
                                                                DateTime.Now - this._StartTime);
            if (!this._Settings.IsGenerateSilverlight)
            {
                return;
            }
            this._CompleteInformation.SilverlightCompleteInformation =
                new CompleteInformation(dcTypeList.Count, num + 3, generationTime);
        }