public ActionResult Create([Bind(Include = "MasterFileId,Revision,Name,Comment")] FileRevision item, HttpPostedFileBase file, long pid)
        {
            if (ModelState.IsValid)
            {
                //double tmp;
                var    prev      = _db.FileRevision.Where(a => a.MasterFileId == item.MasterFileId).OrderByDescending(b => b.Id).Take(1).FirstOrDefault();
                string prefDraft = prev == null ? "" : prev.Draft;
                string draft     = _is.Increment(prefDraft);

                var rootPath = _is.GetRoot().Path;

                if (file != null)
                {
                    // vars
                    var    actionDate = DateTime.Now;
                    string extension  = Path.GetExtension(file.FileName).Replace(".", "").ToUpper();
                    var    filname    = System.IO.Path.GetFileNameWithoutExtension(file.FileName) + "_v" + item.Revision + "." + extension.ToLower();
                    string icon       = DataFeeder.GetIcon(extension);
                    // MasterFile setup
                    MasterFile parent    = _db.MasterFile.Find(item.MasterFileId);
                    var        fullpath  = Path.Combine(rootPath, parent.Number, filname);
                    var        changelog = parent.Changelog + string.Format("{0} - Revision added : {1} \n", actionDate, filname);
                    parent.Changelog = changelog;
                    parent.Edited    = actionDate;

                    //Revision setup
                    item.Added     = actionDate;
                    item.Name      = file.FileName;
                    item.FullPath  = fullpath;
                    item.Draft     = draft;
                    item.Type      = "draft";
                    item.Extension = extension;
                    item.Icon      = icon;
                    file.SaveAs(fullpath);

                    var    md5  = MD5.Create();
                    string hash = _is.GetMd5Hash(md5, fullpath);
                    item.Md5hash = hash;

                    _db.FileRevision.Add(item);
                    _db.SaveChanges();

                    return(Json(new { success = true, responseText = "Draft added", id = item.MasterFileId, parentId = pid }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false, responseText = "File could not be loaded", id = item.MasterFileId, parentId = pid }, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(new { success = false, responseText = "Invalid model", id = item.MasterFileId, parentId = pid }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult SearchProject([FromBody] ProjectSearchModel f)
        {
            DateTime start = f.StartDate;
            DateTime end   = f.EndDate;

            if (f.StartDate.Ticks == 0)
            {
                start = DateTime.Now;
            }
            if (f.EndDate.Ticks == 0)
            {
                end = DateTime.Now.AddMonths(2);
            }
            List <ProjectViewModel> data = new DataFeeder().GetProjectScheduleViewData(start, end);

            return(Json(data));
        }
Beispiel #3
0
 private void GridDataAssetsLoad(object sender, EventArgs e)
 {
     _eventWait.WaitOne();
     ManageGrid();
     lock (visibleAssetList)
     {
         visibleAssetList = AssetList.Select(assetse1 =>
                                             AllAssets.Where(assetse => assetse.Symbol.Equals(assetse1))
                                             .FirstOrDefault() ?? new Assets
         {
             Symbol   = assetse1,
             Position = -1
         }).ToList();
     }
     LoadTable();
     _eventWait.Set();
     DataFeeder.Instance().DSForm.TickEvent += OnTickEvent;
 }
        private void WriteToServer(DataFeeder feeder)
        {
            if (this.tableName.Length == 0)
            {
                throw new ArgumentException("The name of the destination table hasn't been specified", "DestinationTableName");
            }

            StringBuilder builder = new StringBuilder();

            builder.Append("INSERT INTO ");
            if (this.tableName.Contains("."))
            {
                string[] parts = this.tableName.Split(new char[] { '.' });
                bool     first = true;
                foreach (string part in parts)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        builder.Append(".");
                    }
                    builder.Append("`");
                    builder.Append(part.Replace("`", "``"));
                    builder.Append("`");
                }
            }
            else
            {
                builder.Append("`");
                builder.Append(this.tableName.Replace("`", "``"));
                builder.Append("`");
            }
            builder.Append(" ");
            if (mappings.Count == 0)
            {
                // the target table has the same number and names of the columns as in the specified input rows
                builder.Append("VALUES (");
                for (int i = 0; i < feeder.FieldCount; i++)
                {
                    if (i != 0)
                    {
                        builder.Append(", ");
                    }
                    builder.Append("?");
                }
                builder.Append(")");
            }
            else
            {
                DataRowCollection targetColumns = null;
                builder.Append(" (");
                for (int i = 0; i < mappings.Count; i++)
                {
                    NuoDbBulkLoaderColumnMapping mapping = mappings[i];
                    if (i != 0)
                    {
                        builder.Append(", ");
                    }
                    builder.Append("`");
                    if (mapping.DestinationColumn == null)
                    {
                        // we are requested to map to a target column that is identified with its ordinal number, so
                        // fetch the schema of the target table to find out what is its name
                        if (targetColumns == null)
                        {
                            // split the destination table into its different parts
                            string[] parts = this.tableName.Split(new char[] { '.' });

                            DataTable targetSchema = this.connection.GetSchema("Columns", new string[] { null,                                   // catalog
                                                                                                         parts.Length == 2 ? parts[0] : null,    // schema
                                                                                                         parts.Length == 2 ? parts[1] : parts[0] // table
                                                                               });
                            targetColumns = targetSchema.Rows;
                        }

                        if (mapping.DestinationOrdinal < 0 || mapping.DestinationOrdinal > targetColumns.Count)
                        {
                            throw new IndexOutOfRangeException(String.Format("The specified ordinal of the target column ({0}) is outside the range of the column count ({1}) of table {2}",
                                                                             new object[] { mapping.DestinationOrdinal, targetColumns.Count, this.tableName }));
                        }

                        string columnName = (string)(targetColumns[mapping.DestinationOrdinal]["COLUMN_NAME"]);
                        builder.Append(columnName.Replace("`", "``"));
                    }
                    else
                    {
                        builder.Append(mapping.DestinationColumn.Replace("`", "``"));
                    }
                    builder.Append("`");
                }
                builder.Append(") VALUES (");
                for (int i = 0; i < mappings.Count; i++)
                {
                    if (i != 0)
                    {
                        builder.Append(", ");
                    }
                    builder.Append("?");
                }
                builder.Append(")");
            }
            string sqlString = builder.ToString();

#if DEBUG
            System.Diagnostics.Trace.WriteLine("NuoDbBulkLoader::WriteToServer: " + sqlString);
#endif

            if (this.connection.State != ConnectionState.Open)
            {
                this.connection.Open();
            }

            using (NuoDbCommand command = new NuoDbCommand(sqlString, this.connection))
            {
                if (mappings.Count > 0)
                {
                    // do the check for out-of-range values just once
                    foreach (NuoDbBulkLoaderColumnMapping mapping in mappings)
                    {
                        if (mapping.SourceColumn == null && mapping.SourceOrdinal < 0 || mapping.SourceOrdinal > feeder.FieldCount)
                        {
                            throw new IndexOutOfRangeException(String.Format("The specified ordinal of the source column ({0}) is outside the range of the column count ({1})",
                                                                             mapping.SourceOrdinal, feeder.FieldCount));
                        }
                    }
                    feeder = new FeederOrderer(feeder, mappings);
                }

                int batchCount = 0;
                int totalSize  = 0;
                while ((batchCount = command.ExecuteBatch(feeder, this.batchSize)) > 0)
                {
                    totalSize += batchCount;
#if DEBUG
                    System.Diagnostics.Trace.WriteLine("NuoDbBulkLoader::WriteToServer: sent a batch of " + batchCount + " rows");
#endif
                    if (handlers.Count != 0)
                    {
                        BatchProcessedEventHandler[] tmpArray = new BatchProcessedEventHandler[handlers.Count];
                        handlers.CopyTo(tmpArray);
                        BatchProcessedEventArgs args = new BatchProcessedEventArgs();
                        args.BatchSize = batchCount;
                        args.TotalSize = totalSize;
                        args.HasErrors = false;
                        foreach (BatchProcessedEventHandler h in tmpArray)
                        {
                            h.Invoke(this, args);
                        }
                    }
                }
            }
        }
Beispiel #5
0
 public FeederOrderer(DataFeeder parent, NuoDbBulkLoaderColumnMappingCollection mappings)
 {
     this.wrappedFeeder = parent;
     this.mappings      = mappings;
 }
Beispiel #6
0
        internal int ExecuteBatch(DataFeeder feed, int maxBatchSize = Int32.MaxValue)
        {
            checkConnection();
            if (isPrepared)
            {
                Close();
            }
            Prepare(false);
            EncodedDataStream dataStream = new RemEncodedStream(connection.InternalConnection.protocolVersion);

            dataStream.startMessage(Protocol.ExecuteBatchPreparedStatement);
            dataStream.encodeInt(handle);
            int batchCount = 0;

            while (batchCount < maxBatchSize && feed.MoveNext())
            {
                batchCount++;
                dataStream.encodeInt(feed.FieldCount);
                for (int i = 0; i < feed.FieldCount; i++)
                {
                    dataStream.encodeDotNetObject(feed[i]);
                }
            }
            // the iterator hasn't found any more data to import, let's break out
            if (batchCount > 0)
            {
                dataStream.encodeInt(-1);
                dataStream.encodeInt(batchCount);
                connection.InternalConnection.sendAndReceive(dataStream);
                bool   hasErrors    = false;
                string errorMessage = string.Empty;

                for (int i = 0; i < batchCount; i++)
                {
                    int result = dataStream.getInt();
                    if (result < 0)
                    {
                        if (connection.InternalConnection.protocolVersion >= Protocol.PROTOCOL_VERSION6)
                        {
                            int    sqlCode = dataStream.getInt();
                            string message = dataStream.getString();

                            errorMessage = AppendError(errorMessage, message, i);
                        }
                        hasErrors = true;
                    }
                }

                if (connection.InternalConnection.protocolVersion >= Protocol.PROTOCOL_VERSION3)
                {
                    long txnId          = dataStream.getLong();
                    int  nodeId         = dataStream.getInt();
                    long commitSequence = dataStream.getLong();
                    connection.InternalConnection.setLastTransaction(txnId, nodeId, commitSequence);
                }

                if (hasErrors)
                {
                    throw new NuoDbSqlException(errorMessage, NuoDbSqlCode.FindError("BATCH_UPDATE_ERROR"));
                }
            }
            return(batchCount);
        }
Beispiel #7
0
 public FeederOrderer(DataFeeder parent, NuoDbBulkLoaderColumnMappingCollection mappings)
 {
     this.wrappedFeeder = parent;
     this.mappings = mappings;
 }
Beispiel #8
0
        private void WriteToServer(DataFeeder feeder)
        {
            if (this.tableName.Length == 0)
                throw new ArgumentException("The name of the destination table hasn't been specified", "DestinationTableName");

            StringBuilder builder = new StringBuilder();
            builder.Append("INSERT INTO ");
            if (this.tableName.Contains("."))
            {
                string[] parts = this.tableName.Split(new char[] { '.' });
                bool first = true;
                foreach (string part in parts)
                {
                    if (first)
                        first = false;
                    else
                        builder.Append(".");
                    builder.Append("`");
                    builder.Append(part.Replace("`", "``"));
                    builder.Append("`");
                }
            }
            else
            {
                builder.Append("`");
                builder.Append(this.tableName.Replace("`", "``"));
                builder.Append("`");
            }
            builder.Append(" ");
            if (mappings.Count == 0)
            {
                // the target table has the same number and names of the columns as in the specified input rows
                builder.Append("VALUES (");
                for (int i = 0; i < feeder.FieldCount; i++)
                {
                    if (i != 0)
                        builder.Append(", ");
                    builder.Append("?");
                }
                builder.Append(")");
            }
            else
            {
                DataRowCollection targetColumns = null;
                builder.Append(" (");
                for (int i = 0; i < mappings.Count; i++)
                {
                    NuoDbBulkLoaderColumnMapping mapping = mappings[i];
                    if (i != 0)
                        builder.Append(", ");
                    builder.Append("`");
                    if (mapping.DestinationColumn == null)
                    {
                        // we are requested to map to a target column that is identified with its ordinal number, so
                        // fetch the schema of the target table to find out what is its name
                        if (targetColumns == null)
                        {
                            // split the destination table into its different parts
                            string[] parts = this.tableName.Split(new char[] { '.' });

                            DataTable targetSchema = this.connection.GetSchema("Columns", new string[] { null, // catalog
                                                                                    parts.Length == 2 ? parts[0] : null, // schema
                                                                                    parts.Length == 2 ? parts[1] : parts[0] // table
                                                                                });
                            targetColumns = targetSchema.Rows;
                        }

                        if (mapping.DestinationOrdinal < 0 || mapping.DestinationOrdinal > targetColumns.Count)
                            throw new IndexOutOfRangeException(String.Format("The specified ordinal of the target column ({0}) is outside the range of the column count ({1}) of table {2}",
                                new object[] { mapping.DestinationOrdinal, targetColumns.Count, this.tableName }));

                        string columnName = (string)(targetColumns[mapping.DestinationOrdinal]["COLUMN_NAME"]);
                        builder.Append(columnName.Replace("`", "``"));
                    }
                    else
                        builder.Append(mapping.DestinationColumn.Replace("`", "``"));
                    builder.Append("`");
                }
                builder.Append(") VALUES (");
                for (int i = 0; i < mappings.Count; i++)
                {
                    if (i != 0)
                        builder.Append(", ");
                    builder.Append("?");
                }
                builder.Append(")");
            }
            string sqlString = builder.ToString();
            #if DEBUG
            System.Diagnostics.Trace.WriteLine("NuoDbBulkLoader::WriteToServer: " + sqlString);
            #endif

            if (this.connection.State != ConnectionState.Open)
                this.connection.Open();

            using (NuoDbCommand command = new NuoDbCommand(sqlString, this.connection))
            {
                if (mappings.Count > 0)
                {
                    // do the check for out-of-range values just once
                    foreach (NuoDbBulkLoaderColumnMapping mapping in mappings)
                    {
                        if (mapping.SourceColumn == null && mapping.SourceOrdinal < 0 || mapping.SourceOrdinal > feeder.FieldCount)
                            throw new IndexOutOfRangeException(String.Format("The specified ordinal of the source column ({0}) is outside the range of the column count ({1})",
                                mapping.SourceOrdinal, feeder.FieldCount));
                    }
                    feeder = new FeederOrderer(feeder, mappings);
                }

                int batchCount = 0;
                int totalSize = 0;
                while ((batchCount = command.ExecuteBatch(feeder, this.batchSize)) > 0)
                {
                    totalSize += batchCount;
            #if DEBUG
                    System.Diagnostics.Trace.WriteLine("NuoDbBulkLoader::WriteToServer: sent a batch of " + batchCount + " rows");
            #endif
                    if (handlers.Count != 0)
                    {
                        BatchProcessedEventHandler[] tmpArray = new BatchProcessedEventHandler[handlers.Count];
                        handlers.CopyTo(tmpArray);
                        BatchProcessedEventArgs args = new BatchProcessedEventArgs();
                        args.BatchSize = batchCount;
                        args.TotalSize = totalSize;
                        args.HasErrors = false;
                        foreach (BatchProcessedEventHandler h in tmpArray)
                        {
                            h.Invoke(this, args);
                        }
                    }
                }
            }
        }
Beispiel #9
0
        internal int ExecuteBatch(DataFeeder feed, int maxBatchSize = Int32.MaxValue)
        {
            checkConnection();
            if (isPrepared)
            {
                Close();
            }
            Prepare(false);
            EncodedDataStream dataStream = new RemEncodedStream(connection.InternalConnection.protocolVersion);
            dataStream.startMessage(Protocol.ExecuteBatchPreparedStatement);
            dataStream.encodeInt(handle);
            int batchCount = 0;
            while (batchCount < maxBatchSize && feed.MoveNext())
            {
                batchCount++;
                dataStream.encodeInt(feed.FieldCount);
                for (int i = 0; i < feed.FieldCount; i++)
                {
                    dataStream.encodeDotNetObject(feed[i]);
                }
            }
            // the iterator hasn't found any more data to import, let's break out
            if (batchCount > 0)
            {
                dataStream.encodeInt(-1);
                dataStream.encodeInt(batchCount);
                connection.InternalConnection.sendAndReceive(dataStream);
                bool hasErrors = false;
                string errorMessage = string.Empty;

                for (int i = 0; i < batchCount; i++)
                {
                    int result = dataStream.getInt();
                    if (result < 0)
                    {
                        if (connection.InternalConnection.protocolVersion >= Protocol.PROTOCOL_VERSION6)
                        {
                            int sqlCode = dataStream.getInt();
                            string message = dataStream.getString();

                            errorMessage = AppendError(errorMessage, message, i);
                        }
                        hasErrors = true;
                    }
                }

                if (connection.InternalConnection.protocolVersion >= Protocol.PROTOCOL_VERSION3)
                {
                    long txnId = dataStream.getLong();
                    int nodeId = dataStream.getInt();
                    long commitSequence = dataStream.getLong();
                    connection.InternalConnection.setLastTransaction(txnId, nodeId, commitSequence);
                }

                if (hasErrors)
                    throw new NuoDbSqlException(errorMessage, NuoDbSqlCode.FindError("BATCH_UPDATE_ERROR"));
            }
            return batchCount;
        }