Exemplo n.º 1
0
        private string documentUrl(string url, HttpPostedFileBase documentfile, string documenturl, string documentname, string registername, int versionNr)
        {
            if (documentfile != null)
            {
                string fileName = SaveFileToDisk(documentfile, documentname, registername, versionNr);

                if (System.Web.Configuration.WebConfigurationManager.AppSettings["SchemaRemoteSynchEnabled"] == "false" ? false : true)
                {
                    string syncUrl = new SchemaSynchronizer().Synchronize(documentfile, fileName);
                    if (!string.IsNullOrEmpty(syncUrl))
                    {
                        url = syncUrl;
                    }
                }
                string documentUrl = url + fileName;
                return(documentUrl);
            }
            else if (documenturl != null)
            {
                return(documenturl);
            }
            else
            {
                return("ikke angitt");
            }
        }
Exemplo n.º 2
0
 public void Cleanup()
 {
     if (SchemaSynchronizer.ManagmentOperations.IndexExists())
     {
         SchemaSynchronizer.ManagmentOperations.DeleteIndex();
     }
     SchemaSynchronizer.CleaupLocalSchema();
 }
Exemplo n.º 3
0
 public void PostDocuments(ICloudBatch batch)
 {
     try
     {
         PostDocumentsImpl(batch);
     }
     catch (NotFoundException ex)
     {
         SchemaSynchronizer.RefreshLocalSchema();
         PostDocumentsImpl(batch);
     }
 }
Exemplo n.º 4
0
 private void SyncSchema(object state)
 {
     try
     {
         SchemaSynchronizer.RefreshLocalSchema();
         Interlocked.Exchange(ref _schema, new CloudSearchIndexSchema(SchemaSynchronizer.LocalSchemaSnapshot.ToList()));
         OnSchemaSynced(EventArgs.Empty);
     }
     catch (Exception ex)
     {
         SearchLog.Log.Info("Schema synchronization failed", ex);
     }
 }
Exemplo n.º 5
0
        public void Initialize(string indexName, string connectionString)
        {
            var custom = DocumentOperations as AzureSearchServiceClient;

            if (custom != null)
            {
                custom.Initialize(indexName, connectionString);
            }
            else
            {
                (DocumentOperations as ISearchServiceConnectionInitializable)?.Initialize(indexName, connectionString);
            }

            (SchemaSynchronizer as ISearchServiceConnectionInitializable)?.Initialize(indexName, connectionString);
            Name = new CloudSearchServiceSettings(connectionString).SearchService;
            SchemaSynchronizer.EnsureIsInitialized();
            Schema = new CloudSearchIndexSchema(SchemaSynchronizer.LocalSchemaSnapshot);
        }
        private string documentUrl(string url, HttpPostedFileBase documentfile, string documenturl, string documentname, string registername, int versionNr, string status, string previousStatus)
        {
            if (documentfile != null)
            {
                string fileName = SaveFileToDisk(documentfile, documentname, registername, versionNr);

                var schemaRemoteSynchEnabled = System.Web.Configuration.WebConfigurationManager.AppSettings["SchemaRemoteSynchEnabled"] == "false" ? false : true;

                if (registername == "GML applikasjonsskjema" && schemaRemoteSynchEnabled)
                {
                    string syncUrl = new SchemaSynchronizer().Synchronize(documentfile);

                    if (!string.IsNullOrEmpty(syncUrl))
                    {
                        return(syncUrl);
                    }
                }
                string documentUrl = url + fileName;
                return(documentUrl);
            }
            else if (documenturl != null)
            {
                var schemaRemoteSynchEnabled = System.Web.Configuration.WebConfigurationManager.AppSettings["SchemaRemoteSynchEnabled"] == "false" ? false : true;
                if (registername == "GML applikasjonsskjema" && schemaRemoteSynchEnabled)
                {
                    if (previousStatus != status)
                    {
                        if (status == "True")
                        {
                            documenturl = new SchemaSynchronizer().Synchronize(documenturl);
                        }
                    }
                }

                return(documenturl);
            }
            else
            {
                return("ikke angitt");
            }
        }
Exemplo n.º 7
0
        protected void tablesControl_OnSyncTable(object sender, GenericEventArgs <Guid> e)
        {
            var entity = DataContext.LP_Tables.FirstOrDefault(n => n.ID == e.Value);

            if (entity == null)
            {
                return;
            }

            var converter = new TableEntityModelConverter(DataContext);
            var model     = converter.Convert(entity);

            var synchronizer = new SchemaSynchronizer(model);

            synchronizer.Update();

            entity.Status = "Synchronized";

            DataContext.SubmitChanges();

            FillTablesTree();
        }
        public virtual void GenerateEntitiesFromDatabaseTables()
        {
            CurrentSchema = Schema.Current;

            var tables = SchemaSynchronizer.DefaultGetDatabaseDescription(Schema.Current.DatabaseNames()).Values.ToList();

            CleanDiffTables(tables);

            this.Tables = tables.ToDictionary(a=>a.Name);

            Graph = DirectedGraph<DiffTable>.Generate(tables, t =>
                t.Columns.Values.Select(a => a.ForeignKey).NotNull().Select(a => a.TargetTable).Distinct().Select(on => this.Tables.GetOrThrow(on)));

            GetSolutionInfo(out SolutionFolder, out SolutionName);

            string projectFolder = GetProjectFolder();

            if (!Directory.Exists(projectFolder))
                throw new InvalidOperationException("{0} not found. Override GetProjectFolder".FormatWith(projectFolder));

            bool? overwriteFiles = null;

            foreach (var gr in tables.GroupBy(t => GetFileName(t)))
            {
                string str = WriteFile(gr.Key, gr);

                if (str != null)
                {
                    string fileName = Path.Combine(projectFolder, gr.Key);

                    FileTools.CreateParentDirectory(fileName);

                    if (!File.Exists(fileName) || SafeConsole.Ask(ref overwriteFiles, "Overwrite {0}?".FormatWith(fileName)))
                    {
                        File.WriteAllText(fileName, str);
                    }
                }
            }
        }
Exemplo n.º 9
0
        private void PostDocumentsImpl(ICloudBatch batch)
        {
            ICloudSearchIndexSchema schema = _searchIndex.SchemaBuilder?.GetSchema();

            if (schema != null)
            {
                SchemaSynchronizer.EnsureIsInSync(schema.AllFields);
                Schema = new CloudSearchIndexSchema(SchemaSynchronizer.LocalSchemaSnapshot);
                OnSchemaSynced(EventArgs.Empty);
            }
            if (!AvailabilityManager.CanWrite)
            {
                throw new SearchServiceIsUnavailableException(_searchIndex.CloudIndexName, $"The service ${Name} is not available for write operations", null);
            }

            string json = batch.GetJson();

            try
            {
                DocumentOperations.PostDocuments(json);
            }
            catch (PostFailedForSomeDocumentsException ex)
            {
                StringBuilder stringBuilder = new StringBuilder("Post failed for some documents");
                foreach (MultiStatusResponseDocument document1 in ex.Documents)
                {
                    MultiStatusResponseDocument   document           = document1;
                    Dictionary <string, object>   dictionary         = batch.Documents.FirstOrDefault(d => string.Equals((string)d[CloudSearchConfig.VirtualFields.CloudUniqueId], document.Key, StringComparison.OrdinalIgnoreCase));
                    CloudSearchFieldConfiguration fieldConfiguration = _searchIndex.Configuration.FieldMap.GetFieldConfiguration(IDFieldName) as CloudSearchFieldConfiguration;
                    string str = fieldConfiguration == null ? document.Key : (dictionary == null || !dictionary.ContainsKey(fieldConfiguration.CloudFieldName) ? document.Key : dictionary[fieldConfiguration.CloudFieldName].ToString());
                    stringBuilder.AppendLine($"Document id: {str}, message: {document.Message}");
                }
                CrawlingLog.Log.Warn(stringBuilder.ToString(), null);
                CrawlingLog.Log.Debug(ex.RawResponse, null);
            }
        }
Exemplo n.º 10
0
    public static HashSet <SchemaName> GetSchemaNames(List <DatabaseName?> list)
    {
        var sqlBuilder = Connector.Current.SqlBuilder;
        var isPostgres = false;
        HashSet <SchemaName> result = new HashSet <SchemaName>();

        foreach (var db in list)
        {
            using (Administrator.OverrideDatabaseInSysViews(db))
            {
                var schemaNames = Database.View <SysSchemas>().Select(s => s.name).ToList().Except(sqlBuilder.SystemSchemas);

                result.AddRange(schemaNames.Select(sn => new SchemaName(db, sn, isPostgres)).Where(a => !SchemaSynchronizer.IgnoreSchema(a)));
            }
        }
        return(result);
    }
Exemplo n.º 11
0
 protected virtual List <DiffTable> GetTables()
 {
     return(SchemaSynchronizer.DefaultGetDatabaseDescription(Schema.Current.DatabaseNames()).Values.ToList());
 }