Ниже приведен пример использования операции SetMs для изменения данных переменной. В запросе передаются: экземпляр открытого контейнера моделирования, параметры выполнения операции и шаблон изменения данных. В результате выполнения операция возвращает рабочую книгу, содержащую изменённые данные переменной.
{ "Envelope" : { "Body" : { "SetMs" : { "tMs" : { "id" : "S83!M!S!C1" },
"tArg" : { "pattern" : { "obInst" : "true", "item" : { "key" : "4411", "problem" : {
"metamodel" : { "visualControllerPattern" : "" } } } }, "meta" : { "item" :
{ "k" : "4411", "type" : "Problem", "problemMd" : { "metamodel" : { "visualController" : { "variableWorkbookSet" :
{ "refresh" : { "saveData" : "true" }, "pattern" : { "obInst" : "true", "dataEditState" : "true", "cellsTable" :
{ "cells" : "true", "getCellDate" : "true" } }, "meta" : { "dataEditState" : { "readOnly" : "false"
}, "cellsTable" : { "@rowCount" : "1", "@columnCount" : "31", "columns" : { "dims" : { "it" :
{ "k" : "0", "id" : "calendar" } }, "slots" : { "s" : [ {
"@date" : "1990-01-01", "els" : { "e" : { "k" : "YEARS:1.1.1990", "n" : "1990A1" } } },
{ "@date" : "1991-01-01", "els" : { "e" : { "k" : "YEARS:1.1.1991", "n" : "1991A1" } }
}, { "@date" : "1992-01-01", "els" : { "e" : { "k" : "YEARS:1.1.1992", "n" : "1992A1" }
} }, { "@date" : "1993-01-01", "els" : { "e" : { "k" : "YEARS:1.1.1993", "n" : "1993A1"
} } }, { "@date" : "1994-01-01", "els" : { "e" : { "k" : "YEARS:1.1.1994",
"n" : "1994A1" } } }, { "@date" : "1995-01-01", "els" : { "e" : {
"k" : "YEARS:1.1.1995", "n" : "1995A1" } } }, { "@date" : "1996-01-01", "els" : { "e" :
{ "k" : "YEARS:1.1.1996", "n" : "1996A1" } } }, { "@date" : "1997-01-01", "els" : {
"e" : { "k" : "YEARS:1.1.1997", "n" : "1997A1" } } }, { "@date" : "1998-01-01", "els" :
{ "e" : { "k" : "YEARS:1.1.1998", "n" : "1998A1" } } }, { "@date" : "1999-01-01",
"els" : { "e" : { "k" : "YEARS:1.1.1999", "n" : "1999A1" } } }, {
"@date" : "2000-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2000", "n" : "2000A1" } } },
{ "@date" : "2001-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2001", "n" : "2001A1" } }
}, { "@date" : "2002-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2002", "n" : "2002A1" }
} }, { "@date" : "2003-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2003", "n" : "2003A1"
} } }, { "@date" : "2004-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2004",
"n" : "2004A1" } } }, { "@date" : "2005-01-01", "els" : { "e" : {
"k" : "YEARS:1.1.2005", "n" : "2005A1" } } }, { "@date" : "2006-01-01", "els" : { "e" :
{ "k" : "YEARS:1.1.2006", "n" : "2006A1" } } }, { "@date" : "2007-01-01", "els" : {
"e" : { "k" : "YEARS:1.1.2007", "n" : "2007A1" } } }, { "@date" : "2008-01-01", "els" :
{ "e" : { "k" : "YEARS:1.1.2008", "n" : "2008A1" } } }, { "@date" : "2009-01-01",
"els" : { "e" : { "k" : "YEARS:1.1.2009", "n" : "2009A1" } } }, {
"@date" : "2010-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2010", "n" : "2010A1" } } },
{ "@date" : "2011-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2011", "n" : "2011A1" } }
}, { "@date" : "2012-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2012", "n" : "2012A1" }
} }, { "@date" : "2013-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2013", "n" : "2013A1"
} } }, { "@date" : "2014-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2014",
"n" : "2014A1" } } }, { "@date" : "2015-01-01", "els" : { "e" : {
"k" : "YEARS:1.1.2015", "n" : "2015A1" } } }, { "@date" : "2016-01-01", "els" : { "e" :
{ "k" : "YEARS:1.1.2016", "n" : "2016A1" } } }, { "@date" : "2017-01-01", "els" : {
"e" : { "k" : "YEARS:1.1.2017", "n" : "2017A1" } } }, { "@date" : "2018-01-01", "els" :
{ "e" : { "k" : "YEARS:1.1.2018", "n" : "2018A1" } } }, { "@date" : "2019-01-01",
"els" : { "e" : { "k" : "YEARS:1.1.2019", "n" : "2019A1" } } }, {
"@date" : "2020-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2020", "n" : "2020A1" } } }
] } }, "rows" : { "dims" : { "it" : { "k" : "0",
"id" : "series" } }, "slots" : { "s" : { "els" : { "e" :
{ "k" : "Переменная моделирования|A", "n" : "Переменная моделирования|A" } } } } }, "cells" : {
"c" : [ { "@v" : "45", "@dt" : "3", "@row" : "0", "@column" : "0", "@date" : "1990-01-01" }, {
"@v" : "2.000000", "@dt" : "3", "@row" : "0", "@column" : "1", "@date" : "1991-01-01" }, { "@v" : "3.000000", "@dt" : "3", "@row" : "0",
"@column" : "2", "@date" : "1992-01-01" } ] } } } }, "variableWorkbookEaxSet" : {
"pattern" : { "obInst" : "true" }, "meta" : "" } } } } }
}, "metaGet" : { "obInst" : "true", "item" : { "key" : "4411", "problem" : { "metamodel" :
{ "visualControllerPattern" : { "variableWorkbook" : { "pattern" : { "obInst" : "true", "cellsTable" : {
"headers" : "true", "slots" : { "elementKey" : "true", "elementName" : "true" }, "cells" : "true", "emptyCells" : "false", "getCellDate" : "true" }
} }, "variableWorkbookEax" : "" } } } } }, "execParams" : {
"slice" : { "k" : "0", "id" : "364", "n" : "Переменная моделирования", "vis" : "true", "variableKey" : "4642", "stubKey" : "4413", "selections" : {
"its" : { "Item" : { "id" : { "id" : "4426" }, "variant" : "364" }
} }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0",
"parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0"
}, "level" : "None" }, "scenarioKeys" : "", "execFillWithVariable" : "true" } } } } } }
{ "Envelope" : { "Body" : { "SetMsResult" : { "id" : { "id" : "S83!M!S!C1" }, "meta" :
{ "obInst" : { "obDesc" : { "@isShortcut" : "0", "i" : "MODELSPACE", "n" : "Контейнер моделирования", "k" : "1581", "c" : "5121",
"p" : "1580", "h" : "0" } }, "dirty" : "0", "item" : { "k" : "4411", "id" : "MODEL_DEL", "n" : "model_del",
"vis" : "1", "type" : "Problem", "problemMd" : { "metamodel" : { "k" : "4412", "visualController" : { "variableWorkbook" :
{ "id" : { "id" : "S83!M!S!W4" }, "meta" : { "obInst" : { "obDesc" :
{ "@isShortcut" : "0", "i" : "VARIABLESWB_4412", "n" : "VariablesWorkBook", "k" : "4443", "c" : "2827", "p" : "4412", "h" : "0" } },
"dirty" : "1", "windowsPosition" : "Vertical", "hasPivot" : "0", "hasLaner" : "1", "series" : { "@count" : "1", "its" : "" }, "cellsTable" :
{ "@rowCount" : "1", "@columnCount" : "31", "columns" : { "dims" : { "it" : { "k" : "0",
"id" : "calendar" } }, "slots" : { "s" : [ { "@date" : "1990-01-01", "els" :
{ "e" : { "k" : "YEARS:1.1.1990", "n" : "1990A1" } } }, { "@date" : "1991-01-01",
"els" : { "e" : { "k" : "YEARS:1.1.1991", "n" : "1991A1" } } }, {
"@date" : "1992-01-01", "els" : { "e" : { "k" : "YEARS:1.1.1992", "n" : "1992A1" } } },
{ "@date" : "1993-01-01", "els" : { "e" : { "k" : "YEARS:1.1.1993", "n" : "1993A1" } }
}, { "@date" : "1994-01-01", "els" : { "e" : { "k" : "YEARS:1.1.1994", "n" : "1994A1" }
} }, { "@date" : "1995-01-01", "els" : { "e" : { "k" : "YEARS:1.1.1995", "n" : "1995A1"
} } }, { "@date" : "1996-01-01", "els" : { "e" : { "k" : "YEARS:1.1.1996",
"n" : "1996A1" } } }, { "@date" : "1997-01-01", "els" : { "e" : {
"k" : "YEARS:1.1.1997", "n" : "1997A1" } } }, { "@date" : "1998-01-01", "els" : { "e" :
{ "k" : "YEARS:1.1.1998", "n" : "1998A1" } } }, { "@date" : "1999-01-01", "els" : {
"e" : { "k" : "YEARS:1.1.1999", "n" : "1999A1" } } }, { "@date" : "2000-01-01", "els" :
{ "e" : { "k" : "YEARS:1.1.2000", "n" : "2000A1" } } }, { "@date" : "2001-01-01",
"els" : { "e" : { "k" : "YEARS:1.1.2001", "n" : "2001A1" } } }, {
"@date" : "2002-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2002", "n" : "2002A1" } } },
{ "@date" : "2003-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2003", "n" : "2003A1" } }
}, { "@date" : "2004-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2004", "n" : "2004A1" }
} }, { "@date" : "2005-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2005", "n" : "2005A1"
} } }, { "@date" : "2006-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2006",
"n" : "2006A1" } } }, { "@date" : "2007-01-01", "els" : { "e" : {
"k" : "YEARS:1.1.2007", "n" : "2007A1" } } }, { "@date" : "2008-01-01", "els" : { "e" :
{ "k" : "YEARS:1.1.2008", "n" : "2008A1" } } }, { "@date" : "2009-01-01", "els" : {
"e" : { "k" : "YEARS:1.1.2009", "n" : "2009A1" } } }, { "@date" : "2010-01-01", "els" :
{ "e" : { "k" : "YEARS:1.1.2010", "n" : "2010A1" } } }, { "@date" : "2011-01-01",
"els" : { "e" : { "k" : "YEARS:1.1.2011", "n" : "2011A1" } } }, {
"@date" : "2012-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2012", "n" : "2012A1" } } },
{ "@date" : "2013-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2013", "n" : "2013A1" } }
}, { "@date" : "2014-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2014", "n" : "2014A1" }
} }, { "@date" : "2015-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2015", "n" : "2015A1"
} } }, { "@date" : "2016-01-01", "els" : { "e" : { "k" : "YEARS:1.1.2016",
"n" : "2016A1" } } }, { "@date" : "2017-01-01", "els" : { "e" : {
"k" : "YEARS:1.1.2017", "n" : "2017A1" } } }, { "@date" : "2018-01-01", "els" : { "e" :
{ "k" : "YEARS:1.1.2018", "n" : "2018A1" } } }, { "@date" : "2019-01-01", "els" : {
"e" : { "k" : "YEARS:1.1.2019", "n" : "2019A1" } } }, { "@date" : "2020-01-01", "els" :
{ "e" : { "k" : "YEARS:1.1.2020", "n" : "2020A1" } } } ] }
}, "rows" : { "dims" : { "it" : { "k" : "0", "id" : "series" }
}, "slots" : { "s" : { "els" : { "e" : { "k" : "Переменная моделирования|A",
"n" : "Переменная моделирования|A" } } } } }, "cells" : { "c" : [
{ "@v" : "45.000000", "@dt" : "3", "@row" : "0", "@column" : "0", "@date" : "1990-01-01" }, { "@v" : "2.000000", "@dt" : "3",
"@row" : "0", "@column" : "1", "@date" : "1991-01-01" }, { "@v" : "3.000000", "@dt" : "3", "@row" : "0", "@column" : "2", "@date" : "1992-01-01"
} ] } } } }, "variableWorkbookEax" : { "id" : {
"id" : "" }, "meta" : { "obInst" : { "obDesc" : { "@isShortcut" : "0", "i" : "VARIABLESWB_4412",
"n" : "VariablesWorkBook", "k" : "4443", "c" : "2827", "p" : "4412", "h" : "0" } }, "dirty" : "1", "windowsPosition" : "Vertical", "hasPivot" : "0"
} } } } } } } } } } }
Функция SetMsVarData изменяет данные указанной переменной. Входные параметры:
ms. Экземпляр открытого контейнера моделирования;
modelKey. Ключ модели, содержащей переменную;
slice. Срез данных, соответствующий изменяемой переменной;
data. Таблица, содержащая новые данные переменной.
В результате выполнения функция изменяет данные в указанной переменной и возвращает рабочую книгу, содержащую изменённые данные.
public static GetWbkMdResult SetMsVarData(MsId ms, ulong modelKey, MsFormulaTransformSlice slice, WbkCellsTable data) { var setMsOp = new SetMs(); setMsOp.tMs = ms; setMsOp.tArg = new SetMsArg()
{ // Задаем шаблон изменения данных pattern = new MsMdPattern() { item = new MsItemPattern() { // Указываем ключ модели key = modelKey, problem = new MsProblemPattern() { metamodel = new MsMetaModelPattern() { // Задаём шаблон для визуального построения метамодели
visualControllerPattern = new MsMetaModelVisualControllerPattern() { } } } } },// Задаём шаблон извлечения измененных данных metaGet = new MsMdPattern() { item = new MsItemPattern() { // Указываем ключ модели key = modelKey,
problem = new MsProblemPattern() { metamodel = new MsMetaModelPattern() { // Задаём шаблон для визуального построения метамодели visualControllerPattern = new MsMetaModelVisualControllerPattern() { // Задаём шаблон извлечения внутренней рабочей книги variableWorkbook = new GetWbkMdArg() { pattern = new WbkMdPattern() {
cellsTable = new WbkCellsTablePattern() { headers = true, slots = new PvtSlotPattern() { elementKey = true, elementName = true }, cells = true, emptyCells = false } } },// Задаём шаблон извлечения внутреннего экспресс-представления variableWorkbookEax = new GetEaxMdArg() { }
} } } } },// Задаём изменяемые данные meta = new MsMd() { item = new MsItem() { // Указываем ключ модели k = modelKey,
type = MsItemType.Problem, problemMd = new MsProblem() { metamodel = new MsMetaModel() { visualController = new MsMetaModelVisualController() { // Задаём шаблон изменения данных во внутренней рабочей книге variableWorkbookSet = new SetWbkMdArg() { pattern = new WbkMdPattern()
{ dataEditState = true, cellsTable = new WbkCellsTablePattern() { cells = true } }, refresh = new EaxRefresh() { saveData = true }, meta = new WbkMd() { dataEditState = new EaxDataEditState() { readOnly = false }, cellsTable = data }
},// Внутреннее экспресс-представление не изменяем variableWorkbookEaxSet = new SetEaxMdArg() { pattern = new EaxMdPattern() { }, meta = new EaxMd() { } } } } } }
}, // Задаём параметры выполнения операции execParams = new MsMdExecParams() { scenarioKeys = new long[] { }, slice = slice, execFillWithVariable = true } }; // Создаем прокси-объект для выполнения операции
var somClient = new SomPortTypeClient(); // Открываем переменную SetMsResult setMsResult = somClient.SetMs(setMsOp); // Выводим изменённые данные переменной MsMetaModelVisualController metaVC = setMsResult.meta.item.problemMd.metamodel.visualController; Console.WriteLine("Переменная:" + slice.n); WbkCellsTable table = metaVC.variableWorkbook.meta.cellsTable; int ar = table.cells.Length; Console.WriteLine("Дата - Значение"); for (int i = 0; i <= (ar="" -="" 1);="" i++)="" {="" console.write((table.cells.getvalue(i)="" as="" pvttablecell).date="" +="" "="" ");="" console.writeline((table.cells.getvalue(i)="" pvttablecell).v);="" };="" return="" metavc.variableworkbook;="" }
См. также: