Пример #1
0
        static void DeserializeV2(opr opr, DirectoryInfo oprPath, out List <UIModel> models, out List <UIConnection> connections)
        {
            CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo("");

                models      = DeserializeModelsV2(opr, oprPath);
                connections = DeserializeConnectionsV2(opr, models, oprPath);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = currentCulture;
            }
        }
Пример #2
0
        static opr Serialize(List <UIModel> models, UIConnection[] connections, DirectoryInfo oprPath)
        {
            CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

            opr opr = new opr();

            try
            {
                opr.version     = "2.0";
                opr.models      = Models(models.ToArray());
                opr.connections = Connections(models, connections, oprPath);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = currentCulture;
            }

            return(opr);
        }
Пример #3
0
        static List <UIModel> DeserializeModelsV2(opr opr, DirectoryInfo oprPath)
        {
            List <UIModel> models = new List <UIModel>();

            if (opr.models == null)
            {
                return(models);
            }

            UIModel  uiModel;
            FileInfo omiFile = null;

            foreach (oprModel model in opr.models)
            {
                try
                {
                    omiFile = Utils.GetAbsoluteOmiFile(model.omi, oprPath);

                    uiModel = new UIModel();
                    uiModel.OmiDeserializeAndInitialize(omiFile);

                    uiModel.Rect.X      = Int32.Parse(model.rect_x);
                    uiModel.Rect.Y      = Int32.Parse(model.rect_y);
                    uiModel.Rect.Width  = Int32.Parse(model.rect_width);
                    uiModel.Rect.Height = Int32.Parse(model.rect_height);
                    uiModel.IsTrigger   = model.is_trigger;

                    models.Add(uiModel);
                }
                catch (Exception e)
                {
                    throw new Exception("Cannot instatiate model " + omiFile == null ? model.omi : omiFile.FullName, e);
                }
            }

            return(models);
        }
Пример #4
0
        public static void Save(FileInfo file, bool saveRelativePaths, List <UIModel> models, UIConnection[] connections)
        {
            opr opr = Serialize(models, connections, saveRelativePaths ? file.Directory : null);

            if (saveRelativePaths && opr.models != null)
            {
                foreach (oprModel model in opr.models)
                {
                    model.omi = Utils.RelativePath(file.Directory, model.omi);
                }
            }

            XmlSerializer serializer = new XmlSerializer(typeof(opr));

            using (TextWriter tw = new StringWriter())
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.OmitXmlDeclaration  = true;
                settings.Indent              = true;
                settings.NewLineOnAttributes = true;

                using (XmlWriter xmlWriter = XmlWriter.Create(tw, settings))
                {
                    XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
                    namespaces.Add("", "");

                    serializer.Serialize(xmlWriter, opr, namespaces);
                }

                using (FileStream fs = new FileStream(file.FullName, FileMode.Create))
                {
                    byte[] info = new UTF8Encoding(false).GetBytes(tw.ToString());
                    fs.Write(info, 0, info.Length);
                }
            }
        }
Пример #5
0
        // TODO Wrap Arguments so that exception thrown to indicate invalid value
        // can be caught and presented to the user.
        // e.g. valueA now = fred, valueB can only be ethal or freda
        //

        // Arguments list members (count as well as values) can change depending on
        // values of other arguments.
        // So say, 1 argument firstly which is file name to another list of
        // arguments to then display.

        // OpenWEB
        // model file change throws exception saying reload required
        // pipistrelle reconises exception_openweb type and reloads automatically

        static List <UIConnection> DeserializeConnectionsV2(opr opr, List <UIModel> models, DirectoryInfo oprPath)
        {
            List <UIConnection> connections = new List <UIConnection>();

            if (opr.connections == null)
            {
                return(connections);
            }

            Dictionary <string, UIAdaptedOutputItem> adaptedOutputs = new Dictionary <string, UIAdaptedOutputItem>();

            UIInputItem target;

            UIModel      uiSourceModel, uiTargetModel;
            UIConnection uiConnection;

            Dictionary <string, UIOutputItem> sources = new Dictionary <string, UIOutputItem>();
            Dictionary <string, UIInputItem>  targets = new Dictionary <string, UIInputItem>();
            List <Link> links = new List <Link>();


            foreach (oprConnection connection in opr.connections)
            {
                if (!connection.source_model_indexSpecified || !connection.target_model_indexSpecified)
                {
                    throw new NotImplementedException("Incompletly specified connections");
                }

                uiSourceModel = models[connection.source_model_index];
                uiTargetModel = models[connection.target_model_index];

                uiConnection = new UIConnection(uiSourceModel, uiTargetModel);
                connections.Add(uiConnection);

                sources.Clear();
                targets.Clear();

                foreach (ITimeSpaceOutput item in uiSourceModel.LinkableComponent.Outputs)
                {
                    sources.Add(item.Id, new UIOutputItem(item));
                }

                foreach (ITimeSpaceInput item in uiTargetModel.LinkableComponent.Inputs)
                {
                    targets.Add(item.Id, new UIInputItem(item));
                }

                # region delete later
                //nDecorators =  connection.decorators != null ? connection.decorators.Length : 0;

                //ids = new string[nDecorators];
                //oprFactories = new oprConnectionDecoratorFactory[nDecorators];
                //oprArguments = new oprConnectionDecoratorArgument[nDecorators][];

                //for (int n = 0; n < nDecorators; ++n)
                //{
                //    ids[n] = connection.decorators[n].item_id;
                //    oprFactories[n] = connection.decorators[n].factory;
                //    oprArguments[n] = connection.decorators[n].arguments;
                //}

                #endregion

                links = new List <Link>();

                foreach (oprConnectionLink oprLink in connection.links)
                {
                    target = targets[oprLink.target_item_id];

                    oprSourceItem       srcItem  = oprLink.source_item_id;
                    List <UIOutputItem> sourcesm = new List <UIOutputItem>();
                    UIOutputItem        source   = BuildOutputItemChain(uiSourceModel.LinkableComponent, srcItem, connection.decorators, sources, adaptedOutputs, oprPath, target);


                    foreach (oprSourceItem item in oprLink.source_item_ids)
                    {
                        UIOutputItem tempSrc = BuildOutputItemChain(uiSourceModel.LinkableComponent, item, connection.decorators, sources, adaptedOutputs, oprPath, target);
                        sourcesm.Add(tempSrc);
                    }



                    // Just telling target about most decorated source,
                    // not the intermediates (& visa versa).
                    // Probably the safest option re ensuring UI works
                    // in maximum number of cases.
                    // Thats what the UIOuputItem.Parent attribute is for!
                    // TODO ADH: However, might want
                    // to make explicit in Standard?

                    if (target.ExchangeItem is IBaseMultiInput)
                    {
                        IBaseMultiInput mtarget = (IBaseMultiInput)target.ExchangeItem;

                        foreach (UIOutputItem tempout in sourcesm)
                        {
                            mtarget.AddProvider(tempout);
                            tempout.AddConsumer(mtarget);
                        }
                    }
                    else
                    {
                        target.Provider = source;
                        source.AddConsumer(target);
                    }

                    Link tempLink = new Link(sourcesm, target);
                    //tempLink.Source = source;

                    links.Add(tempLink);
                }

                uiConnection.Links = links;
            }