Exemplo n.º 1
0
        internal void SaveNodeData(NodeData nodeData, NodeSaveSettings settings, out int lastMajorVersionId, out int lastMinorVersionId)
        {
            lastMajorVersionId = 0;
            lastMinorVersionId = 0;

            bool isNewNode = nodeData.Id == 0; // shortcut

            var parent = NodeHead.Get(nodeData.ParentId);
            var path   = RepositoryPath.Combine(parent.Path, nodeData.Name);

            Node.AssertPath(path);

            nodeData.Path = path;

            var writer = this.CreateNodeWriter();

            try
            {
                var savingAlgorithm = settings.GetSavingAlgorithm();

                writer.Open();
                if (settings.NeedToSaveData)
                {
                    SaveNodeBaseData(nodeData, savingAlgorithm, writer, settings, out lastMajorVersionId, out lastMinorVersionId);

                    BenchmarkCounter.IncrementBy(BenchmarkCounter.CounterName.SaveNodeBaseData, nodeData.SavingTimer.ElapsedTicks);
                    nodeData.SavingTimer.Restart();

                    if (!isNewNode && nodeData.PathChanged && nodeData.SharedData != null)
                    {
                        writer.UpdateSubTreePath(nodeData.SharedData.Path, nodeData.Path);
                    }
                    SaveNodeProperties(nodeData, savingAlgorithm, writer, isNewNode);
                }
                else
                {
                    writer.UpdateNodeRow(nodeData);
                }
                writer.Close();

                BenchmarkCounter.IncrementBy(BenchmarkCounter.CounterName.SaveNodeFlatProperties, nodeData.SavingTimer.ElapsedTicks);
                nodeData.SavingTimer.Restart();

                foreach (var versionId in settings.DeletableVersionIds)
                {
                    DeleteVersion(versionId, nodeData, out lastMajorVersionId, out lastMinorVersionId);
                }
            }
            catch //rethrow
            {
                if (isNewNode)
                {
                    // Failed save: set NodeId back to 0
                    nodeData.Id = 0;
                }

                throw;
            }
        }
Exemplo n.º 2
0
        private void WriteCounters(HttpContext context)
        {
            var counters = BenchmarkCounter.GetAll();
            var names    = Enum.GetNames(typeof(BenchmarkCounter.CounterName));

            for (int i = 0; i < names.Length; i++)
            {
                context.Response.Write(names[i]);
                context.Response.Write(": ");
                context.Response.Write(counters[i]);
                context.Response.Write("<br/>");
                context.Response.Write(Environment.NewLine);
            }
        }
Exemplo n.º 3
0
        private static void SaveNodeProperties(NodeData nodeData, SavingAlgorithm savingAlgorithm, INodeWriter writer, bool isNewNode)
        {
            int versionId = nodeData.VersionId;

            foreach (var propertyType in nodeData.PropertyTypes)
            {
                var  slotValue  = nodeData.GetDynamicRawData(propertyType) ?? propertyType.DefaultValue;
                bool isModified = nodeData.IsModified(propertyType);

                if (!isModified && !isNewNode)
                {
                    continue;
                }

                switch (propertyType.DataType)
                {
                case DataType.String:
                    writer.SaveStringProperty(versionId, propertyType, (string)slotValue);
                    break;

                case DataType.DateTime:
                    writer.SaveDateTimeProperty(versionId, propertyType, (DateTime)slotValue);
                    break;

                case DataType.Int:
                    writer.SaveIntProperty(versionId, propertyType, (int)slotValue);
                    break;

                case DataType.Currency:
                    writer.SaveCurrencyProperty(versionId, propertyType, (decimal)slotValue);
                    break;

                case DataType.Text:
                    writer.SaveTextProperty(versionId, propertyType, true, (string)slotValue);    //TODO: ?? isLoaded property handling
                    BenchmarkCounter.IncrementBy(BenchmarkCounter.CounterName.SaveNodeTextProperties, nodeData.SavingTimer.ElapsedTicks);
                    nodeData.SavingTimer.Restart();
                    break;

                case DataType.Reference:
                    var ids = (IEnumerable <int>)slotValue;
                    if (!isNewNode || (ids != null && ids.Count() > 0))
                    {
                        var ids1 = ids.Distinct().ToList();
                        if (ids1.Count != ids.Count())
                        {
                            nodeData.SetDynamicRawData(propertyType, ids1);
                        }
                        writer.SaveReferenceProperty(versionId, propertyType, ids1);
                    }
                    BenchmarkCounter.IncrementBy(BenchmarkCounter.CounterName.SaveNodeReferenceProperties, nodeData.SavingTimer.ElapsedTicks);
                    nodeData.SavingTimer.Restart();
                    break;

                case DataType.Binary:
                    var binValue = (BinaryDataValue)slotValue;
                    if (binValue != null)
                    {
                        if (!binValue.IsEmpty)
                        {
                            var vId = nodeData.SharedData == null ? nodeData.VersionId : nodeData.SharedData.VersionId;
                            if (binValue.Stream == null && binValue.Size != -1)
                            {
                                binValue.Stream = DataBackingStore.GetBinaryStream(vId, propertyType.Id);
                            }
                        }
                    }

                    if (binValue == null || binValue.IsEmpty)
                    {
                        writer.DeleteBinaryProperty(versionId, propertyType);
                    }
                    else if (binValue.Id == 0 || savingAlgorithm != SavingAlgorithm.UpdateSameVersion)
                    {
                        var id = writer.InsertBinaryProperty(versionId, propertyType.Id, binValue, isNewNode);
                        binValue.Id = id;
                    }
                    else
                    {
                        writer.UpdateBinaryProperty(binValue.Id, binValue);
                    }

                    BenchmarkCounter.IncrementBy(BenchmarkCounter.CounterName.SaveNodeBinaries, nodeData.SavingTimer.ElapsedTicks);
                    nodeData.SavingTimer.Restart();
                    break;

                default:
                    throw new NotSupportedException(propertyType.DataType.ToString());
                }
            }
        }
Exemplo n.º 4
0
        private void CreateContent(HttpContext context)
        {
            try
            {
                //---- content type

                var contentTypeName = GetRequestParameter("contenttype");
                if (String.IsNullOrEmpty(contentTypeName))
                {
                    WriteError("Parameter 'contenttype' cannot be null or empty.", context);
                    return;
                }

                var contentType = ContentType.GetByName(contentTypeName);
                if (contentType == null)
                {
                    WriteError("Content type not found: " + contentTypeName, context);
                    return;
                }
                //---- create content

                var snPath = GetRequestParameter("snpath");
                if (String.IsNullOrEmpty(snPath))
                {
                    WriteError("Parameter 'snpath' cannot be null or empty.", context);
                    return;
                }

                using (new ContentRepository.Storage.Security.SystemAccount())
                {
                    BenchmarkCounter.Reset();
                    benchmarkTimer = Stopwatch.StartNew();
                    benchmarkTimer.Restart();

                    var parentPath = RepositoryPath.GetParentPath(snPath);

                    BenchmarkCounter.IncrementBy(BenchmarkCounter.CounterName.GetParentPath, benchmarkTimer.ElapsedTicks);
                    benchmarkTimer.Restart();

                    var parent = Node.LoadNode(parentPath);
                    if (parent == null)
                    {
                        WriteError("Cannot load the parent: " + snPath, context);
                        return;
                    }

                    BenchmarkCounter.IncrementBy(BenchmarkCounter.CounterName.LoadParent, benchmarkTimer.ElapsedTicks);
                    benchmarkTimer.Restart();



                    var contentName = RepositoryPath.GetFileName(snPath);
                    var content     = SnContent.CreateNew(contentTypeName, parent, contentName);

                    BenchmarkCounter.IncrementBy(BenchmarkCounter.CounterName.ContentCreate, benchmarkTimer.ElapsedTicks);
                    benchmarkTimer.Restart();

                    //---- create binary

                    if (contentTypeName == "File")
                    {
                        var fsPath = GetRequestParameter("fspath");
                        if (String.IsNullOrEmpty(snPath))
                        {
                            WriteError("Parameter 'fspath' cannot be null or empty if the content type is 'File'.", context);
                            return;
                        }

                        using (var stream = context.Request.InputStream)
                        {
                            var binaryData = new BinaryData();
                            binaryData.FileName = fsPath; //.Replace("$amp;", "&");
                            binaryData.SetStream(stream);

                            content["Binary"] = binaryData;
                            BenchmarkCounter.IncrementBy(BenchmarkCounter.CounterName.BinarySet, benchmarkTimer.ElapsedTicks);
                            benchmarkTimer.Restart();


                            using (new ContentRepository.Storage.Security.SystemAccount())
                                content.Save();
                        }
                    }
                    else
                    {
                        BenchmarkCounter.IncrementBy(BenchmarkCounter.CounterName.BinarySet, benchmarkTimer.ElapsedTicks);
                        benchmarkTimer.Restart();

                        content.Save();
                    }

                    BenchmarkCounter.IncrementBy(BenchmarkCounter.CounterName.FullSave, benchmarkTimer.ElapsedTicks);
                    benchmarkTimer.Restart();
                }
            }
            catch (Exception e)
            {
                //WriteError(String.Concat(e.Message, "\r", e.StackTrace), context);
                Logger.WriteException(e);
                WriteError(e, context);
                return;
            }

            WriteCounters(context);

            context.Response.StatusCode = 200;
            context.Response.Write("ok");
        }