Example #1
0
        public static void GetChanges(Document _doc, string _filepath) // _filepath to .txt file in share folder
        {
            //string[] files = Directory.GetFiles(mapFolderPath, "*.txt");

            float  x = 0, y = 0; // callouts, main and floating topics
            int    index  = 1;   // subtopic index in a branch
            string line   = "";
            string _case  = "";
            string _what  = ""; // case details
            string rollup = SUtils.rollupuri;
            //string numbering = SUtils.numberinguri;

            string mapfolderpath = Path.GetDirectoryName(_filepath) + "\\";

            //foreach (string file in files)
            {
                System.IO.StreamReader _file = null;
                try
                {
                    _file = new System.IO.StreamReader(_filepath);
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show("Exception: " + e.Message, "ReceiveChanges:StreamReader");
                    return;
                }

                line  = _file.ReadLine(); // line 1: case
                _case = line;
                int colon = line.IndexOf(":");

                if (colon != -1)
                {
                    _case = line.Substring(0, colon); // before colon
                    _what = line.Substring(++colon);  // after colon
                    if (!int.TryParse(_what, out index))
                    {
                        index = 1;
                    }
                }

                MapCompanion.received = true; // to repulse event handlers

                switch (_case)
                {
                ///////////////////////// MODIFY TOPIC ///////////////////////
                case "modify":

                    // line 2: topic Guid
                    _t = SUtils.FindTopicByAttrGuid(_doc, _file.ReadLine());
                    if (_t == null)
                    {
                        System.Windows.Forms.MessageBox.Show("ReceiveChanges.CaseModify.TopicNotFound");
                        break;     //TODO
                    }

                    if (_what == "rollup")     // set or remove rollup
                    {
                        if (_t.HasAttributesNamespace[rollup])
                        {
                            _t.IsTaskRollupTopic = false;
                        }
                        else
                        {
                            _t.IsTaskRollupTopic = true;
                        }
                        break;
                    }

                    // line 3: topic text (for chat)
                    forchat = _file.ReadLine();

                    // line 4: timestamp (to attributes)
                    TransactionsWrapper.SetATTR(_t, SUtils.TMODIFIED, _file.ReadLine());

                    // line 5: offset
                    line = _file.ReadLine();
                    if (line != "")
                    {
                        if (_t.IsFloatingTopic || _t.IsMainTopic || _t.IsCalloutTopic)
                        {
                            int w = line.IndexOf(";");
                            float.TryParse(line.Substring(0, w), out x);
                            float.TryParse(line.Substring(w + 1), out y);
                        }
                    }

                    // line 6 to end: value
                    line = _file.ReadLine();
                    string _value = line;

                    while (line != null)
                    {
                        line = _file.ReadLine();
                        if (line != null)
                        {
                            _value = _value + Environment.NewLine + line;
                        }
                    }

                    if (_what != "offset")
                    {
                        PortraitSet.TopicPortrait(_t, _what, _value, mapfolderpath);
                    }

                    if (_t.IsFloatingTopic || _t.IsMainTopic || _t.IsCalloutTopic)
                    {
                        _t.SetOffset(x, y);     //restore topic position
                    }
                    break;
                ////////////////// MODIFY case ends ///////////////////

                /////////////////////////// ADD TOPIC ////////////////////////
                case "add":

                    Topic        _parent  = null;
                    Boundary     _bparent = null;
                    Relationship _rparent = null;

                    // line 2: parent guid
                    line = _file.ReadLine();
                    if (line != "")     // empty if floating topic
                    {
                        if (_what == "relcallout")
                        {
                            _rparent = SUtils.FindRelationshipByAttrGuid(_doc, line);
                        }
                        else if (_what == "bndcallout")
                        {
                            _bparent = SUtils.FindBoundaryByAttrGuid(_doc, line);
                        }
                        else
                        {
                            _parent = SUtils.FindTopicByAttrGuid(_doc, line);
                        }
                        if (_parent == null && _rparent == null && _bparent == null)
                        {
                            System.Windows.Forms.MessageBox.Show("ReceiveChanges.CaseAdd.ObjectNotFound");
                            break;     // TODO обнаружить ошибку - сообщить пользователю?
                        }
                    }

                    // line 3: topic text - for chat
                    forchat = _file.ReadLine();

                    // line 4: added topic guid : add topic
                    line = _file.ReadLine();
                    if (_what == "floating")
                    {
                        _t = _doc.AllFloatingTopics.Add();
                    }
                    else if (_what == "callout")
                    {
                        _t = _parent.AllCalloutTopics.Add();
                    }
                    else if (_what == "relcallout")
                    {
                        _t = _rparent.AllCalloutTopics.Add();
                    }
                    else if (_what == "bndcallout")
                    {
                        _t = _bparent.CreateSummaryTopic(MMUtils.GetString("callout.text"));
                    }
                    else
                    {
                        _t = _parent.AllSubTopics.Add();
                        _parent.AllSubTopics.Insert(_t, index); // EventDocumentClipboardPaste fires!
                        MapCompanion.paste = false;             // so, neutralize it...
                    }

                    TransactionsWrapper.SetATTR(_t, SUtils.OGUID, line);

                    // line 5: timestamp
                    line = _file.ReadLine();
                    TransactionsWrapper.SetATTR(_t, SUtils.TADDED, line);
                    TransactionsWrapper.SetATTR(_t, SUtils.TMODIFIED, line);

                    // line 6: offset
                    line = _file.ReadLine();
                    if (line != "")     // skip standart topics
                    {
                        int w = line.IndexOf(";");
                        float.TryParse(line.Substring(0, w), out x);
                        float.TryParse(line.Substring(w + 1), out y);
                    }
                    if (_t.IsFloatingTopic || _t.IsMainTopic || _t.IsCalloutTopic)
                    {
                        _t.SetOffset(x, y);
                    }

                    // line 7: skip if new topic added, otherwise (topic was pasted) replace whole topic xml
                    line = _file.ReadLine();     // <?xml version="1.0" standalone="no"?>
                    if (line != "newtopic")
                    {
                        _t.Xml = line + _file.ReadLine();     // topic XML
                        if (_t.IsFloatingTopic || _t.IsMainTopic || _t.IsCalloutTopic)
                        {
                            _t.SetOffset(x, y);
                        }
                    }

                    _parent = null; _rparent = null; _bparent = null;
                    break;
                ///////////////////// ADD TOPIC case ends ////////////////////////

                //////////// DELETE TOPIC OR RELATIONSHIP OR BOUNDARY ////////////
                case "delete":

                    // line 2: guid of object to delete
                    line = _file.ReadLine();

                    DocumentObject m_objtodelete = null;
                    m_objtodelete = SUtils.FindObjectByAttrGuid(_doc, line);

                    if (m_objtodelete == null)
                    {
                        System.Windows.Forms.MessageBox.Show("ReceiveChanges.CaseDelete.ObjectNotFound");
                        break;     // TODO map synchro failure, do something
                    }

                    m_objtodelete.Delete();
                    m_objtodelete = null;

                    // line 3: for chat: topic text or "relationship" or "boundary"
                    forchat = _file.ReadLine();

                    // line 4: for chat: name of user who deleted object
                    username = _file.ReadLine();

                    break;
                //////////////////// DELETE case ends ////////////////////

                //////////////////// RELATIONSHIP ADD, MODIFY //////////////////
                case "relationship":
                    Relationship rel = null;

                    // line 2: relationship guid
                    line = _file.ReadLine();
                    if (_what == "modify")
                    {
                        rel = SUtils.FindRelationshipByAttrGuid(_doc, line);
                        if (rel == null)
                        {
                            System.Windows.Forms.MessageBox.Show("ReceiveChanges.CaseRelationships.RelNotFound");
                            break;
                        }
                    }

                    // line 3: Guid of connection 1st object
                    string Guid1 = _file.ReadLine();
                    Topic  t1 = null, t2 = null;

                    Boundary b1 = SUtils.FindBoundaryByAttrGuid(_doc, Guid1);
                    if (b1 == null)
                    {
                        t1 = SUtils.FindTopicByAttrGuid(_doc, Guid1);
                    }

                    if (b1 == null && t1 == null)
                    {
                        System.Windows.Forms.MessageBox.Show("ReceiveChanges.CaseRelationships.Object1NotFound");
                        break;     // TODO
                    }

                    // line 4:
                    string Guid2 = _file.ReadLine();

                    Boundary b2 = SUtils.FindBoundaryByAttrGuid(_doc, Guid2);
                    if (b2 == null)
                    {
                        t2 = SUtils.FindTopicByAttrGuid(_doc, Guid2);
                    }

                    if (b2 == null && t2 == null)
                    {
                        System.Windows.Forms.MessageBox.Show("ReceiveChanges.CaseRelationships.Object2NotFound");
                        break;     // TODO
                    }

                    if (b1 == null)
                    {
                        if (b2 == null)
                        {
                            if (_what == "modify")
                            {
                                rel.SetConnection1ToTopic(t1);
                                rel.SetConnection2ToTopic(t2);
                            }
                            else
                            {
                                rel = t1.AllRelationships.AddToTopic(t2);
                                TransactionsWrapper.SetAttributes(rel, line);
                            }
                        }
                        else
                        if (_what == "modify")
                        {
                            rel.SetConnection1ToTopic(t1);
                            rel.SetConnection2ToBoundary(b2);
                        }
                        else
                        {
                            rel = t1.AllRelationships.AddToBoundary(b2);
                            TransactionsWrapper.SetAttributes(rel, line);
                        }
                    }
                    else
                    {
                        if (b2 == null)
                        {
                            if (_what == "modify")
                            {
                                rel.SetConnection1ToBoundary(b1);
                                rel.SetConnection2ToTopic(t2);
                            }
                            else
                            {
                                rel = b1.AllRelationships.AddToTopic(t2);
                                TransactionsWrapper.SetAttributes(rel, line);
                            }
                        }
                        else
                        if (_what == "modify")
                        {
                            rel.SetConnection1ToBoundary(b1);
                            rel.SetConnection2ToBoundary(b2);
                        }
                        else
                        {
                            rel = b1.AllRelationships.AddToBoundary(b2);
                            TransactionsWrapper.SetAttributes(rel, line);
                        }
                    }

                    // line 5-8: control points
                    if ((line = _file.ReadLine()) == null)     //new rel added, go out
                    {
                        break;
                    }
                    rel.SetControlPoints(
                        Convert.ToSingle(line),
                        Convert.ToSingle(_file.ReadLine()),
                        Convert.ToSingle(_file.ReadLine()),
                        Convert.ToSingle(_file.ReadLine())
                        );

                    // line 9-10:

                    rel.Shape1 = RelationshipShape(_file.ReadLine());
                    rel.Shape2 = RelationshipShape(_file.ReadLine());

                    // line 11:
                    rel.LineColor.Value = Convert.ToInt32(_file.ReadLine());

                    // line 12:
                    rel.LineDashStyle = LineDashStyle(_file.ReadLine());

                    // line 13:
                    rel.LineShape = LineShape(_file.ReadLine());

                    // line 14:
                    rel.LineWidth = Convert.ToSingle(_file.ReadLine());

                    // line 15:
                    rel.AutoRouting = Convert.ToBoolean(_file.ReadLine());

                    rel = null; t1 = null; t2 = null; b1 = null; b2 = null;

                    break;
                /////////////// RELATIONSHIP case ends //////////

                /////////////////// ADD OR MODIFY BOUNDARY ////////////////
                case "boundary":
                    // line 2: topic guid
                    _t = SUtils.FindTopicByAttrGuid(_doc, _file.ReadLine());
                    Boundary b = null;

                    // line 3: boundary shape or portrait
                    if (_what == "add")
                    {
                        b       = _t.CreateBoundary();
                        b.Shape = BoundaryShape(_file.ReadLine());
                    }
                    else     // modify boundary
                    {
                        b = _t.Boundary;
                        string[] bvalues = _file.ReadLine().Split(';');

                        b.Shape           = MMEnums.BoundaryShape(bvalues[0]);
                        b.FillColor.Value = Convert.ToInt32(bvalues[1]);
                        b.LineColor.Value = Convert.ToInt32(bvalues[2]);
                        b.LineDashStyle   = MMEnums.LineDashStyle(bvalues[3]);
                        b.LineWidth       = Convert.ToInt32(bvalues[4]);
                    }

                    // line 4: boundary guid
                    TransactionsWrapper.SetAttributes(b, _file.ReadLine());

                    b = null;
                    break;
                    ////////////// BOUNDARY case ends ////////////////
                }

                MapCompanion.received = false;
                _file.Close();
                _t = null; // TODO dooble-check! very important!!
                //File.Delete(file);
            } // foreach files

            //MMBase.SendMessage("received"); // TODO nedeed?
        }
Example #2
0
        ////////////////////////////////////////////////////////////////////////

        public override void onObjectChanged(MMEventArgs aArgs)
        {
            string _what = aArgs.what;

            Topic        _t = aArgs.target as Topic;
            Relationship _r = aArgs.target as Relationship;
            Boundary     _b = aArgs.target as Boundary;

            string rootfolder = aArgs.aMapFolderPath + "share\\";
            string _path      = rootfolder + SUtils.modtime + "&" + SUtils.currentUserName + ".txt";

            if (_r != null)
            {
                SUtils.ProcessRelationship(_r, _path, "relationship:modify");
                _r = null;
                return;
            }

            if (_b != null)
            {
                SUtils.ProcessBoundary(_b, _path, "boundary:modify");
                _b = null;
                return;
            }

            string rollup  = SUtils.rollupuri;
            string _offset = "";
            string _extra  = "";

            if (_t == null)
            {
                return; // TODO case?
            }
            _extra = aArgs.extra;
            //if (_extra != "")
            //    System.Windows.Forms.Clipboard.SetText(_extra); // TODO для чего?

            if (aArgs.extra.ToString() == rollup)
            {
                _what = "rollup";
                MapCompanion.rollup = true;
            }

            if (_t.IsFloatingTopic || _t.IsMainTopic || _t.IsCalloutTopic)
            {
                float x, y;
                _t.GetOffset(out x, out y);
                _offset = x.ToString() + ";" + y.ToString();
            }

            string _shorttext = MMUtils.TShortText(_t.Text);
            string _attrs     = SUtils.TimeStamp + ";" + SUtils.currentUserName + ";" + SUtils.currentUserEmail;

            TransactionsWrapper.SetATTR(_t, SUtils.TMODIFIED, _attrs);

            string tXML = MMUtils.getCleanTopicXML(_t.Xml);

            if (_what == "task")
            {
                _topicxml = tXML; // впадает в цикл, если изменять Duration, Effort и ресурсы
            }
            string _tguid = _t.get_Attributes(SUtils.SYNERGYNAMESPACE).GetAttributeValue(SUtils.OGUID);

            _t = null;

            try
            {
                StreamWriter sw = new StreamWriter(File.Create(_path));
                sw.WriteLine("modify:" + _what);
                sw.WriteLine(_tguid);
                sw.WriteLine(_shorttext); // short topic text for chat
                sw.WriteLine(_attrs);
                sw.WriteLine(_offset);
                sw.WriteLine(_extra);
                sw.Close();
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Exception: " + e.Message, "SaveChanges:onObjectChanged");
            }
        }
Example #3
0
        public override void onObjectAdded(MMEventArgs aArgs) // only for new topics
        {
            Topic        _t = aArgs.target as Topic;
            Relationship _r = aArgs.target as Relationship;
            Boundary     _b = aArgs.target as Boundary;

            string rootfolder = aArgs.aMapFolderPath + "share\\";
            string _path      = rootfolder + SUtils.modtime + "&" + SUtils.currentUserName + ".txt";
            string _what      = "add:";
            string pGuid      = "";
            string offset     = "";
            int    a          = 0;

            if (_r != null) // add relationship
            {
                SUtils.ProcessRelationship(_r, _path, "relationship:add");
                _r = null;
                return;
            }
            if (_b != null) // add boundary
            {
                SUtils.ProcessBoundary(_b, _path, "boundary:add");
                System.Threading.Thread.Sleep(100); // иначе выноска границы может вперед прийти по облачному хранилищу
                _b = null;
                return;
            }

            if (_t == null)
            {
                return; // TODO case?
            }
            if (_t.IsFloatingTopic)
            {
                _what = "add:floating";
            }

            if (_t.IsCalloutTopic || _t.IsSummaryTopic)
            {
                _what = "add:callout";
                if (_t.ParentRelationship != null) // add callout to relationship
                {
                    _what = "add:relcallout";
                    Relationship rel = _t.ParentRelationship;
                    pGuid = rel.get_Attributes(SUtils.SYNERGYNAMESPACE).GetAttributeValue(SUtils.OGUID);
                }
                if (_t.ParentBoundary != null) // add callout to boundary
                {
                    _what = "add:bndcallout";
                    Boundary bnd = _t.ParentBoundary;
                    pGuid = bnd.get_Attributes(SUtils.SYNERGYNAMESPACE).GetAttributeValue(SUtils.OGUID);
                }
            }

            if (_t.IsFloatingTopic || _t.IsMainTopic || _t.IsCalloutTopic)
            {
                float x, y;
                _t.GetOffset(out x, out y);
                offset = x.ToString() + ";" + y.ToString();
                if (_t.IsMainTopic)
                {
                    a = -1;
                }
            }
            if (!_t.IsFloatingTopic && _what != "add:relcallout" && _what != "add:bndcallout")
            {
                pGuid = _t.ParentTopic.get_Attributes(SUtils.SYNERGYNAMESPACE).GetAttributeValue(SUtils.OGUID);
                a     = MMUtils.SubtopicIndex(_t);
            }

            if (!_t.IsCalloutTopic && !_t.IsFloatingTopic && !_t.IsSummaryTopic)
            {
                _what = _what + a.ToString();
            }

            string _shorttext = MMUtils.TShortText(_t.Text);

            TransactionsWrapper.SetAttributes(_t);

            string _tGuid     = _t.Guid;
            string _topicdata = "";

            if (_t.IsDefaultTopicText)
            {
                _topicdata = "newtopic";
            }
            else
            {
                _topicdata = _t.Xml;
            }

            _t = null;

            try
            {
                StreamWriter sw = new StreamWriter(File.Create(_path));
                sw.WriteLine(_what);
                sw.WriteLine(pGuid);      // parent topic's guid - to which add topic(s)
                sw.WriteLine(_shorttext); // topic text or what added - for chat
                sw.WriteLine(_tGuid);
                sw.WriteLine(SUtils.TimeStamp + ";" + SUtils.currentUserName + ";" + SUtils.currentUserEmail);
                sw.WriteLine(offset); // for main, floating or callout topic
                sw.WriteLine(_topicdata);
                sw.Close();
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Exception: " + e.Message, "SaveChanges:onObjectAdded");
            }
        }
Example #4
0
        /// <summary>
        /// Set Synergy attributes to all objects in the branch of given topic and collect all relationships
        /// </summary>
        void ProcessBranch(Topic _topic)
        {
            TransactionsWrapper.SetAttributes(_topic);

            if (_topic.HasBoundary)
            {
                TransactionsWrapper.SetAttributes(_topic.Boundary, _topic.Boundary.Guid);

                foreach (Relationship _r in _topic.Boundary.AllRelationships)
                {
                    if (BranchRelationships.Contains(_r))
                    {
                        continue;
                    }

                    TransactionsWrapper.SetAttributes(_r, _r.Guid);
                    BranchRelationships.Add(_r); // list of relationships to process further

                    foreach (Topic _t in _r.AllCalloutTopics)
                    {
                        TransactionsWrapper.SetAttributes(_t);
                        foreach (Topic _subtopic in _t.AllSubTopics)
                        {
                            ProcessBranch(_subtopic);
                        }
                    }
                }

                if (_topic.Boundary.HasSummaryTopic)
                {
                    Topic _st = _topic.Boundary.SummaryTopic;
                    TransactionsWrapper.SetAttributes(_st);

                    foreach (Topic _subtopic in _st.AllSubTopics)
                    {
                        ProcessBranch(_subtopic);
                    }
                    _st = null;
                }
            }

            foreach (Relationship _r in _topic.AllRelationships)
            {
                if (BranchRelationships.Contains(_r))
                {
                    continue;
                }

                TransactionsWrapper.SetAttributes(_r, _r.Guid);
                BranchRelationships.Add(_r); // list of relationships to process further

                foreach (Topic _t in _r.AllCalloutTopics)
                {
                    TransactionsWrapper.SetAttributes(_t);
                    foreach (Topic _subtopic in _t.AllSubTopics)
                    {
                        ProcessBranch(_subtopic);
                    }
                }
            }

            foreach (Topic _subtopic in _topic.AllSubTopics)
            {
                ProcessBranch(_subtopic);
            }

            foreach (Topic _subtopic in _topic.AllCalloutTopics)
            {
                ProcessBranch(_subtopic);
            }
        }